@lilydesignsystem/vue-motion-picker 0.2.0 → 0.3.0

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.
package/LICENSE.md ADDED
@@ -0,0 +1,64 @@
1
+ <!-- Synced from the canonical repository by bin/sync-special-files.
2
+ Do not edit here; edit the root copy and re-run the script.
3
+ Canonical: https://github.com/LilyDesignSystem/lily-design-system/blob/main/LICENSE.md -->
4
+
5
+ # License
6
+
7
+ Lily Design System™ is free open source software.
8
+
9
+ License is any of these, at your option, or contact us for custom license options.
10
+
11
+ * [MIT](https://opensource.org/license/mit) ([SPDX: MIT](https://spdx.org/licenses/MIT.html))
12
+
13
+ * [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0) ([SPDX: Apache-2.0](https://spdx.org/licenses/Apache-2.0.html))
14
+
15
+ * [GNU General Public License v2.0](https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html) ([SPDX: GPL-2.0-only](https://spdx.org/licenses/GPL-2.0-only.html))
16
+
17
+ * [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0-standalone.html) ([SPDX: GPL-3.0-only](https://spdx.org/licenses/GPL-3.0-only.html))
18
+
19
+ * [BSD 3-Clause License](https://opensource.org/license/bsd-3-clause) ([SPDX: BSD-3-Clause](https://spdx.org/licenses/BSD-3-Clause.html))
20
+
21
+ ## SPDX
22
+
23
+ The machine-readable expression for the choice above is:
24
+
25
+ ```
26
+ SPDX-License-Identifier: MIT OR Apache-2.0 OR GPL-2.0-only OR GPL-3.0-only OR BSD-3-Clause
27
+ ```
28
+
29
+ Every package manifest in this repository should carry that expression, or a
30
+ single identifier from the list where the packaging format does not accept a
31
+ disjunction. You do not need permission to pick one: choose whichever member of
32
+ the list suits your project and comply with that one.
33
+
34
+ This applies to the whole repository — the component catalog, the seven headless
35
+ libraries, the seven example applications, the seven helper catalogs, the
36
+ `themes/` stylesheets, the `bin/` tooling, and the documentation.
37
+
38
+ ## Scope note
39
+
40
+ This file supersedes an earlier `CC BY-NC-SA` notice. That notice was a content
41
+ license with a non-commercial clause, it was not an open-source license, and it
42
+ contradicted both the specification and the published packages. It should not be
43
+ relied on. If you obtained Lily under it and that raises a question for you,
44
+ contact <joel@joelparkerhenderson.com>.
45
+
46
+ ## Trademarks
47
+
48
+ Lily™ and Lily Design System™ are trademarks. The trademarks are distinct from
49
+ the software license: a trademark claim (™) asserts use of the marks and is
50
+ independent of the licenses above. A license to the software is not a license to
51
+ the marks.
52
+
53
+ You may say your project uses Lily, is built with Lily, or is compatible with
54
+ Lily. Please do not use the marks as the name of your fork or product, or in a
55
+ way that suggests affiliation or endorsement. For any use beyond that, contact
56
+ <joel@joelparkerhenderson.com>.
57
+
58
+ ## Third-party references
59
+
60
+ Lily's example applications and `themes/` stylesheets take visual reference from
61
+ public-sector design systems including NHS UK, GOV.UK, and USWDS. Lily is not
62
+ affiliated with, endorsed by, or connected to any of those organisations. Their
63
+ names and marks belong to them, and this license grants nothing in respect of
64
+ them.
@@ -37,6 +37,8 @@ export type Props = {
37
37
  target?: HTMLElement | null;
38
38
  /** Optional pretty labels per slug. */
39
39
  motionLabels?: Record<string, string>;
40
+ /** Disables the button; an open popup closes. The popup's open state is `v-model:open`. */
41
+ disabled?: boolean;
40
42
  /** Extra CSS class on the root element. */
41
43
  class?: string;
42
44
  };
@@ -57,10 +59,19 @@ export declare function prefersReducedMotion(): boolean;
57
59
  export declare function nextMotionPickerId(): string;
58
60
  declare const _default: typeof __VLS_export;
59
61
  export default _default;
60
- declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
62
+ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<Props & {
63
+ /** Is the popup open? Bindable: `v-model:open` (the picker keeps its own state when none is bound). */
64
+ open?: boolean;
65
+ }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
66
+ "update:open": (value: boolean) => any;
67
+ } & {
61
68
  "update:value": (value: string) => any;
62
69
  change: (value: string) => any;
63
- }, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
70
+ }, string, import("vue").PublicProps, Readonly<Props & {
71
+ /** Is the popup open? Bindable: `v-model:open` (the picker keeps its own state when none is bound). */
72
+ open?: boolean;
73
+ }> & Readonly<{
74
+ "onUpdate:open"?: ((value: boolean) => any) | undefined;
64
75
  "onUpdate:value"?: ((value: string) => any) | undefined;
65
76
  onChange?: ((value: string) => any) | undefined;
66
77
  }>, {
@@ -70,6 +81,7 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<Props,
70
81
  name: string;
71
82
  target: HTMLElement | null;
72
83
  motionLabels: Record<string, string>;
84
+ disabled: boolean;
73
85
  class: string;
74
86
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
75
87
  default?: (props: {
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- import { Fragment as e, computed as t, createElementBlock as n, createElementVNode as r, createVNode as i, defineComponent as a, guardReactiveProps as o, nextTick as s, normalizeClass as ee, normalizeProps as c, onBeforeUnmount as l, onMounted as te, openBlock as u, ref as d, renderList as ne, renderSlot as f, toDisplayString as p, unref as m, watch as h, withCtx as g } from "vue";
2
- import { IconButton as _, Listbox as v } from "@lilydesignsystem/vue-headless";
3
- //#region lily-design-system-vue-motion-picker/MotionPicker.vue?vue&type=script&setup=true&lang.ts
4
- var y = ["name", "value"], b = ["hidden"], re = [
1
+ import { Fragment as e, computed as t, createElementBlock as n, createElementVNode as r, createVNode as i, defineComponent as a, guardReactiveProps as o, mergeModels as s, nextTick as c, normalizeClass as l, normalizeProps as ee, onBeforeUnmount as u, onMounted as te, openBlock as d, ref as f, renderList as p, renderSlot as ne, toDisplayString as m, unref as h, useModel as g, watch as _, withCtx as v } from "vue";
2
+ import { IconButton as re, Listbox as y } from "@lilydesignsystem/vue-headless";
3
+ //#region MotionPicker.vue?vue&type=script&setup=true&lang.ts
4
+ var b = ["name", "value"], x = ["hidden"], ie = [
5
5
  "id",
6
6
  "aria-selected",
7
7
  "data-active",
8
8
  "onClick"
9
9
  ];
10
- function x(e) {
10
+ function S(e) {
11
11
  return e.split("-").map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join(" ");
12
12
  }
13
- function S() {
13
+ function C() {
14
14
  if (typeof window > "u" || typeof window.matchMedia != "function") return !1;
15
15
  try {
16
16
  return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
@@ -18,15 +18,15 @@ function S() {
18
18
  return !1;
19
19
  }
20
20
  }
21
- var C = 0;
22
- function w() {
23
- return C += 1, `motion-picker-${C}`;
21
+ var w = 0;
22
+ function T() {
23
+ return w += 1, `motion-picker-${w}`;
24
24
  }
25
25
  //#endregion
26
- //#region lily-design-system-vue-motion-picker/MotionPicker.vue
27
- var T = /* @__PURE__ */ a({
26
+ //#region MotionPicker.vue
27
+ var E = /* @__PURE__ */ a({
28
28
  __name: "MotionPicker",
29
- props: {
29
+ props: /*@__PURE__*/ s({
30
30
  label: {},
31
31
  motions: {},
32
32
  value: { default: "" },
@@ -35,15 +35,29 @@ var T = /* @__PURE__ */ a({
35
35
  name: { default: "motion" },
36
36
  target: { default: void 0 },
37
37
  motionLabels: { default: () => ({}) },
38
+ disabled: {
39
+ type: Boolean,
40
+ default: !1
41
+ },
38
42
  class: { default: "" }
39
- },
40
- emits: ["update:value", "change"],
41
- setup(a, { emit: C }) {
42
- let T = a, E = C, D = w(), O = `${D}-list`, k = (e) => `${D}-option-${e}`, A = d(!1), j = `${D}-tooltip`, M = d(!1), N = d(!1), P = d(!1), F = d(!1), I = t(() => !A.value && !F.value && (M.value || N.value || P.value));
43
- function ie() {
43
+ }, {
44
+ open: {
45
+ type: Boolean,
46
+ default: !1
47
+ },
48
+ openModifiers: {}
49
+ }),
50
+ emits: /*@__PURE__*/ s(["update:value", "change"], ["update:open"]),
51
+ setup(a, { emit: s }) {
52
+ let w = a, E = s, D = T(), O = `${D}-list`, k = (e) => `${D}-option-${e}`, A = g(a, "open");
53
+ _(() => w.disabled, (e) => {
54
+ e && (A.value = !1);
55
+ }, { immediate: !0 });
56
+ let j = `${D}-tooltip`, M = f(!1), N = f(!1), P = f(!1), F = f(!1), I = t(() => !A.value && !F.value && (M.value || N.value || P.value));
57
+ function ae() {
44
58
  M.value = !0, F.value = !1;
45
59
  }
46
- function ae() {
60
+ function oe() {
47
61
  M.value = !1;
48
62
  }
49
63
  function L(e) {
@@ -66,61 +80,61 @@ var T = /* @__PURE__ */ a({
66
80
  function H(e) {
67
81
  typeof document < "u" && e !== V && (V = e, e ? document.addEventListener("keydown", B) : document.removeEventListener("keydown", B));
68
82
  }
69
- h(I, (e) => H(e), { flush: "sync" }), l(() => H(!1));
70
- let U = d(-1), W = d(null), G = d(null), K = d(null);
83
+ _(I, (e) => H(e), { flush: "sync" }), u(() => H(!1));
84
+ let U = f(-1), W = f(null), G = f(null), K = f(null);
71
85
  function q(e) {
72
- let t = T.motionLabels ?? {};
73
- return e in t ? t[e] : x(e);
86
+ let t = w.motionLabels ?? {};
87
+ return e in t ? t[e] : S(e);
74
88
  }
75
89
  function J(e) {
76
90
  if (typeof document < "u" && e) {
77
- if ((T.target ?? document.documentElement).setAttribute("data-motion", e), T.storageKey) try {
78
- localStorage.setItem(T.storageKey, e);
91
+ if ((w.target ?? document.documentElement).setAttribute("data-motion", e), w.storageKey) try {
92
+ localStorage.setItem(w.storageKey, e);
79
93
  } catch {}
80
94
  E("change", e);
81
95
  }
82
96
  }
83
- let Y = d(T.value ?? "");
84
- function oe(e) {
97
+ let Y = f(w.value ?? "");
98
+ function se(e) {
85
99
  Y.value = e, E("update:value", e);
86
100
  }
87
- h(() => T.value, (e) => {
101
+ _(() => w.value, (e) => {
88
102
  e !== void 0 && e !== Y.value && (Y.value = e);
89
- }), h(Y, (e, t) => {
103
+ }), _(Y, (e, t) => {
90
104
  e && e !== t && J(e);
91
105
  });
92
106
  async function X(e) {
93
- let t = T.motions.indexOf(Y.value);
94
- U.value = T.motions.length === 0 ? -1 : e ?? (t >= 0 ? t : 0), A.value = !0, await s(), G.value?.el?.focus({ preventScroll: !0 });
107
+ let t = w.motions.indexOf(Y.value);
108
+ U.value = w.motions.length === 0 ? -1 : e ?? (t >= 0 ? t : 0), A.value = !0, await c(), G.value?.el?.focus({ preventScroll: !0 });
95
109
  }
96
110
  async function Z(e = !0) {
97
- A.value && (A.value = !1, U.value = -1, e && (await s(), W.value?.el?.focus({ preventScroll: !0 })));
111
+ A.value && (A.value = !1, U.value = -1, e && (await c(), W.value?.el?.focus({ preventScroll: !0 })));
98
112
  }
99
113
  function Q(e) {
100
- let t = T.motions[e];
101
- t && oe(t), Z();
114
+ let t = w.motions[e];
115
+ t && se(t), Z();
102
116
  }
103
- function se() {
117
+ function ce() {
104
118
  U.value < 0 || !G.value?.el || document.getElementById(k(U.value))?.scrollIntoView?.({ block: "nearest" });
105
119
  }
106
- h(U, () => se());
107
- function ce() {
120
+ _(U, () => ce());
121
+ function le() {
108
122
  W.value?.el?.focus?.({ preventScroll: !0 }), Z(!1);
109
123
  }
110
- function le() {
124
+ function ue() {
111
125
  M.value = !1, A.value ? Z() : X();
112
126
  }
113
- function ue(e) {
127
+ function de(e) {
114
128
  switch (z(e), e.key) {
115
129
  case "ArrowDown":
116
130
  case "Enter":
117
131
  case " ":
118
132
  e.preventDefault(), X();
119
133
  break;
120
- case "ArrowUp": e.preventDefault(), X(T.motions.length - 1);
134
+ case "ArrowUp": e.preventDefault(), X(w.motions.length - 1);
121
135
  }
122
136
  }
123
- function de(e) {
137
+ function fe(e) {
124
138
  let t = e.relatedTarget;
125
139
  t && K.value?.contains(t) || Z(!1);
126
140
  }
@@ -132,32 +146,29 @@ var T = /* @__PURE__ */ a({
132
146
  return te(() => {
133
147
  document.addEventListener("click", $);
134
148
  let e = Y.value;
135
- if (!e && T.storageKey) try {
136
- e = localStorage.getItem(T.storageKey) ?? "";
149
+ if (!e && w.storageKey) try {
150
+ e = localStorage.getItem(w.storageKey) ?? "";
137
151
  } catch {}
138
152
  if (!e) {
139
- let t = S() ? "reduce" : "no-preference";
140
- e = T.defaultValue ?? (T.motions.includes(t) ? t : void 0) ?? T.motions[0] ?? "";
141
- }
142
- if (e && e !== Y.value) {
143
- Y.value = e, E("update:value", e);
144
- return;
153
+ let t = C() ? "reduce" : "no-preference";
154
+ e = w.defaultValue ?? (w.motions.includes(t) ? t : void 0) ?? w.motions[0] ?? "";
145
155
  }
146
- e && J(e);
147
- }), l(() => {
156
+ e && e !== Y.value ? (Y.value = e, E("update:value", e)) : e && J(e);
157
+ }), u(() => {
148
158
  document.removeEventListener("click", $);
149
- }), (t, s) => (u(), n("div", {
159
+ }), (t, s) => (d(), n("div", {
150
160
  ref_key: "rootEl",
151
161
  ref: K,
152
- class: ee(`motion-picker ${T.class}`.trim()),
153
- onFocusout: de
162
+ class: l(`motion-picker ${w.class}`.trim()),
163
+ onFocusout: fe
154
164
  }, [
155
165
  r("input", {
156
166
  type: "hidden",
157
167
  name: a.name,
158
168
  value: Y.value
159
- }, null, 8, y),
160
- i(m(_), {
169
+ }, null, 8, b),
170
+ i(h(re), {
171
+ disabled: a.disabled,
161
172
  ref_key: "buttonEl",
162
173
  ref: W,
163
174
  baseClass: "motion-picker-button",
@@ -165,14 +176,14 @@ var T = /* @__PURE__ */ a({
165
176
  "aria-haspopup": "listbox",
166
177
  "aria-expanded": A.value ? "true" : "false",
167
178
  "aria-controls": O,
168
- onClick: le,
169
- onKeydown: ue,
170
- onMouseenter: ie,
171
- onMouseleave: ae,
179
+ onClick: ue,
180
+ onKeydown: de,
181
+ onMouseenter: ae,
182
+ onMouseleave: oe,
172
183
  onFocus: L,
173
184
  onBlur: R
174
185
  }, {
175
- default: g(() => [f(t.$slots, "default", c(o({
186
+ default: v(() => [ne(t.$slots, "default", ee(o({
176
187
  value: Y.value,
177
188
  open: A.value,
178
189
  labelFor: q
@@ -189,7 +200,11 @@ var T = /* @__PURE__ */ a({
189
200
  "stroke-linejoin": "round"
190
201
  }, [r("path", { d: "M5 3v10M11 3v10" })], -1)])]),
191
202
  _: 3
192
- }, 8, ["label", "aria-expanded"]),
203
+ }, 8, [
204
+ "disabled",
205
+ "label",
206
+ "aria-expanded"
207
+ ]),
193
208
  r("div", {
194
209
  class: "motion-picker-tooltip",
195
210
  role: "tooltip",
@@ -197,8 +212,8 @@ var T = /* @__PURE__ */ a({
197
212
  hidden: !I.value || void 0,
198
213
  onMouseenter: s[0] ||= (e) => N.value = !0,
199
214
  onMouseleave: s[1] ||= (e) => N.value = !1
200
- }, p(a.label), 41, b),
201
- i(m(v), {
215
+ }, m(a.label), 41, x),
216
+ i(h(y), {
202
217
  ref_key: "listEl",
203
218
  ref: G,
204
219
  as: "ul",
@@ -214,9 +229,9 @@ var T = /* @__PURE__ */ a({
214
229
  hidden: !A.value || void 0,
215
230
  onActivate: Q,
216
231
  onEscape: s[3] ||= () => Z(),
217
- onTabOut: ce
232
+ onTabOut: le
218
233
  }, {
219
- default: g(() => [(u(!0), n(e, null, ne(a.motions, (e, t) => (u(), n("li", {
234
+ default: v(() => [(d(!0), n(e, null, p(a.motions, (e, t) => (d(), n("li", {
220
235
  key: e,
221
236
  class: "motion-picker-option",
222
237
  id: k(t),
@@ -224,7 +239,7 @@ var T = /* @__PURE__ */ a({
224
239
  "aria-selected": e === Y.value ? "true" : "false",
225
240
  "data-active": t === U.value ? "" : void 0,
226
241
  onClick: (e) => Q(t)
227
- }, p(q(e)), 9, re))), 128))]),
242
+ }, m(q(e)), 9, ie))), 128))]),
228
243
  _: 1
229
244
  }, 8, [
230
245
  "label",
@@ -235,4 +250,4 @@ var T = /* @__PURE__ */ a({
235
250
  }
236
251
  });
237
252
  //#endregion
238
- export { T as MotionPicker, T as default, x as motionName, w as nextMotionPickerId, S as prefersReducedMotion };
253
+ export { E as MotionPicker, E as default, S as motionName, T as nextMotionPickerId, C as prefersReducedMotion };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lilydesignsystem/vue-motion-picker",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "engines": {
5
5
  "node": "=26"
6
6
  },
@@ -21,14 +21,27 @@
21
21
  "README.md"
22
22
  ],
23
23
  "scripts": {
24
- "prepublishOnly": "cd .. && npm run build"
24
+ "build": "node build.mjs",
25
+ "test": "vitest run",
26
+ "test:watch": "vitest",
27
+ "prepublishOnly": "npm run build"
25
28
  },
26
29
  "dependencies": {
27
- "@lilydesignsystem/vue-headless": "^0.2.0"
30
+ "@lilydesignsystem/vue-headless": "^0.4.0"
28
31
  },
29
32
  "peerDependencies": {
30
33
  "vue": "^3.0.0"
31
34
  },
35
+ "devDependencies": {
36
+ "@vitejs/plugin-vue": "^6.0.9",
37
+ "@vue/test-utils": "^2.5.1",
38
+ "jsdom": "^30.1.1",
39
+ "typescript": "^5.9.3",
40
+ "vite": "^8.3.1",
41
+ "vitest": "^5.0.3",
42
+ "vue": "^3.5.43",
43
+ "vue-tsc": "^3.3.11"
44
+ },
32
45
  "keywords": [
33
46
  "lily",
34
47
  "design",
@@ -42,7 +55,7 @@
42
55
  "license": "MIT OR Apache-2.0 OR GPL-2.0-only OR GPL-3.0-only OR BSD-3-Clause",
43
56
  "repository": {
44
57
  "type": "git",
45
- "url": "git+https://github.com/LilyDesignSystem/lily-design-system-vue-helpers.git",
58
+ "url": "git+https://github.com/LilyDesignSystem/lily-design-system.git",
46
59
  "directory": "lily-design-system-vue-motion-picker"
47
60
  },
48
61
  "homepage": "https://lilydesignsystem.com/",