maz-ui 4.3.4-beta.5 → 4.3.4-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,278 +0,0 @@
1
- import { defineComponent, mergeModels, defineAsyncComponent, useModel, computed, useTemplateRef, watch, createBlock, openBlock, normalizeStyle, normalizeClass, withCtx, createElementVNode, unref, renderSlot, createElementBlock, Fragment, renderList, mergeProps, withModifiers, createTextVNode, toDisplayString, withKeys, createVNode, createSlots, resolveDynamicComponent } from "vue";
2
- import { MazChevronDown } from "@maz-ui/icons";
3
- import { useTranslations } from "@maz-ui/translations";
4
- import { i as isClient } from "./isClient.WI4oSt66.js";
5
- import { useInstanceUniqId } from "../composables/useInstanceUniqId.js";
6
- import MazPopover from "../components/MazPopover.js";
7
- import '../assets/MazDropdown.uTis3caD.css';const _hoisted_1 = ["id", "aria-expanded"], _hoisted_2 = ["id"], _hoisted_3 = ["id"], _hoisted_4 = ["onClick", "onKeypress"], _sfc_main = /* @__PURE__ */ defineComponent({
8
- inheritAttrs: !1,
9
- __name: "MazDropdown",
10
- props: /* @__PURE__ */ mergeModels({
11
- modelValue: { type: Boolean },
12
- style: {},
13
- class: {},
14
- items: { default: () => [] },
15
- id: {},
16
- trigger: { default: "adaptive" },
17
- color: { default: "transparent" },
18
- position: { default: "auto" },
19
- closeOnClick: { type: Boolean, default: !1 },
20
- disabled: { type: Boolean, default: !1 },
21
- chevron: { type: Boolean, default: !0 },
22
- screenReaderDescription: {},
23
- menuPanelClass: {},
24
- menuPanelStyle: {},
25
- block: { type: Boolean },
26
- dropdownIcon: { type: [String, Function, Object] },
27
- dropdownIconAnimation: { type: Boolean, default: !0 },
28
- size: { default: "md" },
29
- transition: { default: "scale-pop" },
30
- preferPosition: { default: "bottom-start" },
31
- fallbackPosition: {},
32
- ariaLabel: {},
33
- announceChanges: { type: Boolean },
34
- offset: {},
35
- delay: {},
36
- hoverDelay: {},
37
- teleportTo: {},
38
- overlayClass: {},
39
- panelClass: {},
40
- panelStyle: {},
41
- closeOnClickOutside: { type: Boolean },
42
- closeOnEscape: { type: Boolean },
43
- persistent: { type: Boolean },
44
- ariaLabelledby: {},
45
- ariaDescribedby: {},
46
- trapFocus: { type: Boolean },
47
- keepOpenOnHover: { type: Boolean },
48
- positionReference: {}
49
- }, {
50
- modelValue: {
51
- default: !1
52
- },
53
- modelModifiers: {}
54
- }),
55
- emits: /* @__PURE__ */ mergeModels(["menuitem-clicked", "update:model-value"], ["update:modelValue"]),
56
- setup(__props, { emit: __emit }) {
57
- const emits = __emit, MazBtn = defineAsyncComponent(() => import("../components/MazBtn.js")), MazIcon = defineAsyncComponent(() => import("../components/MazIcon.js")), MazLink = defineAsyncComponent(() => import("../components/MazLink.js")), instanceId = useInstanceUniqId({
58
- componentName: "MazDropdown",
59
- providedId: __props.id
60
- }), { t } = useTranslations(), isOpen = useModel(__props, "modelValue"), iconClassSize = computed(() => __props.size === "xl" ? "maz-text-lg" : __props.size === "lg" || __props.size === "md" || __props.size === "sm" ? "maz-text-base" : __props.size === "xs" || __props.size === "mini" ? "maz-text-sm" : "maz-text-lg");
61
- function setDropdown(value) {
62
- __props.disabled || (isOpen.value = value);
63
- }
64
- function isLinkItem(item) {
65
- return "href" in item || "to" in item;
66
- }
67
- async function runAction(item, event) {
68
- emits("menuitem-clicked", event), await item.onClick?.(), closeDropdown();
69
- }
70
- function closeDropdown() {
71
- __props.closeOnClick && setDropdown(!1);
72
- }
73
- function keydownHandler(event) {
74
- ["ArrowDown", "ArrowUp"].includes(event.key) ? arrowHandler(event) : event.key === "Enter" && (event.preventDefault(), document.activeElement?.click(), closeDropdown());
75
- }
76
- function arrowHandler(event) {
77
- event.preventDefault();
78
- const code = event.key, itemLength = __props.items?.length;
79
- if (!itemLength)
80
- return;
81
- const currentElement = document.activeElement, itemsElements = document.querySelectorAll(`#${instanceId.value}-menu .menuitem`), currentIndex = Array.from(itemsElements).indexOf(currentElement);
82
- if (currentIndex === -1) {
83
- itemsElements[0]?.focus();
84
- return;
85
- }
86
- const nextIndex = code === "ArrowDown" ? (currentIndex + 1) % itemLength : (currentIndex - 1 + itemLength) % itemLength;
87
- itemsElements[nextIndex]?.focus();
88
- }
89
- const mazPopoverElement = useTemplateRef("mazPopoverRef");
90
- function onBlurTrigger(event) {
91
- event.preventDefault();
92
- const nextElementSibling = mazPopoverElement.value?.panelRef, relatedTarget = event.relatedTarget;
93
- nextElementSibling?.contains(relatedTarget) || setDropdown(!1);
94
- }
95
- return watch(
96
- isOpen,
97
- (value) => {
98
- isClient() && (value ? document.addEventListener("keydown", keydownHandler) : document.removeEventListener("keydown", keydownHandler));
99
- }
100
- ), (_ctx, _cache) => (openBlock(), createBlock(MazPopover, {
101
- ref: "mazPopoverRef",
102
- trigger: __props.trigger,
103
- "model-value": isOpen.value,
104
- class: normalizeClass(["m-dropdown m-reset-css", [__props.class]]),
105
- role: "menu",
106
- style: normalizeStyle(__props.style),
107
- "prefer-position": __props.preferPosition,
108
- color: "background",
109
- position: __props.position,
110
- transition: __props.transition,
111
- disabled: __props.disabled,
112
- offset: __props.offset,
113
- delay: __props.delay,
114
- "fallback-position": __props.fallbackPosition,
115
- persistent: __props.persistent,
116
- "hover-delay": __props.hoverDelay,
117
- "panel-class": __props.panelClass,
118
- "panel-style": __props.panelStyle,
119
- "close-on-escape": __props.closeOnEscape,
120
- "close-on-click": __props.closeOnClick,
121
- "teleport-to": __props.teleportTo,
122
- "trap-focus": __props.trapFocus,
123
- "overlay-class": __props.overlayClass,
124
- "close-on-click-outside": __props.closeOnClickOutside,
125
- "aria-describedby": __props.ariaDescribedby,
126
- "announce-changes": __props.announceChanges,
127
- "aria-label": __props.ariaLabel,
128
- "aria-labelledby": __props.ariaLabelledby,
129
- "position-reference": __props.positionReference,
130
- "keep-open-on-hover": __props.trigger === "hover" || __props.trigger === "adaptive",
131
- block: __props.block,
132
- "onUpdate:modelValue": setDropdown
133
- }, {
134
- trigger: withCtx(({ toggle, close, open }) => [
135
- createElementVNode("div", {
136
- id: unref(instanceId),
137
- tabindex: "-1",
138
- class: "m-dropdown__wrapper",
139
- "aria-expanded": isOpen.value,
140
- "aria-haspopup": "menu"
141
- }, [
142
- createElementVNode("span", {
143
- id: `${unref(instanceId)}-labelspan`,
144
- class: "maz-sr-only"
145
- }, [
146
- renderSlot(_ctx.$slots, "screen-reader-description", {}, () => [
147
- createTextVNode(toDisplayString(__props.screenReaderDescription || unref(t)("dropdown.screenReaderDescription")), 1)
148
- ])
149
- ], 8, _hoisted_2),
150
- renderSlot(_ctx.$slots, "trigger", {
151
- isOpen: isOpen.value,
152
- toggle,
153
- close,
154
- open
155
- }, () => [
156
- createVNode(unref(MazBtn), mergeProps({
157
- "aria-labelledby": `${unref(instanceId)}-labelspan`,
158
- color: __props.color,
159
- disabled: __props.disabled
160
- }, _ctx.$attrs, {
161
- block: __props.block,
162
- size: __props.size,
163
- onKeydown: [
164
- withKeys(withModifiers(toggle, ["stop", "prevent"]), ["enter"]),
165
- withKeys(withModifiers(toggle, ["stop", "prevent"]), ["space"]),
166
- withKeys(withModifiers(close, ["stop", "prevent"]), ["escape"])
167
- ],
168
- onBlur: withModifiers(onBlurTrigger, ["stop", "prevent"])
169
- }), createSlots({
170
- default: withCtx(() => [
171
- renderSlot(_ctx.$slots, "default")
172
- ]),
173
- _: 2
174
- }, [
175
- __props.chevron || _ctx.$slots["dropdown-icon"] ? {
176
- name: "right-icon",
177
- fn: withCtx(() => [
178
- renderSlot(_ctx.$slots, "dropdown-icon", {
179
- isOpen: isOpen.value,
180
- toggle,
181
- close,
182
- open
183
- }, () => [
184
- typeof __props.dropdownIcon == "string" ? (openBlock(), createBlock(unref(MazIcon), {
185
- key: 0,
186
- name: __props.dropdownIcon,
187
- class: normalizeClass([{ "--open": isOpen.value && __props.dropdownIconAnimation }, iconClassSize.value])
188
- }, null, 8, ["name", "class"])) : __props.dropdownIcon ? (openBlock(), createBlock(resolveDynamicComponent(__props.dropdownIcon), {
189
- key: 1,
190
- class: normalizeClass([[{ "--open": isOpen.value && __props.dropdownIconAnimation }, iconClassSize.value], "m-dropdown__icon"])
191
- }, null, 8, ["class"])) : (openBlock(), createBlock(unref(MazChevronDown), {
192
- key: 2,
193
- class: normalizeClass([[{ "--open": isOpen.value && __props.dropdownIconAnimation }, iconClassSize.value], "m-dropdown__icon"])
194
- }, null, 8, ["class"]))
195
- ])
196
- ]),
197
- key: "0"
198
- } : void 0
199
- ]), 1040, ["aria-labelledby", "color", "disabled", "block", "size", "onKeydown"])
200
- ])
201
- ], 8, _hoisted_1)
202
- ]),
203
- default: withCtx(({ open, close, toggle }) => [
204
- createElementVNode("div", {
205
- id: `${unref(instanceId)}-menu`,
206
- role: "menu",
207
- "aria-label": "Menu",
208
- class: normalizeClass(["m-dropdown__menu", __props.menuPanelClass]),
209
- tabindex: "-1",
210
- style: normalizeStyle(__props.menuPanelStyle)
211
- }, [
212
- renderSlot(_ctx.$slots, "dropdown", {
213
- items: __props.items,
214
- open,
215
- close,
216
- isOpen: isOpen.value,
217
- toggle
218
- }, () => [
219
- (openBlock(!0), createElementBlock(Fragment, null, renderList(__props.items, (item, index) => renderSlot(_ctx.$slots, "menuitem", {
220
- key: index,
221
- item,
222
- open,
223
- close,
224
- isOpen: isOpen.value,
225
- toggle
226
- }, () => [
227
- isLinkItem(item) ? (openBlock(), createBlock(unref(MazLink), mergeProps({
228
- key: 0,
229
- target: item.href ? item.target ?? "_self" : void 0,
230
- to: item.to,
231
- href: item.href,
232
- color: item.color ?? "contrast"
233
- }, { ref_for: !0 }, item, {
234
- "underline-only-hover": item.underlineOnlyHover ?? !1,
235
- class: ["menuitem", [item.class]],
236
- onClick: withModifiers(closeDropdown, ["stop"])
237
- }), {
238
- default: withCtx(() => [
239
- renderSlot(_ctx.$slots, "menuitem-label", {
240
- item,
241
- open,
242
- close,
243
- isOpen: isOpen.value,
244
- toggle
245
- }, () => [
246
- createTextVNode(toDisplayString(item.label), 1)
247
- ])
248
- ]),
249
- _: 2
250
- }, 1040, ["target", "to", "href", "color", "underline-only-hover", "class"])) : (openBlock(), createElementBlock("button", mergeProps({
251
- key: 1,
252
- type: "button"
253
- }, { ref_for: !0 }, { ...item, onClick: void 0 }, {
254
- class: ["menuitem menuitem__button", [item.class, item.color ? `--${item.color}` : ""]],
255
- onClick: withModifiers(($event) => runAction(item, $event), ["stop"]),
256
- onKeypress: withKeys(withModifiers(($event) => runAction(item, $event), ["stop", "prevent"]), ["enter"])
257
- }), [
258
- renderSlot(_ctx.$slots, "menuitem-label", {
259
- item,
260
- open,
261
- close,
262
- isOpen: isOpen.value,
263
- toggle
264
- }, () => [
265
- createTextVNode(toDisplayString(item.label), 1)
266
- ])
267
- ], 16, _hoisted_4))
268
- ])), 128))
269
- ])
270
- ], 14, _hoisted_3)
271
- ]),
272
- _: 3
273
- }, 8, ["trigger", "model-value", "style", "prefer-position", "position", "transition", "disabled", "offset", "delay", "fallback-position", "persistent", "hover-delay", "panel-class", "panel-style", "close-on-escape", "close-on-click", "teleport-to", "trap-focus", "overlay-class", "close-on-click-outside", "aria-describedby", "announce-changes", "aria-label", "aria-labelledby", "position-reference", "keep-open-on-hover", "class", "block"]));
274
- }
275
- });
276
- export {
277
- _sfc_main as _
278
- };