UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

305 lines (304 loc) 9.36 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); const split_buttonAlpha = require("./split_button-alpha.vue.cjs"); const split_buttonOmega = require("./split_button-omega.vue.cjs"); const common_utils = require("../../common/utils.cjs"); const vue = require("vue"); const _pluginVue_exportHelper = require("../../_virtual/_plugin-vue_export-helper.cjs"); const dropdown = require("../dropdown/dropdown.vue.cjs"); const button_constants = require("../button/button_constants.cjs"); const _sfc_main = { compatConfig: { MODE: 3 }, name: "DtSplitButton", components: { SplitButtonOmega: split_buttonOmega.default, DtDropdown: dropdown.default, SplitButtonAlpha: split_buttonAlpha.default }, inheritAttrs: false, props: { /** * Determines whether the alpha button should have active styling * @values true, false */ alphaActive: { type: Boolean, default: false }, /** * Descriptive label for the alpha button */ alphaAriaLabel: { type: String, default: null }, /** * The position of the icon slot within the alpha button. * @values left, right, top, bottom */ alphaIconPosition: { type: String, default: "left", validator: (position) => Object.keys(button_constants.ICON_POSITION_MODIFIERS).includes(position) }, /** * Used to customize the alpha label container */ alphaLabelClass: { type: [String, Array, Object], default: "" }, /** * Whether the alpha button should display a loading animation or not. * @values true, false */ alphaLoading: { type: Boolean, default: false }, /** * Text shown in tooltip when you hover the alpha button, * required if no content is passed to default slot */ alphaTooltipText: { type: String, default: void 0 }, /** * Determines whether a screenreader reads live updates of * the button content to the user while the button * is in focus. * @values true, false */ assertiveOnFocus: { type: Boolean, default: false }, /** * HTML button disabled attribute * <a class="d-link" href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#disabled" target="_blank"> * (Reference) * </a> * @values true, false */ disabled: { type: Boolean, default: false }, /** * The direction the dropdown displays relative to the anchor. * @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 */ dropdownPlacement: { type: String, default: "bottom-end" }, /** * The fill and outline of the button associated with its visual importance. * @values clear, outlined, primary */ importance: { type: String, default: "primary", validator: (i) => Object.keys(button_constants.BUTTON_IMPORTANCE_MODIFIERS).includes(i) }, /** * The color of the button. * @values default, muted, danger, inverted */ kind: { type: String, default: "default", validator: (k) => Object.keys(button_constants.BUTTON_KIND_MODIFIERS).includes(k) }, /** * Determines whether the omega button should have active styling * @values true, false */ omegaActive: { type: Boolean, default: false }, /** * Descriptive label for the omega button */ omegaAriaLabel: { type: String, default: null }, /** * Element ID, useful in case you need to reference the button * as an external anchor for popover. */ omegaId: { type: String, default: void 0 }, /** * Text shown in tooltip when you hover the omega button, * required as it is an icon only button */ omegaTooltipText: { type: String, default: void 0 }, /** * The size of the button. * @values xs, sm, md, lg, xl */ size: { type: String, default: "md", validator: (s) => Object.keys(button_constants.BUTTON_SIZE_MODIFIERS).includes(s) }, /** * Button width, accepts * <a class="d-link" href="https://developer.mozilla.org/en-US/docs/Web/CSS/width" target="_blank"> * CSS width attribute * </a> * values */ width: { type: String, default: null } }, emits: [ /** * Native alpha button click event * * @event click * @type {PointerEvent | KeyboardEvent} */ "alpha-clicked", /** * Native omega button click event * * @event click * @type {PointerEvent | KeyboardEvent} */ "omega-clicked" ], data() { return { isDropdownOpen: false }; }, computed: { alphaButtonProps() { return { active: this.alphaActive, ariaLabel: this.alphaAriaLabel, assertiveOnFocus: this.assertiveOnFocus, disabled: this.disabled, iconPosition: this.alphaIconPosition, labelClass: this.alphaLabelClass, loading: this.alphaLoading, importance: this.importance, kind: this.kind, size: this.size, tooltipText: this.alphaTooltipText, class: this.$attrs.class, style: this.$attrs.style }; }, omegaButtonProps() { return { id: this.omegaId, active: this.omegaActive, ariaLabel: this.omegaAriaLabel, disabled: this.disabled, importance: this.importance, kind: this.kind, size: this.size, tooltipText: this.omegaTooltipText, class: this.$attrs.class, style: this.$attrs.style }; } }, created() { this.validateProps(); }, updated() { this.validateProps(); }, mounted() { common_utils.warnIfUnmounted(common_utils.returnFirstEl(this.$el), this.$options.name); }, methods: { validateProps() { this.validateAlphaButtonProps(); this.validateOmegaButtonProps(); }, validateAlphaButtonProps() { if (common_utils.hasSlotContent(this.$slots.default)) return; if (common_utils.hasSlotContent(this.$slots.alphaIcon) && !this.alphaTooltipText) { console.warn("alpha-tooltip-text prop must be set if alpha button has an icon only"); } }, validateOmegaButtonProps() { if (common_utils.hasSlotContent(this.$slots.omega)) return; if (!this.omegaTooltipText) { console.warn("omega-tooltip-text prop is required as it is an icon-only button"); } } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { const _component_split_button_alpha = vue.resolveComponent("split-button-alpha"); const _component_split_button_omega = vue.resolveComponent("split-button-omega"); const _component_dt_dropdown = vue.resolveComponent("dt-dropdown"); return vue.openBlock(), vue.createElementBlock("span", { "data-qa": "dt-split-button", class: "d-split-btn", style: vue.normalizeStyle({ width: $props.width }) }, [ vue.createVNode(_component_split_button_alpha, vue.mergeProps($options.alphaButtonProps, { ref: "alphaButton", onClick: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("alpha-clicked")) }), { icon: vue.withCtx(({ size: iconSize }) => [ vue.renderSlot(_ctx.$slots, "alphaIcon", { size: iconSize }) ]), default: vue.withCtx(() => [ vue.renderSlot(_ctx.$slots, "default") ]), _: 3 }, 16), vue.renderSlot(_ctx.$slots, "omega", {}, () => [ _ctx.$slots.dropdownList ? (vue.openBlock(), vue.createBlock(_component_dt_dropdown, { key: 0, placement: $props.dropdownPlacement, onClick: _cache[2] || (_cache[2] = ($event) => $data.isDropdownOpen = true), onOpened: _cache[3] || (_cache[3] = (open) => $data.isDropdownOpen = open) }, { anchor: vue.withCtx((attrs) => [ vue.createVNode(_component_split_button_omega, vue.mergeProps({ ...attrs, ...$options.omegaButtonProps }, { active: $data.isDropdownOpen, onClick: _cache[1] || (_cache[1] = ($event) => _ctx.$emit("omega-clicked")) }), { icon: vue.withCtx(({ size: iconSize }) => [ vue.renderSlot(_ctx.$slots, "omegaIcon", { size: iconSize }) ]), _: 2 }, 1040, ["active"]) ]), list: vue.withCtx(({ close }) => [ vue.renderSlot(_ctx.$slots, "dropdownList", { close }) ]), _: 3 }, 8, ["placement"])) : (vue.openBlock(), vue.createBlock(_component_split_button_omega, vue.mergeProps({ key: 1 }, $options.omegaButtonProps, { onClick: _cache[4] || (_cache[4] = ($event) => _ctx.$emit("omega-clicked")) }), { icon: vue.withCtx(({ size: iconSize }) => [ vue.renderSlot(_ctx.$slots, "omegaIcon", { size: iconSize }) ]), _: 3 }, 16)) ]) ], 4); } const split_button = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["render", _sfc_render]]); exports.default = split_button; //# sourceMappingURL=split_button.vue.cjs.map