@scalar/components 0.16.8 → 0.16.12

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.
Files changed (33) hide show
  1. package/dist/components/ScalarDropdown/ScalarDropdown.vue.d.ts +13 -6
  2. package/dist/components/ScalarDropdown/ScalarDropdown.vue.d.ts.map +1 -1
  3. package/dist/components/ScalarDropdown/ScalarDropdown.vue.js +119 -40
  4. package/dist/components/ScalarDropdown/ScalarDropdownButton.vue.d.ts.map +1 -1
  5. package/dist/components/ScalarDropdown/ScalarDropdownButton.vue.js +2 -2
  6. package/dist/components/ScalarDropdown/ScalarDropdownButton.vue2.js +15 -13
  7. package/dist/components/ScalarDropdown/ScalarDropdownItem.vue.d.ts +2 -0
  8. package/dist/components/ScalarDropdown/ScalarDropdownItem.vue.d.ts.map +1 -1
  9. package/dist/components/ScalarDropdown/ScalarDropdownItem.vue.js +1 -1
  10. package/dist/components/ScalarDropdown/ScalarDropdownItem.vue2.js +19 -18
  11. package/dist/components/ScalarDropdown/ScalarDropdownMenu.vue.d.ts +4 -2
  12. package/dist/components/ScalarDropdown/ScalarDropdownMenu.vue.d.ts.map +1 -1
  13. package/dist/components/ScalarDropdown/ScalarDropdownMenu.vue.js +15 -16
  14. package/dist/components/ScalarDropdown/useDropdown.d.ts +10 -0
  15. package/dist/components/ScalarDropdown/useDropdown.d.ts.map +1 -0
  16. package/dist/components/ScalarDropdown/useDropdown.js +14 -0
  17. package/dist/components/ScalarFloating/ScalarFloating.vue.d.ts +4 -1
  18. package/dist/components/ScalarFloating/ScalarFloating.vue.d.ts.map +1 -1
  19. package/dist/components/ScalarFloating/ScalarFloating.vue.js +38 -34
  20. package/dist/components/ScalarFloating/types.d.ts +4 -3
  21. package/dist/components/ScalarFloating/types.d.ts.map +1 -1
  22. package/dist/components/ScalarModal/ScalarModal.vue.js +1 -1
  23. package/dist/components/ScalarModal/ScalarModal.vue2.js +4 -4
  24. package/dist/components/ScalarSidebar/ScalarSidebarGroup.vue.d.ts +4 -0
  25. package/dist/components/ScalarSidebar/ScalarSidebarGroup.vue.d.ts.map +1 -1
  26. package/dist/components/ScalarSidebar/ScalarSidebarGroup.vue.js +95 -62
  27. package/dist/components/ScalarSidebar/ScalarSidebarNestedItems.vue.d.ts +2 -0
  28. package/dist/components/ScalarSidebar/ScalarSidebarNestedItems.vue.d.ts.map +1 -1
  29. package/dist/components/ScalarSidebar/ScalarSidebarNestedItems.vue.js +17 -16
  30. package/dist/components/ScalarSidebar/types.d.ts +9 -0
  31. package/dist/components/ScalarSidebar/types.d.ts.map +1 -1
  32. package/dist/style.css +1 -1
  33. package/package.json +7 -7
@@ -2,9 +2,6 @@ import { type ScalarFloatingOptions } from '../ScalarFloating';
2
2
  /**
3
3
  * Scalar dropdown component
4
4
  *
5
- * Uses the headlessui Menu component under the hood
6
- * @see https://headlessui.com/v1/vue/menu
7
- *
8
5
  * @example
9
6
  * <ScalarDropdown>
10
7
  * <ScalarButton>Click Me</ScalarButton>
@@ -14,14 +11,24 @@ import { type ScalarFloatingOptions } from '../ScalarFloating';
14
11
  * </template>
15
12
  * </ScalarDropdown>
16
13
  */
