@vertz/ui-primitives 0.2.14 → 0.2.16
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/dist/shared/chunk-0mcr52hc.js +78 -0
- package/dist/shared/chunk-2h5qpc00.js +98 -0
- package/dist/shared/chunk-31yptvbf.js +151 -0
- package/dist/shared/chunk-34yfm2b0.js +182 -0
- package/dist/shared/chunk-3pantb0p.js +108 -0
- package/dist/shared/chunk-3s6s6f06.js +61 -0
- package/dist/shared/chunk-48v8j0vh.js +267 -0
- package/dist/shared/chunk-6dmt4513.js +78 -0
- package/dist/shared/chunk-6pnjrst7.js +108 -0
- package/dist/shared/chunk-6sqwjfg8.js +169 -0
- package/dist/shared/chunk-8qfeqrrz.js +179 -0
- package/dist/shared/chunk-8y1jf6xr.js +17 -0
- package/dist/shared/chunk-9cqe2q6e.js +56 -0
- package/dist/shared/chunk-a6wp8c32.js +32 -0
- package/dist/shared/chunk-bcfzteh0.js +148 -0
- package/dist/shared/chunk-cr9sbwns.js +235 -0
- package/dist/shared/chunk-cvbf1js1.js +52 -0
- package/dist/shared/chunk-dkhst4wv.js +97 -0
- package/dist/shared/chunk-e2v1c9ex.js +62 -0
- package/dist/shared/chunk-e3aj5yw4.js +115 -0
- package/dist/shared/chunk-fv1y77tn.js +225 -0
- package/dist/shared/chunk-h42bk324.js +58 -0
- package/dist/shared/chunk-h9m9x5my.js +119 -0
- package/dist/shared/chunk-jctqs9m4.js +60 -0
- package/dist/shared/chunk-n92bvn5d.js +149 -0
- package/dist/shared/chunk-qpfqyrc5.js +19 -0
- package/dist/shared/chunk-qq0e0gym.js +73 -0
- package/dist/shared/chunk-t1vkvsz2.js +175 -0
- package/dist/shared/chunk-tk1k1bet.js +93 -0
- package/dist/shared/chunk-tvpgeswh.js +216 -0
- package/dist/shared/chunk-vcp10kne.js +175 -0
- package/dist/shared/chunk-ve006hmy.js +51 -0
- package/dist/shared/chunk-vq9tfzh8.js +30 -0
- package/dist/shared/chunk-vvjyx7fe.js +62 -0
- package/dist/shared/chunk-vx1ajy2z.js +115 -0
- package/dist/shared/chunk-w06tst6x.js +57 -0
- package/dist/shared/chunk-wnttq0gv.js +49 -0
- package/dist/shared/chunk-x6qzr3g6.js +100 -0
- package/dist/src/accordion/accordion.d.ts +23 -0
- package/dist/src/accordion/accordion.js +9 -0
- package/dist/src/alert-dialog/alert-dialog.d.ts +26 -0
- package/dist/src/alert-dialog/alert-dialog.js +9 -0
- package/dist/src/badge/badge.d.ts +10 -0
- package/dist/src/badge/badge.js +7 -0
- package/dist/src/button/button.d.ts +18 -0
- package/dist/src/button/button.js +8 -0
- package/dist/src/calendar/calendar.d.ts +40 -0
- package/dist/src/calendar/calendar.js +6 -0
- package/dist/src/carousel/carousel.d.ts +27 -0
- package/dist/src/carousel/carousel.js +8 -0
- package/dist/src/checkbox/checkbox.d.ts +20 -0
- package/dist/src/checkbox/checkbox.js +9 -0
- package/dist/src/collapsible/collapsible.d.ts +21 -0
- package/dist/src/collapsible/collapsible.js +8 -0
- package/dist/src/combobox/combobox.d.ts +23 -0
- package/dist/src/combobox/combobox.js +9 -0
- package/dist/src/command/command.d.ts +29 -0
- package/dist/src/command/command.js +9 -0
- package/dist/src/context-menu/context-menu.d.ts +39 -0
- package/dist/src/context-menu/context-menu.js +11 -0
- package/dist/src/date-picker/date-picker.d.ts +47 -0
- package/dist/src/date-picker/date-picker.js +14 -0
- package/dist/src/dialog/dialog.d.ts +24 -0
- package/dist/src/dialog/dialog.js +10 -0
- package/dist/src/dropdown-menu/dropdown-menu.d.ts +42 -0
- package/dist/src/dropdown-menu/dropdown-menu.js +12 -0
- package/dist/src/hover-card/hover-card.d.ts +33 -0
- package/dist/src/hover-card/hover-card.js +10 -0
- package/dist/src/index.js +136 -0
- package/dist/src/menu/menu.d.ts +39 -0
- package/dist/src/menu/menu.js +11 -0
- package/dist/src/menubar/menubar.d.ts +40 -0
- package/dist/src/menubar/menubar.js +12 -0
- package/dist/src/navigation-menu/navigation-menu.d.ts +25 -0
- package/dist/src/navigation-menu/navigation-menu.js +10 -0
- package/dist/src/popover/popover.d.ts +32 -0
- package/dist/src/popover/popover.js +12 -0
- package/dist/src/progress/progress.d.ts +20 -0
- package/dist/src/progress/progress.js +8 -0
- package/dist/src/radio/radio.d.ts +18 -0
- package/dist/src/radio/radio.js +10 -0
- package/dist/src/resizable-panel/resizable-panel.d.ts +24 -0
- package/dist/src/resizable-panel/resizable-panel.js +8 -0
- package/dist/src/scroll-area/scroll-area.d.ts +25 -0
- package/dist/src/scroll-area/scroll-area.js +6 -0
- package/dist/src/select/select.d.ts +41 -0
- package/dist/src/select/select.js +11 -0
- package/dist/src/sheet/sheet.d.ts +24 -0
- package/dist/src/sheet/sheet.js +10 -0
- package/dist/src/slider/slider.d.ts +24 -0
- package/dist/src/slider/slider.js +9 -0
- package/dist/src/switch/switch.d.ts +9 -0
- package/dist/src/switch/switch.js +8 -0
- package/dist/src/tabs/tabs.d.ts +23 -0
- package/dist/src/tabs/tabs.js +10 -0
- package/dist/src/toast/toast.d.ts +24 -0
- package/dist/src/toast/toast.js +8 -0
- package/dist/src/toggle/toggle.d.ts +9 -0
- package/dist/src/toggle/toggle.js +8 -0
- package/dist/src/toggle-group/toggle-group.d.ts +22 -0
- package/dist/src/toggle-group/toggle-group.js +9 -0
- package/dist/src/tooltip/tooltip.d.ts +32 -0
- package/dist/src/tooltip/tooltip.js +10 -0
- package/dist/src/utils.d.ts +176 -0
- package/dist/src/utils.js +72 -0
- package/package.json +12 -10
- package/dist/index.js +0 -3675
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// src/calendar/calendar.ts
|
|
2
|
+
import { signal } from "@vertz/ui";
|
|
3
|
+
var MONTH_NAMES = [
|
|
4
|
+
"January",
|
|
5
|
+
"February",
|
|
6
|
+
"March",
|
|
7
|
+
"April",
|
|
8
|
+
"May",
|
|
9
|
+
"June",
|
|
10
|
+
"July",
|
|
11
|
+
"August",
|
|
12
|
+
"September",
|
|
13
|
+
"October",
|
|
14
|
+
"November",
|
|
15
|
+
"December"
|
|
16
|
+
];
|
|
17
|
+
var DAY_NAMES = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
|
18
|
+
function getDaysInMonth(year, month) {
|
|
19
|
+
return new Date(year, month + 1, 0).getDate();
|
|
20
|
+
}
|
|
21
|
+
function isSameDay(a, b) {
|
|
22
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
23
|
+
}
|
|
24
|
+
function addDays(date, days) {
|
|
25
|
+
const result = new Date(date);
|
|
26
|
+
result.setDate(result.getDate() + days);
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
function addMonths(date, months) {
|
|
30
|
+
const result = new Date(date);
|
|
31
|
+
result.setMonth(result.getMonth() + months);
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
var Calendar = {
|
|
35
|
+
Root(options = {}) {
|
|
36
|
+
const now = new Date;
|
|
37
|
+
const defaultMonth = options.defaultMonth ?? now;
|
|
38
|
+
const weekStartsOn = options.weekStartsOn ?? 0;
|
|
39
|
+
const mode = options.mode ?? "single";
|
|
40
|
+
const state = {
|
|
41
|
+
value: signal(options.defaultValue ?? null),
|
|
42
|
+
focusedDate: signal(defaultMonth),
|
|
43
|
+
displayMonth: signal(defaultMonth)
|
|
44
|
+
};
|
|
45
|
+
const root = document.createElement("div");
|
|
46
|
+
const header = document.createElement("div");
|
|
47
|
+
const title = document.createElement("div");
|
|
48
|
+
const prevButton = document.createElement("button");
|
|
49
|
+
prevButton.setAttribute("type", "button");
|
|
50
|
+
const nextButton = document.createElement("button");
|
|
51
|
+
nextButton.setAttribute("type", "button");
|
|
52
|
+
const grid = document.createElement("table");
|
|
53
|
+
grid.setAttribute("role", "grid");
|
|
54
|
+
function updateTitle() {
|
|
55
|
+
const month = state.displayMonth.peek();
|
|
56
|
+
title.textContent = `${MONTH_NAMES[month.getMonth()]} ${month.getFullYear()}`;
|
|
57
|
+
}
|
|
58
|
+
function isDateDisabled(date) {
|
|
59
|
+
if (options.disabled?.(date))
|
|
60
|
+
return true;
|
|
61
|
+
if (options.minDate && date < options.minDate && !isSameDay(date, options.minDate)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (options.maxDate && date > options.maxDate && !isSameDay(date, options.maxDate)) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
function isSelected(date) {
|
|
70
|
+
const val = state.value.peek();
|
|
71
|
+
if (val === null)
|
|
72
|
+
return false;
|
|
73
|
+
if (val instanceof Date)
|
|
74
|
+
return isSameDay(val, date);
|
|
75
|
+
if (Array.isArray(val))
|
|
76
|
+
return val.some((d) => isSameDay(d, date));
|
|
77
|
+
if ("from" in val && "to" in val) {
|
|
78
|
+
return isSameDay(val.from, date) || isSameDay(val.to, date);
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
function isInRange(date) {
|
|
83
|
+
const val = state.value.peek();
|
|
84
|
+
if (val === null || !("from" in val))
|
|
85
|
+
return false;
|
|
86
|
+
const range = val;
|
|
87
|
+
return date > range.from && date < range.to;
|
|
88
|
+
}
|
|
89
|
+
function selectDate(date) {
|
|
90
|
+
if (isDateDisabled(date))
|
|
91
|
+
return;
|
|
92
|
+
if (mode === "single") {
|
|
93
|
+
state.value.value = date;
|
|
94
|
+
} else if (mode === "multiple") {
|
|
95
|
+
const current = state.value.peek() ?? [];
|
|
96
|
+
const existing = current.findIndex((d) => isSameDay(d, date));
|
|
97
|
+
if (existing >= 0) {
|
|
98
|
+
const next = [...current];
|
|
99
|
+
next.splice(existing, 1);
|
|
100
|
+
state.value.value = next;
|
|
101
|
+
} else {
|
|
102
|
+
state.value.value = [...current, date];
|
|
103
|
+
}
|
|
104
|
+
} else if (mode === "range") {
|
|
105
|
+
const current = state.value.peek();
|
|
106
|
+
if (!current || "to" in current && current.to) {
|
|
107
|
+
state.value.value = { from: date, to: date };
|
|
108
|
+
} else {
|
|
109
|
+
if (date < current.from) {
|
|
110
|
+
state.value.value = { from: date, to: current.from };
|
|
111
|
+
} else {
|
|
112
|
+
state.value.value = { from: current.from, to: date };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
options.onValueChange?.(state.value.peek());
|
|
117
|
+
}
|
|
118
|
+
function buildGrid() {
|
|
119
|
+
grid.innerHTML = "";
|
|
120
|
+
const display = state.displayMonth.peek();
|
|
121
|
+
const year = display.getFullYear();
|
|
122
|
+
const month = display.getMonth();
|
|
123
|
+
const daysInMonth = getDaysInMonth(year, month);
|
|
124
|
+
const thead = document.createElement("thead");
|
|
125
|
+
const headerRow = document.createElement("tr");
|
|
126
|
+
for (let i = 0;i < 7; i++) {
|
|
127
|
+
const dayIndex = (weekStartsOn + i) % 7;
|
|
128
|
+
const th = document.createElement("th");
|
|
129
|
+
th.setAttribute("scope", "col");
|
|
130
|
+
th.textContent = DAY_NAMES[dayIndex] ?? "";
|
|
131
|
+
headerRow.appendChild(th);
|
|
132
|
+
}
|
|
133
|
+
thead.appendChild(headerRow);
|
|
134
|
+
grid.appendChild(thead);
|
|
135
|
+
const tbody = document.createElement("tbody");
|
|
136
|
+
const firstDay = new Date(year, month, 1);
|
|
137
|
+
const firstDayOfWeek = firstDay.getDay();
|
|
138
|
+
const offset = (firstDayOfWeek - weekStartsOn + 7) % 7;
|
|
139
|
+
const startDate = addDays(firstDay, -offset);
|
|
140
|
+
let currentDate = startDate;
|
|
141
|
+
const totalCells = offset + daysInMonth;
|
|
142
|
+
const totalRows = Math.ceil(totalCells / 7);
|
|
143
|
+
for (let row = 0;row < totalRows; row++) {
|
|
144
|
+
const tr = document.createElement("tr");
|
|
145
|
+
for (let col = 0;col < 7; col++) {
|
|
146
|
+
const td = document.createElement("td");
|
|
147
|
+
td.setAttribute("role", "gridcell");
|
|
148
|
+
const btn = document.createElement("button");
|
|
149
|
+
btn.setAttribute("type", "button");
|
|
150
|
+
const cellDate = new Date(currentDate);
|
|
151
|
+
btn.textContent = String(cellDate.getDate());
|
|
152
|
+
btn.setAttribute("data-date", cellDate.toISOString().split("T")[0] ?? "");
|
|
153
|
+
const isOutside = cellDate.getMonth() !== month;
|
|
154
|
+
if (isOutside) {
|
|
155
|
+
btn.setAttribute("data-outside-month", "true");
|
|
156
|
+
}
|
|
157
|
+
if (isSameDay(cellDate, now)) {
|
|
158
|
+
btn.setAttribute("data-today", "true");
|
|
159
|
+
}
|
|
160
|
+
if (isDateDisabled(cellDate)) {
|
|
161
|
+
btn.setAttribute("aria-disabled", "true");
|
|
162
|
+
}
|
|
163
|
+
if (isSelected(cellDate)) {
|
|
164
|
+
btn.setAttribute("aria-selected", "true");
|
|
165
|
+
}
|
|
166
|
+
if (mode === "range") {
|
|
167
|
+
const val = state.value.peek();
|
|
168
|
+
if (val && "from" in val) {
|
|
169
|
+
if (isSameDay(cellDate, val.from)) {
|
|
170
|
+
btn.setAttribute("data-range-start", "true");
|
|
171
|
+
}
|
|
172
|
+
if (isSameDay(cellDate, val.to)) {
|
|
173
|
+
btn.setAttribute("data-range-end", "true");
|
|
174
|
+
}
|
|
175
|
+
if (isInRange(cellDate)) {
|
|
176
|
+
btn.setAttribute("data-in-range", "true");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
btn.addEventListener("click", () => {
|
|
181
|
+
selectDate(cellDate);
|
|
182
|
+
rebuildGrid();
|
|
183
|
+
});
|
|
184
|
+
td.appendChild(btn);
|
|
185
|
+
tr.appendChild(td);
|
|
186
|
+
currentDate = addDays(currentDate, 1);
|
|
187
|
+
}
|
|
188
|
+
tbody.appendChild(tr);
|
|
189
|
+
}
|
|
190
|
+
grid.appendChild(tbody);
|
|
191
|
+
}
|
|
192
|
+
function rebuildGrid() {
|
|
193
|
+
updateTitle();
|
|
194
|
+
buildGrid();
|
|
195
|
+
}
|
|
196
|
+
function navigateMonth(delta) {
|
|
197
|
+
state.displayMonth.value = addMonths(state.displayMonth.peek(), delta);
|
|
198
|
+
options.onMonthChange?.(state.displayMonth.peek());
|
|
199
|
+
rebuildGrid();
|
|
200
|
+
}
|
|
201
|
+
prevButton.addEventListener("click", () => navigateMonth(-1));
|
|
202
|
+
nextButton.addEventListener("click", () => navigateMonth(1));
|
|
203
|
+
grid.addEventListener("keydown", (event) => {
|
|
204
|
+
const active = document.activeElement;
|
|
205
|
+
if (!active || active.tagName !== "BUTTON")
|
|
206
|
+
return;
|
|
207
|
+
const dateStr = active.getAttribute("data-date");
|
|
208
|
+
if (!dateStr)
|
|
209
|
+
return;
|
|
210
|
+
const focused = new Date(dateStr + "T00:00:00");
|
|
211
|
+
let next = null;
|
|
212
|
+
if (event.key === "ArrowLeft") {
|
|
213
|
+
event.preventDefault();
|
|
214
|
+
next = addDays(focused, -1);
|
|
215
|
+
} else if (event.key === "ArrowRight") {
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
next = addDays(focused, 1);
|
|
218
|
+
} else if (event.key === "ArrowUp") {
|
|
219
|
+
event.preventDefault();
|
|
220
|
+
next = addDays(focused, -7);
|
|
221
|
+
} else if (event.key === "ArrowDown") {
|
|
222
|
+
event.preventDefault();
|
|
223
|
+
next = addDays(focused, 7);
|
|
224
|
+
} else if (event.key === "Home") {
|
|
225
|
+
event.preventDefault();
|
|
226
|
+
const dayOfWeek = (focused.getDay() - weekStartsOn + 7) % 7;
|
|
227
|
+
next = addDays(focused, -dayOfWeek);
|
|
228
|
+
} else if (event.key === "End") {
|
|
229
|
+
event.preventDefault();
|
|
230
|
+
const dayOfWeek = (focused.getDay() - weekStartsOn + 7) % 7;
|
|
231
|
+
next = addDays(focused, 6 - dayOfWeek);
|
|
232
|
+
} else if (event.key === "PageUp") {
|
|
233
|
+
event.preventDefault();
|
|
234
|
+
next = event.shiftKey ? addMonths(focused, -12) : addMonths(focused, -1);
|
|
235
|
+
} else if (event.key === "PageDown") {
|
|
236
|
+
event.preventDefault();
|
|
237
|
+
next = event.shiftKey ? addMonths(focused, 12) : addMonths(focused, 1);
|
|
238
|
+
} else if (event.key === "Enter" || event.key === " ") {
|
|
239
|
+
event.preventDefault();
|
|
240
|
+
selectDate(focused);
|
|
241
|
+
rebuildGrid();
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (next) {
|
|
245
|
+
state.focusedDate.value = next;
|
|
246
|
+
if (next.getMonth() !== state.displayMonth.peek().getMonth() || next.getFullYear() !== state.displayMonth.peek().getFullYear()) {
|
|
247
|
+
state.displayMonth.value = new Date(next.getFullYear(), next.getMonth(), 1);
|
|
248
|
+
options.onMonthChange?.(state.displayMonth.peek());
|
|
249
|
+
rebuildGrid();
|
|
250
|
+
}
|
|
251
|
+
const dateKey = next.toISOString().split("T")[0];
|
|
252
|
+
const btn = grid.querySelector(`button[data-date="${dateKey}"]`);
|
|
253
|
+
btn?.focus();
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
updateTitle();
|
|
257
|
+
buildGrid();
|
|
258
|
+
root.appendChild(header);
|
|
259
|
+
root.appendChild(grid);
|
|
260
|
+
header.appendChild(prevButton);
|
|
261
|
+
header.appendChild(title);
|
|
262
|
+
header.appendChild(nextButton);
|
|
263
|
+
return { root, header, title, prevButton, nextButton, grid, state };
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
export { Calendar };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createFloatingPosition
|
|
3
|
+
} from "./chunk-0mcr52hc.js";
|
|
4
|
+
import {
|
|
5
|
+
Keys,
|
|
6
|
+
isKey
|
|
7
|
+
} from "./chunk-jctqs9m4.js";
|
|
8
|
+
import {
|
|
9
|
+
setDataState,
|
|
10
|
+
setDescribedBy,
|
|
11
|
+
setHidden,
|
|
12
|
+
setHiddenAnimated
|
|
13
|
+
} from "./chunk-vvjyx7fe.js";
|
|
14
|
+
import {
|
|
15
|
+
uniqueId
|
|
16
|
+
} from "./chunk-8y1jf6xr.js";
|
|
17
|
+
|
|
18
|
+
// src/tooltip/tooltip.ts
|
|
19
|
+
import { signal } from "@vertz/ui";
|
|
20
|
+
var Tooltip = {
|
|
21
|
+
Root(options = {}) {
|
|
22
|
+
const { delay = 300, onOpenChange, positioning } = options;
|
|
23
|
+
const contentId = uniqueId("tooltip");
|
|
24
|
+
const state = { open: signal(false) };
|
|
25
|
+
let showTimeout = null;
|
|
26
|
+
let floatingCleanup = null;
|
|
27
|
+
const trigger = document.createElement("span");
|
|
28
|
+
setDescribedBy(trigger, contentId);
|
|
29
|
+
const content = document.createElement("div");
|
|
30
|
+
content.setAttribute("role", "tooltip");
|
|
31
|
+
content.id = contentId;
|
|
32
|
+
setHidden(content, true);
|
|
33
|
+
setDataState(content, "closed");
|
|
34
|
+
function show() {
|
|
35
|
+
if (showTimeout !== null)
|
|
36
|
+
return;
|
|
37
|
+
showTimeout = setTimeout(() => {
|
|
38
|
+
state.open.value = true;
|
|
39
|
+
setHidden(content, false);
|
|
40
|
+
setDataState(content, "open");
|
|
41
|
+
if (positioning) {
|
|
42
|
+
const effectivePlacement = positioning.placement ?? "top";
|
|
43
|
+
const result = createFloatingPosition(trigger, content, {
|
|
44
|
+
...positioning,
|
|
45
|
+
placement: effectivePlacement
|
|
46
|
+
});
|
|
47
|
+
floatingCleanup = result.cleanup;
|
|
48
|
+
}
|
|
49
|
+
onOpenChange?.(true);
|
|
50
|
+
showTimeout = null;
|
|
51
|
+
}, delay);
|
|
52
|
+
}
|
|
53
|
+
function hide() {
|
|
54
|
+
if (showTimeout !== null) {
|
|
55
|
+
clearTimeout(showTimeout);
|
|
56
|
+
showTimeout = null;
|
|
57
|
+
}
|
|
58
|
+
state.open.value = false;
|
|
59
|
+
setDataState(content, "closed");
|
|
60
|
+
setHiddenAnimated(content, true);
|
|
61
|
+
floatingCleanup?.();
|
|
62
|
+
floatingCleanup = null;
|
|
63
|
+
onOpenChange?.(false);
|
|
64
|
+
}
|
|
65
|
+
trigger.addEventListener("mouseenter", show);
|
|
66
|
+
trigger.addEventListener("mouseleave", hide);
|
|
67
|
+
trigger.addEventListener("focus", show);
|
|
68
|
+
trigger.addEventListener("blur", hide);
|
|
69
|
+
trigger.addEventListener("keydown", (event) => {
|
|
70
|
+
if (isKey(event, Keys.Escape)) {
|
|
71
|
+
hide();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return { trigger, content, state };
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export { Tooltip };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Calendar
|
|
3
|
+
} from "./chunk-48v8j0vh.js";
|
|
4
|
+
import {
|
|
5
|
+
Popover
|
|
6
|
+
} from "./chunk-dkhst4wv.js";
|
|
7
|
+
|
|
8
|
+
// src/date-picker/date-picker.ts
|
|
9
|
+
import { signal } from "@vertz/ui";
|
|
10
|
+
function defaultFormatDate(date) {
|
|
11
|
+
return date.toLocaleDateString();
|
|
12
|
+
}
|
|
13
|
+
function formatRangeDisplay(value, fmt) {
|
|
14
|
+
return `${fmt(value.from)} – ${fmt(value.to)}`;
|
|
15
|
+
}
|
|
16
|
+
var DatePicker = {
|
|
17
|
+
Root(options = {}) {
|
|
18
|
+
const {
|
|
19
|
+
mode = "single",
|
|
20
|
+
defaultValue = null,
|
|
21
|
+
minDate,
|
|
22
|
+
maxDate,
|
|
23
|
+
disabled,
|
|
24
|
+
formatDate = defaultFormatDate,
|
|
25
|
+
placeholder = "Pick a date",
|
|
26
|
+
onValueChange,
|
|
27
|
+
onOpenChange
|
|
28
|
+
} = options;
|
|
29
|
+
const defaultMonth = options.defaultMonth ?? (defaultValue instanceof Date ? defaultValue : defaultValue && ("from" in defaultValue) ? defaultValue.from : new Date);
|
|
30
|
+
const calendarMode = mode === "range" ? "range" : "single";
|
|
31
|
+
const calendarDefaultValue = defaultValue instanceof Date ? defaultValue : defaultValue && ("from" in defaultValue) ? defaultValue : undefined;
|
|
32
|
+
const popover = Popover.Root({
|
|
33
|
+
onOpenChange(open) {
|
|
34
|
+
state.open.value = open;
|
|
35
|
+
onOpenChange?.(open);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const calendarResult = Calendar.Root({
|
|
39
|
+
mode: calendarMode,
|
|
40
|
+
defaultValue: calendarDefaultValue,
|
|
41
|
+
defaultMonth,
|
|
42
|
+
minDate,
|
|
43
|
+
maxDate,
|
|
44
|
+
disabled,
|
|
45
|
+
onValueChange(value) {
|
|
46
|
+
if (mode === "single" && value instanceof Date) {
|
|
47
|
+
state.value.value = value;
|
|
48
|
+
updateTriggerText();
|
|
49
|
+
onValueChange?.(value);
|
|
50
|
+
hide();
|
|
51
|
+
} else if (mode === "range" && value && "from" in value) {
|
|
52
|
+
const range = value;
|
|
53
|
+
state.value.value = range;
|
|
54
|
+
updateTriggerText();
|
|
55
|
+
onValueChange?.(range);
|
|
56
|
+
if (range.from && range.to && range.from.getTime() !== range.to.getTime()) {
|
|
57
|
+
hide();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
popover.content.appendChild(calendarResult.root);
|
|
63
|
+
const state = {
|
|
64
|
+
open: signal(false),
|
|
65
|
+
value: signal(defaultValue),
|
|
66
|
+
displayMonth: calendarResult.state.displayMonth
|
|
67
|
+
};
|
|
68
|
+
function updateTriggerText() {
|
|
69
|
+
const val = state.value.peek();
|
|
70
|
+
if (val === null) {
|
|
71
|
+
popover.trigger.textContent = placeholder;
|
|
72
|
+
popover.trigger.setAttribute("data-placeholder", "true");
|
|
73
|
+
} else if (val instanceof Date) {
|
|
74
|
+
popover.trigger.textContent = formatDate(val);
|
|
75
|
+
popover.trigger.removeAttribute("data-placeholder");
|
|
76
|
+
} else if ("from" in val) {
|
|
77
|
+
popover.trigger.textContent = formatRangeDisplay(val, formatDate);
|
|
78
|
+
popover.trigger.removeAttribute("data-placeholder");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function show() {
|
|
82
|
+
popover.trigger.click();
|
|
83
|
+
}
|
|
84
|
+
function hide() {
|
|
85
|
+
if (state.open.peek()) {
|
|
86
|
+
popover.trigger.click();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
updateTriggerText();
|
|
90
|
+
return {
|
|
91
|
+
trigger: popover.trigger,
|
|
92
|
+
content: popover.content,
|
|
93
|
+
calendar: {
|
|
94
|
+
root: calendarResult.root,
|
|
95
|
+
header: calendarResult.header,
|
|
96
|
+
title: calendarResult.title,
|
|
97
|
+
prevButton: calendarResult.prevButton,
|
|
98
|
+
nextButton: calendarResult.nextButton,
|
|
99
|
+
grid: calendarResult.grid
|
|
100
|
+
},
|
|
101
|
+
state,
|
|
102
|
+
show,
|
|
103
|
+
hide
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { DatePicker };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
focusFirst,
|
|
3
|
+
setRovingTabindex
|
|
4
|
+
} from "./chunk-e2v1c9ex.js";
|
|
5
|
+
import {
|
|
6
|
+
Keys,
|
|
7
|
+
handleListNavigation,
|
|
8
|
+
isKey
|
|
9
|
+
} from "./chunk-jctqs9m4.js";
|
|
10
|
+
import {
|
|
11
|
+
setDataState,
|
|
12
|
+
setExpanded,
|
|
13
|
+
setHidden,
|
|
14
|
+
setHiddenAnimated
|
|
15
|
+
} from "./chunk-vvjyx7fe.js";
|
|
16
|
+
import {
|
|
17
|
+
linkedIds
|
|
18
|
+
} from "./chunk-8y1jf6xr.js";
|
|
19
|
+
|
|
20
|
+
// src/navigation-menu/navigation-menu.ts
|
|
21
|
+
import { signal } from "@vertz/ui";
|
|
22
|
+
var NavigationMenu = {
|
|
23
|
+
Root(options = {}) {
|
|
24
|
+
const { orientation = "horizontal", delayOpen = 200, delayClose = 300 } = options;
|
|
25
|
+
const state = { activeItem: signal(null) };
|
|
26
|
+
const triggers = [];
|
|
27
|
+
const items = new Map;
|
|
28
|
+
let openTimeout = null;
|
|
29
|
+
let closeTimeout = null;
|
|
30
|
+
const root = document.createElement("nav");
|
|
31
|
+
const list = document.createElement("div");
|
|
32
|
+
const viewport = document.createElement("div");
|
|
33
|
+
function cancelTimers() {
|
|
34
|
+
if (openTimeout) {
|
|
35
|
+
clearTimeout(openTimeout);
|
|
36
|
+
openTimeout = null;
|
|
37
|
+
}
|
|
38
|
+
if (closeTimeout) {
|
|
39
|
+
clearTimeout(closeTimeout);
|
|
40
|
+
closeTimeout = null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function openItem(value) {
|
|
44
|
+
cancelTimers();
|
|
45
|
+
const current = state.activeItem.peek();
|
|
46
|
+
if (current && current !== value) {
|
|
47
|
+
const prev = items.get(current);
|
|
48
|
+
if (prev) {
|
|
49
|
+
setExpanded(prev.trigger, false);
|
|
50
|
+
setDataState(prev.trigger, "closed");
|
|
51
|
+
setDataState(prev.content, "closed");
|
|
52
|
+
setHiddenAnimated(prev.content, true);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const item = items.get(value);
|
|
56
|
+
if (!item)
|
|
57
|
+
return;
|
|
58
|
+
state.activeItem.value = value;
|
|
59
|
+
setExpanded(item.trigger, true);
|
|
60
|
+
setHidden(item.content, false);
|
|
61
|
+
setDataState(item.trigger, "open");
|
|
62
|
+
setDataState(item.content, "open");
|
|
63
|
+
}
|
|
64
|
+
function closeAll() {
|
|
65
|
+
cancelTimers();
|
|
66
|
+
const current = state.activeItem.peek();
|
|
67
|
+
if (current) {
|
|
68
|
+
const item = items.get(current);
|
|
69
|
+
if (item) {
|
|
70
|
+
setExpanded(item.trigger, false);
|
|
71
|
+
setDataState(item.trigger, "closed");
|
|
72
|
+
setDataState(item.content, "closed");
|
|
73
|
+
setHiddenAnimated(item.content, true);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
state.activeItem.value = null;
|
|
77
|
+
}
|
|
78
|
+
function Item(value, label) {
|
|
79
|
+
const ids = linkedIds("nav-menu");
|
|
80
|
+
const trigger = document.createElement("button");
|
|
81
|
+
trigger.setAttribute("type", "button");
|
|
82
|
+
trigger.id = ids.triggerId;
|
|
83
|
+
trigger.setAttribute("aria-controls", ids.contentId);
|
|
84
|
+
trigger.setAttribute("data-value", value);
|
|
85
|
+
trigger.textContent = label ?? value;
|
|
86
|
+
setExpanded(trigger, false);
|
|
87
|
+
setDataState(trigger, "closed");
|
|
88
|
+
const content = document.createElement("div");
|
|
89
|
+
content.id = ids.contentId;
|
|
90
|
+
setHidden(content, true);
|
|
91
|
+
setDataState(content, "closed");
|
|
92
|
+
trigger.addEventListener("click", () => {
|
|
93
|
+
if (state.activeItem.peek() === value) {
|
|
94
|
+
closeAll();
|
|
95
|
+
} else {
|
|
96
|
+
openItem(value);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
trigger.addEventListener("mouseenter", () => {
|
|
100
|
+
cancelTimers();
|
|
101
|
+
openTimeout = setTimeout(() => {
|
|
102
|
+
openItem(value);
|
|
103
|
+
openTimeout = null;
|
|
104
|
+
}, delayOpen);
|
|
105
|
+
});
|
|
106
|
+
trigger.addEventListener("mouseleave", () => {
|
|
107
|
+
cancelTimers();
|
|
108
|
+
closeTimeout = setTimeout(() => {
|
|
109
|
+
closeAll();
|
|
110
|
+
closeTimeout = null;
|
|
111
|
+
}, delayClose);
|
|
112
|
+
});
|
|
113
|
+
content.addEventListener("mouseenter", () => {
|
|
114
|
+
cancelTimers();
|
|
115
|
+
});
|
|
116
|
+
content.addEventListener("mouseleave", () => {
|
|
117
|
+
cancelTimers();
|
|
118
|
+
closeTimeout = setTimeout(() => {
|
|
119
|
+
closeAll();
|
|
120
|
+
closeTimeout = null;
|
|
121
|
+
}, delayClose);
|
|
122
|
+
});
|
|
123
|
+
trigger.addEventListener("keydown", (event) => {
|
|
124
|
+
if (isKey(event, Keys.Enter, Keys.Space)) {
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
openItem(value);
|
|
127
|
+
queueMicrotask(() => focusFirst(content));
|
|
128
|
+
}
|
|
129
|
+
if (isKey(event, Keys.Escape)) {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
closeAll();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
content.addEventListener("keydown", (event) => {
|
|
135
|
+
if (isKey(event, Keys.Escape)) {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
event.stopPropagation();
|
|
138
|
+
closeAll();
|
|
139
|
+
trigger.focus();
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
triggers.push(trigger);
|
|
143
|
+
setRovingTabindex(triggers, 0);
|
|
144
|
+
items.set(value, { trigger, content });
|
|
145
|
+
list.appendChild(trigger);
|
|
146
|
+
viewport.appendChild(content);
|
|
147
|
+
return { trigger, content };
|
|
148
|
+
}
|
|
149
|
+
function Link(href, label) {
|
|
150
|
+
const a = document.createElement("a");
|
|
151
|
+
a.href = href;
|
|
152
|
+
a.textContent = label;
|
|
153
|
+
list.appendChild(a);
|
|
154
|
+
return a;
|
|
155
|
+
}
|
|
156
|
+
list.addEventListener("keydown", (event) => {
|
|
157
|
+
if (isKey(event, Keys.ArrowLeft, Keys.ArrowRight, Keys.Home, Keys.End)) {
|
|
158
|
+
handleListNavigation(event, triggers, {
|
|
159
|
+
orientation: orientation === "horizontal" ? "horizontal" : "vertical"
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
root.appendChild(list);
|
|
164
|
+
root.appendChild(viewport);
|
|
165
|
+
return { root, list, viewport, state, Item, Link };
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export { NavigationMenu };
|