UNPKG

@dialpad/dialtone-vue

Version:

Vue component library for Dialpad's design system Dialtone

1 lines 11.4 kB
{"version":3,"file":"input.cjs","sources":["../../../common/mixins/input.js"],"sourcesContent":["import Vue from 'vue';\nimport { VALIDATION_MESSAGE_TYPES } from '@/common/constants';\nimport { validationMessageValidator } from '@/common/validators';\nimport { formatMessages } from '@/common/utils';\n\n/**\n * This mixin provides a base set of props, watchers and data attributes that are commonly used in our input components.\n * @displayName Input Mixin\n */\nexport const InputMixin = {\n inheritAttrs: false,\n\n props: {\n /**\n * A provided label for the input\n */\n label: {\n type: String,\n default: '',\n },\n\n /**\n * The name of the input\n */\n name: {\n type: String,\n default: '',\n },\n\n /**\n * The value of the input\n * @model value\n */\n value: {\n type: [String, Number, Boolean, Object],\n default: null,\n },\n\n /**\n * Describes the input\n */\n description: {\n type: String,\n default: '',\n },\n\n /**\n * Disables the input\n */\n disabled: {\n type: Boolean,\n default: false,\n },\n\n /**\n * The validation state of the input\n */\n validationState: {\n type: String,\n default: '',\n validator: validationState => {\n if (!validationState) {\n return true;\n }\n\n return Object.values(VALIDATION_MESSAGE_TYPES).includes(validationState);\n },\n },\n\n /**\n * Used to customize the input element\n */\n inputClass: {\n type: [String, Array, Object],\n default: '',\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 * 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 data () {\n return {\n internalDisabled: this.disabled,\n internalValidationState: this.validationState,\n };\n },\n\n watch: {\n disabled (newDisabled) {\n // update internal disabled when the prop changes\n this.internalDisabled = newDisabled;\n },\n\n validationState (newValidationState) {\n // update internal validation state when the prop changes\n this.internalValidationState = newValidationState;\n },\n },\n\n methods: {\n /**\n * @param {Boolean | String} hasLabelOrLabel either a boolean indicating the label exists or the label itself\n * @param {String} ariaLabel the aria-label passed (null/undefined if it's not passed)\n */\n validateInputLabels (hasLabelOrLabel, ariaLabel) {\n if (!hasLabelOrLabel && !ariaLabel) {\n Vue.util.warn(\n 'You must provide an aria-label when there is no label passed',\n this,\n );\n }\n },\n },\n};\n\n/**\n * This mixin provides common logic shared amongst our checkable inputs.\n *\n * This includes the group context, checked model & prop, internal data attributes as well as a set common computed\n * properties and watchers. It also includes the group name warning logic.\n * @displayName Checkable Mixin\n */\nexport const CheckableMixin = {\n model: {\n prop: 'checked',\n },\n\n props: {\n /**\n * Used to set the state of the checkable input\n * @model checked\n */\n checked: {\n type: Boolean,\n default: false,\n },\n /**\n * Indeterminate State, toggling indeterminate checkbox will uncheck\n */\n indeterminate: {\n type: Boolean,\n default: false,\n },\n /**\n * The value of the input\n */\n value: {\n type: [String, Number, Boolean],\n default: null,\n },\n },\n\n data () {\n return {\n internalChecked: this.checked,\n internalIndeterminate: this.indeterminate,\n };\n },\n\n watch: {\n checked (newChecked) {\n // update internal checked when the prop changes\n this.internalChecked = newChecked;\n },\n\n indeterminate (newValue) {\n this.internalIndeterminate = newValue;\n },\n },\n};\n\n/**\n * This mixin provides common logic shared amongst our groupable inputs.\n *\n * This includes the group context and internal data attributes as well as a set common computed\n * properties and watchers. It also includes the group name warning logic.\n * @displayName Groupable Mixin\n */\nexport const GroupableMixin = {\n inject: {\n // Object used to pass data from the group\n groupContext: {\n default: {},\n },\n\n // Method used to update the group value\n setGroupValue: {\n default: () => { return () => {}; },\n },\n },\n\n data () {\n return {\n internalValue: this.value,\n };\n },\n\n computed: {\n hasGroup () {\n return Object.prototype.hasOwnProperty.call(this.groupContext, 'name');\n },\n\n groupName () {\n return this.groupContext?.name ?? '';\n },\n\n groupValue () {\n return this.groupContext?.value;\n },\n\n groupDisabled () {\n return this.groupContext?.disabled ?? false;\n },\n\n groupValidationState () {\n return this.groupContext?.validationState ?? null;\n },\n\n internalName () {\n return this.name || this.groupName;\n },\n },\n\n watch: {\n value (newValue) {\n // update internal value when the prop changes\n this.internalValue = newValue;\n },\n\n groupValue: {\n immediate: true,\n handler (newGroupValue) {\n if (this.hasGroup) {\n // update internal value when the group disabled changes\n this.internalValue = newGroupValue;\n }\n },\n },\n\n groupDisabled: {\n immediate: true,\n handler (newGroupDisabled) {\n if (this.hasGroup) {\n // update internal disabled when the group disabled changes\n this.internalDisabled = this.disabled || newGroupDisabled;\n }\n },\n },\n\n groupValidationState: {\n immediate: true,\n handler (newGroupValidationState) {\n if (this.hasGroup) {\n // update internal validation state when the group validation state changes\n this.internalValidationState = newGroupValidationState || this.validationState;\n }\n },\n },\n },\n\n created () {\n const hasGroupName = Object.prototype.hasOwnProperty.call(this.groupContext, 'name');\n const reactiveGroupName = this.groupContext?.name;\n\n if (!!this.name && hasGroupName && reactiveGroupName !== this.name) {\n Vue.util.warn(\n 'Component is being used inside a Group. Did you mean to override the name prop value ' +\n `(${reactiveGroupName}) with (${this.name})? It is recommended to only set name at the Group level.`,\n this,\n );\n }\n },\n};\n\n/**\n * This mixin provides common logic shared amongst our validation messages inputs.\n * @displayName Messages Mixin\n */\nexport const MessagesMixin = {\n props: {\n /**\n * Used to customize the validation messages component\n */\n messagesClass: {\n type: [String, Array, Object],\n default: '',\n },\n\n /**\n * A set of props that are passed into the validation messages component\n */\n messagesChildProps: {\n type: Object,\n default: () => ({}),\n },\n\n /**\n * Used to hide / show the validation messages\n * @values true, false\n */\n showMessages: {\n type: Boolean,\n default: true,\n },\n\n /**\n * Validation messages\n */\n messages: {\n type: Array,\n default: () => [],\n validator: messages => {\n return validationMessageValidator(messages);\n },\n },\n },\n\n computed: {\n formattedMessages () {\n return formatMessages(this.messages);\n },\n },\n};\n\nexport default {\n InputMixin,\n CheckableMixin,\n GroupableMixin,\n MessagesMixin,\n};\n"],"names":["InputMixin","validationState","VALIDATION_MESSAGE_TYPES","newDisabled","newValidationState","hasLabelOrLabel","ariaLabel","Vue","CheckableMixin","newChecked","newValue","GroupableMixin","_a","newGroupValue","newGroupDisabled","newGroupValidationState","hasGroupName","reactiveGroupName","MessagesMixin","messages","validationMessageValidator","formatMessages","input"],"mappings":"4OASaA,EAAa,CACxB,aAAc,GAEd,MAAO,CAIL,MAAO,CACL,KAAM,OACN,QAAS,EACf,EAKI,KAAM,CACJ,KAAM,OACN,QAAS,EACf,EAMI,MAAO,CACL,KAAM,CAAC,OAAQ,OAAQ,QAAS,MAAM,EACtC,QAAS,IACf,EAKI,YAAa,CACX,KAAM,OACN,QAAS,EACf,EAKI,SAAU,CACR,KAAM,QACN,QAAS,EACf,EAKI,gBAAiB,CACf,KAAM,OACN,QAAS,GACT,UAAWC,GACJA,EAIE,OAAO,OAAOC,EAAAA,wBAAwB,EAAE,SAASD,CAAe,EAH9D,EAKjB,EAKI,WAAY,CACV,KAAM,CAAC,OAAQ,MAAO,MAAM,EAC5B,QAAS,EACf,EAKI,WAAY,CACV,KAAM,CAAC,OAAQ,MAAO,MAAM,EAC5B,QAAS,EACf,EAKI,iBAAkB,CAChB,KAAM,CAAC,OAAQ,MAAO,MAAM,EAC5B,QAAS,EACf,EAKI,gBAAiB,CACf,KAAM,OACN,QAAS,KAAO,CAAA,EACtB,EAKI,sBAAuB,CACrB,KAAM,OACN,QAAS,KAAO,CAAA,EACtB,CACA,EAEE,MAAQ,CACN,MAAO,CACL,iBAAkB,KAAK,SACvB,wBAAyB,KAAK,eACpC,CACE,EAEA,MAAO,CACL,SAAUE,EAAa,CAErB,KAAK,iBAAmBA,CAC1B,EAEA,gBAAiBC,EAAoB,CAEnC,KAAK,wBAA0BA,CACjC,CACJ,EAEE,QAAS,CAKP,oBAAqBC,EAAiBC,EAAW,CAC3C,CAACD,GAAmB,CAACC,GACvBC,EAAI,KAAK,KACP,+DACA,IACV,CAEI,CACJ,CACA,EASaC,EAAiB,CAC5B,MAAO,CACL,KAAM,SACV,EAEE,MAAO,CAKL,QAAS,CACP,KAAM,QACN,QAAS,EACf,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