17
- declare const _default: __VLS_WithSlots<import("vue").DefineComponent<ScalarFloatingOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<ScalarFloatingOptions> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
14
+ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<ScalarFloatingOptions & {
15
+ /** Whether or not the dropdown is open */
16
+ open?: boolean;
17
+ }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
18
+ "update:open": (value: boolean) => any;
19
+ }, string, import("vue").PublicProps, Readonly<ScalarFloatingOptions & {
20
+ /** Whether or not the dropdown is open */
21
+ open?: boolean;
22
+ }> & Readonly<{
23
+ "onUpdate:open"?: ((value: boolean) => any) | undefined;
24
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
18
25
  /** The reference element for the element in the #floating slot */
19
- default(props: {
26
+ default?(props: {
20
27
  /** Whether or not the dropdown is open */
21
28
  open: boolean;
22
29
  }): unknown;
23
30
  /** The list of dropdown items */
24
- items(props: {
31
+ items?(props: {
25
32
  /** Whether or not the dropdown is open */
26
33
  open: boolean;
27
34
  }): unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"ScalarDropdown.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDropdown/ScalarDropdown.vue"],"names":[],"mappings":"AAsEA,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAI9E;;;;;;;;;;;;;;GAcG;;IAMD,kEAAkE;mBACnD;QACb,0CAA0C;QAC1C,IAAI,EAAE,OAAO,CAAA;KACd,GAAG,OAAO;IACX,iCAAiC;iBACpB;QACX,0CAA0C;QAC1C,IAAI,EAAE,OAAO,CAAA;KACd,GAAG,OAAO;;AAdb,wBA4HC;AAOD,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"ScalarDropdown.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDropdown/ScalarDropdown.vue"],"names":[],"mappings":"AA8OA,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAI9E;;;;;;;;;;;GAWG;;IAmLH,0CAA0C;WACjC,OAAO;;;;IADhB,0CAA0C;WACjC,OAAO;;;;IA9Kd,kEAAkE;oBAClD;QACd,0CAA0C;QAC1C,IAAI,EAAE,OAAO,CAAA;KACd,GAAG,OAAO;IACX,iCAAiC;kBACnB;QACZ,0CAA0C;QAC1C,IAAI,EAAE,OAAO,CAAA;KACd,GAAG,OAAO;;AAdb,wBAkTC;AAOD,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
@@ -1,53 +1,132 @@
1
- import { defineComponent as i, createBlock as p, openBlock as f, unref as e, withCtx as t, createVNode as r, mergeProps as a, renderSlot as s } from "vue";
2
- import { Menu as u, MenuButton as c, MenuItems as _ } from "@headlessui/vue";
3
- import { useBindCx as d } from "@scalar/use-hooks/useBindCx";
4
- import h from "./ScalarDropdownMenu.vue.js";
5
- import B from "../ScalarFloating/ScalarFloating.vue.js";
6
- const y = {}, S = /* @__PURE__ */ i({
7
- ...y,
1
+ import { defineComponent as B, mergeModels as D, ref as b, useModel as g, useId as _, watch as $, computed as K, createBlock as L, openBlock as M, unref as m, mergeProps as I, createSlots as N, withCtx as A, renderSlot as R, createVNode as q, createElementVNode as O, withKeys as a, withModifiers as i, nextTick as C } from "vue";
2
+ import { useDropdown as U } from "./useDropdown.js";
3
+ import { useBindCx as V } from "@scalar/use-hooks/useBindCx";
4
+ import { onClickOutside as j } from "@vueuse/core";
5
+ import z from "./ScalarDropdownMenu.vue.js";
6
+ import F from "../ScalarFloating/ScalarFloating.vue.js";
7
+ const P = ["id", "aria-activedescendant", "aria-labelledby", "onKeydown"], G = {}, Z = /* @__PURE__ */ B({
8
+ ...G,
8
9
  inheritAttrs: !1,
9
10
  __name: "ScalarDropdown",
10
- props: {
11
+ props: /* @__PURE__ */ D({
11
12
  placement: {},
12
13
  offset: { type: [Number, Object, Function] },
13
14
  resize: { type: Boolean },
14
15
  target: {},
15
16
  middleware: {},
16
17
  teleport: { type: [Boolean, String] }
17
- },
18
- setup($) {
19
- const { cx: l } = d();
20
- return (o, g) => (f(), p(e(u), null, {
21
- default: t(({ open: n }) => [
22
- r(e(B), a(o.$props, {
23
- placement: o.placement ?? "bottom-start"
24
- }), {
25
- floating: t(({ width: m }) => [
26
- r(h, a({
27
- is: e(_),
28
- style: { width: m }
29
- }, e(l)("max-h-[inherit] max-w-[inherit]")), {
30
- default: t(() => [
31
- s(o.$slots, "items", { open: n })
32
- ]),
33
- _: 2
34
- }, 1040, ["is", "style"])
35
- ]),
36
- default: t(() => [
37
- r(e(c), { as: "template" }, {
38
- default: t(() => [
39
- s(o.$slots, "default", { open: n })
40
- ]),
41
- _: 2
42
- }, 1024)
43
- ]),
44
- _: 2
45
- }, 1040, ["placement"])
18
+ }, {
19
+ open: { type: Boolean, default: !1 },
20
+ openModifiers: {}
21
+ }),
22
+ emits: ["update:open"],
23
+ setup(E) {
24
+ const l = b(), r = b(), n = g(E, "open"), { active: o } = U(), v = _(), f = b(v), y = _();
25
+ async function k() {
26
+ n.value = !n.value, await C(), n.value && r.value?.focus();
27
+ }
28
+ async function h(e) {
29
+ if (["ArrowDown", "ArrowUp", " ", "Enter"].includes(e.key))
30
+ e.preventDefault();
31
+ else return;
32
+ n.value || (n.value = !0), await C(), r.value?.focus(), ["ArrowDown", " ", "Enter"].includes(e.key) ? d(1) : e.key === "ArrowUp" && d(-1);
33
+ }
34
+ $(
35
+ () => l.value?.targetRef,
36
+ (e, t) => {
37
+ e && (e.id ? f.value = e.id : (f.value = v, e.setAttribute("id", f.value)), e.setAttribute("aria-haspopup", "menu"), e.setAttribute("aria-expanded", `${n.value}`), n.value && e.setAttribute("aria-controls", y), e.addEventListener("click", k), e.addEventListener("keydown", h)), t && t !== e && (t.id === v && t.removeAttribute("id"), t.removeAttribute("aria-controls"), t.removeAttribute("aria-haspopup"), t.removeAttribute("aria-expanded"), t.removeEventListener("click", k), t.removeEventListener("keydown", h));
38
+ },
39
+ { immediate: !0 }
40
+ ), $(
41
+ n,
42
+ (e) => {
43
+ const t = l.value?.targetRef;
44
+ t && (t.setAttribute("aria-expanded", `${e}`), e ? t.setAttribute("aria-controls", y) : t.removeAttribute("aria-controls"));
45
+ },
46
+ { immediate: !0 }
47
+ );
48
+ async function u() {
49
+ l.value?.targetRef?.focus(), n.value = !1;
50
+ }
51
+ function x() {
52
+ if (!o.value || !r.value) return;
53
+ const e = r.value.querySelector(
54
+ `#${o.value}[role="menuitem"]:not([aria-disabled="true"])`
55
+ );
56
+ e && (e.click(), u());
57
+ }
58
+ function d(e) {
59
+ if (!n.value || !r.value) return;
60
+ const t = Array.from(
61
+ r.value.querySelectorAll(
62
+ '[role="menuitem"]:not([aria-disabled="true"])'
63
+ )
64
+ );
65
+ if (t.length === 0) return;
66
+ const c = t.findIndex((p) => p.id === o.value);
67
+ if (c === -1) {
68
+ const p = t[e > 0 ? 0 : t.length - 1];
69
+ p?.id && (o.value = p.id);
70
+ return;
71
+ }
72
+ const s = c + e;
73
+ if (s < 0 || s > t.length - 1)
74
+ return;
75
+ const w = t[s];
76
+ w?.id && (o.value = w.id);
77
+ }
78
+ j(r, u, {
79
+ ignore: [K(() => l.value?.targetRef)]
80
+ });
81
+ const { cx: S } = V();
82
+ return (e, t) => (M(), L(m(F), I({
83
+ ref_key: "floatingRef",
84
+ ref: l
85
+ }, e.$props, {
86
+ placement: e.placement ?? "bottom-start"
87
+ }), N({
88
+ default: A(() => [
89
+ R(e.$slots, "default", { open: n.value })
46
90
  ]),
47
- _: 3
48
- }));
91
+ _: 2
92
+ }, [
93
+ n.value ? {
94
+ name: "floating",
95
+ fn: A(({ width: c }) => [
96
+ q(z, I({
97
+ style: { width: c }
98
+ }, m(S)("max-h-[inherit] max-w-[inherit]")), {
99
+ menu: A(() => [
100
+ O("div", {
101
+ class: "flex flex-col p-0.75 outline-none",
102
+ ref_key: "menuRef",
103
+ ref: r,
104
+ role: "menu",
105
+ id: m(y),
106
+ "aria-activedescendant": m(o),
107
+ "aria-labelledby": f.value,
108
+ onClick: i(u, ["stop"]),
109
+ onKeydown: [
110
+ a(i(x, ["prevent", "stop"]), ["enter"]),
111
+ a(i(x, ["prevent", "stop"]), ["space"]),
112
+ a(i(u, ["prevent", "stop"]), ["escape"]),
113
+ a(i(u, ["prevent", "stop"]), ["tab"]),
114
+ t[0] || (t[0] = a(i((s) => d(1), ["prevent", "stop"]), ["down"])),
115
+ t[1] || (t[1] = a(i((s) => d(-1), ["prevent", "stop"]), ["up"]))
116
+ ],
117
+ tabindex: "-1"
118
+ }, [
119
+ R(e.$slots, "items", { open: n.value })
120
+ ], 40, P)
121
+ ]),
122
+ _: 3
123
+ }, 16, ["style"])
124
+ ]),
125
+ key: "0"
126
+ } : void 0
127
+ ]), 1040, ["placement"]));
49
128
  }
50
129
  });
51
130
  export {
52
- S as default
131
+ Z as default
53
132
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ScalarDropdownButton.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDropdown/ScalarDropdownButton.vue"],"names":[],"mappings":"AA4DA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAGpC;;;;;;;;;;;;;;GAcG;;SAGI,MAAM,GAAG,SAAS;aACd,OAAO;eACL,OAAO;;SAFb,MAAM,GAAG,SAAS;aACd,OAAO;eACL,OAAO;;cAqDN,CAAC,KAAK,IAAgB,KAAK,GAAG;;AAzD5C,wBAuFC;AAOD,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"ScalarDropdownButton.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDropdown/ScalarDropdownButton.vue"],"names":[],"mappings":"AA8DA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAGpC;;;;;;;;;;;;;;GAcG;;SAGI,MAAM,GAAG,SAAS;aACd,OAAO;eACL,OAAO;;SAFb,MAAM,GAAG,SAAS;aACd,OAAO;eACL,OAAO;;cAwDN,CAAC,KAAK,IAAgB,KAAK,GAAG;;AA5D5C,wBA0FC;AAOD,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import o from "./ScalarDropdownButton.vue2.js";
2
2
  /* empty css */
3
3
  import t from "../../_virtual/_plugin-vue_export-helper.js";
4
- const f = /* @__PURE__ */ t(o, [["__scopeId", "data-v-7e7bf818"]]);
4
+ const m = /* @__PURE__ */ t(o, [["__scopeId", "data-v-12a6b6d1"]]);
5
5
  export {
6
- f as default
6
+ m as default
7
7
  };
@@ -1,6 +1,6 @@
1
- import { defineComponent as n, createBlock as a, openBlock as r, resolveDynamicComponent as s, normalizeClass as i, unref as t, withCtx as l, renderSlot as c } from "vue";
2
- import { cva as d, cx as p } from "@scalar/use-hooks/useBindCx";
3
- const u = {}, _ = /* @__PURE__ */ n({
1
+ import { defineComponent as o, createBlock as n, openBlock as s, resolveDynamicComponent as r, normalizeClass as i, unref as t, withCtx as d, renderSlot as l } from "vue";
2
+ import { cva as c, cx as p } from "@scalar/use-hooks/useBindCx";
3
+ const u = {}, _ = /* @__PURE__ */ o({
4
4
  ...u,
5
5
  __name: "ScalarDropdownButton",
6
6
  props: {
@@ -8,30 +8,32 @@ const u = {}, _ = /* @__PURE__ */ n({
8
8
  active: { type: Boolean },
9
9
  disabled: { type: Boolean }
10
10
  },
11
- setup(m) {
12
- const o = d({
11
+ setup(b) {
12
+ const a = c({
13
13
  base: [
14
14
  // Layout
15
15
  "block h-8 min-w-0 gap-1.5 rounded px-2.5 py-1.5 text-left",
16
16
  // Text / background style
17
17
  "truncate no-underline text-sm text-c-1",
18
18
  // Interaction
19
- "cursor-pointer hover:bg-b-2 hover:text-c-1"
19
+ "cursor-pointer hover:bg-b-2"
20
20
  ],
21
21
  variants: {
22
22
  disabled: { true: "pointer-events-none text-c-3" },
23
- active: { true: "bg-b-2 text-c-1" }
24
- }
23
+ active: { true: "" }
24
+ },
25
+ compoundVariants: [{ disabled: !1, active: !0, class: "bg-b-2" }]
25
26
  });
26
- return (e, b) => (r(), a(s(e.is), {
27
- class: i(["item", t(p)("scalar-dropdown-item", t(o)({ active: e.active, disabled: e.disabled }))]),
27
+ return (e, m) => (s(), n(r(e.is), {
28
+ class: i(["item", t(p)("scalar-dropdown-item", t(a)({ active: e.active, disabled: e.disabled }))]),
29
+ "aria-disabled": e.disabled,
28
30
  type: e.is === "button" ? "button" : void 0
29
31
  }, {
30
- default: l(() => [
31
- c(e.$slots, "default", {}, void 0, !0)
32
+ default: d(() => [
33
+ l(e.$slots, "default", {}, void 0, !0)
32
34
  ]),
33
35
  _: 3
34
- }, 8, ["class", "type"]));
36
+ }, 8, ["aria-disabled", "class", "type"]));
35
37
  }
36
38
  });
37
39
  export {
@@ -9,10 +9,12 @@
9
9
  * </ScalarDropdownItem>
10
10
  */
11
11
  declare const _default: __VLS_WithSlots<import("vue").DefineComponent<{
12
+ id?: string;
12
13
  disabled?: boolean;
13
14
  }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
14
15
  click: (event: MouseEvent) => any;
15
16
  }, string, import("vue").PublicProps, Readonly<{
17
+ id?: string;
16
18
  disabled?: boolean;
17
19
  }> & Readonly<{
18
20
  onClick?: ((event: MouseEvent) => any) | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"ScalarDropdownItem.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDropdown/ScalarDropdownItem.vue"],"names":[],"mappings":"AAkDA;;;;;;;;;GASG;;eAGU,OAAO;;;;eAAP,OAAO;;;;cA8DN,CAAC,KAAK,IAAiB,KAAK,GAAG;;AAhE7C,wBAgGC;AAOD,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"ScalarDropdownItem.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDropdown/ScalarDropdownItem.vue"],"names":[],"mappings":"AAuDA;;;;;;;;;GASG;;SAGI,MAAM;eACA,OAAO;;;;SADb,MAAM;eACA,OAAO;;;;cA6DN,CAAC,KAAK,IAAiB,KAAK,GAAG;;AAhE7C,wBAgGC;AAOD,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import o from "./ScalarDropdownItem.vue2.js";
2
2
  /* empty css */
3
3
  import r from "../../_virtual/_plugin-vue_export-helper.js";
4
- const m = /* @__PURE__ */ r(o, [["__scopeId", "data-v-788cdfbc"]]);
4
+ const m = /* @__PURE__ */ r(o, [["__scopeId", "data-v-ab7c0c49"]]);
5
5
  export {
6
6
  m as default
7
7
  };
@@ -1,31 +1,32 @@
1
- import { defineComponent as a, createBlock as l, openBlock as i, unref as n, withCtx as t, createVNode as s, renderSlot as p } from "vue";
2
- import { MenuItem as m } from "@headlessui/vue";
3
- import u from "./ScalarDropdownButton.vue.js";
4
- const f = {}, B = /* @__PURE__ */ a({
1
+ import { defineComponent as i, useId as r, createBlock as n, openBlock as l, unref as a, withCtx as s, renderSlot as u } from "vue";
2
+ import { useDropdownItem as m } from "./useDropdown.js";
3
+ import p from "./ScalarDropdownButton.vue.js";
4
+ const f = {}, w = /* @__PURE__ */ i({
5
5
  ...f,
6
6
  __name: "ScalarDropdownItem",
7
7
  props: {
8
+ id: { default: () => r() },
8
9
  disabled: { type: Boolean }
9
10
  },
10
11
  emits: ["click"],
11
12
  setup(c) {
12
- return (e, o) => (i(), l(n(m), { disabled: e.disabled }, {
13
- default: t(({ active: d }) => [
14
- s(u, {
15
- active: d,
16
- disabled: e.disabled,
17
- onClick: o[0] || (o[0] = (r) => e.$emit("click", r))
18
- }, {
19
- default: t(() => [
20
- p(e.$slots, "default", {}, void 0, !0)
21
- ]),
22
- _: 3
23
- }, 8, ["active", "disabled"])
13
+ const { active: t } = m();
14
+ return (e, o) => (l(), n(p, {
15
+ active: a(t) === e.id,
16
+ tabindex: "-1",
17
+ disabled: e.disabled,
18
+ role: "menuitem",
19
+ id: e.id,
20
+ onMouseenter: o[0] || (o[0] = (d) => t.value = e.id),
21
+ onClick: o[1] || (o[1] = (d) => e.$emit("click", d))
22
+ }, {
23
+ default: s(() => [
24
+ u(e.$slots, "default", {}, void 0, !0)
24
25
  ]),
25
26
  _: 3
26
- }, 8, ["disabled"]));
27
+ }, 8, ["active", "disabled", "id"]));
27
28
  }
28
29
  });
29
30
  export {
30
- B as default
31
+ w as default
31
32
  };
@@ -1,4 +1,4 @@
1
- import type { Component } from 'vue';
1
+ import { type Component } from 'vue';
2
2
  /**
3
3
  * Scalar dropdown menu component
4
4
  *
@@ -22,7 +22,9 @@ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<{
22
22
  is?: string | Component;
23
23
  }> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
24
24
  /** The menu contents */
25
- default(): unknown;
25
+ default?(): unknown;
26
+ /** Overrides the normal menu list element */
27
+ menu?(): unknown;
26
28
  /** Overrides the backdrop for the dropdown */
27
29
  backdrop?(): unknown;
28
30
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"ScalarDropdownMenu.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDropdown/ScalarDropdownMenu.vue"],"names":[],"mappings":"AA6DA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAKpC;;;;;;;;;;;;;;GAcG;;IAGD,8BAA8B;SACzB,MAAM,GAAG,SAAS;;IADvB,8BAA8B;SACzB,MAAM,GAAG,SAAS;;IAKvB,wBAAwB;eACb,OAAO;IAClB,8CAA8C;iBACjC,OAAO;;AAXtB,wBA2FC;AAOD,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"ScalarDropdownMenu.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDropdown/ScalarDropdownMenu.vue"],"names":[],"mappings":"AA+DA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,KAAK,CAAA;AAKpC;;;;;;;;;;;;;;GAcG;;IAGD,8BAA8B;SACzB,MAAM,GAAG,SAAS;;IADvB,8BAA8B;SACzB,MAAM,GAAG,SAAS;;IAKvB,wBAAwB;gBACZ,OAAO;IACnB,6CAA6C;aACpC,OAAO;IAChB,8CAA8C;iBACjC,OAAO;;AAbtB,wBA2FC;AAOD,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
@@ -1,26 +1,25 @@
1
- import { defineComponent as n, createBlock as l, openBlock as a, resolveDynamicComponent as c, mergeProps as i, unref as o, withCtx as d, createElementVNode as t, renderSlot as r, createVNode as m } from "vue";
1
+ import { defineComponent as n, createBlock as l, openBlock as a, resolveDynamicComponent as i, normalizeProps as c, guardReactiveProps as d, unref as s, withCtx as m, createElementVNode as t, renderSlot as o, createVNode as p } from "vue";
2
2
  import { useBindCx as f } from "@scalar/use-hooks/useBindCx";
3
- import p from "../ScalarFloating/ScalarFloatingBackdrop.vue.js";
4
- const _ = { class: "custom-scroll min-h-0 flex-1" }, u = { class: "flex flex-col p-0.75" }, x = {}, B = /* @__PURE__ */ n({
5
- ...x,
3
+ import _ from "../ScalarFloating/ScalarFloatingBackdrop.vue.js";
4
+ const u = { class: "custom-scroll min-h-0 flex-1" }, h = { class: "flex flex-col p-0.75" }, v = {}, B = /* @__PURE__ */ n({
5
+ ...v,
6
6
  inheritAttrs: !1,
7
7
  __name: "ScalarDropdownMenu",
8
8
  props: {
9
9
  is: {}
10
10
  },
11
- setup(h) {
12
- const { cx: s } = f();
13
- return (e, v) => (a(), l(c(e.is ?? "div"), i({
14
- role: "menu",
15
- tabindex: "0"
16
- }, o(s)("relative flex w-56")), {
17
- default: d(() => [
18
- t("div", _, [
19
- t("div", u, [
20
- r(e.$slots, "default")
11
+ setup(x) {
12
+ const { cx: r } = f();
13
+ return (e, C) => (a(), l(i(e.is ?? "div"), c(d(s(r)("relative flex w-56"))), {
14
+ default: m(() => [
15
+ t("div", u, [
16
+ o(e.$slots, "menu", {}, () => [
17
+ t("div", h, [
18
+ o(e.$slots, "default")
19
+ ])
21
20
  ]),
22
- r(e.$slots, "backdrop", {}, () => [
23
- m(o(p))
21
+ o(e.$slots, "backdrop", {}, () => [
22
+ p(s(_))
24
23
  ])
25
24
  ])
26
25
  ]),
@@ -0,0 +1,10 @@
1
+ import { type Ref } from 'vue';
2
+ /** Provides a ref for the currently active dropdown item */
3
+ export declare function useDropdown(): {
4
+ active: Ref<string | undefined, string | undefined>;
5
+ };
6
+ /** Injects the ref for the currently active dropdown item */
7
+ export declare function useDropdownItem(): {
8
+ active: Ref<string | undefined, string | undefined> | undefined;
9
+ };
10
+ //# sourceMappingURL=useDropdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDropdown.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDropdown/useDropdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,GAAG,EAAwB,MAAM,KAAK,CAAA;AAKvE,4DAA4D;AAC5D,wBAAgB,WAAW;;EAK1B;AAED,6DAA6D;AAC7D,wBAAgB,eAAe;;EAM9B"}
@@ -0,0 +1,14 @@
1
+ import { ref as e, provide as t, inject as r } from "vue";
2
+ const n = Symbol();
3
+ function i() {
4
+ const o = e();
5
+ return t(n, o), { active: o };
6
+ }
7
+ function s() {
8
+ const o = r(n);
9
+ return o || console.warn("useDropdownItem must be used within a ScalarDropdown"), { active: o };
10
+ }
11
+ export {
12
+ i as useDropdown,
13
+ s as useDropdownItem
14
+ };
@@ -13,7 +13,10 @@ type __VLS_Slots = {
13
13
  data?: MiddlewareData;
14
14
  }): unknown;
15
15
  };
16
- declare const __VLS_component: import("vue").DefineComponent<FloatingOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<FloatingOptions> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
16
+ declare const __VLS_component: import("vue").DefineComponent<FloatingOptions, {
17
+ /** The resolved target element */
18
+ targetRef: import("vue").ComputedRef<HTMLElement | undefined>;
19
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<FloatingOptions> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
17
20
  declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
18
21
  export default _default;
19
22
  type __VLS_WithSlots<T, S> = T & {
@@ -1 +1 @@
1
- {"version":3,"file":"ScalarFloating.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarFloating/ScalarFloating.vue"],"names":[],"mappings":"AA+HA,OAAO,EACL,KAAK,cAAc,EAOpB,MAAM,kBAAkB,CAAA;AAIzB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAa9C,KAAK,WAAW,GAAG;IACjB,kEAAkE;IAClE,OAAO,IAAI,OAAO,CAAA;IAClB,2BAA2B;IAC3B,QAAQ,CAAC,CAAC,KAAK,EAAE;QACf,4FAA4F;QAC5F,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,6FAA6F;QAC7F,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,gDAAgD;QAChD,IAAI,CAAC,EAAE,cAAc,CAAA;KACtB,GAAG,OAAO,CAAA;CACZ,CAAC;AAuIF,QAAA,MAAM,eAAe,0SAMnB,CAAC;wBACkB,eAAe,CAAC,OAAO,eAAe,EAAE,WAAW,CAAC;AAAzE,wBAA0E;AAQ1E,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"ScalarFloating.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarFloating/ScalarFloating.vue"],"names":[],"mappings":"AAwIA,OAAO,EACL,KAAK,cAAc,EAOpB,MAAM,kBAAkB,CAAA;AAIzB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAa9C,KAAK,WAAW,GAAG;IACjB,kEAAkE;IAClE,OAAO,IAAI,OAAO,CAAA;IAClB,2BAA2B;IAC3B,QAAQ,CAAC,CAAC,KAAK,EAAE;QACf,4FAA4F;QAC5F,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,6FAA6F;QAC7F,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,gDAAgD;QAChD,IAAI,CAAC,EAAE,cAAc,CAAA;KACtB,GAAG,OAAO,CAAA;CACZ,CAAC;AAiJF,QAAA,MAAM,eAAe;IA3EnB,kCAAkC;;wPAkFlC,CAAC;wBACkB,eAAe,CAAC,OAAO,eAAe,EAAE,WAAW,CAAC;AAAzE,wBAA0E;AAQ1E,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
@@ -1,9 +1,9 @@
1
- import { defineComponent as w, ref as d, computed as a, createElementBlock as b, openBlock as s, Fragment as z, createElementVNode as m, createBlock as S, createCommentVNode as $, normalizeClass as k, renderSlot as u, unref as n, withCtx as B, normalizeStyle as R } from "vue";
1
+ import { defineComponent as b, ref as d, computed as a, createElementBlock as z, openBlock as s, Fragment as S, createElementVNode as m, createBlock as $, createCommentVNode as k, normalizeClass as x, renderSlot as u, unref as i, withCtx as B, normalizeStyle as E } from "vue";
2
2
  import { getSideAxis as c } from "@floating-ui/utils";
3
- import { useFloating as x, autoUpdate as E, offset as F, flip as C, shift as M, size as H } from "@floating-ui/vue";
3
+ import { useFloating as R, autoUpdate as C, offset as F, flip as M, shift as H, size as T } from "@floating-ui/vue";
4
4
  import { useResizeWithTarget as N } from "./useResizeWithTarget.js";
5
- import T from "../ScalarTeleport/ScalarTeleport.vue.js";
6
- const D = /* @__PURE__ */ w({
5
+ import W from "../ScalarTeleport/ScalarTeleport.vue.js";
6
+ const D = /* @__PURE__ */ b({
7
7
  inheritAttrs: !1,
8
8
  __name: "ScalarFloating",
9
9
  props: {
@@ -14,51 +14,55 @@ const D = /* @__PURE__ */ w({
14
14
  middleware: { default: () => [] },
15
15
  teleport: { type: [Boolean, String] }
16
16
  },
17
- setup(t) {
18
- const o = d(null), l = d(null), i = a(() => {
19
- if (typeof window < "u" && l.value) {
17
+ setup(t, { expose: g }) {
18
+ const r = d(null), n = d(null), o = a(() => {
19
+ if (typeof window < "u" && n.value) {
20
20
  if (typeof t.target == "string") {
21
- const e = document.getElementById(t.target);
22
- if (e)
23
- return e;
21
+ const l = document.getElementById(t.target);
22
+ if (l)
23
+ return l;
24
24
  console.warn(`ScalarFloating: Target with id="${t.target}" not found`);
25
25
  } else if (t.target instanceof HTMLElement)
26
26
  return t.target;
27
- return l.value.children?.[0] || l.value;
27
+ const e = n.value.children?.[0];
28
+ return e instanceof HTMLElement ? e : n.value;
28
29
  }
29
- }), r = N(i, {
30
+ }), f = N(o, {
30
31
  enabled: a(() => t.resize)
31
- }), g = a(
32
- () => c(t.placement ?? "bottom") === "y" ? r.width.value : void 0
33
- ), h = a(
34
- () => c(t.placement ?? "bottom") === "x" ? r.height.value : void 0
35
- ), { floatingStyles: p, middlewareData: y } = x(i, o, {
32
+ }), h = a(
33
+ () => c(t.placement ?? "bottom") === "y" ? f.width.value : void 0
34
+ ), p = a(
35
+ () => c(t.placement ?? "bottom") === "x" ? f.height.value : void 0
36
+ ), { floatingStyles: y, middlewareData: v } = R(o, r, {
36
37
  placement: a(() => t.placement ?? "bottom"),
37
- whileElementsMounted: E,
38
+ whileElementsMounted: C,
38
39
  middleware: a(() => [
39
40
  F(t.offset),
40
- C(),
41
- M({ padding: 10 }),
42
- H({
43
- apply({ availableWidth: e, availableHeight: f, elements: v }) {
44
- Object.assign(v.floating.style, {
41
+ M(),
42
+ H({ padding: 10 }),
43
+ T({
44
+ apply({ availableWidth: e, availableHeight: l, elements: w }) {
45
+ Object.assign(w.floating.style, {
45
46
  maxWidth: `${Math.max(0, e) - 20}px`,
46
- maxHeight: `${Math.max(0, f) - 20}px`
47
+ maxHeight: `${Math.max(0, l) - 20}px`
47
48
  });
48
49
  }
49
50
  }),
50
51
  ...t.middleware
51
52
  ])
52
53
  });
53
- return (e, f) => (s(), b(z, null, [
54
+ return g({
55
+ /** The resolved target element */
56
+ targetRef: o
57
+ }), (e, l) => (s(), z(S, null, [
54
58
  m("div", {
55
59
  ref_key: "wrapperRef",
56
- ref: l,
57
- class: k({ contents: !!e.$slots.default })
60
+ ref: n,
61
+ class: x({ contents: !!e.$slots.default })
58
62
  }, [
59
63
  u(e.$slots, "default")
60
64
  ], 2),
61
- e.$slots.floating ? (s(), S(n(T), {
65
+ e.$slots.floating ? (s(), $(i(W), {
62
66
  key: 0,
63
67
  disabled: !e.teleport,
64
68
  to: typeof e.teleport == "string" ? e.teleport : void 0
@@ -66,19 +70,19 @@ const D = /* @__PURE__ */ w({
66
70
  default: B(() => [
67
71
  m("div", {
68
72
  ref_key: "floatingRef",
69
- ref: o,
73
+ ref: r,
70
74
  class: "relative z-context",
71
- style: R(n(p))
75
+ style: E(i(y))
72
76
  }, [
73
77
  u(e.$slots, "floating", {
74
- data: n(y),
75
- height: h.value,
76
- width: g.value
78
+ data: i(v),
79
+ height: p.value,
80
+ width: h.value
77
81
  })
78
82
  ], 4)
79
83
  ]),
80
84
  _: 3
81
- }, 8, ["disabled", "to"])) : $("", !0)
85
+ }, 8, ["disabled", "to"])) : k("", !0)
82
86
  ], 64));
83
87
  }
84
88
  });
@@ -1,4 +1,5 @@
1
- import type { Middleware, OffsetOptions, Placement } from '@floating-ui/vue';
1
+ import type { AlignedPlacement, Middleware, OffsetOptions, Side } from '@floating-ui/vue';
2
+ import type { MaybeRefOrGetter } from 'vue';
2
3
  /** The props for the ScalarFloating component */
3
4
  export type FloatingOptions = {
4
5
  /**
@@ -7,7 +8,7 @@ export type FloatingOptions = {
7
8
  *
8
9
  * @see https://floating-ui.com/docs/computePosition#placement
9
10
  */
10
- placement?: Placement;
11
+ placement?: Side | AlignedPlacement;
11
12
  /**
12
13
  * The offset of the floating element relative to its reference element.
13
14
  * @default 5 (5px)
@@ -28,7 +29,7 @@ export type FloatingOptions = {
28
29
  *
29
30
  * Can be a string id or a reference to an element
30
31
  */
31
- target?: string | HTMLElement;
32
+ target?: MaybeRefOrGetter<HTMLElement | string>;
32
33
  /**
33
34
  * Floating UI Middleware to be passed to Floating UI
34
35
  *