@krak-stack/registry 0.5.0 → 0.7.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/CHANGELOG.md +14 -0
- package/dist/components/ui/animated-list.d.ts +22 -0
- package/dist/components/ui/animated-list.js +219 -0
- package/dist/components/ui/animated-number.d.ts +9 -0
- package/dist/components/ui/animated-number.js +52 -0
- package/dist/components/ui/async-action-button.d.ts +16 -0
- package/dist/components/ui/async-action-button.js +147 -0
- package/dist/components/ui/auto-height.d.ts +9 -0
- package/dist/components/ui/auto-height.js +45 -0
- package/dist/components/ui/danger-confirmation.d.ts +20 -0
- package/dist/components/ui/danger-confirmation.js +394 -0
- package/dist/components/ui/editable-text.d.ts +19 -0
- package/dist/components/ui/editable-text.js +334 -0
- package/dist/components/ui/image-crop-editor.d.ts +41 -0
- package/dist/components/ui/image-crop-editor.js +408 -0
- package/dist/components/ui/presence-transition.d.ts +9 -0
- package/dist/components/ui/presence-transition.js +41 -0
- package/dist/components/ui/timezone-select.d.ts +56 -0
- package/dist/components/ui/timezone-select.js +898 -0
- package/dist/components/ui/timezone-select.schema.d.ts +9 -0
- package/dist/components/ui/unsaved-changes-guard.d.ts +15 -0
- package/dist/components/ui/unsaved-changes-guard.js +235 -0
- package/package.json +42 -1
|
@@ -0,0 +1,898 @@
|
|
|
1
|
+
// ../../src/components/ui/timezone-select.tsx
|
|
2
|
+
import { useId, useMemo, useState, useSyncExternalStore } from "react";
|
|
3
|
+
|
|
4
|
+
// ../../src/components/ui/button.tsx
|
|
5
|
+
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
6
|
+
import { cva } from "class-variance-authority";
|
|
7
|
+
|
|
8
|
+
// ../../src/lib/utils.ts
|
|
9
|
+
import { cn } from "cn";
|
|
10
|
+
|
|
11
|
+
// ../../src/components/ui/button.tsx
|
|
12
|
+
import { jsx } from "react/jsx-runtime";
|
|
13
|
+
var buttonVariants = cva("group/button inline-flex shrink-0 items-center justify-center rounded-md border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", {
|
|
14
|
+
variants: {
|
|
15
|
+
variant: {
|
|
16
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
17
|
+
outline: "border-border bg-background shadow-xs hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
|
18
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
|
19
|
+
ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
20
|
+
destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
|
|
21
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
22
|
+
},
|
|
23
|
+
size: {
|
|
24
|
+
default: "h-9 gap-1.5 px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
25
|
+
xs: "h-6 gap-1 rounded-[min(var(--radius-md),8px)] px-2 text-xs in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
26
|
+
sm: "h-8 gap-1 rounded-[min(var(--radius-md),10px)] px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
|
|
27
|
+
lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
28
|
+
icon: "size-9",
|
|
29
|
+
"icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
|
|
30
|
+
"icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
|
|
31
|
+
"icon-lg": "size-10"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
defaultVariants: {
|
|
35
|
+
variant: "default",
|
|
36
|
+
size: "default"
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
function Button({
|
|
40
|
+
className,
|
|
41
|
+
variant = "default",
|
|
42
|
+
size = "default",
|
|
43
|
+
...props
|
|
44
|
+
}) {
|
|
45
|
+
return /* @__PURE__ */ jsx(ButtonPrimitive, {
|
|
46
|
+
"data-slot": "button",
|
|
47
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
48
|
+
...props
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ../../src/components/ui/timezone-select.tsx
|
|
53
|
+
import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
|
|
54
|
+
|
|
55
|
+
// ../../src/components/ui/virtualized-combobox.tsx
|
|
56
|
+
import { Combobox as ComboboxPrimitive } from "@base-ui/react";
|
|
57
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
58
|
+
import { Check, ChevronsUpDown, X } from "lucide-react";
|
|
59
|
+
import {
|
|
60
|
+
useCallback,
|
|
61
|
+
useEffect,
|
|
62
|
+
useImperativeHandle,
|
|
63
|
+
useRef
|
|
64
|
+
} from "react";
|
|
65
|
+
|
|
66
|
+
// ../../src/components/ui/input-group.tsx
|
|
67
|
+
import { cva as cva2 } from "class-variance-authority";
|
|
68
|
+
|
|
69
|
+
// ../../src/components/ui/input.tsx
|
|
70
|
+
import { Input as InputPrimitive } from "@base-ui/react/input";
|
|
71
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
72
|
+
function Input({ className, type, ...props }) {
|
|
73
|
+
return /* @__PURE__ */ jsx2(InputPrimitive, {
|
|
74
|
+
type,
|
|
75
|
+
"data-slot": "input",
|
|
76
|
+
className: cn("h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-2.5 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40", className),
|
|
77
|
+
...props
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ../../src/components/ui/input-group.tsx
|
|
82
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
83
|
+
function InputGroup({ className, ...props }) {
|
|
84
|
+
return /* @__PURE__ */ jsx3("div", {
|
|
85
|
+
"data-slot": "input-group",
|
|
86
|
+
role: "group",
|
|
87
|
+
className: cn("group/input-group relative flex h-9 w-full min-w-0 items-center rounded-md border border-input shadow-xs transition-[color,box-shadow] outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5", className),
|
|
88
|
+
...props
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
var inputGroupAddonVariants = cva2("flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4", {
|
|
92
|
+
variants: {
|
|
93
|
+
align: {
|
|
94
|
+
"inline-start": "order-first pl-2 has-[>button]:-ml-1 has-[>kbd]:ml-[-0.15rem]",
|
|
95
|
+
"inline-end": "order-last pr-2 has-[>button]:-mr-1 has-[>kbd]:mr-[-0.15rem]",
|
|
96
|
+
"block-start": "order-first w-full justify-start px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2",
|
|
97
|
+
"block-end": "order-last w-full justify-start px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2"
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
defaultVariants: { align: "inline-start" }
|
|
101
|
+
});
|
|
102
|
+
var inputGroupButtonVariants = cva2("flex items-center gap-2 text-sm shadow-none", {
|
|
103
|
+
variants: {
|
|
104
|
+
size: {
|
|
105
|
+
xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
|
|
106
|
+
sm: "",
|
|
107
|
+
"icon-xs": "size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0",
|
|
108
|
+
"icon-sm": "size-8 p-0 has-[>svg]:p-0"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
defaultVariants: { size: "xs" }
|
|
112
|
+
});
|
|
113
|
+
function InputGroupInput({
|
|
114
|
+
className,
|
|
115
|
+
...props
|
|
116
|
+
}) {
|
|
117
|
+
return /* @__PURE__ */ jsx3(Input, {
|
|
118
|
+
"data-slot": "input-group-control",
|
|
119
|
+
className: cn("flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent", className),
|
|
120
|
+
...props
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ../../src/components/ui/virtualized-combobox.tsx
|
|
125
|
+
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
|
|
126
|
+
import { jsx as jsx4, jsxs, Fragment } from "react/jsx-runtime";
|
|
127
|
+
"use client";
|
|
128
|
+
var messages = {
|
|
129
|
+
en: {
|
|
130
|
+
clear: "Clear selection",
|
|
131
|
+
search: "Search...",
|
|
132
|
+
selected: (count) => `${count} selected`,
|
|
133
|
+
selectMore: "Select more"
|
|
134
|
+
},
|
|
135
|
+
fr: {
|
|
136
|
+
clear: "Effacer la sélection",
|
|
137
|
+
search: "Rechercher...",
|
|
138
|
+
selected: (count) => `${count} sélectionnés`,
|
|
139
|
+
selectMore: "Sélectionner davantage"
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
var virtualizedComboboxMessages = (locale, translations) => ({
|
|
143
|
+
...locale.startsWith("fr") ? messages.fr : messages.en,
|
|
144
|
+
...translations?.[locale.split("-")[0] ?? locale],
|
|
145
|
+
...translations?.[locale]
|
|
146
|
+
});
|
|
147
|
+
var optionEquals = (item, selected) => item.value === selected.value;
|
|
148
|
+
var VirtualizedComboboxList = ({
|
|
149
|
+
emptyLabel,
|
|
150
|
+
groupSelections,
|
|
151
|
+
itemIndexRef,
|
|
152
|
+
locale = "en",
|
|
153
|
+
messages: messageOverrides,
|
|
154
|
+
renderItem,
|
|
155
|
+
selectedValues,
|
|
156
|
+
virtualizerRef
|
|
157
|
+
}) => {
|
|
158
|
+
const filteredItems = ComboboxPrimitive.useFilteredItems();
|
|
159
|
+
const labels = virtualizedComboboxMessages(locale, messageOverrides);
|
|
160
|
+
const itemEntries = filteredItems.map((item, index) => ({
|
|
161
|
+
kind: "item",
|
|
162
|
+
item,
|
|
163
|
+
index
|
|
164
|
+
}));
|
|
165
|
+
const selectedEntries = itemEntries.filter(({ item }) => selectedValues.has(item.value));
|
|
166
|
+
const availableEntries = itemEntries.filter(({ item }) => !selectedValues.has(item.value));
|
|
167
|
+
const entries = filteredItems.length === 0 ? [] : groupSelections ? [
|
|
168
|
+
...selectedEntries.length > 0 ? [
|
|
169
|
+
{
|
|
170
|
+
kind: "group",
|
|
171
|
+
key: "selected",
|
|
172
|
+
label: labels.selected(selectedValues.size)
|
|
173
|
+
},
|
|
174
|
+
...selectedEntries
|
|
175
|
+
] : [],
|
|
176
|
+
{
|
|
177
|
+
kind: "group",
|
|
178
|
+
key: "available",
|
|
179
|
+
label: labels.selectMore
|
|
180
|
+
},
|
|
181
|
+
...availableEntries
|
|
182
|
+
] : itemEntries;
|
|
183
|
+
const scrollRef = useRef(null);
|
|
184
|
+
const virtualizer = useVirtualizer({
|
|
185
|
+
count: entries.length,
|
|
186
|
+
getScrollElement: () => scrollRef.current,
|
|
187
|
+
getItemKey: (index) => {
|
|
188
|
+
const entry = entries[index];
|
|
189
|
+
return entry?.kind === "group" ? `group-${entry.key}` : entry?.item.value ?? index;
|
|
190
|
+
},
|
|
191
|
+
estimateSize: () => 36,
|
|
192
|
+
overscan: 8
|
|
193
|
+
});
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
itemIndexRef.current = new Map(entries.flatMap((entry, index) => entry.kind === "item" ? [[entry.index, index]] : []));
|
|
196
|
+
});
|
|
197
|
+
useImperativeHandle(virtualizerRef, () => virtualizer, [virtualizer]);
|
|
198
|
+
const handleScrollElementRef = useCallback((element) => {
|
|
199
|
+
scrollRef.current = element;
|
|
200
|
+
if (element)
|
|
201
|
+
virtualizer.measure();
|
|
202
|
+
}, [virtualizer]);
|
|
203
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
204
|
+
children: [
|
|
205
|
+
filteredItems.length === 0 && /* @__PURE__ */ jsx4("div", {
|
|
206
|
+
className: "text-muted-foreground flex min-h-0 flex-1 flex-col items-center justify-center overflow-auto py-6 text-center text-sm",
|
|
207
|
+
children: emptyLabel
|
|
208
|
+
}),
|
|
209
|
+
/* @__PURE__ */ jsx4(ComboboxPrimitive.List, {
|
|
210
|
+
className: "min-h-0 flex-1 scroll-py-1 overflow-auto overscroll-contain p-1",
|
|
211
|
+
hidden: filteredItems.length === 0,
|
|
212
|
+
ref: handleScrollElementRef,
|
|
213
|
+
style: {
|
|
214
|
+
height: Math.min(virtualizer.getTotalSize() + 8, 288),
|
|
215
|
+
maxHeight: "var(--available-height)"
|
|
216
|
+
},
|
|
217
|
+
children: /* @__PURE__ */ jsx4("div", {
|
|
218
|
+
className: "relative w-full",
|
|
219
|
+
role: "presentation",
|
|
220
|
+
style: { height: virtualizer.getTotalSize() },
|
|
221
|
+
children: virtualizer.getVirtualItems().map((virtualItem) => {
|
|
222
|
+
const entry = entries[virtualItem.index];
|
|
223
|
+
if (!entry)
|
|
224
|
+
return null;
|
|
225
|
+
const style = {
|
|
226
|
+
height: virtualItem.size,
|
|
227
|
+
transform: `translateY(${virtualItem.start}px)`
|
|
228
|
+
};
|
|
229
|
+
if (entry.kind === "group") {
|
|
230
|
+
return /* @__PURE__ */ jsx4(ComboboxPrimitive.Group, {
|
|
231
|
+
className: "contents",
|
|
232
|
+
children: /* @__PURE__ */ jsx4(ComboboxPrimitive.GroupLabel, {
|
|
233
|
+
className: "text-muted-foreground absolute top-0 left-0 w-full px-2 pt-3 pb-1 text-xs",
|
|
234
|
+
"data-index": virtualItem.index,
|
|
235
|
+
ref: virtualizer.measureElement,
|
|
236
|
+
style,
|
|
237
|
+
children: entry.label
|
|
238
|
+
})
|
|
239
|
+
}, entry.key);
|
|
240
|
+
}
|
|
241
|
+
return /* @__PURE__ */ jsxs(ComboboxPrimitive.Item, {
|
|
242
|
+
"aria-posinset": entry.index + 1,
|
|
243
|
+
"aria-setsize": filteredItems.length,
|
|
244
|
+
className: "data-highlighted:bg-accent data-highlighted:text-accent-foreground absolute top-0 left-0 flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50",
|
|
245
|
+
"data-index": virtualItem.index,
|
|
246
|
+
index: entry.index,
|
|
247
|
+
ref: virtualizer.measureElement,
|
|
248
|
+
style,
|
|
249
|
+
value: entry.item,
|
|
250
|
+
children: [
|
|
251
|
+
renderItem?.(entry.item) ?? /* @__PURE__ */ jsx4("span", {
|
|
252
|
+
className: "min-w-0 truncate",
|
|
253
|
+
children: entry.item.label
|
|
254
|
+
}),
|
|
255
|
+
/* @__PURE__ */ jsx4(ComboboxPrimitive.ItemIndicator, {
|
|
256
|
+
className: "absolute right-2 flex size-4 items-center justify-center",
|
|
257
|
+
children: /* @__PURE__ */ jsx4(Check, {})
|
|
258
|
+
})
|
|
259
|
+
]
|
|
260
|
+
}, entry.item.value);
|
|
261
|
+
})
|
|
262
|
+
})
|
|
263
|
+
})
|
|
264
|
+
]
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
var VirtualizedComboboxContent = ({
|
|
268
|
+
contentClassName,
|
|
269
|
+
emptyLabel,
|
|
270
|
+
groupSelections,
|
|
271
|
+
itemIndexRef,
|
|
272
|
+
locale = "en",
|
|
273
|
+
messages: messageOverrides,
|
|
274
|
+
renderItem,
|
|
275
|
+
selectedValues,
|
|
276
|
+
virtualizerRef
|
|
277
|
+
}) => {
|
|
278
|
+
const labels = virtualizedComboboxMessages(locale, messageOverrides);
|
|
279
|
+
return /* @__PURE__ */ jsx4(ComboboxPrimitive.Portal, {
|
|
280
|
+
children: /* @__PURE__ */ jsx4(ComboboxPrimitive.Positioner, {
|
|
281
|
+
align: "start",
|
|
282
|
+
className: "isolate z-50",
|
|
283
|
+
side: "bottom",
|
|
284
|
+
sideOffset: 6,
|
|
285
|
+
children: /* @__PURE__ */ jsxs(ComboboxPrimitive.Popup, {
|
|
286
|
+
className: cn("bg-popover text-popover-foreground ring-foreground/10 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-in-95 relative flex max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) flex-col overflow-hidden rounded-md shadow-md ring-1 duration-100", contentClassName),
|
|
287
|
+
children: [
|
|
288
|
+
/* @__PURE__ */ jsx4("div", {
|
|
289
|
+
className: "min-w-0 shrink-0 p-1 pb-0",
|
|
290
|
+
children: /* @__PURE__ */ jsx4(InputGroup, {
|
|
291
|
+
className: "border-input/30 bg-input/30 h-8 w-full min-w-0 shadow-none",
|
|
292
|
+
children: /* @__PURE__ */ jsx4(ComboboxPrimitive.Input, {
|
|
293
|
+
placeholder: labels.search,
|
|
294
|
+
render: /* @__PURE__ */ jsx4(InputGroupInput, {})
|
|
295
|
+
})
|
|
296
|
+
})
|
|
297
|
+
}),
|
|
298
|
+
/* @__PURE__ */ jsx4(VirtualizedComboboxList, {
|
|
299
|
+
emptyLabel,
|
|
300
|
+
groupSelections,
|
|
301
|
+
itemIndexRef,
|
|
302
|
+
locale,
|
|
303
|
+
messages: messageOverrides,
|
|
304
|
+
renderItem,
|
|
305
|
+
selectedValues,
|
|
306
|
+
virtualizerRef
|
|
307
|
+
})
|
|
308
|
+
]
|
|
309
|
+
})
|
|
310
|
+
})
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
var defaultTrigger = (ariaLabel, ariaInvalid, disabled, label, triggerId) => /* @__PURE__ */ jsxs(Button, {
|
|
314
|
+
"aria-label": ariaLabel,
|
|
315
|
+
"aria-invalid": ariaInvalid,
|
|
316
|
+
className: "w-full max-w-full min-w-0 justify-between overflow-hidden",
|
|
317
|
+
disabled,
|
|
318
|
+
id: triggerId,
|
|
319
|
+
type: "button",
|
|
320
|
+
variant: "outline",
|
|
321
|
+
children: [
|
|
322
|
+
/* @__PURE__ */ jsx4("span", {
|
|
323
|
+
className: "min-w-0 flex-1 truncate pr-7 text-left",
|
|
324
|
+
children: label
|
|
325
|
+
}),
|
|
326
|
+
/* @__PURE__ */ jsx4(ChevronsUpDown, {
|
|
327
|
+
className: "text-muted-foreground shrink-0 opacity-70"
|
|
328
|
+
})
|
|
329
|
+
]
|
|
330
|
+
});
|
|
331
|
+
var defaultClear = (label) => /* @__PURE__ */ jsx4(ComboboxPrimitive.Clear, {
|
|
332
|
+
"aria-label": label,
|
|
333
|
+
className: "text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 absolute top-1/2 right-7 z-10 flex size-6 -translate-y-1/2 items-center justify-center rounded-sm outline-none focus-visible:border focus-visible:ring-3",
|
|
334
|
+
type: "button",
|
|
335
|
+
children: /* @__PURE__ */ jsx4(X, {
|
|
336
|
+
className: "size-3.5"
|
|
337
|
+
})
|
|
338
|
+
});
|
|
339
|
+
var selectedLabel = (value, placeholder) => {
|
|
340
|
+
if (Array.isArray(value)) {
|
|
341
|
+
return value.length > 0 ? value.map(({ label }) => label).join(", ") : placeholder;
|
|
342
|
+
}
|
|
343
|
+
return value && "label" in value ? value.label : placeholder;
|
|
344
|
+
};
|
|
345
|
+
var useComboboxVirtualizerRef = (providedRef) => {
|
|
346
|
+
const localRef = useRef(null);
|
|
347
|
+
return providedRef ?? localRef;
|
|
348
|
+
};
|
|
349
|
+
var VirtualizedComboboxSingle = (props) => {
|
|
350
|
+
const virtualizerRef = useComboboxVirtualizerRef(props.virtualizerRef);
|
|
351
|
+
const itemIndexRef = useRef(new Map);
|
|
352
|
+
const labels = virtualizedComboboxMessages(props.locale ?? "en", props.messages);
|
|
353
|
+
return /* @__PURE__ */ jsxs(ComboboxPrimitive.Root, {
|
|
354
|
+
disabled: props.disabled,
|
|
355
|
+
inputValue: props.searchValue,
|
|
356
|
+
items: [...props.items],
|
|
357
|
+
itemToStringLabel: (item) => item.label,
|
|
358
|
+
isItemEqualToValue: optionEquals,
|
|
359
|
+
onInputValueChange: (value) => props.onSearchValueChange?.(value),
|
|
360
|
+
onItemHighlighted: (_, { index, reason }) => {
|
|
361
|
+
if (reason === "keyboard" && index >= 0) {
|
|
362
|
+
virtualizerRef.current?.scrollToIndex(itemIndexRef.current.get(index) ?? index, { align: "auto" });
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
onOpenChange: (open) => props.onOpenChange?.(open),
|
|
366
|
+
onValueChange: (value) => props.onValueChange(value),
|
|
367
|
+
open: props.open,
|
|
368
|
+
value: props.value,
|
|
369
|
+
virtualized: true,
|
|
370
|
+
children: [
|
|
371
|
+
/* @__PURE__ */ jsxs("div", {
|
|
372
|
+
className: "relative",
|
|
373
|
+
children: [
|
|
374
|
+
/* @__PURE__ */ jsx4(ComboboxPrimitive.Trigger, {
|
|
375
|
+
render: props.trigger ?? defaultTrigger(props.ariaLabel, props.ariaInvalid, props.disabled, selectedLabel(props.value, props.placeholder), props.triggerId)
|
|
376
|
+
}),
|
|
377
|
+
props.trigger ? null : defaultClear(labels.clear)
|
|
378
|
+
]
|
|
379
|
+
}),
|
|
380
|
+
/* @__PURE__ */ jsx4(VirtualizedComboboxContent, {
|
|
381
|
+
...props,
|
|
382
|
+
groupSelections: false,
|
|
383
|
+
itemIndexRef,
|
|
384
|
+
selectedValues: new Set(props.value ? [props.value.value] : []),
|
|
385
|
+
virtualizerRef
|
|
386
|
+
})
|
|
387
|
+
]
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
var VirtualizedComboboxMultiple = (props) => {
|
|
391
|
+
const virtualizerRef = useComboboxVirtualizerRef(props.virtualizerRef);
|
|
392
|
+
const itemIndexRef = useRef(new Map);
|
|
393
|
+
const labels = virtualizedComboboxMessages(props.locale ?? "en", props.messages);
|
|
394
|
+
return /* @__PURE__ */ jsxs(ComboboxPrimitive.Root, {
|
|
395
|
+
disabled: props.disabled,
|
|
396
|
+
inputValue: props.searchValue,
|
|
397
|
+
items: [...props.items],
|
|
398
|
+
itemToStringLabel: (item) => item.label,
|
|
399
|
+
isItemEqualToValue: optionEquals,
|
|
400
|
+
multiple: true,
|
|
401
|
+
onInputValueChange: (value) => props.onSearchValueChange?.(value),
|
|
402
|
+
onItemHighlighted: (_, { index, reason }) => {
|
|
403
|
+
if (reason === "keyboard" && index >= 0) {
|
|
404
|
+
virtualizerRef.current?.scrollToIndex(itemIndexRef.current.get(index) ?? index, { align: "auto" });
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
onOpenChange: (open) => props.onOpenChange?.(open),
|
|
408
|
+
onValueChange: (value) => props.onValueChange(value),
|
|
409
|
+
open: props.open,
|
|
410
|
+
value: [...props.value],
|
|
411
|
+
virtualized: true,
|
|
412
|
+
children: [
|
|
413
|
+
/* @__PURE__ */ jsxs("div", {
|
|
414
|
+
className: "relative",
|
|
415
|
+
children: [
|
|
416
|
+
/* @__PURE__ */ jsx4(ComboboxPrimitive.Trigger, {
|
|
417
|
+
render: props.trigger ?? defaultTrigger(props.ariaLabel, props.ariaInvalid, props.disabled, selectedLabel(props.value, props.placeholder), props.triggerId)
|
|
418
|
+
}),
|
|
419
|
+
props.trigger ? null : defaultClear(labels.clear)
|
|
420
|
+
]
|
|
421
|
+
}),
|
|
422
|
+
/* @__PURE__ */ jsx4(VirtualizedComboboxContent, {
|
|
423
|
+
...props,
|
|
424
|
+
groupSelections: true,
|
|
425
|
+
itemIndexRef,
|
|
426
|
+
selectedValues: new Set(props.value.map(({ value }) => value)),
|
|
427
|
+
virtualizerRef
|
|
428
|
+
})
|
|
429
|
+
]
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
function VirtualizedCombobox(props) {
|
|
433
|
+
const locale = useKrakstackLocale(props.locale);
|
|
434
|
+
return props.multiple ? /* @__PURE__ */ jsx4(VirtualizedComboboxMultiple, {
|
|
435
|
+
...props,
|
|
436
|
+
locale
|
|
437
|
+
}) : /* @__PURE__ */ jsx4(VirtualizedComboboxSingle, {
|
|
438
|
+
...props,
|
|
439
|
+
locale
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// ../../src/components/ui/timezone-select.schema.ts
|
|
444
|
+
import { Schema } from "effect";
|
|
445
|
+
var TimeZoneIdSchema = Schema.NonEmptyString.pipe(Schema.check(Schema.makeFilter((value) => {
|
|
446
|
+
try {
|
|
447
|
+
new Intl.DateTimeFormat("en", { timeZone: value });
|
|
448
|
+
return true;
|
|
449
|
+
} catch {
|
|
450
|
+
return "Expected a runtime-supported time-zone identifier";
|
|
451
|
+
}
|
|
452
|
+
}))).annotate({ identifier: "TimeZoneId" });
|
|
453
|
+
var TimeZoneReferenceDateSchema = Schema.Date.pipe(Schema.check(Schema.makeFilter((value) => Number.isFinite(value.getTime()) || "Expected a valid reference date"))).annotate({ identifier: "TimeZoneReferenceDate" });
|
|
454
|
+
var isTimeZoneId = Schema.is(TimeZoneIdSchema);
|
|
455
|
+
var isTimeZoneReferenceDate = Schema.is(TimeZoneReferenceDateSchema);
|
|
456
|
+
var TimeZoneContinentFilterSchema = Schema.Literals([
|
|
457
|
+
"all",
|
|
458
|
+
"north-america",
|
|
459
|
+
"south-america",
|
|
460
|
+
"europe",
|
|
461
|
+
"africa",
|
|
462
|
+
"asia",
|
|
463
|
+
"oceania",
|
|
464
|
+
"antarctica"
|
|
465
|
+
]).annotate({ identifier: "TimeZoneContinentFilter" });
|
|
466
|
+
var isTimeZoneContinentFilter = Schema.is(TimeZoneContinentFilterSchema);
|
|
467
|
+
|
|
468
|
+
// ../../src/components/ui/timezone-select.tsx
|
|
469
|
+
import { jsx as jsx5, jsxs as jsxs2, Fragment as Fragment2 } from "react/jsx-runtime";
|
|
470
|
+
var labels = {
|
|
471
|
+
en: {
|
|
472
|
+
label: "Time zone",
|
|
473
|
+
placeholder: "Select a time zone",
|
|
474
|
+
search: "Search city, time zone or UTC offset…",
|
|
475
|
+
empty: "No matching time zones.",
|
|
476
|
+
clear: "Clear time zone",
|
|
477
|
+
yourTime: "Your time",
|
|
478
|
+
comparisonTime: "Comparison time",
|
|
479
|
+
selectedTime: "Selected time",
|
|
480
|
+
useLocal: "Use my time zone",
|
|
481
|
+
unavailable: "Time comparison unavailable.",
|
|
482
|
+
invalid: "This time zone is not supported. Choose another time zone.",
|
|
483
|
+
invalidReference: "The reference date is invalid. Local times are unavailable.",
|
|
484
|
+
same: "Same time",
|
|
485
|
+
ahead: (duration) => `${duration} ahead`,
|
|
486
|
+
behind: (duration) => `${duration} behind`
|
|
487
|
+
},
|
|
488
|
+
fr: {
|
|
489
|
+
label: "Fuseau horaire",
|
|
490
|
+
placeholder: "Choisir un fuseau horaire",
|
|
491
|
+
search: "Rechercher une ville, un fuseau ou un décalage UTC…",
|
|
492
|
+
empty: "Aucun fuseau horaire correspondant.",
|
|
493
|
+
clear: "Effacer le fuseau horaire",
|
|
494
|
+
yourTime: "Votre heure",
|
|
495
|
+
comparisonTime: "Heure de comparaison",
|
|
496
|
+
selectedTime: "Heure sélectionnée",
|
|
497
|
+
useLocal: "Utiliser mon fuseau horaire",
|
|
498
|
+
unavailable: "Comparaison des heures indisponible.",
|
|
499
|
+
invalid: "Ce fuseau n’est pas pris en charge. Choisissez un autre fuseau.",
|
|
500
|
+
invalidReference: "La date de référence est invalide. Les heures locales sont indisponibles.",
|
|
501
|
+
same: "Même heure",
|
|
502
|
+
ahead: (duration) => `${duration} d’avance`,
|
|
503
|
+
behind: (duration) => `${duration} de retard`
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
var southAmericanLocations = new Set([
|
|
507
|
+
"Araguaina",
|
|
508
|
+
"Asuncion",
|
|
509
|
+
"Bahia",
|
|
510
|
+
"Belem",
|
|
511
|
+
"Boa_Vista",
|
|
512
|
+
"Bogota",
|
|
513
|
+
"Buenos_Aires",
|
|
514
|
+
"Campo_Grande",
|
|
515
|
+
"Caracas",
|
|
516
|
+
"Catamarca",
|
|
517
|
+
"Cayenne",
|
|
518
|
+
"Cordoba",
|
|
519
|
+
"Coyhaique",
|
|
520
|
+
"Cuiaba",
|
|
521
|
+
"Eirunepe",
|
|
522
|
+
"Fortaleza",
|
|
523
|
+
"Guayaquil",
|
|
524
|
+
"Guyana",
|
|
525
|
+
"Jujuy",
|
|
526
|
+
"La_Paz",
|
|
527
|
+
"Lima",
|
|
528
|
+
"Maceio",
|
|
529
|
+
"Manaus",
|
|
530
|
+
"Mendoza",
|
|
531
|
+
"Montevideo",
|
|
532
|
+
"Noronha",
|
|
533
|
+
"Paramaribo",
|
|
534
|
+
"Porto_Acre",
|
|
535
|
+
"Porto_Velho",
|
|
536
|
+
"Punta_Arenas",
|
|
537
|
+
"Recife",
|
|
538
|
+
"Rio_Branco",
|
|
539
|
+
"Rosario",
|
|
540
|
+
"Santarem",
|
|
541
|
+
"Santiago",
|
|
542
|
+
"Sao_Paulo"
|
|
543
|
+
]);
|
|
544
|
+
var continentForLocation = (zone) => {
|
|
545
|
+
const [region, location = ""] = zone.split("/");
|
|
546
|
+
switch (region) {
|
|
547
|
+
case "US":
|
|
548
|
+
return location === "Hawaii" || location === "Samoa" ? "oceania" : "north-america";
|
|
549
|
+
case "Canada":
|
|
550
|
+
case "Mexico":
|
|
551
|
+
case "Cuba":
|
|
552
|
+
case "Jamaica":
|
|
553
|
+
case "Navajo":
|
|
554
|
+
return "north-america";
|
|
555
|
+
case "Brazil":
|
|
556
|
+
case "Chile":
|
|
557
|
+
return "south-america";
|
|
558
|
+
case "GB":
|
|
559
|
+
case "GB-Eire":
|
|
560
|
+
case "Eire":
|
|
561
|
+
case "Iceland":
|
|
562
|
+
case "Poland":
|
|
563
|
+
case "Portugal":
|
|
564
|
+
case "W-SU":
|
|
565
|
+
return "europe";
|
|
566
|
+
case "Egypt":
|
|
567
|
+
case "Libya":
|
|
568
|
+
return "africa";
|
|
569
|
+
case "Hongkong":
|
|
570
|
+
case "Iran":
|
|
571
|
+
case "Israel":
|
|
572
|
+
case "Japan":
|
|
573
|
+
case "PRC":
|
|
574
|
+
case "ROC":
|
|
575
|
+
case "ROK":
|
|
576
|
+
case "Singapore":
|
|
577
|
+
case "Turkey":
|
|
578
|
+
return "asia";
|
|
579
|
+
case "NZ":
|
|
580
|
+
case "NZ-CHAT":
|
|
581
|
+
case "W-Samoa":
|
|
582
|
+
return "oceania";
|
|
583
|
+
case "America":
|
|
584
|
+
return location === "Argentina" || southAmericanLocations.has(location) ? "south-america" : "north-america";
|
|
585
|
+
case "Europe":
|
|
586
|
+
case "Arctic":
|
|
587
|
+
return "europe";
|
|
588
|
+
case "Africa":
|
|
589
|
+
return "africa";
|
|
590
|
+
case "Asia":
|
|
591
|
+
return "asia";
|
|
592
|
+
case "Australia":
|
|
593
|
+
return "oceania";
|
|
594
|
+
case "Antarctica":
|
|
595
|
+
return "antarctica";
|
|
596
|
+
case "Pacific":
|
|
597
|
+
return location === "Easter" || location === "Galapagos" ? "south-america" : "oceania";
|
|
598
|
+
case "Atlantic":
|
|
599
|
+
if (location === "Bermuda")
|
|
600
|
+
return "north-america";
|
|
601
|
+
if (["Canary", "Cape_Verde", "St_Helena"].includes(location))
|
|
602
|
+
return "africa";
|
|
603
|
+
if (["South_Georgia", "Stanley"].includes(location))
|
|
604
|
+
return "south-america";
|
|
605
|
+
if (["Azores", "Faeroe", "Faroe", "Madeira", "Reykjavik"].includes(location))
|
|
606
|
+
return "europe";
|
|
607
|
+
return null;
|
|
608
|
+
case "Indian":
|
|
609
|
+
if (["Chagos", "Maldives"].includes(location))
|
|
610
|
+
return "asia";
|
|
611
|
+
if (["Christmas", "Cocos"].includes(location))
|
|
612
|
+
return "oceania";
|
|
613
|
+
if (location === "Kerguelen")
|
|
614
|
+
return "antarctica";
|
|
615
|
+
if ([
|
|
616
|
+
"Antananarivo",
|
|
617
|
+
"Comoro",
|
|
618
|
+
"Mahe",
|
|
619
|
+
"Mauritius",
|
|
620
|
+
"Mayotte",
|
|
621
|
+
"Reunion"
|
|
622
|
+
].includes(location))
|
|
623
|
+
return "africa";
|
|
624
|
+
return null;
|
|
625
|
+
default:
|
|
626
|
+
return null;
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
var getTimeZoneContinent = (timeZone) => {
|
|
630
|
+
if (!isTimeZoneId(timeZone))
|
|
631
|
+
return null;
|
|
632
|
+
return continentForLocation(timeZone) ?? continentForLocation(new Intl.DateTimeFormat("en", { timeZone }).resolvedOptions().timeZone);
|
|
633
|
+
};
|
|
634
|
+
var getTimeZones = (additional = []) => [
|
|
635
|
+
...new Set([
|
|
636
|
+
"UTC",
|
|
637
|
+
...Intl.supportedValuesOf("timeZone"),
|
|
638
|
+
...Array.from({ length: 27 }, (_, index) => `Etc/GMT${index - 14 >= 0 ? "+" : ""}${index - 14}`).filter(isTimeZoneId),
|
|
639
|
+
...additional.filter(isTimeZoneId)
|
|
640
|
+
])
|
|
641
|
+
].sort();
|
|
642
|
+
var getTimeZoneDetails = ({
|
|
643
|
+
timeZone,
|
|
644
|
+
at,
|
|
645
|
+
locale = "en"
|
|
646
|
+
}) => {
|
|
647
|
+
if (!isTimeZoneId(timeZone) || !isTimeZoneReferenceDate(at))
|
|
648
|
+
return;
|
|
649
|
+
const offsetParts = new Intl.DateTimeFormat("en-US", {
|
|
650
|
+
timeZone,
|
|
651
|
+
timeZoneName: "longOffset"
|
|
652
|
+
}).formatToParts(at);
|
|
653
|
+
const offset = (offsetParts.find((part) => part.type === "timeZoneName")?.value ?? "GMT").replace("GMT", "UTC");
|
|
654
|
+
const civil = new Intl.DateTimeFormat("en-US-u-ca-gregory-nu-latn", {
|
|
655
|
+
timeZone,
|
|
656
|
+
year: "numeric",
|
|
657
|
+
month: "2-digit",
|
|
658
|
+
day: "2-digit",
|
|
659
|
+
hour: "2-digit",
|
|
660
|
+
minute: "2-digit",
|
|
661
|
+
second: "2-digit",
|
|
662
|
+
hourCycle: "h23"
|
|
663
|
+
}).formatToParts(at);
|
|
664
|
+
const number = (type) => Number(civil.find((part) => part.type === type)?.value);
|
|
665
|
+
const offsetMinutes = (Date.UTC(number("year"), number("month") - 1, number("day"), number("hour"), number("minute"), number("second")) - Math.floor(at.getTime() / 1000) * 1000) / 60000;
|
|
666
|
+
const named = new Intl.DateTimeFormat(locale, {
|
|
667
|
+
timeZone,
|
|
668
|
+
timeZoneName: "long"
|
|
669
|
+
}).formatToParts(at);
|
|
670
|
+
return {
|
|
671
|
+
timeZone,
|
|
672
|
+
name: named.find((part) => part.type === "timeZoneName")?.value ?? timeZone,
|
|
673
|
+
offset,
|
|
674
|
+
offsetMinutes,
|
|
675
|
+
time: new Intl.DateTimeFormat(locale, {
|
|
676
|
+
timeZone,
|
|
677
|
+
hour: "2-digit",
|
|
678
|
+
minute: "2-digit"
|
|
679
|
+
}).format(at),
|
|
680
|
+
date: new Intl.DateTimeFormat(locale, {
|
|
681
|
+
timeZone,
|
|
682
|
+
weekday: "short",
|
|
683
|
+
year: "numeric",
|
|
684
|
+
month: "short",
|
|
685
|
+
day: "numeric"
|
|
686
|
+
}).format(at)
|
|
687
|
+
};
|
|
688
|
+
};
|
|
689
|
+
var subscribeClock = (notify) => {
|
|
690
|
+
const interval = setInterval(notify, 15000);
|
|
691
|
+
return () => clearInterval(interval);
|
|
692
|
+
};
|
|
693
|
+
var noSubscription = () => () => {};
|
|
694
|
+
var currentMinute = () => Math.floor(Date.now() / 60000) * 60000;
|
|
695
|
+
var noTime = () => null;
|
|
696
|
+
var browserTimeZone = () => Intl.DateTimeFormat().resolvedOptions().timeZone || null;
|
|
697
|
+
var prettyZone = (value) => value.replaceAll("_", " ");
|
|
698
|
+
var TimezoneSelect = ({
|
|
699
|
+
value,
|
|
700
|
+
onValueChange,
|
|
701
|
+
label,
|
|
702
|
+
continent = "north-america",
|
|
703
|
+
comparisonTimeZone,
|
|
704
|
+
referenceTime,
|
|
705
|
+
name,
|
|
706
|
+
disabled,
|
|
707
|
+
className,
|
|
708
|
+
locale: override,
|
|
709
|
+
messages
|
|
710
|
+
}) => {
|
|
711
|
+
const locale = useKrakstackLocale2(override);
|
|
712
|
+
const copy = {
|
|
713
|
+
...locale.startsWith("fr") ? labels.fr : labels.en,
|
|
714
|
+
...messages?.[locale.split("-")[0] ?? locale],
|
|
715
|
+
...messages?.[locale]
|
|
716
|
+
};
|
|
717
|
+
const id = useId();
|
|
718
|
+
const [search, setSearch] = useState("");
|
|
719
|
+
const detected = useSyncExternalStore(noSubscription, browserTimeZone, noTime);
|
|
720
|
+
const clock = useSyncExternalStore(referenceTime ? noSubscription : subscribeClock, currentMinute, noTime);
|
|
721
|
+
const referenceValid = !referenceTime || isTimeZoneReferenceDate(referenceTime);
|
|
722
|
+
const timestamp = referenceTime ? referenceValid ? referenceTime.getTime() : null : clock;
|
|
723
|
+
const baselineZone = comparisonTimeZone === undefined ? detected : comparisonTimeZone;
|
|
724
|
+
const baseline = useMemo(() => baselineZone && timestamp !== null ? getTimeZoneDetails({
|
|
725
|
+
timeZone: baselineZone,
|
|
726
|
+
at: new Date(timestamp),
|
|
727
|
+
locale
|
|
728
|
+
}) : undefined, [baselineZone, timestamp, locale]);
|
|
729
|
+
const zones = useMemo(() => getTimeZones([
|
|
730
|
+
...value ? [value] : [],
|
|
731
|
+
...baselineZone ? [baselineZone] : []
|
|
732
|
+
]), [value, baselineZone]);
|
|
733
|
+
const items = useMemo(() => zones.filter((timeZone) => continent === "all" || timeZone === value || getTimeZoneContinent(timeZone) === continent).map((timeZone) => {
|
|
734
|
+
const data = timestamp !== null ? getTimeZoneDetails({
|
|
735
|
+
timeZone,
|
|
736
|
+
at: new Date(timestamp),
|
|
737
|
+
locale
|
|
738
|
+
}) : undefined;
|
|
739
|
+
return {
|
|
740
|
+
value: timeZone,
|
|
741
|
+
label: `${prettyZone(timeZone)}${data ? ` · ${data.offset} · ${data.name}` : ""}`,
|
|
742
|
+
data
|
|
743
|
+
};
|
|
744
|
+
}), [zones, timestamp, locale, continent, value]);
|
|
745
|
+
const selected = items.find((item) => item.value === value) ?? null;
|
|
746
|
+
const invalid = value !== null && !isTimeZoneId(value);
|
|
747
|
+
const difference = (info) => {
|
|
748
|
+
if (!baseline)
|
|
749
|
+
return null;
|
|
750
|
+
const minutes = info.offsetMinutes - baseline.offsetMinutes;
|
|
751
|
+
if (minutes === 0)
|
|
752
|
+
return copy.same;
|
|
753
|
+
const duration = new Intl.NumberFormat(locale, {
|
|
754
|
+
style: "unit",
|
|
755
|
+
unit: "hour",
|
|
756
|
+
unitDisplay: "short",
|
|
757
|
+
maximumFractionDigits: 2
|
|
758
|
+
}).format(Math.abs(minutes) / 60);
|
|
759
|
+
return minutes > 0 ? copy.ahead(duration) : copy.behind(duration);
|
|
760
|
+
};
|
|
761
|
+
return /* @__PURE__ */ jsx5("div", {
|
|
762
|
+
className,
|
|
763
|
+
children: /* @__PURE__ */ jsxs2("div", {
|
|
764
|
+
className: "grid min-w-0 grid-cols-1 gap-3",
|
|
765
|
+
children: [
|
|
766
|
+
/* @__PURE__ */ jsx5("label", {
|
|
767
|
+
htmlFor: id,
|
|
768
|
+
className: "text-sm font-medium",
|
|
769
|
+
children: label ?? copy.label
|
|
770
|
+
}),
|
|
771
|
+
/* @__PURE__ */ jsx5(VirtualizedCombobox, {
|
|
772
|
+
ariaLabel: label ?? copy.label,
|
|
773
|
+
ariaInvalid: invalid,
|
|
774
|
+
triggerId: id,
|
|
775
|
+
contentClassName: "[&_[role=option]]:h-auto!",
|
|
776
|
+
disabled,
|
|
777
|
+
locale,
|
|
778
|
+
value: selected,
|
|
779
|
+
onValueChange: (item) => onValueChange(item?.value ?? null),
|
|
780
|
+
items,
|
|
781
|
+
placeholder: copy.placeholder,
|
|
782
|
+
emptyLabel: copy.empty,
|
|
783
|
+
searchValue: search,
|
|
784
|
+
onSearchValueChange: (value) => setSearch(value.replaceAll("_", " ")),
|
|
785
|
+
messages: { [locale]: { search: copy.search, clear: copy.clear } },
|
|
786
|
+
renderItem: (item) => /* @__PURE__ */ jsxs2("span", {
|
|
787
|
+
className: "grid min-w-0 flex-1 gap-0.5 py-1 text-left",
|
|
788
|
+
children: [
|
|
789
|
+
/* @__PURE__ */ jsx5("span", {
|
|
790
|
+
className: "font-medium wrap-anywhere",
|
|
791
|
+
children: prettyZone(item.value)
|
|
792
|
+
}),
|
|
793
|
+
item.data && /* @__PURE__ */ jsxs2(Fragment2, {
|
|
794
|
+
children: [
|
|
795
|
+
/* @__PURE__ */ jsxs2("span", {
|
|
796
|
+
className: "text-muted-foreground text-xs wrap-anywhere",
|
|
797
|
+
children: [
|
|
798
|
+
item.data.name,
|
|
799
|
+
" · ",
|
|
800
|
+
item.data.offset
|
|
801
|
+
]
|
|
802
|
+
}),
|
|
803
|
+
/* @__PURE__ */ jsxs2("span", {
|
|
804
|
+
className: "text-xs wrap-anywhere",
|
|
805
|
+
children: [
|
|
806
|
+
item.data.time,
|
|
807
|
+
" · ",
|
|
808
|
+
item.data.date,
|
|
809
|
+
baseline ? ` · ${difference(item.data)}` : ""
|
|
810
|
+
]
|
|
811
|
+
})
|
|
812
|
+
]
|
|
813
|
+
})
|
|
814
|
+
]
|
|
815
|
+
})
|
|
816
|
+
}),
|
|
817
|
+
name && /* @__PURE__ */ jsx5("input", {
|
|
818
|
+
type: "hidden",
|
|
819
|
+
name,
|
|
820
|
+
value: value ?? "",
|
|
821
|
+
disabled
|
|
822
|
+
}),
|
|
823
|
+
invalid && /* @__PURE__ */ jsx5("p", {
|
|
824
|
+
role: "alert",
|
|
825
|
+
className: "text-destructive text-sm",
|
|
826
|
+
children: copy.invalid
|
|
827
|
+
}),
|
|
828
|
+
!referenceValid && /* @__PURE__ */ jsx5("p", {
|
|
829
|
+
role: "alert",
|
|
830
|
+
className: "text-destructive text-sm",
|
|
831
|
+
children: copy.invalidReference
|
|
832
|
+
}),
|
|
833
|
+
selected?.data && /* @__PURE__ */ jsxs2("dl", {
|
|
834
|
+
className: "grid gap-1 rounded-lg border p-3 text-sm",
|
|
835
|
+
children: [
|
|
836
|
+
/* @__PURE__ */ jsx5("dt", {
|
|
837
|
+
className: "text-muted-foreground",
|
|
838
|
+
children: copy.selectedTime
|
|
839
|
+
}),
|
|
840
|
+
/* @__PURE__ */ jsxs2("dd", {
|
|
841
|
+
className: "wrap-anywhere",
|
|
842
|
+
children: [
|
|
843
|
+
selected.data.time,
|
|
844
|
+
" · ",
|
|
845
|
+
selected.data.date,
|
|
846
|
+
" ·",
|
|
847
|
+
" ",
|
|
848
|
+
selected.data.offset,
|
|
849
|
+
baseline ? ` · ${difference(selected.data)}` : ""
|
|
850
|
+
]
|
|
851
|
+
})
|
|
852
|
+
]
|
|
853
|
+
}),
|
|
854
|
+
comparisonTimeZone !== null && /* @__PURE__ */ jsx5("div", {
|
|
855
|
+
className: "grid gap-2 text-sm",
|
|
856
|
+
children: baseline ? /* @__PURE__ */ jsxs2("p", {
|
|
857
|
+
className: "text-muted-foreground wrap-anywhere",
|
|
858
|
+
children: [
|
|
859
|
+
comparisonTimeZone === undefined ? copy.yourTime : copy.comparisonTime,
|
|
860
|
+
": ",
|
|
861
|
+
prettyZone(baseline.timeZone),
|
|
862
|
+
" · ",
|
|
863
|
+
baseline.time,
|
|
864
|
+
" ·",
|
|
865
|
+
" ",
|
|
866
|
+
baseline.date,
|
|
867
|
+
" · ",
|
|
868
|
+
baseline.offset
|
|
869
|
+
]
|
|
870
|
+
}) : /* @__PURE__ */ jsx5("p", {
|
|
871
|
+
className: "text-muted-foreground",
|
|
872
|
+
children: copy.unavailable
|
|
873
|
+
})
|
|
874
|
+
}),
|
|
875
|
+
/* @__PURE__ */ jsx5(Button, {
|
|
876
|
+
type: "button",
|
|
877
|
+
variant: "outline",
|
|
878
|
+
className: "justify-self-start",
|
|
879
|
+
disabled: disabled || !detected || !isTimeZoneId(detected),
|
|
880
|
+
onClick: () => {
|
|
881
|
+
if (detected)
|
|
882
|
+
onValueChange(detected);
|
|
883
|
+
},
|
|
884
|
+
children: copy.useLocal
|
|
885
|
+
})
|
|
886
|
+
]
|
|
887
|
+
})
|
|
888
|
+
});
|
|
889
|
+
};
|
|
890
|
+
export {
|
|
891
|
+
TimeZoneContinentFilterSchema,
|
|
892
|
+
TimeZoneIdSchema,
|
|
893
|
+
TimezoneSelect,
|
|
894
|
+
getTimeZoneContinent,
|
|
895
|
+
getTimeZoneDetails,
|
|
896
|
+
getTimeZones,
|
|
897
|
+
isTimeZoneId
|
|
898
|
+
};
|