I am building a component which has two icons: like and dislike. When any of the icon is clicked, the icon should get bigger, show color and the upper heading should disappear.
I'm able to implement the functionality of hiding the heading when icon is clicked. The icon is coming from a shared Button component. I'm not able to comprehend how to give value to the bgColor based on condition that the icon is clicked on not.
For clarity:
- This is initial screen where icons aren't clicked yet: [![enter image description here][1]][1]
2.1. This is the screen which is appearing now when icon is clicked [Problem State] [![enter image description here][2]][2]
2.2: This is how the screen should appear when any icon is clicked [ Desired State]. [![enter image description here][3]][3]
My code for the component is:
<template v-slot:main>
<div class="feedbackComponent">
<div class="feedback-content">
<label v-if="!hideText" class="title">Appointment Confirmed!</label>
<label class="subtitle">How would you rate your experience?</label>
<div>
<ButtonIcon
symbol="thumbs-up"
@click="handleFeedback('up')"
bgColor= "transparent; width: 70px; height: 70px; stroke-width: 1px"
/>
<ButtonIcon
symbol="thumbs-down"
bgColor="transparent; width: 70px; height: 70px; stroke-width: 1px"
@click="handleFeedback('down')"
/>
</div>
</div>
</div>
</template>
This is script functions:
<script>
import ModalLayout from "@/components/Shared/ModalLayout.vue";
import ButtonIcon from '../Shared/ButtonIcon.vue';
export default {
name: 'ScheduleTourFeedback',
components: {
ModalLayout,
ButtonIcon,
},
data() {
return {
selected: null,
hideText: false,
}
},
methods: {
handleFeedback(feedback) {
this.selected = feedback
this.$emit('feedback-clicked', true);
this.handleClick();
},
handleClick() {
this.hideText = true;
},
},
}
</script>
I want to implement conditional rendering on bgColor such that based on the icon click it changes to the value to
bgColor="transparent; width: 90px; height: 90px; stroke-width: 1px; fill: #d64ba1"
Sorry about the long post. I just wanted to make the use-case clear. Any help would be appreciated as I'm stuck on this for a while.
UPDATED: My ButtonIcon.vue component looks like this:
<template>
<!---<button :disabled="disabled">{{ text }}</button>-->
<a @click="onClick" :style="backgroundColor" :class="text ? 'TextIcon' : ''">
{{ text }}
<i
:data-feather="symbol"
:class="type ? 'btn-white' : 'btn-continue'"
:style="backgroundColor"
/>
</a>
</template>
<script>
import feather from 'feather-icons'
export default {
name: 'ButtonIcon',
props: {
// iconCode: String,
// iconColor: String,
bgColor: String,
symbol: String,
disabled: Boolean,
type: String,
text: String,
},
computed: {
backgroundColor() {
let bgColor = this.bgColor ? this.bgColor : '#d64ba1'
return 'background: ' + bgColor + ';' + 'border-radius: 24px;'
}
},
mounted() {
feather.replace()
},
data() {
return {}
},
methods: {
onClick() {
this.$emit('onClick')
},
},
}
</script>
<style scoped>
.btn-continue {
padding: 8px 10px;
gap: 10px;
width: 37px;
height: 37px;
position: relative;
/* Quext/Pink */
background: #d64ba1;
border-radius: 24px;
color: white;
flex: none;
order: 0;
flex-grow: 0;
}
.btn-white {
padding: 8px 10px;
gap: 10px;
width: 45px;
height: 45px;
position: relative;
/* Quext/Transparent */
background: white;
border-radius: 24px;
color: black;
border: 2px solid #000;
/* Inside auto layout */
flex: none;
order: 0;
flex-grow: 0;
}
.TextIcon {
display: flex;
align-items: center;
justify-content: center;
width: 95px;
}
a {
color: #fff;
}
</style>