UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

305 lines (304 loc) 9.11 kB
import SplitButtonAlpha from "./split_button-alpha.vue.js"; import SplitButtonOmega from "./split_button-omega.vue.js"; import { warnIfUnmounted, returnFirstEl, hasSlotContent } from "../../common/utils.js"; import { resolveComponent, openBlock, createElementBlock, normalizeStyle, createVNode, mergeProps, withCtx, renderSlot, createBlock } from "vue"; import _export_sfc from "../../_virtual/_plugin-vue_export-helper.js"; import DtDropdown from "../dropdown/dropdown.vue.js"; import { ICON_POSITION_MODIFIERS, BUTTON_IMPORTANCE_MODIFIERS, BUTTON_KIND_MODIFIERS, BUTTON_SIZE_MODIFIERS } from "../button/button_constants.js"; const _sfc_main = { compatConfig: { MODE: 3 }, name: "DtSplitButton", components: { SplitButtonOmega, DtDropdown, SplitButtonAlpha }, 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(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_IMPORTANCE_MODIFIERS).includes(i) }, /** * The color of the button. * @values default, muted, danger, inverted */ kind: { type: String, default: "default", validator: (k) => Object.keys(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_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() { warnIfUnmounted(returnFirstEl(this.$el), this.$options.name); }, methods: { validateProps() { this.validateAlphaButtonProps(); this.validateOmegaButtonProps(); }, validateAlphaButtonProps() { if (hasSlotContent(this.$slots.default)) return; if (hasSlotContent(this.$slots.alphaIcon) && !this.alphaTooltipText) { console.warn("alpha-tooltip-text prop must be set if alpha button has an icon only"); } }, validateOmegaButtonProps() { if (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 = resolveComponent("split-button-alpha"); const _component_split_button_omega = resolveComponent("split-button-omega"); const _component_dt_dropdown = resolveComponent("dt-dropdown"); return openBlock(), createElementBlock("span", { "data-qa": "dt-split-button", class: "d-split-btn", style: normalizeStyle({ width: $props.width }) }, [ createVNode(_component_split_button_alpha, mergeProps($options.alphaButtonProps, { ref: "alphaButton", onClick: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("alpha-clicked")) }), { icon: withCtx(({ size: iconSize }) => [ renderSlot(_ctx.$slots, "alphaIcon", { size: iconSize }) ]), default: withCtx(() => [ renderSlot(_ctx.$slots, "default") ]), _: 3 }, 16), renderSlot(_ctx.$slots, "omega", {}, () => [ _ctx.$slots.dropdownList ? (openBlock(), 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: withCtx((attrs) => [ createVNode(_component_split_button_omega, mergeProps({ ...attrs, ...$options.omegaButtonProps }, { active: $data.isDropdownOpen, onClick: _cache[1] || (_cache[1] = ($event) => _ctx.$emit("omega-clicked")) }), { icon: withCtx(({ size: iconSize }) => [ renderSlot(_ctx.$slots, "omegaIcon", { size: iconSize }) ]), _: 2 }, 1040, ["active"]) ]), list: withCtx(({ close }) => [ renderSlot(_ctx.$slots, "dropdownList", { close }) ]), _: 3 }, 8, ["placement"])) : (openBlock(), createBlock(_component_split_button_omega, mergeProps({ key: 1 }, $options.omegaButtonProps, { onClick: _cache[4] || (_cache[4] = ($event) => _ctx.$emit("omega-clicked")) }), { icon: withCtx(({ size: iconSize }) => [ renderSlot(_ctx.$slots, "omegaIcon", { size: iconSize }) ]), _: 3 }, 16)) ]) ], 4); } const split_button = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); export { split_button as default }; //# sourceMappingURL=split_button.vue.js.map