<script>
export default {
data() {
return {
width: 150,
height: 8,
triangle: 12
};
},
props: {
text: {
type: String,
required: true
},
left: {
type: Boolean,
default: false
},
right: {
type: Boolean,
default: false
},
icon: {
type: String,
default: null
}
},
computed: {
rightTriangle() {
const t = this.triangle;
const h = this.height;
return this.right
? `l 0 ${h} l ${t} ${t} l -${t} ${t} l 0 ${h}`
: `l 0 ${h} l 0 ${t} l 0 ${t} l 0 ${h}`;
},
leftTriangle() {
const t = this.triangle;
const h = this.height;
return this.left
? `l 0 -${h} l -${t} -${t} l ${t} -${t} l 0 -${h}`
: `l 0 -${h} l 0 -${t} l 0 -${t} l 0 -${h}`;
},
svgPath() {
return `m ${this.svgMargin.x} ${this.svgMargin.y} l ${this.width} 0 ${
this.rightTriangle
} l -${this.width} 0 ${this.leftTriangle}`;
},
svgHeight() {
return this.height * 2 + this.triangle * 2 + 4;
},
svgWidth() {
//https://stackoverflow.com/a/20916980
//distance between [0,0] to [x, y]
var triangleWidth = Math.sqrt(this.triangle * this.triangle);
var numTriangles = 2;
return this.width + triangleWidth * numTriangles + 2;
},
svgMargin() {
return {
x: this.triangle + 1,
y: 2
};
}
},
watch: {
text: {
handler() {
this.$nextTick(() => {
this.updateButtonWidth();
});
},
immediate: true
}
},
methods: {
updateButtonWidth() {
const iconSize = this.icon ? 40 : 0;
this.width =
document.querySelector(".atc-button-text").getBBox().width +
40 +
iconSize;
},
handleClickEvent() {
this.$emit("click-event");
}
}
};
</script>
<style scoped>
.atc-button-wrapper {
display: flex;
justify-content: center;
position: relative;
}
.atc-button-wrapper.push-left {
justify-content: flex-start;
}
.atc-button-wrapper.push-right {
justify-content: flex-end;
}
.svg-content {
position: relative;
}
.atc-button-content:hover {
cursor: pointer;
}
.atc-button-content path {
fill: transparent;
stroke: #ccba83;
}
.atc-button-content:hover path {
fill: #ccba83;
stroke: #ccba83;
}
.atc-button-content text {
fill: #ccba83;
font-family: cursive;
font-weight: bold;
}
.atc-button-content:hover text {
fill: white;
}
.atc-button-icon-wrapper {
position: absolute;
display: flex;
align-items: center;
margin: auto;
top: -4px;
left: 30px;
bottom: 0;
}
.atc-button-icon {
font-size: 20pt;
color: #ccba83;
}
.atc-button-icon:hover {
cursor: pointer;
color: white;
}
.atc-button-content:hover ~ .atc-button-icon-wrapper .atc-button-icon {
color: white;
}
.atc-button-icon-wrapper:hover ~ .atc-button .atc-button-content path {
fill: #ccba83 !important;
stroke: #ccba83 !important;
}
</style>
<template>
<div class="atc-button-wrapper">
<div class="svg-content">
<svg class="atc-button" :height="svgHeight" :width="svgWidth">
<g @click="handleClickEvent()" class="atc-button-content">
<path stroke="red" :d="svgPath"></path>
<text
class="atc-button-text"
:x="icon ? '56%' : '50%'"
y="52%"
dominant-baseline="middle"
text-anchor="middle"
>{{text}}</text>
</g>
</svg>
<div class="atc-button-icon-wrapper">
<fa-icon :icon="icon" class="atc-button-icon"></fa-icon>
</div>
</div>
</div>
</template>