@dialpad/dialtone-vue
Version:
Vue component library for Dialpad's design system Dialtone
1 lines • 9.89 kB
Source Map (JSON)
{"version":3,"file":"select-menu.cjs","sources":["../../../components/select_menu/select_menu.vue"],"sourcesContent":["<template>\n <div>\n <label>\n <div\n v-if=\"$slots.label || label\"\n :aria-details=\"labelAriaDetails\"\n :class=\"[\n 'd-label',\n LABEL_SIZE_MODIFIERS[size],\n labelClass,\n ]\"\n v-bind=\"labelChildProps\"\n data-qa=\"dt-select-label\"\n >\n <!-- @slot Slot for label, defaults to label prop -->\n <slot name=\"label\">{{ label }}</slot>\n </div>\n <div\n v-if=\"$slots.description || description\"\n :id=\"descriptionKey\"\n :class=\"[\n 'd-description',\n DESCRIPTION_SIZE_MODIFIERS[size],\n descriptionClass,\n ]\"\n v-bind=\"descriptionChildProps\"\n data-qa=\"dt-select-description\"\n >\n <!-- @slot Slot for description, defaults to description prop -->\n <slot name=\"description\">{{ description }}</slot>\n </div>\n <div\n :class=\"[\n 'd-select',\n SELECT_SIZE_MODIFIERS[size],\n selectClass,\n { 'd-select--disabled': disabled },\n ]\"\n data-qa=\"dt-select-wrapper\"\n >\n <select\n ref=\"selectElement\"\n :class=\"[\n 'd-select__input',\n SELECT_STATE_MODIFIERS[state],\n ]\"\n v-bind=\"$attrs\"\n :value=\"value\"\n data-qa=\"dt-select\"\n :disabled=\"disabled\"\n v-on=\"selectListeners\"\n >\n <!-- @slot Slot for select menu options, defaults to options prop -->\n <slot>\n <option\n v-for=\"option in options\"\n :key=\"getOptionKey(option.value)\"\n :value=\"option.value\"\n :class=\"optionClass\"\n v-bind=\"optionChildProps\"\n >\n {{ option.label }}\n </option>\n </slot>\n </select>\n </div>\n </label>\n <dt-validation-messages\n :validation-messages=\"formattedMessages\"\n :show-messages=\"showMessages\"\n :class=\"messagesClass\"\n v-bind=\"messagesChildProps\"\n data-qa=\"dt-select-messages\"\n />\n </div>\n</template>\n\n<script>\nimport Vue from 'vue';\nimport {\n LABEL_SIZE_MODIFIERS,\n DESCRIPTION_SIZE_MODIFIERS,\n} from '@/common/constants';\nimport {\n SELECT_SIZE_MODIFIERS,\n SELECT_STATE_MODIFIERS,\n} from './select_menu_constants';\nimport {\n getUniqueString,\n getValidationState,\n} from '@/common/utils';\nimport { MessagesMixin } from '@/common/mixins/input';\nimport { optionsValidator } from './select_menu_validators.js';\nimport { DtValidationMessages } from '../validation_messages';\n\n/**\n * A select menu is an input control that allows users to choose one option from a list.\n * @property {Boolean} disabled attribute\n * @property {String} name attribute\n * @property {String} value attribute\n * @see https://dialtone.dialpad.com/components/select.html\n */\nexport default {\n name: 'DtSelectMenu',\n\n components: { DtValidationMessages },\n\n mixins: [MessagesMixin],\n\n inheritAttrs: false,\n\n props: {\n /**\n * Label for the select\n */\n label: {\n type: String,\n default: '',\n },\n\n /**\n * Description for the select\n */\n description: {\n type: String,\n default: '',\n },\n\n /**\n * Select Menu Options, overridden by default slot. Each option has the following structure:\n * `{ value: number || string (required), label: string (required) }`\n * @param {Object[]} options - Optional - A list that can be used to create a list of select menu options\n * @param {number|string} options[].value - Required - The option value\n * @param {string} options[].label - Required - The option Label\n */\n options: {\n type: Array,\n default: () => [],\n validator: options => optionsValidator(options),\n },\n\n /**\n * Sets the selected value of the select menu. If it does not match a value in the options array, then it will be\n * 'unselected'.\n */\n value: {\n type: String,\n default: null,\n },\n\n /**\n * Controls the size of the select\n * @values xs, sm, md, lg, xl\n */\n size: {\n type: String,\n default: 'md',\n validator: (s) => Object.keys(SELECT_SIZE_MODIFIERS).includes(s),\n },\n\n /**\n * Used to customize the label container\n */\n labelClass: {\n type: [String, Array, Object],\n default: '',\n },\n\n /**\n * Used to customize the description container\n */\n descriptionClass: {\n type: [String, Array, Object],\n default: '',\n },\n\n /**\n * Used to customize the select\n */\n selectClass: {\n type: [String, Array, Object],\n default: '',\n },\n\n /**\n * Used to customize each option, should options be provided via prop\n */\n optionClass: {\n type: [String, Array, Object],\n default: '',\n },\n\n /**\n * A set of props that are passed into the label container\n */\n labelChildProps: {\n type: Object,\n default: () => ({}),\n },\n\n /**\n * A set of props that are passed into the description container\n */\n descriptionChildProps: {\n type: Object,\n default: () => ({}),\n },\n\n /**\n * A set of props that are passed into each option, should options be provided via prop\n */\n optionChildProps: {\n type: Object,\n default: () => ({}),\n },\n\n /**\n * Disabled state of the select\n * @values true, false\n */\n disabled: {\n type: Boolean,\n default: false,\n },\n },\n\n emits: [\n /**\n * Native input event\n *\n * @event input\n * @type {String | Number}\n */\n 'input',\n\n /**\n * Native change event\n *\n * @event change\n * @type {String | Number}\n */\n 'change',\n ],\n\n data () {\n return {\n LABEL_SIZE_MODIFIERS,\n DESCRIPTION_SIZE_MODIFIERS,\n SELECT_SIZE_MODIFIERS,\n SELECT_STATE_MODIFIERS,\n };\n },\n\n computed: {\n selectListeners () {\n return {\n /* TODO\n Check if any usages of this component leverage $listeners and either remove if unused or scope the removal\n and migration prior to upgrading to Vue 3.x\n */\n ...this.$listeners,\n /*\n * Override input listener to as no-op. Prevents parent input listeners from being passed through onto the input\n * element which will result in the hander being called twice (once on the select element and once by the\n * emitted input event by the change listener).\n */\n input: () => {},\n change: event => this.emitValue(event.target.value, event),\n };\n },\n\n state () {\n return getValidationState(this.formattedMessages);\n },\n\n selectKey () {\n return getUniqueString();\n },\n\n descriptionKey () {\n return `select-${this.selectKey}-description`;\n },\n\n labelAriaDetails () {\n if (this.$slots.description || this.description) {\n return this.descriptionKey;\n }\n\n return this.$attrs['aria-details'];\n },\n },\n\n mounted () {\n this.validateOptionsPresence();\n },\n\n beforeUpdate () {\n this.validateOptionsPresence();\n },\n\n methods: {\n emitValue (value, event) {\n this.$emit('input', value, event);\n this.$emit('change', value, event);\n },\n\n getOptionKey (value) {\n return `select-${this.selectKey}-option-${value}`;\n },\n\n validateOptionsPresence () {\n if (this.options?.length < 1 && !this.$slots.default) {\n Vue.util.warn('Options are expected to be provided via prop or slot', this);\n }\n },\n },\n};\n</script>\n"],"names":["_sfc_main","DtValidationMessages","MessagesMixin","options","optionsValidator","s","SELECT_SIZE_MODIFIERS","LABEL_SIZE_MODIFIERS","DESCRIPTION_SIZE_MODIFIERS","SELECT_STATE_MODIFIERS","event","getValidationState","getUniqueString","value","_a","Vue"],"mappings":"6cAsGAA,EAAA,CACA,KAAA,eAEA,WAAA,CAAA,qBAAAC,EAAAA,OAAA,EAEA,OAAA,CAAAC,EAAAA,aAAA,EAEA,aAAA,GAEA,MAAA,CAIA,MAAA,CACA,KAAA,OACA,QAAA,EACA,EAKA,YAAA,CACA,KAAA,OACA,QAAA,EACA,EASA,QAAA,CACA,KAAA,MACA,QAAA,IAAA,CAAA,EACA,UAAAC,GAAAC,EAAAA,iBAAAD,CAAA,CACA,EAMA,MAAA,CACA,KAAA,OACA,QAAA,IACA,EAMA,KAAA,CACA,KAAA,OACA,QAAA,KACA,UAAAE,GAAA,OAAA,KAAAC,uBAAA,EAAA,SAAAD,CAAA,CACA,EAKA,WAAA,CACA,KAAA,CAAA,OAAA,MAAA,MAAA,EACA,QAAA,EACA,EAKA,iBAAA,CACA,KAAA,CAAA,OAAA,MAAA,MAAA,EACA,QAAA,EACA,EAKA,YAAA,CACA,KAAA,CAAA,OAAA,MAAA,MAAA,EACA,QAAA,EACA,EAKA,YAAA,CACA,KAAA,CAAA,OAAA,MAAA,MAAA,EACA,QAAA,EACA,EAKA,gBAAA,CACA,KAAA,OACA,QAAA,KAAA,CAAA,EACA,EAKA,sBAAA,CACA,KAAA,OACA,QAAA,KAAA,CAAA,EACA,EAKA,iBAAA,CACA,KAAA,OACA,QAAA,KAAA,CAAA,EACA,EAMA,SAAA,CACA,KAAA,QACA,QAAA,EACA,CACA,EAEA,MAAA,CAOA,QAQA,QACA,EAEA,MAAA,CACA,MAAA,CACA,qBAAAE,EAAAA,qBACA,2BAAAC,EAAAA,2BACA,sBAAAF,EAAAA,sBACA,uBAAAG,EAAAA,sBACA,CACA,EAEA,SAAA,CACA,iBAAA,CACA,MAAA,CAKA,GAAA,KAAA,WAMA,MAAA,IAAA,CAAA,EACA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