@crystal-neuo/vue 0.0.0-stage → 4.0.1
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 +21 -0
- package/README.md +6 -2
- package/dist/Alert.d.ts +24 -0
- package/dist/Alert.d.ts.map +1 -0
- package/dist/Alert.js +6 -0
- package/dist/Alert.js.map +1 -0
- package/dist/Alert.vue_vue_type_script_setup_true_lang.js +41 -0
- package/dist/Alert.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Avatar.d.ts +16 -0
- package/dist/Avatar.d.ts.map +1 -0
- package/dist/Avatar.js +6 -0
- package/dist/Avatar.js.map +1 -0
- package/dist/Avatar.vue_vue_type_script_setup_true_lang.js +33 -0
- package/dist/Avatar.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Badge.d.ts +24 -0
- package/dist/Badge.d.ts.map +1 -0
- package/dist/Badge.js +6 -0
- package/dist/Badge.js.map +1 -0
- package/dist/Badge.vue_vue_type_script_setup_true_lang.js +23 -0
- package/dist/Badge.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Breadcrumb.d.ts +17 -0
- package/dist/Breadcrumb.d.ts.map +1 -0
- package/dist/Breadcrumb.js +6 -0
- package/dist/Breadcrumb.js.map +1 -0
- package/dist/Breadcrumb.vue_vue_type_script_setup_true_lang.js +42 -0
- package/dist/Breadcrumb.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Button.d.ts +34 -0
- package/dist/Button.d.ts.map +1 -0
- package/dist/Button.js +6 -0
- package/dist/Button.js.map +1 -0
- package/dist/Button.vue_vue_type_script_setup_true_lang.js +42 -0
- package/dist/Button.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Card.d.ts +24 -0
- package/dist/Card.d.ts.map +1 -0
- package/dist/Card.js +6 -0
- package/dist/Card.js.map +1 -0
- package/dist/Card.vue_vue_type_script_setup_true_lang.js +23 -0
- package/dist/Card.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Checkbox.d.ts +24 -0
- package/dist/Checkbox.d.ts.map +1 -0
- package/dist/Checkbox.js +6 -0
- package/dist/Checkbox.js.map +1 -0
- package/dist/Checkbox.vue_vue_type_script_setup_true_lang.js +55 -0
- package/dist/Checkbox.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/DatePicker.d.ts +25 -0
- package/dist/DatePicker.d.ts.map +1 -0
- package/dist/DatePicker.js +6 -0
- package/dist/DatePicker.js.map +1 -0
- package/dist/DatePicker.vue_vue_type_script_setup_true_lang.js +62 -0
- package/dist/DatePicker.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Dialog.d.ts +40 -0
- package/dist/Dialog.d.ts.map +1 -0
- package/dist/Dialog.js +6 -0
- package/dist/Dialog.js.map +1 -0
- package/dist/Dialog.vue_vue_type_script_setup_true_lang.js +75 -0
- package/dist/Dialog.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Drawer.d.ts +33 -0
- package/dist/Drawer.d.ts.map +1 -0
- package/dist/Drawer.js +6 -0
- package/dist/Drawer.js.map +1 -0
- package/dist/Drawer.vue_vue_type_script_setup_true_lang.js +47 -0
- package/dist/Drawer.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/FileUpload.d.ts +33 -0
- package/dist/FileUpload.d.ts.map +1 -0
- package/dist/FileUpload.js +6 -0
- package/dist/FileUpload.js.map +1 -0
- package/dist/FileUpload.vue_vue_type_script_setup_true_lang.js +108 -0
- package/dist/FileUpload.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Input.d.ts +27 -0
- package/dist/Input.d.ts.map +1 -0
- package/dist/Input.js +6 -0
- package/dist/Input.js.map +1 -0
- package/dist/Input.vue_vue_type_script_setup_true_lang.js +67 -0
- package/dist/Input.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/List.d.ts +24 -0
- package/dist/List.d.ts.map +1 -0
- package/dist/List.js +6 -0
- package/dist/List.js.map +1 -0
- package/dist/List.vue_vue_type_script_setup_true_lang.js +23 -0
- package/dist/List.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/ListItem.d.ts +19 -0
- package/dist/ListItem.d.ts.map +1 -0
- package/dist/ListItem.js +6 -0
- package/dist/ListItem.js.map +1 -0
- package/dist/ListItem.vue_vue_type_script_setup_true_lang.js +21 -0
- package/dist/ListItem.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Menu.d.ts +25 -0
- package/dist/Menu.d.ts.map +1 -0
- package/dist/Menu.js +6 -0
- package/dist/Menu.js.map +1 -0
- package/dist/Menu.vue_vue_type_script_setup_true_lang.js +94 -0
- package/dist/Menu.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Modal.d.ts +31 -0
- package/dist/Modal.d.ts.map +1 -0
- package/dist/Modal.js +6 -0
- package/dist/Modal.js.map +1 -0
- package/dist/Modal.vue_vue_type_script_setup_true_lang.js +46 -0
- package/dist/Modal.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Nav.d.ts +23 -0
- package/dist/Nav.d.ts.map +1 -0
- package/dist/Nav.js +6 -0
- package/dist/Nav.js.map +1 -0
- package/dist/Nav.vue_vue_type_script_setup_true_lang.js +24 -0
- package/dist/Nav.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/NavLink.d.ts +21 -0
- package/dist/NavLink.d.ts.map +1 -0
- package/dist/NavLink.js +6 -0
- package/dist/NavLink.js.map +1 -0
- package/dist/NavLink.vue_vue_type_script_setup_true_lang.js +29 -0
- package/dist/NavLink.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Pagination.d.ts +24 -0
- package/dist/Pagination.d.ts.map +1 -0
- package/dist/Pagination.js +6 -0
- package/dist/Pagination.js.map +1 -0
- package/dist/Pagination.vue_vue_type_script_setup_true_lang.js +84 -0
- package/dist/Pagination.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Progress.d.ts +19 -0
- package/dist/Progress.d.ts.map +1 -0
- package/dist/Progress.js +6 -0
- package/dist/Progress.js.map +1 -0
- package/dist/Progress.vue_vue_type_script_setup_true_lang.js +40 -0
- package/dist/Progress.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Radio.d.ts +29 -0
- package/dist/Radio.d.ts.map +1 -0
- package/dist/Radio.js +6 -0
- package/dist/Radio.js.map +1 -0
- package/dist/Radio.vue_vue_type_script_setup_true_lang.js +51 -0
- package/dist/Radio.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/SegmentedControl.d.ts +32 -0
- package/dist/SegmentedControl.d.ts.map +1 -0
- package/dist/SegmentedControl.js +6 -0
- package/dist/SegmentedControl.js.map +1 -0
- package/dist/SegmentedControl.vue_vue_type_script_setup_true_lang.js +47 -0
- package/dist/SegmentedControl.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Select.d.ts +29 -0
- package/dist/Select.d.ts.map +1 -0
- package/dist/Select.js +6 -0
- package/dist/Select.js.map +1 -0
- package/dist/Select.vue_vue_type_script_setup_true_lang.js +69 -0
- package/dist/Select.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Sheet.d.ts +28 -0
- package/dist/Sheet.d.ts.map +1 -0
- package/dist/Sheet.js +6 -0
- package/dist/Sheet.js.map +1 -0
- package/dist/Sheet.vue_vue_type_script_setup_true_lang.js +52 -0
- package/dist/Sheet.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Skeleton.d.ts +14 -0
- package/dist/Skeleton.d.ts.map +1 -0
- package/dist/Skeleton.js +6 -0
- package/dist/Skeleton.js.map +1 -0
- package/dist/Skeleton.vue_vue_type_script_setup_true_lang.js +24 -0
- package/dist/Skeleton.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Slider.d.ts +29 -0
- package/dist/Slider.d.ts.map +1 -0
- package/dist/Slider.js +6 -0
- package/dist/Slider.js.map +1 -0
- package/dist/Slider.vue_vue_type_script_setup_true_lang.js +61 -0
- package/dist/Slider.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/TabBar.d.ts +27 -0
- package/dist/TabBar.d.ts.map +1 -0
- package/dist/TabBar.js +6 -0
- package/dist/TabBar.js.map +1 -0
- package/dist/TabBar.vue_vue_type_script_setup_true_lang.js +33 -0
- package/dist/TabBar.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Table.d.ts +32 -0
- package/dist/Table.d.ts.map +1 -0
- package/dist/Table.js +6 -0
- package/dist/Table.js.map +1 -0
- package/dist/Table.vue_vue_type_script_setup_true_lang.js +33 -0
- package/dist/Table.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Tabs.d.ts +39 -0
- package/dist/Tabs.d.ts.map +1 -0
- package/dist/Tabs.js +6 -0
- package/dist/Tabs.js.map +1 -0
- package/dist/Tabs.vue_vue_type_script_setup_true_lang.js +82 -0
- package/dist/Tabs.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Textarea.d.ts +26 -0
- package/dist/Textarea.d.ts.map +1 -0
- package/dist/Textarea.js +6 -0
- package/dist/Textarea.js.map +1 -0
- package/dist/Textarea.vue_vue_type_script_setup_true_lang.js +67 -0
- package/dist/Textarea.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Toast.d.ts +31 -0
- package/dist/Toast.d.ts.map +1 -0
- package/dist/Toast.js +6 -0
- package/dist/Toast.js.map +1 -0
- package/dist/Toast.vue_vue_type_script_setup_true_lang.js +75 -0
- package/dist/Toast.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Toggle.d.ts +22 -0
- package/dist/Toggle.d.ts.map +1 -0
- package/dist/Toggle.js +6 -0
- package/dist/Toggle.js.map +1 -0
- package/dist/Toggle.vue_vue_type_script_setup_true_lang.js +48 -0
- package/dist/Toggle.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/Tooltip.d.ts +22 -0
- package/dist/Tooltip.d.ts.map +1 -0
- package/dist/Tooltip.js +6 -0
- package/dist/Tooltip.js.map +1 -0
- package/dist/Tooltip.vue_vue_type_script_setup_true_lang.js +36 -0
- package/dist/Tooltip.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/cn.d.ts +2 -0
- package/dist/cn.d.ts.map +1 -0
- package/dist/cn.js +7 -0
- package/dist/cn.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/useControlAttrs.d.ts +16 -0
- package/dist/useControlAttrs.d.ts.map +1 -0
- package/dist/useControlAttrs.js +18 -0
- package/dist/useControlAttrs.js.map +1 -0
- package/dist/useFocusTrap.d.ts +10 -0
- package/dist/useFocusTrap.d.ts.map +1 -0
- package/dist/useFocusTrap.js +37 -0
- package/dist/useFocusTrap.js.map +1 -0
- package/dist/useModalDialog.d.ts +12 -0
- package/dist/useModalDialog.d.ts.map +1 -0
- package/dist/useModalDialog.js +29 -0
- package/dist/useModalDialog.js.map +1 -0
- package/package.json +42 -4
- package/src/Alert.vue +31 -0
- package/src/Avatar.vue +35 -0
- package/src/Badge.vue +21 -0
- package/src/Breadcrumb.vue +34 -0
- package/src/Button.vue +38 -0
- package/src/Card.vue +21 -0
- package/src/Checkbox.vue +56 -0
- package/src/DatePicker.vue +51 -0
- package/src/Dialog.vue +73 -0
- package/src/Drawer.vue +55 -0
- package/src/FileUpload.vue +107 -0
- package/src/Input.vue +58 -0
- package/src/List.vue +23 -0
- package/src/ListItem.vue +12 -0
- package/src/Menu.vue +132 -0
- package/src/Modal.vue +44 -0
- package/src/Nav.vue +18 -0
- package/src/NavLink.vue +20 -0
- package/src/Pagination.vue +69 -0
- package/src/Progress.vue +41 -0
- package/src/Radio.vue +53 -0
- package/src/SegmentedControl.vue +53 -0
- package/src/Select.vue +62 -0
- package/src/Sheet.vue +40 -0
- package/src/Skeleton.vue +18 -0
- package/src/Slider.vue +49 -0
- package/src/TabBar.vue +39 -0
- package/src/Table.vue +47 -0
- package/src/Tabs.vue +95 -0
- package/src/Textarea.vue +58 -0
- package/src/Toast.vue +83 -0
- package/src/Toggle.vue +45 -0
- package/src/Tooltip.vue +39 -0
- package/src/cn.ts +5 -0
- package/src/index.ts +47 -0
- package/src/shims-vue.d.ts +5 -0
- package/src/useControlAttrs.ts +18 -0
- package/src/useFocusTrap.ts +74 -0
- package/src/useModalDialog.ts +65 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { cn as e } from "./cn.js";
|
|
2
|
+
import t from "./Button.js";
|
|
3
|
+
import n from "./Card.js";
|
|
4
|
+
import r from "./Input.js";
|
|
5
|
+
import i from "./Toggle.js";
|
|
6
|
+
import a from "./Nav.js";
|
|
7
|
+
import o from "./NavLink.js";
|
|
8
|
+
import { useModalDialog as s } from "./useModalDialog.js";
|
|
9
|
+
import c from "./Modal.js";
|
|
10
|
+
import l from "./Tabs.js";
|
|
11
|
+
import u from "./Tooltip.js";
|
|
12
|
+
import d from "./Badge.js";
|
|
13
|
+
import f from "./Select.js";
|
|
14
|
+
import p from "./Checkbox.js";
|
|
15
|
+
import m from "./Radio.js";
|
|
16
|
+
import h from "./Slider.js";
|
|
17
|
+
import g from "./DatePicker.js";
|
|
18
|
+
import _ from "./Textarea.js";
|
|
19
|
+
import v from "./FileUpload.js";
|
|
20
|
+
import y from "./Table.js";
|
|
21
|
+
import b from "./List.js";
|
|
22
|
+
import x from "./ListItem.js";
|
|
23
|
+
import S from "./Avatar.js";
|
|
24
|
+
import C from "./Progress.js";
|
|
25
|
+
import w from "./Skeleton.js";
|
|
26
|
+
import T from "./Breadcrumb.js";
|
|
27
|
+
import E from "./Pagination.js";
|
|
28
|
+
import D from "./Toast.js";
|
|
29
|
+
import O from "./Alert.js";
|
|
30
|
+
import k from "./Dialog.js";
|
|
31
|
+
import A from "./Drawer.js";
|
|
32
|
+
import j from "./SegmentedControl.js";
|
|
33
|
+
import M from "./Sheet.js";
|
|
34
|
+
import N from "./TabBar.js";
|
|
35
|
+
import P from "./Menu.js";
|
|
36
|
+
import { useFocusTrap as F } from "./useFocusTrap.js";
|
|
37
|
+
export { O as Alert, S as Avatar, d as Badge, T as Breadcrumb, t as Button, n as Card, p as Checkbox, g as DatePicker, k as Dialog, A as Drawer, v as FileUpload, r as Input, b as List, x as ListItem, P as Menu, c as Modal, a as Nav, o as NavLink, E as Pagination, C as Progress, m as Radio, j as SegmentedControl, f as Select, M as Sheet, w as Skeleton, h as Slider, N as TabBar, y as Table, l as Tabs, _ as Textarea, D as Toast, i as Toggle, u as Tooltip, e as cn, F as useFocusTrap, s as useModalDialog };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits fallthrough attributes for a field component: `class` and `style`
|
|
3
|
+
* stay on the wrapper, everything else (`name`, `required`, `autocomplete`,
|
|
4
|
+
* listeners, …) goes to the native control so forms and validation work.
|
|
5
|
+
* Pair with `defineOptions({ inheritAttrs: false })`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useControlAttrs(): {
|
|
8
|
+
rootAttrs: import("vue").ComputedRef<{
|
|
9
|
+
class: import("vue").ClassValue;
|
|
10
|
+
style: import("vue").StyleValue;
|
|
11
|
+
}>;
|
|
12
|
+
controlAttrs: import("vue").ComputedRef<{
|
|
13
|
+
[x: string]: unknown;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=useControlAttrs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useControlAttrs.d.ts","sourceRoot":"","sources":["../src/useControlAttrs.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,eAAe;;;;;;;;EAS9B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { computed as e, useAttrs as t } from "vue";
|
|
2
|
+
// src/useControlAttrs.ts
|
|
3
|
+
function n() {
|
|
4
|
+
let n = t();
|
|
5
|
+
return {
|
|
6
|
+
rootAttrs: e(() => ({
|
|
7
|
+
class: n.class,
|
|
8
|
+
style: n.style
|
|
9
|
+
})),
|
|
10
|
+
controlAttrs: e(() => {
|
|
11
|
+
let { class: e, style: t, ...r } = n;
|
|
12
|
+
return r;
|
|
13
|
+
})
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export { n as useControlAttrs };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=useControlAttrs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useControlAttrs.js","names":["useControlAttrs","attrs","useAttrs","computed","_class","_style","rest"],"sources":["../src/useControlAttrs.ts"],"sourcesContent":["import { computed, useAttrs } from \"vue\";\n\n/**\n * Splits fallthrough attributes for a field component: `class` and `style`\n * stay on the wrapper, everything else (`name`, `required`, `autocomplete`,\n * listeners, …) goes to the native control so forms and validation work.\n * Pair with `defineOptions({ inheritAttrs: false })`.\n */\nexport function useControlAttrs() {\n const attrs = useAttrs();\n return {\n rootAttrs: computed(() => ({ class: attrs.class, style: attrs.style })),\n controlAttrs: computed(() => {\n const { class: _class, style: _style, ...rest } = attrs;\n return rest;\n }),\n };\n}\n"],"mappings":";;AAQA,SAAgBA,IAAkB;CAChC,IAAMC,IAAQC,EAAS;CACvB,OAAO;EACL,WAAWC,SAAgB;GAAE,OAAOF,EAAM;GAAO,OAAOA,EAAM;EAAM,EAAE;EACtE,cAAcE,QAAe;GAC3B,IAAM,EAAE,OAAOC,GAAQ,OAAOC,GAAQ,GAAGC,MAASL;GAClD,OAAOK;EACT,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Ref } from "vue";
|
|
2
|
+
/**
|
|
3
|
+
* Traps focus inside `el` while `active`, closes on Escape, restores focus on
|
|
4
|
+
* deactivate. Mirrors the React useFocusTrap.
|
|
5
|
+
*
|
|
6
|
+
* For non-modal surfaces that cannot be a native `<dialog>`. Modal, Dialog,
|
|
7
|
+
* and Drawer use `useModalDialog`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useFocusTrap(el: Ref<HTMLElement | null>, active: Ref<boolean>, onClose: () => void): void;
|
|
10
|
+
//# sourceMappingURL=useFocusTrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusTrap.d.ts","sourceRoot":"","sources":["../src/useFocusTrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAmC,MAAM,KAAK,CAAC;AAKhE;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI,CA6DzG"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { nextTick as e, onScopeDispose as t, watch as n } from "vue";
|
|
2
|
+
// src/useFocusTrap.ts
|
|
3
|
+
var r = "a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
|
|
4
|
+
function i(i, a, o) {
|
|
5
|
+
let s = null, c = null;
|
|
6
|
+
function l(e) {
|
|
7
|
+
return Array.from(e.querySelectorAll(r));
|
|
8
|
+
}
|
|
9
|
+
function u(e) {
|
|
10
|
+
if (e.defaultPrevented || !c) return;
|
|
11
|
+
if (e.key === "Escape") {
|
|
12
|
+
e.preventDefault(), o();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (e.key !== "Tab") return;
|
|
16
|
+
let t = l(c);
|
|
17
|
+
if (t.length === 0) {
|
|
18
|
+
e.preventDefault();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
let n = t[0], r = t[t.length - 1];
|
|
22
|
+
e.shiftKey && (document.activeElement === n || document.activeElement === c) ? (e.preventDefault(), r.focus()) : !e.shiftKey && document.activeElement === r && (e.preventDefault(), n.focus());
|
|
23
|
+
}
|
|
24
|
+
function d() {
|
|
25
|
+
c && (c.removeEventListener("keydown", u), c = null, s?.focus?.());
|
|
26
|
+
}
|
|
27
|
+
n(a, async (t) => {
|
|
28
|
+
if (typeof document > "u") return;
|
|
29
|
+
if (!t) return d();
|
|
30
|
+
s = document.activeElement, await e();
|
|
31
|
+
let n = i.value;
|
|
32
|
+
n && a.value && (c = n, n.addEventListener("keydown", u), n.hasAttribute("tabindex") || n.setAttribute("tabindex", "-1"), (l(n)[0] ?? n).focus());
|
|
33
|
+
}, { immediate: !0 }), t(d);
|
|
34
|
+
}
|
|
35
|
+
export { i as useFocusTrap };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=useFocusTrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusTrap.js","names":["FOCUSABLE","useFocusTrap","previouslyFocused","trapped","focusables","node","onKey","onClose","items","first","last","release","watch","active","isActive","nextTick","el","onScopeDispose"],"sources":["../src/useFocusTrap.ts"],"sourcesContent":["import { type Ref, nextTick, onScopeDispose, watch } from \"vue\";\n\nconst FOCUSABLE =\n 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Traps focus inside `el` while `active`, closes on Escape, restores focus on\n * deactivate. Mirrors the React useFocusTrap.\n *\n * For non-modal surfaces that cannot be a native `<dialog>`. Modal, Dialog,\n * and Drawer use `useModalDialog`.\n */\nexport function useFocusTrap(el: Ref<HTMLElement | null>, active: Ref<boolean>, onClose: () => void): void {\n let previouslyFocused: HTMLElement | null = null;\n let trapped: HTMLElement | null = null;\n\n function focusables(node: HTMLElement): HTMLElement[] {\n return Array.from(node.querySelectorAll<HTMLElement>(FOCUSABLE));\n }\n\n function onKey(e: KeyboardEvent) {\n // A nested surface already handled this key.\n if (e.defaultPrevented || !trapped) return;\n if (e.key === \"Escape\") {\n e.preventDefault();\n onClose();\n return;\n }\n if (e.key !== \"Tab\") return;\n const items = focusables(trapped);\n if (items.length === 0) {\n e.preventDefault();\n return;\n }\n const first = items[0]!;\n const last = items[items.length - 1]!;\n if (e.shiftKey && (document.activeElement === first || document.activeElement === trapped)) {\n e.preventDefault();\n last.focus();\n } else if (!e.shiftKey && document.activeElement === last) {\n e.preventDefault();\n first.focus();\n }\n }\n\n function release() {\n if (!trapped) return;\n trapped.removeEventListener(\"keydown\", onKey);\n trapped = null;\n previouslyFocused?.focus?.();\n }\n\n watch(\n active,\n async (isActive) => {\n // `immediate` runs during setup, which includes SSR.\n if (typeof document === \"undefined\") return;\n if (!isActive) return release();\n previouslyFocused = document.activeElement as HTMLElement | null;\n await nextTick();\n const node = el.value;\n if (!node || !active.value) return;\n trapped = node;\n // Listen on the trapped node so Escape is scoped to the focused surface.\n node.addEventListener(\"keydown\", onKey);\n if (!node.hasAttribute(\"tabindex\")) node.setAttribute(\"tabindex\", \"-1\");\n (focusables(node)[0] ?? node).focus();\n },\n { immediate: true },\n );\n\n // Unmounting while active must not leave a listener behind.\n onScopeDispose(release);\n}\n"],"mappings":";;AAEA,IAAMA,IACJ;AASF,SAAgBC,EAAa,GAA6B,GAAsB,GAA2B;CACzG,IAAIC,IAAwC,MACxCC,IAA8B;CAElC,SAASC,EAAW,GAAkC;EACpD,OAAO,MAAM,KAAKC,EAAK,iBAA8BL,CAAS,CAAC;CACjE;CAEA,SAASM,EAAM,GAAkB;EAE/B,IAAI,EAAE,oBAAoB,CAACH,GAAS;EACpC,IAAI,EAAE,QAAQ,UAAU;GAEtB,AADA,EAAE,eAAe,GACjBI,EAAQ;GACR;EACF;EACA,IAAI,EAAE,QAAQ,OAAO;EACrB,IAAMC,IAAQJ,EAAWD,CAAO;EAChC,IAAIK,EAAM,WAAW,GAAG;GACtB,EAAE,eAAe;GACjB;EACF;EACA,IAAMC,IAAQD,EAAM,IACdE,IAAOF,EAAMA,EAAM,SAAS;EAClC,AAAI,EAAE,aAAa,SAAS,kBAAkBC,KAAS,SAAS,kBAAkBN,MAChF,EAAE,eAAe,GACjBO,EAAK,MAAM,KACF,CAAC,EAAE,YAAY,SAAS,kBAAkBA,MACnD,EAAE,eAAe,GACjBD,EAAM,MAAM;CAEhB;CAEA,SAASE,IAAU;EACjB,AAAKR,MACLA,EAAQ,oBAAoB,WAAWG,CAAK,GAC5C,IAAU,MACVJ,GAAmB,QAAQ;CAC7B;CAsBA,AApBAU,EACEC,GACA,OAAO,MAAa;EAElB,IAAI,OAAO,WAAa,KAAa;EACrC,IAAI,CAACC,GAAU,OAAOH,EAAQ;EAE9B,AADA,IAAoB,SAAS,eAC7B,MAAMI,EAAS;EACf,IAAMV,IAAOW,EAAG;EAChB,AAAKX,KAASQ,EAAO,UACrB,IAAUR,GAEVA,EAAK,iBAAiB,WAAWC,CAAK,GACjCD,EAAK,aAAa,UAAU,KAAGA,EAAK,aAAa,YAAY,IAAI,IACrED,EAAWC,CAAI,CAAC,CAAC,MAAMA,EAAA,CAAM,MAAM;CACtC,GACA,EAAE,WAAW,GAAK,CACpB,GAGAY,EAAeN,CAAO;AACxB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Ref } from "vue";
|
|
2
|
+
/**
|
|
3
|
+
* Drives a native `<dialog>` as a modal overlay from a two-way `open` model.
|
|
4
|
+
* Mirrors the React useModalDialog so Modal/Dialog/Drawer behave identically
|
|
5
|
+
* across frameworks.
|
|
6
|
+
*
|
|
7
|
+
* `showModal()` makes the rest of the page inert, renders in the top layer
|
|
8
|
+
* (no teleport needed), routes Escape to the topmost dialog only, and returns
|
|
9
|
+
* focus to the opener on close.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useModalDialog(el: Ref<HTMLDialogElement | null>, open: Ref<boolean>): void;
|
|
12
|
+
//# sourceMappingURL=useModalDialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useModalDialog.d.ts","sourceRoot":"","sources":["../src/useModalDialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAA+C,MAAM,KAAK,CAAC;AAa5E;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,GAAG,CAAC,iBAAiB,GAAG,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,CA0C1F"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { nextTick as e, onBeforeUnmount as t, onMounted as n, watch as r } from "vue";
|
|
2
|
+
// src/useModalDialog.ts
|
|
3
|
+
function i(e, t) {
|
|
4
|
+
let n = document.activeElement;
|
|
5
|
+
(!n || n === document.body || e.contains(n)) && t?.isConnected && t.focus();
|
|
6
|
+
}
|
|
7
|
+
function a(a, o) {
|
|
8
|
+
let s = null;
|
|
9
|
+
function c() {
|
|
10
|
+
let e = a.value;
|
|
11
|
+
e && (o.value && !e.open ? (s = document.activeElement, e.showModal()) : !o.value && e.open && (e.close(), i(e, s)));
|
|
12
|
+
}
|
|
13
|
+
function l(e) {
|
|
14
|
+
e.preventDefault(), o.value = !1;
|
|
15
|
+
}
|
|
16
|
+
function u() {
|
|
17
|
+
o.value &&= !1;
|
|
18
|
+
}
|
|
19
|
+
n(() => {
|
|
20
|
+
let e = a.value;
|
|
21
|
+
e && (e.addEventListener("cancel", l), e.addEventListener("close", u), c());
|
|
22
|
+
}), r(o, () => e(c)), t(() => {
|
|
23
|
+
let e = a.value;
|
|
24
|
+
e && (e.removeEventListener("cancel", l), e.removeEventListener("close", u), e.open && e.close());
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export { a as useModalDialog };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=useModalDialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useModalDialog.js","names":["restoreFocus","active","dialog","opener","useModalDialog","sync","el","open","onCancel","onNativeClose","onMounted","watch","nextTick","onBeforeUnmount"],"sources":["../src/useModalDialog.ts"],"sourcesContent":["import { type Ref, nextTick, onBeforeUnmount, onMounted, watch } from \"vue\";\n\n/**\n * The platform returns focus to the opener only if focus is still inside the\n * dialog when it closes. The slot content has already unmounted by then (focus\n * fell to <body>), so restore explicitly unless focus has moved on elsewhere.\n */\nfunction restoreFocus(dialog: HTMLElement, opener: HTMLElement | null): void {\n const active = document.activeElement;\n const lost = !active || active === document.body || dialog.contains(active);\n if (lost && opener?.isConnected) opener.focus();\n}\n\n/**\n * Drives a native `<dialog>` as a modal overlay from a two-way `open` model.\n * Mirrors the React useModalDialog so Modal/Dialog/Drawer behave identically\n * across frameworks.\n *\n * `showModal()` makes the rest of the page inert, renders in the top layer\n * (no teleport needed), routes Escape to the topmost dialog only, and returns\n * focus to the opener on close.\n */\nexport function useModalDialog(el: Ref<HTMLDialogElement | null>, open: Ref<boolean>): void {\n let opener: HTMLElement | null = null;\n\n function sync() {\n const dialog = el.value;\n if (!dialog) return;\n if (open.value && !dialog.open) {\n opener = document.activeElement as HTMLElement | null;\n dialog.showModal();\n } else if (!open.value && dialog.open) {\n dialog.close();\n restoreFocus(dialog, opener);\n }\n }\n\n // Escape fires `cancel`; keep the dialog open until the model says so.\n function onCancel(e: Event) {\n e.preventDefault();\n open.value = false;\n }\n // The browser may still close the dialog itself; keep the model in step.\n function onNativeClose() {\n if (open.value) open.value = false;\n }\n\n onMounted(() => {\n const dialog = el.value;\n if (!dialog) return;\n dialog.addEventListener(\"cancel\", onCancel);\n dialog.addEventListener(\"close\", onNativeClose);\n // Covers a dialog that mounts already open.\n sync();\n });\n // Wait for the slot content to render so showModal() can focus into it.\n watch(open, () => nextTick(sync));\n onBeforeUnmount(() => {\n const dialog = el.value;\n if (!dialog) return;\n dialog.removeEventListener(\"cancel\", onCancel);\n dialog.removeEventListener(\"close\", onNativeClose);\n if (dialog.open) dialog.close();\n });\n}\n"],"mappings":";;AAOA,SAASA,EAAa,GAAqB,GAAkC;CAC3E,IAAMC,IAAS,SAAS;CAExB,CADa,CAACA,KAAUA,MAAW,SAAS,QAAQC,EAAO,SAASD,CAAM,MAC9DE,GAAQ,eAAaA,EAAO,MAAM;AAChD;AAWA,SAAgBC,EAAe,GAAmC,GAA0B;CAC1F,IAAID,IAA6B;CAEjC,SAASE,IAAO;EACd,IAAMH,IAASI,EAAG;EAClB,AAAKJ,MACDK,EAAK,SAAS,CAACL,EAAO,QACxB,IAAS,SAAS,eAClBA,EAAO,UAAU,KACR,CAACK,EAAK,SAASL,EAAO,SAC/BA,EAAO,MAAM,GACbF,EAAaE,GAAQC,CAAM;CAE/B;CAGA,SAASK,EAAS,GAAU;EAE1B,AADA,EAAE,eAAe,GACjB,EAAK,QAAQ;CACf;CAEA,SAASC,IAAgB;EACvB,AAAgBF,EAAK,UAAQ;CAC/B;CAYA,AAVAG,QAAgB;EACd,IAAMR,IAASI,EAAG;EAClB,AAAKJ,MACLA,EAAO,iBAAiB,UAAUM,CAAQ,GAC1CN,EAAO,iBAAiB,SAASO,CAAa,GAE9CJ,EAAK;CACP,CAAC,GAEDM,EAAMJ,SAAYK,EAASP,CAAI,CAAC,GAChCQ,QAAsB;EACpB,IAAMX,IAASI,EAAG;EAClB,AAAKJ,MACLA,EAAO,oBAAoB,UAAUM,CAAQ,GAC7CN,EAAO,oBAAoB,SAASO,CAAa,GAC7CP,EAAO,QAAMA,EAAO,MAAM;CAChC,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crystal-neuo/vue",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.0.1",
|
|
4
|
+
"description": "Crystal Neuo Vue 3 components (Composition API, <script setup>, TS). API parity with @crystal-neuo/react via @crystal-neuo/contract.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/AnoRebel/crystal-neuo.git",
|
|
9
|
+
"directory": "packages/vue"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://crystal-neuo.anorebel.net",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"src"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"source": "./src/index.ts",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "bun run build-vue.ts",
|
|
26
|
+
"typecheck": "vue-tsc --noEmit"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"vue": ">=3.4"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@crystal-neuo/contract": "4.0.1",
|
|
33
|
+
"@crystal-neuo/css": "4.0.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"typescript": "^6.0.3",
|
|
37
|
+
"vue": "^3.5.44",
|
|
38
|
+
"vue-tsc": "^3.3.13",
|
|
39
|
+
"vite": "^8.3.5",
|
|
40
|
+
"@vitejs/plugin-vue": "^6.0.10",
|
|
41
|
+
"@types/bun": "1.4.4"
|
|
42
|
+
},
|
|
43
|
+
"sideEffects": false
|
|
44
|
+
}
|
package/src/Alert.vue
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import type { AlertVariant, Material } from "@crystal-neuo/contract";
|
|
4
|
+
import { cn } from "./cn.ts";
|
|
5
|
+
|
|
6
|
+
const props = withDefaults(
|
|
7
|
+
defineProps<{
|
|
8
|
+
material?: Material;
|
|
9
|
+
variant?: AlertVariant;
|
|
10
|
+
title?: string;
|
|
11
|
+
live?: boolean;
|
|
12
|
+
class?: string;
|
|
13
|
+
}>(),
|
|
14
|
+
{ variant: "info" },
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const classes = computed(() => cn("cn-alert", `cn-alert--${props.variant}`, props.class));
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<template>
|
|
21
|
+
<div data-slot="alert" :data-material="props.material" :role="live ? 'alert' : 'note'" :class="classes">
|
|
22
|
+
<svg class="cn-alert__icon" viewBox="0 0 20 20" aria-hidden="true">
|
|
23
|
+
<circle cx="10" cy="10" r="8" fill="none" stroke="currentColor" stroke-width="1.5" />
|
|
24
|
+
<path d="M10 6v5M10 14h.01" stroke="currentColor" stroke-width="1.5" fill="none" />
|
|
25
|
+
</svg>
|
|
26
|
+
<div>
|
|
27
|
+
<strong v-if="title">{{ title }}</strong>
|
|
28
|
+
<div><slot /></div>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</template>
|
package/src/Avatar.vue
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import type { AvatarVariant, AvatarSize, Material } from "@crystal-neuo/contract";
|
|
4
|
+
import { cn } from "./cn.ts";
|
|
5
|
+
|
|
6
|
+
const props = withDefaults(
|
|
7
|
+
defineProps<{
|
|
8
|
+
material?: Material;
|
|
9
|
+
variant?: AvatarVariant;
|
|
10
|
+
size?: AvatarSize;
|
|
11
|
+
src?: string;
|
|
12
|
+
name: string;
|
|
13
|
+
class?: string;
|
|
14
|
+
}>(),
|
|
15
|
+
{ variant: "circle", size: "md" },
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const classes = computed(() =>
|
|
19
|
+
cn("cn-avatar", `cn-avatar--${props.variant}`, `cn-avatar--size-${props.size}`, props.class),
|
|
20
|
+
);
|
|
21
|
+
const initials = computed(() =>
|
|
22
|
+
props.name
|
|
23
|
+
.split(/\s+/)
|
|
24
|
+
.slice(0, 2)
|
|
25
|
+
.map((p) => p.charAt(0).toUpperCase())
|
|
26
|
+
.join(""),
|
|
27
|
+
);
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<template>
|
|
31
|
+
<span data-slot="avatar" :data-material="props.material" :class="classes">
|
|
32
|
+
<img v-if="src" :src="src" :alt="name" />
|
|
33
|
+
<span v-else role="img" :aria-label="name">{{ initials }}</span>
|
|
34
|
+
</span>
|
|
35
|
+
</template>
|
package/src/Badge.vue
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import type { BadgeVariant, BadgeSize, Material } from "@crystal-neuo/contract";
|
|
4
|
+
import { cn } from "./cn.ts";
|
|
5
|
+
|
|
6
|
+
const props = withDefaults(
|
|
7
|
+
defineProps<{ material?: Material; variant?: BadgeVariant; size?: BadgeSize; class?: string }>(),
|
|
8
|
+
{
|
|
9
|
+
variant: "neutral",
|
|
10
|
+
size: "md",
|
|
11
|
+
},
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const classes = computed(() =>
|
|
15
|
+
cn("cn-badge", `cn-badge--${props.variant}`, `cn-badge--size-${props.size}`, props.class),
|
|
16
|
+
);
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<span data-slot="badge" :data-material="props.material" :class="classes"><slot /></span>
|
|
21
|
+
</template>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import type { BreadcrumbSize, Material } from "@crystal-neuo/contract";
|
|
4
|
+
import { cn } from "./cn.ts";
|
|
5
|
+
|
|
6
|
+
export interface Crumb {
|
|
7
|
+
label: string;
|
|
8
|
+
href?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(
|
|
12
|
+
defineProps<{ material?: Material; size?: BreadcrumbSize; items: Crumb[]; class?: string }>(),
|
|
13
|
+
{
|
|
14
|
+
size: "md",
|
|
15
|
+
},
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const classes = computed(() => cn("cn-breadcrumb", `cn-breadcrumb--size-${props.size}`, props.class));
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<nav data-slot="breadcrumb" :data-material="props.material" aria-label="Breadcrumb" :class="classes">
|
|
23
|
+
<ol class="cn-breadcrumb__list">
|
|
24
|
+
<li v-for="(c, i) in items" :key="i" class="cn-breadcrumb__item">
|
|
25
|
+
<span v-if="i === items.length - 1" class="cn-breadcrumb__current" aria-current="page">
|
|
26
|
+
{{ c.label }}
|
|
27
|
+
</span>
|
|
28
|
+
<span v-else-if="!c.href" class="cn-breadcrumb__text">{{ c.label }}</span>
|
|
29
|
+
<a v-else class="cn-breadcrumb__link" :href="c.href">{{ c.label }}</a>
|
|
30
|
+
<span v-if="i !== items.length - 1" class="cn-breadcrumb__sep" aria-hidden="true">/</span>
|
|
31
|
+
</li>
|
|
32
|
+
</ol>
|
|
33
|
+
</nav>
|
|
34
|
+
</template>
|
package/src/Button.vue
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import type { ButtonVariant, ButtonSize, Material } from "@crystal-neuo/contract";
|
|
4
|
+
import { cn } from "./cn.ts";
|
|
5
|
+
|
|
6
|
+
const props = withDefaults(
|
|
7
|
+
defineProps<{
|
|
8
|
+
material?: Material;
|
|
9
|
+
variant?: ButtonVariant;
|
|
10
|
+
size?: ButtonSize;
|
|
11
|
+
loading?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
type?: "button" | "submit" | "reset";
|
|
14
|
+
class?: string;
|
|
15
|
+
}>(),
|
|
16
|
+
{ variant: "primary", size: "md", loading: false, disabled: false, type: "button" },
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
defineEmits<{ click: [event: MouseEvent] }>();
|
|
20
|
+
|
|
21
|
+
const classes = computed(() =>
|
|
22
|
+
cn("cn-button", `cn-button--${props.variant}`, `cn-button--size-${props.size}`, props.class),
|
|
23
|
+
);
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<button
|
|
28
|
+
data-slot="button"
|
|
29
|
+
:data-material="props.material"
|
|
30
|
+
:class="classes"
|
|
31
|
+
:type="type"
|
|
32
|
+
:disabled="disabled || loading"
|
|
33
|
+
:aria-busy="loading || undefined"
|
|
34
|
+
@click="$emit('click', $event)"
|
|
35
|
+
>
|
|
36
|
+
<slot />
|
|
37
|
+
</button>
|
|
38
|
+
</template>
|
package/src/Card.vue
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import type { CardVariant, CardSize, Material } from "@crystal-neuo/contract";
|
|
4
|
+
import { cn } from "./cn.ts";
|
|
5
|
+
|
|
6
|
+
const props = withDefaults(
|
|
7
|
+
defineProps<{ material?: Material; variant?: CardVariant; size?: CardSize; class?: string }>(),
|
|
8
|
+
{
|
|
9
|
+
variant: "glass",
|
|
10
|
+
size: "md",
|
|
11
|
+
},
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const classes = computed(() =>
|
|
15
|
+
cn("cn-card", `cn-card--${props.variant}`, `cn-card--size-${props.size}`, props.class),
|
|
16
|
+
);
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<section data-slot="card" :data-material="props.material" :class="classes"><slot /></section>
|
|
21
|
+
</template>
|
package/src/Checkbox.vue
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onMounted, useId, useTemplateRef, watch } from "vue";
|
|
3
|
+
import type { CheckboxSize, Material } from "@crystal-neuo/contract";
|
|
4
|
+
import { cn } from "./cn.ts";
|
|
5
|
+
import { useControlAttrs } from "./useControlAttrs.ts";
|
|
6
|
+
|
|
7
|
+
defineOptions({ inheritAttrs: false });
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(
|
|
10
|
+
defineProps<{
|
|
11
|
+
material?: Material;
|
|
12
|
+
size?: CheckboxSize;
|
|
13
|
+
label: string;
|
|
14
|
+
error?: boolean;
|
|
15
|
+
indeterminate?: boolean;
|
|
16
|
+
id?: string;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
}>(),
|
|
19
|
+
{ size: "md" },
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const checked = defineModel<boolean>("checked", { default: false });
|
|
23
|
+
|
|
24
|
+
const autoId = useId();
|
|
25
|
+
const cbId = computed(() => props.id ?? autoId);
|
|
26
|
+
const inputEl = useTemplateRef<HTMLInputElement>("inputEl");
|
|
27
|
+
// `indeterminate` is a DOM property, not an attribute. Sync it once the input
|
|
28
|
+
// exists, whenever the prop changes, and after a click (which clears the flag):
|
|
29
|
+
// the prop stays the source of truth until the owner changes it.
|
|
30
|
+
function syncIndeterminate() {
|
|
31
|
+
if (inputEl.value) inputEl.value.indeterminate = props.indeterminate ?? false;
|
|
32
|
+
}
|
|
33
|
+
onMounted(syncIndeterminate);
|
|
34
|
+
watch(() => props.indeterminate, syncIndeterminate, { flush: "post" });
|
|
35
|
+
const classes = computed(() =>
|
|
36
|
+
cn("cn-choice", `cn-choice--size-${props.size}`, props.error && "cn-choice--error"),
|
|
37
|
+
);
|
|
38
|
+
const { rootAttrs, controlAttrs } = useControlAttrs();
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<template>
|
|
42
|
+
<label v-bind="rootAttrs" :class="classes" :for="cbId" data-slot="checkbox" :data-material="props.material">
|
|
43
|
+
<input
|
|
44
|
+
v-bind="controlAttrs"
|
|
45
|
+
ref="inputEl"
|
|
46
|
+
:id="cbId"
|
|
47
|
+
v-model="checked"
|
|
48
|
+
type="checkbox"
|
|
49
|
+
class="cn-choice__input"
|
|
50
|
+
:disabled="disabled"
|
|
51
|
+
:aria-invalid="error ? true : undefined"
|
|
52
|
+
@change="syncIndeterminate"
|
|
53
|
+
/>
|
|
54
|
+
<span class="cn-choice__label">{{ label }}</span>
|
|
55
|
+
</label>
|
|
56
|
+
</template>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, useId } from "vue";
|
|
3
|
+
import type { DatePickerSize, Material } from "@crystal-neuo/contract";
|
|
4
|
+
import { cn } from "./cn.ts";
|
|
5
|
+
import { useControlAttrs } from "./useControlAttrs.ts";
|
|
6
|
+
|
|
7
|
+
defineOptions({ inheritAttrs: false });
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(
|
|
10
|
+
defineProps<{
|
|
11
|
+
material?: Material;
|
|
12
|
+
size?: DatePickerSize;
|
|
13
|
+
label?: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
id?: string;
|
|
16
|
+
min?: string;
|
|
17
|
+
max?: string;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
}>(),
|
|
20
|
+
{ size: "md" },
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const model = defineModel<string>({ default: "" });
|
|
24
|
+
|
|
25
|
+
const autoId = useId();
|
|
26
|
+
const dpId = computed(() => props.id ?? autoId);
|
|
27
|
+
const msgId = computed(() => `${dpId.value}-msg`);
|
|
28
|
+
const inputClass = computed(() =>
|
|
29
|
+
cn("cn-input", `cn-input--size-${props.size}`, props.error && "cn-input--error"),
|
|
30
|
+
);
|
|
31
|
+
const { rootAttrs, controlAttrs } = useControlAttrs();
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<div v-bind="rootAttrs" class="cn-field" data-slot="date-field" :data-material="props.material">
|
|
36
|
+
<label v-if="label" class="cn-field__label" :for="dpId">{{ label }}</label>
|
|
37
|
+
<input
|
|
38
|
+
v-bind="controlAttrs"
|
|
39
|
+
:id="dpId"
|
|
40
|
+
v-model="model"
|
|
41
|
+
type="date"
|
|
42
|
+
:class="inputClass"
|
|
43
|
+
:min="min"
|
|
44
|
+
:max="max"
|
|
45
|
+
:disabled="disabled"
|
|
46
|
+
:aria-invalid="error ? true : undefined"
|
|
47
|
+
:aria-describedby="error ? msgId : undefined"
|
|
48
|
+
/>
|
|
49
|
+
<span v-if="error" class="cn-field__message" :id="msgId">{{ error }}</span>
|
|
50
|
+
</div>
|
|
51
|
+
</template>
|
package/src/Dialog.vue
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, useId } from "vue";
|
|
3
|
+
import type { DialogVariant, DialogSize, Material } from "@crystal-neuo/contract";
|
|
4
|
+
import { cn } from "./cn.ts";
|
|
5
|
+
import { useModalDialog } from "./useModalDialog.ts";
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(
|
|
8
|
+
defineProps<{
|
|
9
|
+
material?: Material;
|
|
10
|
+
title: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
variant?: DialogVariant;
|
|
13
|
+
size?: DialogSize;
|
|
14
|
+
confirmLabel?: string;
|
|
15
|
+
cancelLabel?: string;
|
|
16
|
+
class?: string;
|
|
17
|
+
}>(),
|
|
18
|
+
{ variant: "default", size: "sm", confirmLabel: "Confirm", cancelLabel: "Cancel" },
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const open = defineModel<boolean>("open", { default: false });
|
|
22
|
+
const emit = defineEmits<{ confirm: [] }>();
|
|
23
|
+
|
|
24
|
+
const dialog = ref<HTMLDialogElement | null>(null);
|
|
25
|
+
const titleId = useId();
|
|
26
|
+
const descId = useId();
|
|
27
|
+
useModalDialog(dialog, open);
|
|
28
|
+
|
|
29
|
+
const classes = computed(() => cn("cn-dialog", `cn-dialog--size-${props.size}`, props.class));
|
|
30
|
+
const confirmClass = computed(() =>
|
|
31
|
+
cn(
|
|
32
|
+
"cn-button",
|
|
33
|
+
props.variant === "destructive" ? "cn-button--danger" : "cn-button--primary",
|
|
34
|
+
"cn-button--size-md",
|
|
35
|
+
),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
function onScrim(e: MouseEvent) {
|
|
39
|
+
if (e.target !== e.currentTarget) return;
|
|
40
|
+
// Keep the press from moving focus to the closing dialog, so focus returns to the opener.
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
open.value = false;
|
|
43
|
+
}
|
|
44
|
+
function confirm() {
|
|
45
|
+
emit("confirm");
|
|
46
|
+
open.value = false;
|
|
47
|
+
}
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<template>
|
|
51
|
+
<dialog
|
|
52
|
+
ref="dialog"
|
|
53
|
+
class="cn-scrim"
|
|
54
|
+
data-slot="dialog-scrim"
|
|
55
|
+
:data-material="props.material"
|
|
56
|
+
role="alertdialog"
|
|
57
|
+
:aria-labelledby="titleId"
|
|
58
|
+
:aria-describedby="description ? descId : undefined"
|
|
59
|
+
@mousedown="onScrim"
|
|
60
|
+
>
|
|
61
|
+
<div v-if="open" :class="classes">
|
|
62
|
+
<h2 :id="titleId" class="cn-dialog__title">{{ title }}</h2>
|
|
63
|
+
<p v-if="description" :id="descId">{{ description }}</p>
|
|
64
|
+
<slot />
|
|
65
|
+
<div class="cn-dialog__actions">
|
|
66
|
+
<button type="button" class="cn-button cn-button--ghost cn-button--size-md" @click="open = false">
|
|
67
|
+
{{ cancelLabel }}
|
|
68
|
+
</button>
|
|
69
|
+
<button type="button" :class="confirmClass" @click="confirm">{{ confirmLabel }}</button>
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
</dialog>
|
|
73
|
+
</template>
|