This commit is contained in:
Kulbhushan Kaushik 2022-11-14 12:22:21 -05:00
parent 7ecd40bdf3
commit 7b82d05f6a

View file

@ -1,64 +1,46 @@
<!-- Documented in confluence https://safelite.atlassian.net/wiki/spaces/DC/pages/76644418/Button+Question+Component -->
<template> <template>
<div <div :class="isOverflowScrollable ? 'button-question button-question-overflow' : 'button-question'">
:class="
isOverflowScrollable ? 'button-question button-question-overflow' : 'button-question'
">
<div v-if="questionText && answers && answers.length > 0" class="question-text d-flex"> <div v-if="questionText && answers && answers.length > 0" class="question-text d-flex">
<span class="fw-bold w-100">{{ questionText }}</span> <span class="fw-bold w-100">{{ questionText }}</span>
</div> </div>
<div class="w-100 d-flex justify-content-center"> <div class="w-100 d-flex justify-content-center">
<fieldset <fieldset class="w-100" :aria-required=isRequired :class="getFieldSetClasses" :role="isMultiSelect ? 'group' : 'radiogroup'" :aria-labelledby="formatString(groupName)">
class="w-100" <legend class="sr-only" :data-focus-target="formatString(groupName)" :id="formatString(groupName)" tabindex="-1">
:aria-required="isRequired"
:class="getFieldSetClasses"
:role="isMultiSelect ? 'group' : 'radiogroup'"
:aria-labelledby="formatString(groupName)">
<legend
class="sr-only"
:data-focus-target="formatString(groupName)"
tabindex="-1"
:id="formatString(groupName)">
{{ questionText }} {{ questionText }}
{{ {{(isMultiSelect && answers && answers.length > 1) ? 'Select one or more options below.' : 'Select an option below.' }}
isMultiSelect && answers && answers.length > 1
? "Select one or more options below."
: "Select an option below."
}}
</legend> </legend>
<div :class="getComponentLoopWrapperClasses"> <div :class="getComponentLoopWrapperClasses">
<div <div :class="getComponentWrapperClasses" v-for="answer in answers" :key="answer.Name ? answer.Name : answer">
:class="getComponentWrapperClasses"
v-for="answer in buttonsInfo"
:key="answer.value ? answer.value : answer">
<component <component
:is="buttonTypeString" :is="buttonType"
:buttonLabel="answer.buttonLabel" @isCheckedChanged="handleCheckedChanged"
:buttonLabelSubCopy="answer.buttonLabelSubCopy" :buttonID="answer.Name ? formatString(groupName) + '-' + answer.Name : formatString(groupName) + '-' + getAnswerString(answer, 'Text')"
:buttonBodyCopy="answer.buttonBodyCopy" :value="getValue(answer)"
:buttonAuxillaryCopy="answer.buttonAuxillaryCopy" :buttonLabel="answer.Text ? answer.Text : getAnswerString(answer, 'Name')"
:buttonFooterCopy="answer.buttonFooterCopy" :buttonLabelSubCopy="answer.SubText"
:buttonImage="answer.buttonImage"
:buttonImageId="answer.buttonImageId"
:groupName="answer.groupName"
:isMultiSelect="isMultiSelect"
:value="answer.value"
:selectingInitiatesLoad="selectingInitiatesLoad"
:isWide="isWide"
:validationRules="validationRules"
:textPosition="textPosition" :textPosition="textPosition"
:additionalButtonStyling="additionalButtonStyling" :isMultiSelect="isMultiSelect"
:lastValuePushedToGa="lastValuePushedToGa" :groupName="formatString(groupName)"
:setLastValuePushedToGa="setLastValuePushedToGa" :selectingInitiatesLoad="selectingInitiatesLoad"
v-model="selectedValues" /> :loaderColor="loaderColor"
:loaderPosition="loaderPosition"
:isWide=isWide
:isCashOrInsurance=isCashOrInsurance
:isRequired=isRequired
:buttonImage="answer.AnswerImageUrl"
:buttonImageId="answer.ImageId"
:altText="answer.Name ? answer.Name : answer"
screenReaderOnlyText="(opens new window)"
:colLength="getColLength"
:selectedValues="selectedValues"
data-test="button"
:validationRules="validationRules"
:class="[suppressError ? 'alertError' : '' , isCashOrInsurance ? 'radio-fancy' : '']"
:valueToLogType="valueToLogType"
/>
<!-- For nested questions --> <!-- For nested questions -->
<transition name="fade" mode="out-in"> <transition name="fade" mode="out-in">
<div <div v-if="typeof selectedValues == 'string' && selectedValues == answer.Name">
v-if="
typeof selectedValues == 'string' &&
selectedValues == answer.value
">
<slot></slot> <slot></slot>
</div> </div>
</transition> </transition>
@ -70,26 +52,22 @@
<error-message :name="formatString(groupName)" v-if="!suppressError"></error-message> <error-message :name="formatString(groupName)" v-if="!suppressError"></error-message>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import listButton from "@/ux-components/list-button/list-button"; import listButton from "@/ux-components/list-button/list-button";
import listButtonHorizontal from "@/ux-components/list-button-horizontal/list-button-horizontal"; import listButtonHorizontal from "@/ux-components/list-button-horizontal/list-button-horizontal";
import listCard from "@/ux-components/list-card/list-card"; import listCard from "@/ux-components/list-card/list-card";
import radio from "@/ux-components/radio/radio"; import { ErrorMessage } from 'vee-validate';
import { ErrorMessage } from "vee-validate"; import radio from "@/ux-components/radio/radio";
export default { export default {
name: "buttonQuestion", name: "buttonQuestion",
props: { props: {
buttonTypeString: { buttonType: {
type: String, type: String,
default: "listButton", default: "listButton",
}, },
buttonTypeObject: {
type: Object,
default: null,
},
isMultiSelect: Boolean, isMultiSelect: Boolean,
groupName: String, groupName: String,
questionText: String, questionText: String,
@ -111,54 +89,38 @@ export default {
isOverflowScrollable: Boolean, isOverflowScrollable: Boolean,
isWide: Boolean, isWide: Boolean,
isCashOrInsurance: Boolean, isCashOrInsurance: Boolean,
modelValue: [Array, Number, String], modelValue: [Array, String],
value: [Number, String],
validationRules: String, validationRules: String,
suppressError: Boolean, suppressError: Boolean,
useTextForValue: Boolean, useTextForValue: Boolean,
valueToLogType: String, valueToLogType: String,
additionalButtonStyling: String,
},
beforeMount() {
if (this.buttonTypeObject) {
this.$options.components[this.buttonTypeString] = this.buttonTypeObject;
}
},
data() {
return {
lastValuePushedToGa: null,
};
}, },
computed: { computed: {
getFieldSetClasses() { getFieldSetClasses() {
if (this.isOverflowScrollable) { if (this.isOverflowScrollable) {
return "container-fluid overflow-scroll position-absolute px-5 pt-1 py-0"; return "container-fluid overflow-scroll position-absolute px-5 pt-1 py-0";
} else if (this.buttonTypeString == "listCard") { }
else if (this.buttonType == "listCard") {
return "w-100"; return "w-100";
} else { }
else {
return ""; return "";
} }
}, },
getComponentLoopWrapperClasses() { getComponentLoopWrapperClasses() {
let classes; let classes;
switch (this.buttonTypeString) { switch (this.buttonType) {
case "listButton": case "listButton":
classes = "w-100"; classes = "w-100";
break; break;
case "listButtonHorizontal": case "listButtonHorizontal":
classes = "d-flex flex-row p-0"; classes = "d-flex flex-row p-0";
break; break;
case "listCard": case 'listCard':
classes = "row g-2 justify-content-center"; classes = "row g-2 justify-content-center";
if (this.isWide) {
classes += " flex-column";
}
break; break;
case "radio": case 'radio':
classes = "ui-radio d-flex"; classes = 'ui-radio d-flex'
break;
case "servicePackageRadio":
classes = "package-main";
break; break;
} }
return classes; return classes;
@ -168,46 +130,65 @@ export default {
classes += this.isWide ? "col-12" : "col"; classes += this.isWide ? "col-12" : "col";
if (this.buttonTypeString == "radio") { if (this.buttonType == "radio") {
classes += " radio-button-container"; classes += " radio-button-container";
} else if (this.buttonTypeString == "servicePackageRadio") {
classes = "package-wrapper";
} }
return classes; return classes;
}, },
buttonsInfo() { getColLength(){
return (Array.isArray(this.answers) ? this.answers : [])?.map((answer) => ({ if(this.isWide) {
buttonLabel: answer.buttonLabel ?? answer.Text ?? answer, return "12"
altText: answer.altText ?? (answer.Name ? answer.Name : answer), } else {
buttonLabelSubCopy: answer.buttonLabelSubCopy ?? answer.SubText, return "";
buttonBodyCopy: answer.buttonBodyCopy ?? answer.buttonBodyCopy, }
buttonAuxillaryCopy: answer.buttonAuxillaryCopy ?? answer.buttonAuxillaryCopy,
buttonFooterCopy: answer.buttonFooterCopy ?? answer.buttonFooterCopy,
buttonImage: answer.buttonImage ?? answer.AnswerImageUrl,
buttonImageId: answer.buttonImageId ?? answer.ImageId,
groupName: this.formatString(this.groupName),
value:
answer.value ??
(this.useTextForValue && answer.Text ? answer.Text : answer.Name) ??
(typeof answer !== "object" ? answer : null),
}));
}, },
selectedValues: { selectedValues: {
get() { get: function() {
return this.modelValue; return this.modelValue;
}, },
set(selectedAnswers) { set: function(newValue) {
this.$emit("update:modelValue", selectedAnswers); this.$emit("update:modelValue", newValue);
}, }
}, },
}, },
methods: { methods: {
formatString(str) { formatString(str) {
return str?.replaceAll(" ", "-"); return str.replace(" ", "-");
}, },
setLastValuePushedToGa(lastValuePushedToGa) { getValue(answer){
this.lastValuePushedToGa = lastValuePushedToGa; if (this.useTextForValue) { return answer.Text }
return answer.Name ? answer.Name : answer;
},
getAnswerString(answer, prop = "Name") {
switch (typeof answer) {
case "string":
case "number":
case "boolean":
return this.formatString(answer.toString());
default:
return answer[prop] ? this.formatString(answer[prop]) : this.formatString(answer.toString());
}
},
handleCheckedChanged(val) {
if(this.selectingInitiatesLoad) {
this.selectedValues = val.value;
} else {
if(this.isMultiSelect) {
const newSelectedValues = this.selectedValues;
val.checkValue ? newSelectedValues.push(val.value) : newSelectedValues.splice(newSelectedValues.indexOf(val.value), 1);
this.selectedValues = newSelectedValues;
}
else if (Array.isArray(this.selectedValues)) {
this.selectedValues[0] = val.value;
const temp = this.selectedValues;
this.selectedValues = temp;
}
else {
this.selectedValues = val.value;
}
}
this.$emit("isCheckedChanged", val);
}, },
}, },
components: { components: {
@ -217,11 +198,11 @@ export default {
ErrorMessage, ErrorMessage,
radio, radio,
}, },
}; };
</script> </script>
<style lang="scss"> <style lang="scss">
.button-question-overflow { .button-question-overflow {
height: calc(100vh - 274px); height: calc(100vh - 274px);
.overflow-scroll { .overflow-scroll {
@ -230,8 +211,8 @@ export default {
overflow-x: hidden !important; overflow-x: hidden !important;
-webkit-overflow-scrolling: touch; -webkit-overflow-scrolling: touch;
} }
} }
.button-question { .button-question {
color: $black; color: $black;
.radio-button-container { .radio-button-container {
@ -239,24 +220,24 @@ export default {
padding-bottom: map-get($spacers, 2); padding-bottom: map-get($spacers, 2);
} }
} }
} }
.question-text { .question-text {
margin-top: 1.5rem; margin-top: 1.5rem;
margin-bottom: 1rem; margin-bottom: 1rem;
font-size: 1rem; font-size: 1rem;
line-height: 1.625rem; line-height: 1.5rem;
& > span { & > span {
text-align: center; text-align: center;
} }
} }
.vehicle-parts { .vehicle-parts {
.question-text { .question-text {
span { span {
font-size: 0.875rem; font-size: .875rem;
text-align: left; text-align: left;
margin: 0 0 0.5rem 0; margin: 0 0 .5rem 0;
} }
} }
.question-text { .question-text {
@ -267,5 +248,6 @@ export default {
margin: 0; margin: 0;
} }
} }
} }
</style> </style>