UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

300 lines (299 loc) 9.08 kB
import { DtIconChevronUp as f } from "@dialpad/dialtone-icons/vue3"; import w, { addClassStyleAttrs as h, removeClassStyleAttrs as _, warnIfUnmounted as C, returnFirstEl as y } from "../../common/utils/index.js"; import { DialtoneLocalization as B } from "../../localization/index.js"; import { resolveComponent as a, createElementBlock as k, openBlock as d, mergeProps as c, createVNode as r, createBlock as A, createCommentVNode as g, withCtx as l, renderSlot as n, normalizeClass as S } from "vue"; import { _ as v } from "../../_plugin-vue_export-helper-CHgC5LLL.js"; import { CALLBAR_BUTTON_VALID_WIDTH_SIZE as D } from "../callbar-button/callbar-button-constants.js"; import O from "../button/button.js"; import T from "../dropdown/dropdown.js"; import L from "../callbar-button/callbar-button.js"; const z = { name: "DtRecipeCallbarButtonWithDropdown", components: { DtRecipeCallbarButton: L, DtDropdown: T, DtButton: O, DtIconChevronUp: f }, /* inheritAttrs: false is generally an option we want to set on library components. This allows any attributes passed in that are not recognized as props to be passed down to another element or component using v-bind:$attrs more info: https://vuejs.org/v2/api/#inheritAttrs */ inheritAttrs: !1, props: { /** * Id for the item. */ id: { type: String, default() { return w.getUniqueString(); } }, /** * Aria label for the button. If empty, it takes its value from the default slot. */ ariaLabel: { type: String, default: null, validator: (t) => t || (void 0).$slots.default }, /** * The direction the dropdown displays relative to the anchor. * @values 'bottom', 'bottom-start', 'bottom-end', * 'right', 'right-start', 'right-end', * 'left', 'left-start', 'left-end', * 'top', 'top-start', 'top-end' * @default 'top' */ placement: { type: String, default: "top" }, /** * If the dropdown does not fit in the direction described by "placement", * it will attempt to change it's direction to the "fallbackPlacements". * * @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 * */ fallbackPlacements: { type: Array, default: () => ["auto"] }, /** * Determines whether the button should be disabled * default is false. * @values true, false */ disabled: { type: Boolean, default: !1 }, /** * Forces showing the arrow, even if the button is disabled. * default is false * @values true, false */ forceShowArrow: { type: Boolean, default: !1 }, /** * Determines whether the button should have active styling * default is false. * @values true, false * @see https://dialtone.dialpad.com/components/button/ */ active: { type: Boolean, default: !1 }, /** * Determines whether the button should have danger styling * default is false. * @values true, false * @see https://dialtone.dialpad.com/components/button/ */ danger: { type: Boolean, default: !1 }, /** * We need this declaration because of how Vue3 informs the component about a listener. * Spoiler alert: it doesn't. * Vue3 intends to work as a real pub-sub, meaning the publisher has not a clue of who the subscribers are. * This makes it impossible from the regular declaration (emits: ['click']) to check whether * we actually have a click handler or not. * We're hacking it by adding an onClick prop: https://github.com/vuejs/core/issues/5220 */ /* eslint-disable-next-line vue/no-unused-properties */ onClick: { type: Function, default: null }, /** * Additional class name for the button wrapper element. */ buttonClass: { type: [String, Array, Object], default: "" }, /** * Additional class name for the button text. */ textClass: { type: [String, Array, Object], default: "" }, /* * Width size. Valid values are: 'xl', 'lg', 'md' and 'sm'. */ buttonWidthSize: { type: String, default: "xl", validator: (t) => D.includes(t) }, /** * Whether the tooltip has an inverted background color. * @values true, false */ invertedTooltip: { type: Boolean, default: !1 }, /** * Use this if you would like to manually override the logic for when the tooltip shows. * Otherwise it will just show on hover/focus. * @values null, true, false */ showTooltip: { type: Boolean, default: null }, /** * The message that displays in the tooltip. This will be overridden by the tooltip slot. */ tooltipText: { type: String, default: void 0 }, /** * Whether there is a delay before the tooltip shows on hover/focus. * @values true, false */ tooltipDelay: { type: Boolean, default: void 0 } }, emits: [ /** * Emitted when the arrow is clicked */ "arrow-click", /** * Native click event * * @event click * @type {PointerEvent | KeyboardEvent} */ "click", /** * Emitted when modal dropdown is opened or closed. */ "opened" ], data() { return { open: !1, i18n: new B() }; }, computed: { showArrowButton() { return this.forceShowArrow || !this.disabled; }, isCompactMode() { return this.buttonWidthSize === "sm" || this.buttonWidthSize === "md"; }, arrowButtonLabel() { return this.i18n.$t("DIALTONE_CALLBAR_BUTTON_WITH_DROPDOWN_ARROW_BUTTON_ARIA_LABEL"); } }, mounted() { C(y(this.$el), this.$options.name); }, methods: { removeClassStyleAttrs: _, addClassStyleAttrs: h, arrowClick(t) { return this.$emit("arrow-click", t), this.toggleOpen(); }, toggleOpen() { return this.open = !this.open; }, syncOpenState() { this.open = this.openDropdown; }, buttonClick(t) { this.$props.onClick ? this.$emit("click", t) : this.arrowClick(t); }, onModalIsOpened(t) { this.open = t, this.$emit("opened", t); } } }; function I(t, W, e, R, i, o) { const s = a("dt-recipe-callbar-button"), p = a("dt-icon-chevron-up"), u = a("dt-button"), m = a("dt-dropdown"); return d(), k("div", c({ class: "dt-recipe--callbar-button-with-dropdown" }, o.addClassStyleAttrs(t.$attrs)), [ r(s, { active: e.active, "aria-label": e.ariaLabel, "button-class": e.buttonClass, "button-width-size": e.buttonWidthSize, danger: e.danger, disabled: e.disabled, "inverted-tooltip": e.invertedTooltip, "show-tooltip": e.showTooltip, "text-class": e.textClass, "tooltip-delay": e.tooltipDelay, "tooltip-text": e.tooltipText, class: "dt-recipe--callbar-button-with-dropdown--main-button", onClick: o.buttonClick }, { icon: l(() => [ n(t.$slots, "icon") ]), tooltip: l(() => [ n(t.$slots, "tooltip") ]), default: l(() => [ n(t.$slots, "default") ]), _: 3 }, 8, ["active", "aria-label", "button-class", "button-width-size", "danger", "disabled", "inverted-tooltip", "show-tooltip", "text-class", "tooltip-delay", "tooltip-text", "onClick"]), o.showArrowButton ? (d(), A(m, c({ key: 0, id: e.id, "fallback-placements": e.fallbackPlacements, open: i.open, modal: !1, placement: e.placement, class: "dt-recipe--callbar-button-with-dropdown--dropdown-wrapper", padding: "none" }, o.removeClassStyleAttrs(t.$attrs), { onOpened: o.onModalIsOpened }), { anchor: l(() => [ r(u, { active: i.open, class: S([ "dt-recipe--callbar-button-with-dropdown--arrow", { "dt-recipe--callbar-button-with-dropdown--arrow--large": !o.isCompactMode } ]), circle: !0, importance: "clear", size: "lg", "aria-label": o.arrowButtonLabel, title: o.arrowButtonLabel, width: "2rem", onClick: o.arrowClick }, { icon: l(() => [ r(p, { class: "dt-recipe--callbar-button-with-dropdown--arrow__icon", size: "200" }) ]), _: 1 }, 8, ["active", "class", "aria-label", "title", "onClick"]) ]), list: l(({ close: b }) => [ n(t.$slots, "list", { close: b }) ]), _: 3 }, 16, ["id", "fallback-placements", "open", "placement", "onOpened"])) : g("", !0) ], 16); } const H = /* @__PURE__ */ v(z, [["render", I]]); export { H as default }; //# sourceMappingURL=callbar-button-with-dropdown.js.map