UNPKG

@dialpad/dialtone-vue

Version:

Vue component library for Dialpad's design system Dialtone

1 lines 11.6 kB
{"version":3,"file":"split-button.cjs","sources":["../../../components/split_button/split_button.vue"],"sourcesContent":["<template>\n <span\n data-qa=\"dt-split-button\"\n class=\"d-split-btn\"\n :style=\"{ width }\"\n >\n <split-button-alpha\n v-bind=\"alphaButtonProps\"\n ref=\"alphaButton\"\n @click.native=\"$emit('alpha-clicked')\"\n >\n <template #icon=\"{ size: iconSize }\">\n <!-- @slot Alpha (left) button icon slot -->\n <slot\n name=\"alphaIcon\"\n :size=\"iconSize\"\n />\n </template>\n <!-- @slot Default content slot -->\n <slot name=\"default\" />\n </split-button-alpha>\n <!-- @slot Omega (right) content slot, overrides omega button styling and functionality completely -->\n <slot name=\"omega\">\n <dt-dropdown\n v-if=\"$slots.dropdownList\"\n :placement=\"dropdownPlacement\"\n @click=\"isDropdownOpen = true\"\n @opened=\"open => isDropdownOpen = open\"\n >\n <template #anchor=\"attrs\">\n <split-button-omega\n v-bind=\"{ ...attrs, ...omegaButtonProps }\"\n :active=\"isDropdownOpen\"\n @click.native=\"$emit('omega-clicked')\"\n >\n <template #icon=\"{ size: iconSize }\">\n <!-- @slot Omega (right) button icon slot -->\n <slot\n name=\"omegaIcon\"\n :size=\"iconSize\"\n />\n </template>\n </split-button-omega>\n </template>\n <template #list=\"{ close }\">\n <!-- @slot Built-in dropdown content slot, use of dt-list-item is highly recommended here. -->\n <slot\n name=\"dropdownList\"\n :close=\"close\"\n />\n </template>\n </dt-dropdown>\n\n <split-button-omega\n v-else\n v-bind=\"omegaButtonProps\"\n @click.native=\"$emit('omega-clicked')\"\n >\n <template #icon=\"{ size: iconSize }\">\n <!-- @slot Omega (right) button icon slot -->\n <slot\n name=\"omegaIcon\"\n :size=\"iconSize\"\n />\n </template>\n </split-button-omega>\n </slot>\n </span>\n</template>\n\n<script>\nimport {\n BUTTON_IMPORTANCE_MODIFIERS,\n BUTTON_KIND_MODIFIERS,\n BUTTON_SIZE_MODIFIERS,\n ICON_POSITION_MODIFIERS,\n} from '@/components/button';\nimport SplitButtonAlpha from './split_button-alpha.vue';\nimport SplitButtonOmega from './split_button-omega.vue';\nimport { DtDropdown } from '@/components/dropdown';\nimport { warnIfUnmounted } from '@/common/utils';\n\nexport default {\n name: 'DtSplitButton',\n\n components: {\n SplitButtonOmega,\n DtDropdown,\n SplitButtonAlpha,\n },\n\n inheritAttrs: false,\n\n props: {\n /**\n * Determines whether the alpha button should have active styling\n * @values true, false\n */\n alphaActive: {\n type: Boolean,\n default: false,\n },\n\n /**\n * Descriptive label for the alpha button\n */\n alphaAriaLabel: {\n type: String,\n default: null,\n },\n\n /**\n * The position of the icon slot within the alpha button.\n * @values left, right, top, bottom\n */\n alphaIconPosition: {\n type: String,\n default: 'left',\n validator: (position) => Object.keys(ICON_POSITION_MODIFIERS).includes(position),\n },\n\n /**\n * Used to customize the alpha label container\n */\n alphaLabelClass: {\n type: [String, Array, Object],\n default: '',\n },\n\n /**\n * Whether the alpha button should display a loading animation or not.\n * @values true, false\n */\n alphaLoading: {\n type: Boolean,\n default: false,\n },\n\n /**\n * Text shown in tooltip when you hover the alpha button,\n * required if no content is passed to default slot\n */\n alphaTooltipText: {\n type: String,\n default: undefined,\n },\n\n /**\n * Determines whether a screenreader reads live updates of\n * the button content to the user while the button\n * is in focus.\n * @values true, false\n */\n assertiveOnFocus: {\n type: Boolean,\n default: false,\n },\n\n /**\n * HTML button disabled attribute\n * <a class=\"d-link\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#disabled\" target=\"_blank\">\n * (Reference)\n * </a>\n * @values true, false\n */\n disabled: {\n type: Boolean,\n default: false,\n },\n\n /**\n * The direction the dropdown displays relative to the anchor.\n * @values top, top-start, top-end, right, right-start, right-end, left, left-start, left-end, bottom, bottom-start, bottom-end, auto, auto-start, auto-end\n */\n dropdownPlacement: {\n type: String,\n default: 'bottom-end',\n },\n\n /**\n * The fill and outline of the button associated with its visual importance.\n * @values clear, outlined, primary\n */\n importance: {\n type: String,\n default: 'primary',\n validator: (i) => Object.keys(BUTTON_IMPORTANCE_MODIFIERS).includes(i),\n },\n\n /**\n * The color of the button.\n * @values default, muted, danger, inverted\n */\n kind: {\n type: String,\n default: 'default',\n validator: (k) => Object.keys(BUTTON_KIND_MODIFIERS).includes(k),\n },\n\n /**\n * Determines whether the omega button should have active styling\n * @values true, false\n */\n omegaActive: {\n type: Boolean,\n default: false,\n },\n\n /**\n * Descriptive label for the omega button\n */\n omegaAriaLabel: {\n type: String,\n default: null,\n },\n\n /**\n * Element ID, useful in case you need to reference the button\n * as an external anchor for popover\n */\n omegaId: {\n type: String,\n default: undefined,\n },\n\n /**\n * Text shown in tooltip when you hover the omega button,\n * required as it is an icon only button\n */\n omegaTooltipText: {\n type: String,\n default: undefined,\n },\n\n /**\n * The size of the button.\n * @values xs, sm, md, lg, xl\n */\n size: {\n type: String,\n default: 'md',\n validator: (s) => Object.keys(BUTTON_SIZE_MODIFIERS).includes(s),\n },\n\n /**\n * Button width, accepts\n * <a class=\"d-link\" href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/width\" target=\"_blank\">\n * CSS width attribute\n * </a>\n * values\n */\n width: {\n type: String,\n default: null,\n },\n },\n\n emits: [\n /**\n * Native alpha button click event\n *\n * @event click\n * @type {PointerEvent | KeyboardEvent}\n */\n 'alpha-clicked',\n\n /**\n * Native omega button click event\n *\n * @event click\n * @type {PointerEvent | KeyboardEvent}\n */\n 'omega-clicked',\n ],\n\n data () {\n return {\n isDropdownOpen: false,\n };\n },\n\n computed: {\n alphaButtonProps () {\n return {\n active: this.alphaActive,\n ariaLabel: this.alphaAriaLabel,\n assertiveOnFocus: this.assertiveOnFocus,\n disabled: this.disabled,\n iconPosition: this.alphaIconPosition,\n labelClass: this.alphaLabelClass,\n loading: this.alphaLoading,\n importance: this.importance,\n kind: this.kind,\n size: this.size,\n tooltipText: this.alphaTooltipText,\n class: this.$attrs.class,\n };\n },\n\n omegaButtonProps () {\n return {\n id: this.omegaId,\n active: this.omegaActive,\n ariaLabel: this.omegaAriaLabel,\n disabled: this.disabled,\n importance: this.importance,\n kind: this.kind,\n size: this.size,\n tooltipText: this.omegaTooltipText,\n class: this.$attrs.class,\n };\n },\n\n defaultSlotHasContent () {\n return this.$scopedSlots.default && this.$scopedSlots.default() && this.$scopedSlots.default()[0]?.text?.trim();\n },\n\n omegaSlotIsSet () {\n return this.$scopedSlots.omega && this.$scopedSlots.omega();\n },\n },\n\n created () {\n this.validateProps();\n },\n\n updated () {\n this.validateProps();\n },\n\n mounted () {\n warnIfUnmounted(this.$el, this.$options.name);\n },\n\n methods: {\n validateProps () {\n this.validateAlphaButtonProps();\n this.validateOmegaButtonProps();\n },\n\n validateAlphaButtonProps () {\n if (this.defaultSlotHasContent) return;\n\n // This can't be a computed prop due to reactivity issues.\n const isAlphaIconSet = this.$refs.alphaButton?.$scopedSlots.icon && this.$refs.alphaButton.$scopedSlots.icon();\n\n if (isAlphaIconSet && !this.alphaTooltipText) {\n console.warn('alpha-tooltip-text prop must be set if alpha button has an icon only');\n }\n },\n\n validateOmegaButtonProps () {\n if (this.omegaSlotIsSet) return;\n\n if (!this.omegaTooltipText) {\n console.warn('omega-tooltip-text prop is required as it is an icon-only button');\n }\n },\n },\n};\n</script>\n"],"names":["_sfc_main","SplitButtonOmega","DtDropdown","SplitButtonAlpha","position","ICON_POSITION_MODIFIERS","i","BUTTON_IMPORTANCE_MODIFIERS","k","BUTTON_KIND_MODIFIERS","s","BUTTON_SIZE_MODIFIERS","_b","_a","warnIfUnmounted"],"mappings":"0ZAkFA,MAAAA,EAAA,CACA,KAAA,gBAEA,WAAA,CACA,iBAAAC,EAAAA,QACA,WAAAC,EAAAA,QACA,iBAAAC,EAAAA,OACA,EAEA,aAAA,GAEA,MAAA,CAKA,YAAA,CACA,KAAA,QACA,QAAA,EACA,EAKA,eAAA,CACA,KAAA,OACA,QAAA,IACA,EAMA,kBAAA,CACA,KAAA,OACA,QAAA,OACA,UAAAC,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