create-dalila 1.1.13 → 1.2.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/package.json +1 -1
- package/template/src/components/ui/accordion/accordion.css +90 -0
- package/template/src/components/ui/accordion/index.ts +121 -0
- package/template/src/components/ui/alert/alert.css +78 -0
- package/template/src/components/ui/avatar/avatar.css +45 -0
- package/template/src/components/ui/badge/badge.css +71 -0
- package/template/src/components/ui/breadcrumb/breadcrumb.css +41 -0
- package/template/src/components/ui/button/button.css +135 -0
- package/template/src/components/ui/calendar/calendar.css +96 -0
- package/template/src/components/ui/calendar/index.ts +157 -0
- package/template/src/components/ui/card/card.css +93 -0
- package/template/src/components/ui/checkbox/checkbox.css +57 -0
- package/template/src/components/ui/chip/chip.css +62 -0
- package/template/src/components/ui/collapsible/collapsible.css +61 -0
- package/template/src/components/ui/combobox/combobox.css +85 -0
- package/template/src/components/ui/combobox/index.ts +181 -0
- package/template/src/components/ui/dalila/dalila.css +42 -0
- package/template/src/components/ui/dalila-core/dalila-core.css +14 -0
- package/template/src/components/ui/dialog/dialog.css +125 -0
- package/template/src/components/ui/dialog/index.ts +68 -0
- package/template/src/components/ui/drawer/drawer.css +122 -0
- package/template/src/components/ui/drawer/index.ts +53 -0
- package/template/src/components/ui/dropdown/dropdown.css +87 -0
- package/template/src/components/ui/dropdown/index.ts +57 -0
- package/template/src/components/ui/dropzone/dropzone.css +47 -0
- package/template/src/components/ui/dropzone/index.ts +114 -0
- package/template/src/components/ui/empty-state/empty-state.css +33 -0
- package/template/src/components/ui/env.ts +4 -0
- package/template/src/components/ui/form/form.css +44 -0
- package/template/src/components/ui/index.ts +13 -0
- package/template/src/components/ui/input/input.css +106 -0
- package/template/src/components/ui/layout/layout.css +62 -0
- package/template/src/components/ui/pagination/pagination.css +55 -0
- package/template/src/components/ui/popover/index.ts +185 -0
- package/template/src/components/ui/popover/popover.css +55 -0
- package/template/src/components/ui/radio/radio.css +56 -0
- package/template/src/components/ui/runtime.ts +514 -0
- package/template/src/components/ui/separator/separator.css +38 -0
- package/template/src/components/ui/skeleton/skeleton.css +57 -0
- package/template/src/components/ui/slider/slider.css +60 -0
- package/template/src/components/ui/spinner/spinner.css +38 -0
- package/template/src/components/ui/table/table.css +54 -0
- package/template/src/components/ui/tabs/index.ts +128 -0
- package/template/src/components/ui/tabs/tabs.css +74 -0
- package/template/src/components/ui/toast/index.ts +144 -0
- package/template/src/components/ui/toast/toast.css +100 -0
- package/template/src/components/ui/toggle/toggle.css +90 -0
- package/template/src/components/ui/tokens/tokens.css +161 -0
- package/template/src/components/ui/tooltip/tooltip.css +53 -0
- package/template/src/components/ui/typography/typography.css +81 -0
- package/template/src/components/ui/ui-types.ts +238 -0
- package/template/src/components/ui/validate.ts +83 -0
- package/template/src/style.css +13 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { signal } from "../../../core/signal.js";
|
|
2
|
+
import { getCurrentScope } from "../../../core/scope.js";
|
|
3
|
+
import type { Dropzone, DropzoneOptions } from "../ui-types.js";
|
|
4
|
+
import { validateDropzoneOptions } from "../validate.js";
|
|
5
|
+
|
|
6
|
+
export function createDropzone(options: DropzoneOptions = {}): Dropzone {
|
|
7
|
+
validateDropzoneOptions(options as Record<string, unknown>);
|
|
8
|
+
const { accept, multiple = true, maxFiles, maxSize } = options;
|
|
9
|
+
|
|
10
|
+
const dragging = signal(false);
|
|
11
|
+
const files = signal<File[]>([]);
|
|
12
|
+
|
|
13
|
+
let inputEl: HTMLInputElement | null = null;
|
|
14
|
+
|
|
15
|
+
const filterFiles = (fileList: File[]): File[] => {
|
|
16
|
+
let result = fileList;
|
|
17
|
+
|
|
18
|
+
if (accept) {
|
|
19
|
+
const types = accept.split(",").map((t) => t.trim().toLowerCase());
|
|
20
|
+
result = result.filter((f) => {
|
|
21
|
+
const ext = "." + f.name.split(".").pop()?.toLowerCase();
|
|
22
|
+
const mime = f.type.toLowerCase();
|
|
23
|
+
return types.some(
|
|
24
|
+
(t) => t === ext || t === mime || (t.endsWith("/*") && mime.startsWith(t.slice(0, -1)))
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (maxSize) {
|
|
30
|
+
result = result.filter((f) => f.size <= maxSize);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (maxFiles) {
|
|
34
|
+
result = result.slice(0, maxFiles);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const addFiles = (newFiles: File[]) => {
|
|
41
|
+
const filtered = filterFiles(newFiles);
|
|
42
|
+
if (multiple) {
|
|
43
|
+
files.update((current) => {
|
|
44
|
+
const combined = [...current, ...filtered];
|
|
45
|
+
return maxFiles ? combined.slice(0, maxFiles) : combined;
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
files.set(filtered.slice(0, 1));
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const browse = () => {
|
|
53
|
+
inputEl?.click();
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handleClick = () => browse();
|
|
57
|
+
|
|
58
|
+
const handleDragover = (ev: DragEvent) => {
|
|
59
|
+
ev.preventDefault();
|
|
60
|
+
dragging.set(true);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const handleDragleave = () => {
|
|
64
|
+
dragging.set(false);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const handleDrop = (ev: DragEvent) => {
|
|
68
|
+
ev.preventDefault();
|
|
69
|
+
dragging.set(false);
|
|
70
|
+
if (ev.dataTransfer?.files) {
|
|
71
|
+
addFiles(Array.from(ev.dataTransfer.files));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const _attachTo = (el: HTMLElement) => {
|
|
76
|
+
const scope = getCurrentScope();
|
|
77
|
+
|
|
78
|
+
// ARIA
|
|
79
|
+
el.setAttribute("role", "button");
|
|
80
|
+
el.setAttribute("tabindex", "0");
|
|
81
|
+
|
|
82
|
+
inputEl = el.querySelector<HTMLInputElement>('input[type="file"]');
|
|
83
|
+
|
|
84
|
+
if (inputEl) {
|
|
85
|
+
if (accept) inputEl.accept = accept;
|
|
86
|
+
inputEl.multiple = multiple;
|
|
87
|
+
|
|
88
|
+
const onInputChange = () => {
|
|
89
|
+
if (inputEl?.files) {
|
|
90
|
+
addFiles(Array.from(inputEl.files));
|
|
91
|
+
inputEl.value = "";
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
inputEl.addEventListener("change", onInputChange);
|
|
95
|
+
|
|
96
|
+
if (scope) {
|
|
97
|
+
scope.onCleanup(() => {
|
|
98
|
+
inputEl?.removeEventListener("change", onInputChange);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
dragging,
|
|
106
|
+
files,
|
|
107
|
+
browse,
|
|
108
|
+
handleClick,
|
|
109
|
+
handleDragover,
|
|
110
|
+
handleDragleave,
|
|
111
|
+
handleDrop,
|
|
112
|
+
_attachTo,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* Dalila UI — Empty State */
|
|
2
|
+
|
|
3
|
+
.d-empty {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
align-items: center;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
text-align: center;
|
|
9
|
+
padding: var(--d-space-12) var(--d-space-6);
|
|
10
|
+
font-family: var(--d-font-sans);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.d-empty-icon {
|
|
14
|
+
font-size: 3rem;
|
|
15
|
+
color: var(--d-text-muted);
|
|
16
|
+
margin-bottom: var(--d-space-4);
|
|
17
|
+
opacity: 0.5;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.d-empty-title {
|
|
21
|
+
font-size: var(--d-text-lg);
|
|
22
|
+
font-weight: var(--d-font-semibold);
|
|
23
|
+
color: var(--d-text-primary);
|
|
24
|
+
margin: 0 0 var(--d-space-2);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.d-empty-text {
|
|
28
|
+
font-size: var(--d-text-sm);
|
|
29
|
+
color: var(--d-text-muted);
|
|
30
|
+
max-width: 24rem;
|
|
31
|
+
margin: 0 0 var(--d-space-6);
|
|
32
|
+
line-height: var(--d-leading);
|
|
33
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* Dalila UI — Form */
|
|
2
|
+
|
|
3
|
+
.d-form {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
gap: var(--d-space-5);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.d-form-section {
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
gap: var(--d-space-4);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.d-form-section-title {
|
|
16
|
+
font-family: var(--d-font-sans);
|
|
17
|
+
font-size: var(--d-text-lg);
|
|
18
|
+
font-weight: var(--d-font-semibold);
|
|
19
|
+
color: var(--d-text-primary);
|
|
20
|
+
padding-bottom: var(--d-space-2);
|
|
21
|
+
border-bottom: 1px solid var(--d-border-color);
|
|
22
|
+
margin: 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.d-form-row {
|
|
26
|
+
display: grid;
|
|
27
|
+
grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
|
|
28
|
+
gap: var(--d-space-4);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.d-form-actions {
|
|
32
|
+
display: flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
gap: var(--d-space-3);
|
|
35
|
+
padding-top: var(--d-space-4);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.d-form-actions-end {
|
|
39
|
+
justify-content: flex-end;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.d-form-actions-between {
|
|
43
|
+
justify-content: space-between;
|
|
44
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./ui-types.js";
|
|
2
|
+
export { createDialog, _attachDialogBehavior } from "./dialog/index.js";
|
|
3
|
+
export { createDrawer } from "./drawer/index.js";
|
|
4
|
+
export { createToast, toastIcon } from "./toast/index.js";
|
|
5
|
+
export { createTabs, tabBindings } from "./tabs/index.js";
|
|
6
|
+
export { createDropdown } from "./dropdown/index.js";
|
|
7
|
+
export { createCombobox } from "./combobox/index.js";
|
|
8
|
+
export { createAccordion } from "./accordion/index.js";
|
|
9
|
+
export { createCalendar } from "./calendar/index.js";
|
|
10
|
+
export { createDropzone } from "./dropzone/index.js";
|
|
11
|
+
export { createPopover } from "./popover/index.js";
|
|
12
|
+
export { mountUI } from "./runtime.js";
|
|
13
|
+
export type { MountUIOptions } from "./runtime.js";
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/* Dalila UI — Input */
|
|
2
|
+
|
|
3
|
+
.d-field {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
gap: var(--d-space-1);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.d-field-label {
|
|
10
|
+
font-family: var(--d-font-sans);
|
|
11
|
+
font-size: var(--d-text-sm);
|
|
12
|
+
font-weight: var(--d-font-medium);
|
|
13
|
+
color: var(--d-text-primary);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.d-field-hint {
|
|
17
|
+
font-size: var(--d-text-xs);
|
|
18
|
+
color: var(--d-text-muted);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.d-field-error {
|
|
22
|
+
font-size: var(--d-text-xs);
|
|
23
|
+
color: var(--d-error);
|
|
24
|
+
font-weight: var(--d-font-medium);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.d-input,
|
|
28
|
+
.d-textarea,
|
|
29
|
+
.d-select {
|
|
30
|
+
width: 100%;
|
|
31
|
+
padding: var(--d-space-2) var(--d-space-3);
|
|
32
|
+
min-height: 2.25rem;
|
|
33
|
+
|
|
34
|
+
font-family: var(--d-font-sans);
|
|
35
|
+
font-size: var(--d-text-base);
|
|
36
|
+
color: var(--d-text-primary);
|
|
37
|
+
line-height: var(--d-leading);
|
|
38
|
+
|
|
39
|
+
background: var(--d-surface-page);
|
|
40
|
+
border: 1px solid var(--d-border-color);
|
|
41
|
+
border-radius: var(--d-radius-md);
|
|
42
|
+
|
|
43
|
+
transition: border-color var(--d-duration-fast) ease, box-shadow var(--d-duration-fast) ease;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.d-input::placeholder,
|
|
47
|
+
.d-textarea::placeholder {
|
|
48
|
+
color: var(--d-text-muted);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.d-input:focus,
|
|
52
|
+
.d-textarea:focus,
|
|
53
|
+
.d-select:focus {
|
|
54
|
+
outline: none;
|
|
55
|
+
border-color: var(--d-accent);
|
|
56
|
+
box-shadow: none;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.d-input[aria-invalid="true"],
|
|
60
|
+
.d-textarea[aria-invalid="true"],
|
|
61
|
+
.d-select[aria-invalid="true"],
|
|
62
|
+
.d-input-error,
|
|
63
|
+
.d-textarea-error,
|
|
64
|
+
.d-select-error {
|
|
65
|
+
border-color: var(--d-error);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.d-input[aria-invalid="true"]:focus,
|
|
69
|
+
.d-textarea[aria-invalid="true"]:focus,
|
|
70
|
+
.d-select[aria-invalid="true"]:focus,
|
|
71
|
+
.d-input-error:focus,
|
|
72
|
+
.d-textarea-error:focus,
|
|
73
|
+
.d-select-error:focus {
|
|
74
|
+
box-shadow: none;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.d-input:disabled,
|
|
78
|
+
.d-textarea:disabled,
|
|
79
|
+
.d-select:disabled {
|
|
80
|
+
opacity: 0.5;
|
|
81
|
+
cursor: not-allowed;
|
|
82
|
+
background: var(--d-surface-raised);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.d-textarea {
|
|
86
|
+
min-height: 5rem;
|
|
87
|
+
resize: vertical;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.d-select {
|
|
91
|
+
appearance: none;
|
|
92
|
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' viewBox='0 0 12 12'%3E%3Cpath stroke='%23737373' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m3 4.5 3 3 3-3'/%3E%3C/svg%3E");
|
|
93
|
+
background-repeat: no-repeat;
|
|
94
|
+
background-position: right var(--d-space-3) center;
|
|
95
|
+
padding-right: var(--d-space-8);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
[data-theme="light"] .d-select {
|
|
99
|
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' viewBox='0 0 12 12'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m3 4.5 3 3 3-3'/%3E%3C/svg%3E");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.d-input-sm {
|
|
103
|
+
padding: var(--d-space-1) var(--d-space-2);
|
|
104
|
+
min-height: 1.75rem;
|
|
105
|
+
font-size: var(--d-text-sm);
|
|
106
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* Dalila UI — Layout */
|
|
2
|
+
|
|
3
|
+
.d-container {
|
|
4
|
+
width: 100%;
|
|
5
|
+
max-width: 56rem;
|
|
6
|
+
margin-left: auto;
|
|
7
|
+
margin-right: auto;
|
|
8
|
+
padding-left: var(--d-space-6);
|
|
9
|
+
padding-right: var(--d-space-6);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.d-container-sm { max-width: 40rem; }
|
|
13
|
+
.d-container-lg { max-width: 72rem; }
|
|
14
|
+
.d-container-xl { max-width: 90rem; }
|
|
15
|
+
|
|
16
|
+
.d-box {
|
|
17
|
+
padding: var(--d-space-4);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.d-stack {
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
gap: var(--d-space-4);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.d-stack-1 { gap: var(--d-space-1); }
|
|
27
|
+
.d-stack-2 { gap: var(--d-space-2); }
|
|
28
|
+
.d-stack-3 { gap: var(--d-space-3); }
|
|
29
|
+
.d-stack-6 { gap: var(--d-space-6); }
|
|
30
|
+
.d-stack-8 { gap: var(--d-space-8); }
|
|
31
|
+
|
|
32
|
+
.d-flex {
|
|
33
|
+
display: flex;
|
|
34
|
+
gap: var(--d-space-3);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.d-flex-wrap { flex-wrap: wrap; }
|
|
38
|
+
.d-flex-center { align-items: center; justify-content: center; }
|
|
39
|
+
.d-flex-between { justify-content: space-between; }
|
|
40
|
+
.d-flex-end { justify-content: flex-end; }
|
|
41
|
+
.d-flex-col { flex-direction: column; }
|
|
42
|
+
|
|
43
|
+
.d-grid {
|
|
44
|
+
display: grid;
|
|
45
|
+
gap: var(--d-space-4);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.d-grid-2 { grid-template-columns: repeat(2, 1fr); }
|
|
49
|
+
.d-grid-3 { grid-template-columns: repeat(3, 1fr); }
|
|
50
|
+
.d-grid-4 { grid-template-columns: repeat(4, 1fr); }
|
|
51
|
+
.d-grid-auto { grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); }
|
|
52
|
+
|
|
53
|
+
@media (max-width: 640px) {
|
|
54
|
+
.d-grid-2, .d-grid-3, .d-grid-4 {
|
|
55
|
+
grid-template-columns: 1fr;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.d-container {
|
|
59
|
+
padding-left: var(--d-space-4);
|
|
60
|
+
padding-right: var(--d-space-4);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* Dalila UI — Pagination */
|
|
2
|
+
|
|
3
|
+
.d-pagination {
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
gap: var(--d-space-1);
|
|
7
|
+
font-family: var(--d-font-sans);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.d-page {
|
|
11
|
+
display: inline-flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
justify-content: center;
|
|
14
|
+
min-width: 2rem;
|
|
15
|
+
height: 2rem;
|
|
16
|
+
padding: 0 var(--d-space-2);
|
|
17
|
+
font-size: var(--d-text-sm);
|
|
18
|
+
font-weight: var(--d-font-medium);
|
|
19
|
+
color: var(--d-text-muted);
|
|
20
|
+
background: none;
|
|
21
|
+
border: 1px solid transparent;
|
|
22
|
+
border-radius: var(--d-radius-sm);
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
transition: all var(--d-duration-fast) ease;
|
|
25
|
+
text-decoration: none;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.d-page:hover {
|
|
29
|
+
background: var(--d-surface-raised);
|
|
30
|
+
color: var(--d-text-primary);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.d-page.active,
|
|
34
|
+
.d-page[aria-current="page"] {
|
|
35
|
+
background: var(--d-accent);
|
|
36
|
+
color: #fff;
|
|
37
|
+
border-color: var(--d-accent);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.d-page:disabled,
|
|
41
|
+
.d-page[aria-disabled="true"] {
|
|
42
|
+
opacity: 0.4;
|
|
43
|
+
pointer-events: none;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.d-page-ellipsis {
|
|
47
|
+
display: inline-flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
justify-content: center;
|
|
50
|
+
min-width: 2rem;
|
|
51
|
+
height: 2rem;
|
|
52
|
+
font-size: var(--d-text-sm);
|
|
53
|
+
color: var(--d-text-muted);
|
|
54
|
+
cursor: default;
|
|
55
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { signal } from "../../../core/signal.js";
|
|
2
|
+
import { getCurrentScope } from "../../../core/scope.js";
|
|
3
|
+
import type { Popover, PopoverOptions, PopoverPlacement } from "../ui-types.js";
|
|
4
|
+
import { validatePopoverOptions } from "../validate.js";
|
|
5
|
+
import { isBrowser } from "../env.js";
|
|
6
|
+
|
|
7
|
+
let popoverUid = 0;
|
|
8
|
+
|
|
9
|
+
function computePosition(
|
|
10
|
+
trigger: HTMLElement,
|
|
11
|
+
popoverEl: HTMLElement,
|
|
12
|
+
placement: PopoverPlacement,
|
|
13
|
+
gap: number,
|
|
14
|
+
viewportPadding: number
|
|
15
|
+
): { top: number; left: number } {
|
|
16
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
17
|
+
const popRect = popoverEl.getBoundingClientRect();
|
|
18
|
+
const vw = isBrowser ? window.innerWidth : 1024;
|
|
19
|
+
const vh = isBrowser ? window.innerHeight : 768;
|
|
20
|
+
|
|
21
|
+
// ── Flip when not enough space ──
|
|
22
|
+
let effective = placement as string;
|
|
23
|
+
|
|
24
|
+
if (effective.startsWith("bottom") && triggerRect.bottom + gap + popRect.height > vh - viewportPadding) {
|
|
25
|
+
if (triggerRect.top - gap - popRect.height >= viewportPadding) {
|
|
26
|
+
effective = effective.replace("bottom", "top");
|
|
27
|
+
}
|
|
28
|
+
} else if (effective.startsWith("top") && triggerRect.top - gap - popRect.height < viewportPadding) {
|
|
29
|
+
if (triggerRect.bottom + gap + popRect.height <= vh - viewportPadding) {
|
|
30
|
+
effective = effective.replace("top", "bottom");
|
|
31
|
+
}
|
|
32
|
+
} else if (effective === "left" && triggerRect.left - gap - popRect.width < viewportPadding) {
|
|
33
|
+
if (triggerRect.right + gap + popRect.width <= vw - viewportPadding) {
|
|
34
|
+
effective = "right";
|
|
35
|
+
}
|
|
36
|
+
} else if (effective === "right" && triggerRect.right + gap + popRect.width > vw - viewportPadding) {
|
|
37
|
+
if (triggerRect.left - gap - popRect.width >= viewportPadding) {
|
|
38
|
+
effective = "left";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let top = 0;
|
|
43
|
+
let left = 0;
|
|
44
|
+
|
|
45
|
+
switch (effective) {
|
|
46
|
+
case "bottom":
|
|
47
|
+
top = triggerRect.bottom + gap;
|
|
48
|
+
left = triggerRect.left + (triggerRect.width - popRect.width) / 2;
|
|
49
|
+
break;
|
|
50
|
+
case "bottom-start":
|
|
51
|
+
top = triggerRect.bottom + gap;
|
|
52
|
+
left = triggerRect.left;
|
|
53
|
+
break;
|
|
54
|
+
case "top":
|
|
55
|
+
top = triggerRect.top - popRect.height - gap;
|
|
56
|
+
left = triggerRect.left + (triggerRect.width - popRect.width) / 2;
|
|
57
|
+
break;
|
|
58
|
+
case "top-start":
|
|
59
|
+
top = triggerRect.top - popRect.height - gap;
|
|
60
|
+
left = triggerRect.left;
|
|
61
|
+
break;
|
|
62
|
+
case "left":
|
|
63
|
+
top = triggerRect.top + (triggerRect.height - popRect.height) / 2;
|
|
64
|
+
left = triggerRect.left - popRect.width - gap;
|
|
65
|
+
break;
|
|
66
|
+
case "right":
|
|
67
|
+
top = triggerRect.top + (triggerRect.height - popRect.height) / 2;
|
|
68
|
+
left = triggerRect.right + gap;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Viewport clamping
|
|
73
|
+
const maxLeft = vw - popRect.width - viewportPadding;
|
|
74
|
+
left = Math.min(Math.max(viewportPadding, left), Math.max(viewportPadding, maxLeft));
|
|
75
|
+
|
|
76
|
+
const maxTop = vh - popRect.height - viewportPadding;
|
|
77
|
+
top = Math.min(Math.max(viewportPadding, top), Math.max(viewportPadding, maxTop));
|
|
78
|
+
|
|
79
|
+
return { top, left };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function createPopover(options: PopoverOptions = {}): Popover {
|
|
83
|
+
validatePopoverOptions(options as Record<string, unknown>);
|
|
84
|
+
const {
|
|
85
|
+
placement: initialPlacement = "bottom",
|
|
86
|
+
gap = 8,
|
|
87
|
+
viewportPadding = 12,
|
|
88
|
+
} = options;
|
|
89
|
+
|
|
90
|
+
const open = signal(false);
|
|
91
|
+
const placement = signal<PopoverPlacement>(initialPlacement);
|
|
92
|
+
|
|
93
|
+
const show = () => open.set(true);
|
|
94
|
+
const hide = () => open.set(false);
|
|
95
|
+
const toggle = () => open.update((v) => !v);
|
|
96
|
+
|
|
97
|
+
const position = (trigger: HTMLElement, popoverEl: HTMLElement) => {
|
|
98
|
+
const { top, left } = computePosition(
|
|
99
|
+
trigger,
|
|
100
|
+
popoverEl,
|
|
101
|
+
placement(),
|
|
102
|
+
gap,
|
|
103
|
+
viewportPadding
|
|
104
|
+
);
|
|
105
|
+
popoverEl.style.position = "fixed";
|
|
106
|
+
popoverEl.style.top = `${top}px`;
|
|
107
|
+
popoverEl.style.left = `${left}px`;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const _attachTo = (trigger: HTMLElement, popoverEl: HTMLElement) => {
|
|
111
|
+
const scope = getCurrentScope();
|
|
112
|
+
|
|
113
|
+
// Ensure popover attribute for native API
|
|
114
|
+
if (!popoverEl.hasAttribute("popover")) {
|
|
115
|
+
popoverEl.setAttribute("popover", "manual");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const reposition = () => {
|
|
119
|
+
try {
|
|
120
|
+
if (!popoverEl.matches(":popover-open")) return;
|
|
121
|
+
} catch {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
position(trigger, popoverEl);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// Sync open signal → native popover
|
|
128
|
+
const unsub = open.on((isOpen) => {
|
|
129
|
+
try {
|
|
130
|
+
const isNativeOpen = popoverEl.matches(":popover-open");
|
|
131
|
+
if (isOpen && !isNativeOpen) {
|
|
132
|
+
popoverEl.showPopover();
|
|
133
|
+
reposition();
|
|
134
|
+
} else if (!isOpen && isNativeOpen) {
|
|
135
|
+
popoverEl.hidePopover();
|
|
136
|
+
}
|
|
137
|
+
} catch {
|
|
138
|
+
// Popover API not supported or element not connected
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Sync native toggle → signal
|
|
143
|
+
const onToggle = (ev: Event) => {
|
|
144
|
+
const state = (ev as ToggleEvent).newState;
|
|
145
|
+
if (state === "open") {
|
|
146
|
+
if (!open.peek()) open.set(true);
|
|
147
|
+
reposition();
|
|
148
|
+
} else {
|
|
149
|
+
if (open.peek()) open.set(false);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
popoverEl.addEventListener("toggle", onToggle);
|
|
153
|
+
|
|
154
|
+
// Reposition on scroll/resize
|
|
155
|
+
if (isBrowser) {
|
|
156
|
+
window.addEventListener("resize", reposition);
|
|
157
|
+
window.addEventListener("scroll", reposition, { passive: true });
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ARIA
|
|
161
|
+
const popoverId = popoverEl.id || `d-popover-${++popoverUid}`;
|
|
162
|
+
if (!popoverEl.id) popoverEl.id = popoverId;
|
|
163
|
+
trigger.setAttribute("aria-controls", popoverId);
|
|
164
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
165
|
+
trigger.setAttribute("aria-haspopup", "true");
|
|
166
|
+
|
|
167
|
+
const unsubAria = open.on((isOpen) => {
|
|
168
|
+
trigger.setAttribute("aria-expanded", String(isOpen));
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
if (scope) {
|
|
172
|
+
scope.onCleanup(() => {
|
|
173
|
+
unsub();
|
|
174
|
+
unsubAria();
|
|
175
|
+
popoverEl.removeEventListener("toggle", onToggle);
|
|
176
|
+
if (isBrowser) {
|
|
177
|
+
window.removeEventListener("resize", reposition);
|
|
178
|
+
window.removeEventListener("scroll", reposition);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
return { open, show, hide, toggle, placement, position, _attachTo };
|
|
185
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* Dalila UI — Popover */
|
|
2
|
+
|
|
3
|
+
.d-popover {
|
|
4
|
+
margin: 0;
|
|
5
|
+
padding: var(--d-space-4);
|
|
6
|
+
border: 1px solid var(--d-border-color);
|
|
7
|
+
border-radius: var(--d-radius-md);
|
|
8
|
+
background: var(--d-surface-card);
|
|
9
|
+
color: var(--d-text-primary);
|
|
10
|
+
box-shadow: var(--d-shadow-md);
|
|
11
|
+
font-family: var(--d-font-sans);
|
|
12
|
+
font-size: var(--d-text-sm);
|
|
13
|
+
min-width: 12rem;
|
|
14
|
+
max-width: 20rem;
|
|
15
|
+
z-index: var(--d-z-dropdown);
|
|
16
|
+
isolation: isolate;
|
|
17
|
+
|
|
18
|
+
opacity: 0;
|
|
19
|
+
transform: scale(0.97);
|
|
20
|
+
transition:
|
|
21
|
+
opacity var(--d-duration-fast) ease,
|
|
22
|
+
transform var(--d-duration-fast) ease,
|
|
23
|
+
overlay var(--d-duration-fast) ease allow-discrete,
|
|
24
|
+
display var(--d-duration-fast) ease allow-discrete;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.d-popover:popover-open {
|
|
28
|
+
opacity: 1;
|
|
29
|
+
transform: scale(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@starting-style {
|
|
33
|
+
.d-popover:popover-open {
|
|
34
|
+
opacity: 0;
|
|
35
|
+
transform: scale(0.97);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.d-popover::backdrop {
|
|
40
|
+
background: transparent;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.d-popover-title {
|
|
44
|
+
font-size: var(--d-text-sm);
|
|
45
|
+
font-weight: var(--d-font-semibold);
|
|
46
|
+
color: var(--d-text-primary);
|
|
47
|
+
margin: 0 0 var(--d-space-2);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.d-popover-text {
|
|
51
|
+
font-size: var(--d-text-sm);
|
|
52
|
+
color: var(--d-text-secondary);
|
|
53
|
+
line-height: var(--d-leading);
|
|
54
|
+
margin: 0;
|
|
55
|
+
}
|