UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

242 lines (241 loc) 6.84 kB
import { hasSlotContent as b, extractVueListeners as g, getUniqueString as s } from "../../common/utils/index.js"; import C from "./collapsible-lazy-show.js"; import { DtIconChevronRight as x, DtIconChevronDown as S } from "@dialpad/dialtone-icons/vue3"; import { resolveComponent as a, createBlock as o, openBlock as i, resolveDynamicComponent as v, mergeProps as c, toHandlers as d, withCtx as r, createElementVNode as h, createVNode as p, normalizeClass as L, renderSlot as m, normalizeStyle as O, toDisplayString as T } from "vue"; import { _ as w } from "../../_plugin-vue_export-helper-CHgC5LLL.js"; import D from "../lazy-show/lazy-show.js"; import B from "../button/button.js"; const z = { compatConfig: { MODE: 3 }, name: "DtCollapsible", components: { DtButton: B, DtCollapsibleLazyShow: C, DtLazyShow: D, DtIconChevronDown: S, DtIconChevronRight: x }, props: { /** * Text that is displayed on the anchor if nothing is passed in the slot. * Ignored if the anchor slot is used. */ anchorText: { type: String, default: null }, /** * Controls whether the collapsible is shown. Leaving this null will have the collapsible start * expanded and trigger on click by default. If you set this value, the default trigger * behavior will be disabled, and you can control it as you need. * Supports .sync modifier * @values null, true, false */ open: { type: Boolean, default: null }, /** * The id of the content wrapper. */ id: { type: String, default() { return s(); } }, /** * HTML element type (tag name) of the root element of the component. */ elementType: { type: String, default: "div" }, /** * HTML element type (tag name) of the content wrapper element. */ contentElementType: { type: String, default: "div" }, /** * Additional class name for the anchor wrapper element. */ anchorClass: { type: [String, Array, Object], default: null }, /** * Additional class name for the content wrapper element. */ contentClass: { type: [String, Array, Object], default: null }, /** * The maximum width of the anchor and collapsible element. * Possible units rem|px|%|em */ maxWidth: { type: String, default: null }, /** * The maximum height of the collapsible element. * Possible units rem|px|%|em */ maxHeight: { type: String, default: null }, /** * Label on the collapsible content. Should provide this or ariaLabelledBy but not both. */ ariaLabel: { type: String, default: null }, /** * Id of the element that labels the collapsible content. Defaults to the anchor element. * Should provide this or ariaLabel but not both. */ ariaLabelledBy: { type: String, default: null } }, emits: [ /** * Event fired to sync the open prop with the parent component * @event update:open */ "update:open", /** * Event fired when the content is shown or hidden * * @event opened * @type {Boolean} */ "opened" ], data() { return { isOpen: !0 }; }, computed: { labelledBy() { return this.ariaLabelledBy || !this.ariaLabel && s("DtCollapsible__anchor"); }, collapsibleListeners() { return g(this.$attrs); } }, watch: { open: { handler: function(n) { n !== null && (this.isOpen = n); }, immediate: !0 } }, created() { this.validateProperAnchor(); }, methods: { onLeaveTransitionComplete() { this.$emit("opened", !1), this.open !== null && this.$emit("update:open", !1); }, onEnterTransitionComplete() { this.$emit("opened", !0, this.$refs.content), this.open !== null && this.$emit("update:open", !0); }, defaultToggleOpen() { this.open === null && this.toggleOpen(); }, toggleOpen() { this.isOpen = !this.isOpen; }, validateProperAnchor() { !this.anchorText && !b(this.$slots.anchor) && console.error("anchor text and anchor slot content cannot both be falsy"); } } }, A = ["id"], E = ["title"]; function k(n, W, e, H, l, t) { const u = a("dt-icon-chevron-down"), f = a("dt-icon-chevron-right"), y = a("dt-button"), _ = a("dt-collapsible-lazy-show"); return i(), o(v(e.elementType), c({ ref: "collapsible" }, d(t.collapsibleListeners)), { default: r(() => [ h("div", { id: !e.ariaLabelledBy && t.labelledBy, ref: "anchor", class: L(e.anchorClass) }, [ m(n.$slots, "anchor", { attrs: { "aria-controls": e.id, "aria-expanded": l.isOpen.toString(), role: "button" } }, () => [ p(y, { importance: "clear", kind: "muted", "aria-controls": e.id, "aria-expanded": `${l.isOpen}`, style: O({ width: e.maxWidth }), onClick: t.defaultToggleOpen }, { default: r(() => [ l.isOpen ? (i(), o(u, { key: 0, class: "d-collapsible__icon", size: "300" })) : (i(), o(f, { key: 1, class: "d-collapsible__icon", size: "300" })), h("span", { class: "d-collapsible__anchor-text", title: e.anchorText }, T(e.anchorText), 9, E) ]), _: 1 }, 8, ["aria-controls", "aria-expanded", "style", "onClick"]) ]) ], 10, A), p(_, c({ id: e.id, ref: "contentWrapper", "aria-hidden": `${!l.isOpen}`, "aria-labelledby": t.labelledBy, "aria-label": e.ariaLabel, show: l.isOpen, "element-type": e.contentElementType, class: e.contentClass, style: { "max-height": e.maxHeight, "max-width": e.maxWidth }, "data-qa": "dt-collapsible--content", tabindex: "-1", appear: "" }, d(t.collapsibleListeners), { onAfterLeave: t.onLeaveTransitionComplete, onAfterEnter: t.onEnterTransitionComplete }), { default: r(() => [ m(n.$slots, "content") ]), _: 3 }, 16, ["id", "aria-hidden", "aria-labelledby", "aria-label", "show", "element-type", "class", "style", "onAfterLeave", "onAfterEnter"]) ]), _: 3 }, 16); } const R = /* @__PURE__ */ w(z, [["render", k]]); export { R as default }; //# sourceMappingURL=collapsible.js.map