@dialpad/dialtone
Version:
Dialpad's Dialtone design system monorepo
1 lines • 12.1 kB
Source Map (JSON)
{"version":3,"file":"select-menu.cjs","sources":["../../../components/select_menu/select_menu.vue"],"sourcesContent":["<template>\n <div\n v-bind=\"addClassStyleAttrs($attrs)\"\n >\n <label>\n <div\n v-if=\"hasSlotContent($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=\"hasSlotContent($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=\"removeClassStyleAttrs($attrs)\"\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 { warn } 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 hasSlotContent,\n removeClassStyleAttrs,\n addClassStyleAttrs,\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 compatConfig: { MODE: 3 },\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 * 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 * Event fired to sync the modelValue prop with the parent component\n *\n * @event input\n * @type {String | Number}\n */\n 'update:modelValue',\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 hasSlotContent,\n };\n },\n\n computed: {\n selectListeners () {\n return {\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 handler 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 removeClassStyleAttrs,\n addClassStyleAttrs,\n emitValue (value, event) {\n this.$emit('update:modelValue', 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 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","hasSlotContent","event","getValidationState","getUniqueString","removeClassStyleAttrs","addClassStyleAttrs","value","_a","warn","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_openBlock","_createElementBlock","_normalizeProps","_guardReactiveProps","$options","_ctx","_createElementVNode","$data","$props","_mergeProps","_renderSlot","_createTextVNode","_toDisplayString","_createCommentVNode","_normalizeClass","_toHandlers","_Fragment","_renderList","option","_createVNode","_component_dt_validation_messages"],"mappings":"+cA0GKA,EAAU,CACb,aAAc,CAAE,KAAM,GACtB,KAAM,eAEN,WAAY,CAAA,qBAAEC,EAAAA,SAEd,OAAQ,CAACC,EAAAA,aAAa,EAEtB,aAAc,GAEd,MAAO,CAIL,MAAO,CACL,KAAM,OACN,QAAS,IAMX,YAAa,CACX,KAAM,OACN,QAAS,IAUX,QAAS,CACP,KAAM,MACN,QAAS,IAAM,CAAA,EACf,UAAWC,GAAWC,EAAAA,iBAAiBD,CAAO,GAOhD,KAAM,CACJ,KAAM,OACN,QAAS,KACT,UAAYE,GAAM,OAAO,KAAKC,uBAAqB,EAAE,SAASD,CAAC,GAMjE,WAAY,CACV,KAAM,CAAC,OAAQ,MAAO,MAAM,EAC5B,QAAS,IAMX,iBAAkB,CAChB,KAAM,CAAC,OAAQ,MAAO,MAAM,EAC5B,QAAS,IAMX,YAAa,CACX,KAAM,CAAC,OAAQ,MAAO,MAAM,EAC5B,QAAS,IAMX,YAAa,CACX,KAAM,CAAC,OAAQ,MAAO,MAAM,EAC5B,QAAS,IAMX,gBAAiB,CACf,KAAM,OACN,QAAS,KAAO,CAAA,IAMlB,sBAAuB,CACrB,KAAM,OACN,QAAS,KAAO,CAAA,IAMlB,iBAAkB,CAChB,KAAM,OACN,QAAS,KAAO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