Radio button component accepts object input for options

This commit is contained in:
Alicia Sykes 2021-10-28 23:38:43 +01:00
parent 2facae3dc1
commit e4ea1c802d
3 changed files with 32 additions and 16 deletions

View File

@ -2,15 +2,15 @@
<div class="radio-container"> <div class="radio-container">
<label v-if="label" class="radio-label">{{ label }}</label> <label v-if="label" class="radio-label">{{ label }}</label>
<div class="radio-wrapper"> <div class="radio-wrapper">
<div v-for="radio in options" :key="radio" class="radio-option"> <div v-for="radio in options" :key="radio.value"
<label :for="`id-${radio}`" class="option-label">{{ radio }}</label> :class="`radio-option ${disabled ? 'wrap-disabled' : ''}`">
<input <label :for="`id-${radio.value}`" class="option-label">{{ radio.label }}</label>
:value="radio" <input type="radio" class="radio-input"
:id=" `id-${radio}`" :id=" `id-${radio.value}`"
v-model="selectedRadio"
type="radio"
:name="makeGroupName" :name="makeGroupName"
class="radio-input" :value="radio.value"
:disabled="disabled || radio.disabled"
v-model="selectedRadio"
v-on:input="updateValue($event.target.value)" v-on:input="updateValue($event.target.value)"
/> />
</div> </div>
@ -25,10 +25,11 @@ export default {
name: 'Radio', name: 'Radio',
components: {}, components: {},
props: { props: {
options: Array, // Array of available options options: Array, // Array of objects for available options
initialOption: String, // Optional default option initialOption: String, // Optional default option
label: String, // Form label for element label: String, // Form label for element
description: String, // Optional description text description: String, // Optional description text
disabled: Boolean, // Disable all radio buttons
}, },
data() { data() {
return { return {
@ -91,9 +92,12 @@ div.radio-container {
cursor: pointer; cursor: pointer;
border: 1px solid transparent; border: 1px solid transparent;
border-radius: var(--curve-factor); border-radius: var(--curve-factor);
&:hover { &:hover:not(.wrap-disabled) {
border: 1px solid var(--primary); border: 1px solid var(--primary);
} }
&:disabled {
opacity: var(--dimming-factor);
}
label.option-label, input.radio-input { label.option-label, input.radio-input {
cursor: pointer; cursor: pointer;
text-transform: capitalize; text-transform: capitalize;

View File

@ -32,7 +32,7 @@
v-model="formData[index].value" v-model="formData[index].value"
:description="row.description" :description="row.description"
:label="row.title || row.name" :label="row.title || row.name"
:options="['true', 'false']" :options="[ ...boolRadioOptions ]"
:initialOption="boolToStr(formData[index].value)" :initialOption="boolToStr(formData[index].value)"
/> />
<!-- Select/ dropdown for enum multiple-choice input --> <!-- Select/ dropdown for enum multiple-choice input -->
@ -90,6 +90,10 @@ export default {
formData: [], // Array of form fields formData: [], // Array of form fields
additionalFormData: [], // Array of not-yet-used form fields additionalFormData: [], // Array of not-yet-used form fields
item: {}, item: {},
boolRadioOptions: [
{ label: 'true', value: 'true' },
{ label: 'false', value: 'false' },
],
}; };
}, },
props: { props: {

View File

@ -9,7 +9,7 @@
<!-- Radio, for move or copy --> <!-- Radio, for move or copy -->
<Radio <Radio
v-model="operation" v-model="operation"
:options="['Move', 'Copy']" :options="operationRadioOptions"
label="Operation Type" label="Operation Type"
:initialOption="operation" :initialOption="operation"
/> />
@ -23,7 +23,7 @@
<!-- Radio, for choosing append to beginning or end --> <!-- Radio, for choosing append to beginning or end -->
<Radio <Radio
v-model="appendTo" v-model="appendTo"
:options="['Begining', 'End']" :options="appendToRadioOptions"
label="Append To" label="Append To"
:initialOption="appendTo" :initialOption="appendTo"
/> />
@ -54,9 +54,17 @@ export default {
data() { data() {
return { return {
selectedSection: '', selectedSection: '',
operation: 'Move', operation: 'move',
appendTo: 'End', appendTo: 'end',
modalName: `${modalNames.MOVE_ITEM_TO}-${this.itemId}`, modalName: `${modalNames.MOVE_ITEM_TO}-${this.itemId}`,
operationRadioOptions: [
{ label: 'Move', value: 'move' },
{ label: 'Copy', value: 'copy' },
],
appendToRadioOptions: [
{ label: 'Beginning', value: 'beginning' },
{ label: 'End', value: 'end' },
],
}; };
}, },
computed: { computed: {
@ -86,7 +94,7 @@ export default {
const copyPayload = { item, toSection: this.selectedSection, appendTo: this.appendTo }; const copyPayload = { item, toSection: this.selectedSection, appendTo: this.appendTo };
this.$store.commit(StoreKeys.COPY_ITEM, copyPayload); this.$store.commit(StoreKeys.COPY_ITEM, copyPayload);
// Remove item from previous section // Remove item from previous section
if (this.operation === 'Move') { if (this.operation === 'move') {
const payload = { itemId: this.itemId, sectionName: this.currentSection }; const payload = { itemId: this.itemId, sectionName: this.currentSection };
this.$store.commit(StoreKeys.REMOVE_ITEM, payload); this.$store.commit(StoreKeys.REMOVE_ITEM, payload);
} }