@geomak/ui 3.0.0 → 5.0.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/dist/index.cjs +487 -352
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +114 -67
- package/dist/index.d.ts +114 -67
- package/dist/index.js +487 -352
- package/dist/index.js.map +1 -1
- package/dist/styles.css +42 -60
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3143,6 +3143,26 @@ function AutoComplete({
|
|
|
3143
3143
|
}
|
|
3144
3144
|
) });
|
|
3145
3145
|
}
|
|
3146
|
+
function flattenVisible(items, expanded, depth = 0, out = []) {
|
|
3147
|
+
for (const node of items) {
|
|
3148
|
+
const isParent2 = !!node.children && node.children.length > 0;
|
|
3149
|
+
out.push({ node, depth, isParent: isParent2 });
|
|
3150
|
+
if (isParent2 && expanded.has(node.key)) {
|
|
3151
|
+
flattenVisible(node.children, expanded, depth + 1, out);
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
3154
|
+
return out;
|
|
3155
|
+
}
|
|
3156
|
+
function findNodeByKey(items, key) {
|
|
3157
|
+
for (const n of items) {
|
|
3158
|
+
if (n.key === key) return n;
|
|
3159
|
+
if (n.children) {
|
|
3160
|
+
const found = findNodeByKey(n.children, key);
|
|
3161
|
+
if (found) return found;
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
return null;
|
|
3165
|
+
}
|
|
3146
3166
|
function TreeSelect({
|
|
3147
3167
|
label,
|
|
3148
3168
|
name,
|
|
@@ -3151,106 +3171,231 @@ function TreeSelect({
|
|
|
3151
3171
|
disabled,
|
|
3152
3172
|
layout = "horizontal",
|
|
3153
3173
|
errorMessage,
|
|
3154
|
-
style
|
|
3174
|
+
style,
|
|
3155
3175
|
htmlFor,
|
|
3156
|
-
items = []
|
|
3176
|
+
items = [],
|
|
3177
|
+
placeholder = "Select\u2026",
|
|
3178
|
+
parentsSelectable = true,
|
|
3179
|
+
defaultExpandedKeys = []
|
|
3157
3180
|
}) {
|
|
3181
|
+
const errorId = useId();
|
|
3182
|
+
const hasError = errorMessage != null;
|
|
3158
3183
|
const [open, setOpen] = useState(false);
|
|
3159
|
-
const [
|
|
3160
|
-
const [
|
|
3184
|
+
const [expanded, setExpanded] = useState(() => new Set(defaultExpandedKeys));
|
|
3185
|
+
const [activeIndex, setActiveIndex] = useState(0);
|
|
3186
|
+
const listRef = useRef(null);
|
|
3187
|
+
const visible = useMemo(() => flattenVisible(items, expanded), [items, expanded]);
|
|
3161
3188
|
useEffect(() => {
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3189
|
+
if (!open) return;
|
|
3190
|
+
const selectedIdx = visible.findIndex((v) => v.node.key === value);
|
|
3191
|
+
setActiveIndex(selectedIdx >= 0 ? selectedIdx : 0);
|
|
3192
|
+
}, [open, visible, value]);
|
|
3193
|
+
const selectedNode = useMemo(
|
|
3194
|
+
() => value != null ? findNodeByKey(items, value) : null,
|
|
3195
|
+
[items, value]
|
|
3196
|
+
);
|
|
3197
|
+
const toggleExpand = (key) => {
|
|
3198
|
+
setExpanded((prev) => {
|
|
3199
|
+
const next = new Set(prev);
|
|
3200
|
+
if (next.has(key)) next.delete(key);
|
|
3201
|
+
else next.add(key);
|
|
3202
|
+
return next;
|
|
3203
|
+
});
|
|
3204
|
+
};
|
|
3205
|
+
const selectKey = (key) => {
|
|
3165
3206
|
onChange?.({ target: { value: key, id: htmlFor, name } });
|
|
3166
3207
|
setOpen(false);
|
|
3167
3208
|
};
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3209
|
+
const onListKey = (e) => {
|
|
3210
|
+
if (visible.length === 0) return;
|
|
3211
|
+
const cur = visible[activeIndex];
|
|
3212
|
+
if (e.key === "ArrowDown") {
|
|
3213
|
+
e.preventDefault();
|
|
3214
|
+
setActiveIndex((i) => Math.min(i + 1, visible.length - 1));
|
|
3215
|
+
} else if (e.key === "ArrowUp") {
|
|
3216
|
+
e.preventDefault();
|
|
3217
|
+
setActiveIndex((i) => Math.max(i - 1, 0));
|
|
3218
|
+
} else if (e.key === "ArrowRight") {
|
|
3219
|
+
e.preventDefault();
|
|
3220
|
+
if (cur.isParent) {
|
|
3221
|
+
if (!expanded.has(cur.node.key)) toggleExpand(cur.node.key);
|
|
3222
|
+
else setActiveIndex((i) => Math.min(i + 1, visible.length - 1));
|
|
3223
|
+
}
|
|
3224
|
+
} else if (e.key === "ArrowLeft") {
|
|
3225
|
+
e.preventDefault();
|
|
3226
|
+
if (cur.isParent && expanded.has(cur.node.key)) {
|
|
3227
|
+
toggleExpand(cur.node.key);
|
|
3228
|
+
} else if (cur.depth > 0) {
|
|
3229
|
+
for (let i = activeIndex - 1; i >= 0; i--) {
|
|
3230
|
+
if (visible[i].depth < cur.depth) {
|
|
3231
|
+
setActiveIndex(i);
|
|
3232
|
+
break;
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
3237
|
+
e.preventDefault();
|
|
3238
|
+
if (cur.node.disabled) return;
|
|
3239
|
+
if (cur.isParent && !parentsSelectable) {
|
|
3240
|
+
toggleExpand(cur.node.key);
|
|
3241
|
+
} else {
|
|
3242
|
+
selectKey(cur.node.key);
|
|
3243
|
+
}
|
|
3244
|
+
} else if (e.key === "Escape") {
|
|
3245
|
+
e.preventDefault();
|
|
3246
|
+
setOpen(false);
|
|
3247
|
+
}
|
|
3248
|
+
};
|
|
3249
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
3250
|
+
/* @__PURE__ */ jsxs("div", { className: `flex ${layout === "vertical" ? "flex-col gap-1" : "flex-row items-center gap-2"}`, children: [
|
|
3251
|
+
label && /* @__PURE__ */ jsx(
|
|
3252
|
+
"label",
|
|
3253
|
+
{
|
|
3254
|
+
className: "text-sm font-medium ml-1 max-content select-none text-foreground",
|
|
3255
|
+
htmlFor,
|
|
3256
|
+
children: label
|
|
3257
|
+
}
|
|
3258
|
+
),
|
|
3259
|
+
/* @__PURE__ */ jsxs(Popover.Root, { open: open && !disabled, onOpenChange: (o) => !disabled && setOpen(o), children: [
|
|
3260
|
+
/* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
3261
|
+
"button",
|
|
3262
|
+
{
|
|
3263
|
+
id: htmlFor,
|
|
3264
|
+
type: "button",
|
|
3265
|
+
style,
|
|
3266
|
+
role: "combobox",
|
|
3267
|
+
"aria-expanded": open,
|
|
3268
|
+
"aria-haspopup": "listbox",
|
|
3269
|
+
"aria-invalid": hasError || void 0,
|
|
3270
|
+
"aria-describedby": hasError ? errorId : void 0,
|
|
3271
|
+
disabled,
|
|
3272
|
+
className: `flex items-center justify-between h-9 rounded-lg border ${hasError ? "border-status-error" : "border-border"} px-3 cursor-pointer select-none focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${disabled ? "cursor-not-allowed bg-surface-raised text-foreground-muted" : "bg-surface text-foreground"} ${!style?.width ? "min-w-[240px]" : ""}`,
|
|
3273
|
+
children: [
|
|
3274
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm truncate text-left", children: selectedNode ? selectedNode.label : /* @__PURE__ */ jsx("span", { className: "text-foreground-muted", children: placeholder }) }),
|
|
3275
|
+
/* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, className: `h-4 w-4 flex-shrink-0 transition-transform duration-200 ${open ? "rotate-180" : ""}`, "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19 9l-7 7-7-7" }) })
|
|
3276
|
+
]
|
|
3277
|
+
}
|
|
3278
|
+
) }),
|
|
3279
|
+
/* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(
|
|
3280
|
+
Popover.Content,
|
|
3281
|
+
{
|
|
3282
|
+
align: "start",
|
|
3283
|
+
sideOffset: 4,
|
|
3284
|
+
style: { width: style?.width || 280 },
|
|
3285
|
+
className: "bg-surface text-foreground border border-border rounded-lg shadow-md z-50 p-1 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",
|
|
3286
|
+
onOpenAutoFocus: (e) => {
|
|
3287
|
+
e.preventDefault();
|
|
3288
|
+
listRef.current?.focus();
|
|
3289
|
+
},
|
|
3290
|
+
children: /* @__PURE__ */ jsx(
|
|
3184
3291
|
"div",
|
|
3185
3292
|
{
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
"aria-
|
|
3190
|
-
|
|
3191
|
-
className:
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
/* @__PURE__ */ jsx("div", { className: `h-7 ${!style?.width ? "min-w-[240px]" : ""} focus:outline-none text-prussian-blue flex items-center gap-1`, children: Array.isArray(value) ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3195
|
-
value.slice(0, 1).map((val, id) => /* @__PURE__ */ jsx(
|
|
3196
|
-
DropdownPill,
|
|
3197
|
-
{
|
|
3198
|
-
hasSiblings: value.length > 1,
|
|
3199
|
-
value: innerItems.find((it) => it.key === val)?.label
|
|
3200
|
-
},
|
|
3201
|
-
id
|
|
3202
|
-
)),
|
|
3203
|
-
value.length > 1 && /* @__PURE__ */ jsx(DropdownPill, { value: `+${value.length - 1} more` })
|
|
3204
|
-
] }) : value != null ? /* @__PURE__ */ jsx(DropdownPill, { value: innerItems.find((it) => it.key === value)?.label }) : null }),
|
|
3205
|
-
/* @__PURE__ */ jsx("div", { className: `transition-transform duration-300 ml-2 ${open ? "rotate-180" : "rotate-0"}`, children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: colors_default.PALETTE["prussian-blue"], strokeWidth: 2, className: "h-4 w-4", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19 9l-7 7-7-7" }) }) })
|
|
3206
|
-
]
|
|
3207
|
-
}
|
|
3208
|
-
) }),
|
|
3209
|
-
/* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(
|
|
3210
|
-
Popover.Content,
|
|
3211
|
-
{
|
|
3212
|
-
align: "start",
|
|
3213
|
-
sideOffset: 4,
|
|
3214
|
-
style: { width: style?.width || 240 },
|
|
3215
|
-
className: "bg-ice rounded-lg shadow-md z-50 p-2 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",
|
|
3216
|
-
children: /* @__PURE__ */ jsx("div", { role: "listbox", className: "max-h-40 overflow-y-auto", children: innerItems.map((item, idx) => /* @__PURE__ */ jsxs(
|
|
3217
|
-
"div",
|
|
3293
|
+
ref: listRef,
|
|
3294
|
+
role: "tree",
|
|
3295
|
+
tabIndex: -1,
|
|
3296
|
+
"aria-activedescendant": visible[activeIndex] ? `tree-opt-${visible[activeIndex].node.key}` : void 0,
|
|
3297
|
+
onKeyDown: onListKey,
|
|
3298
|
+
className: "max-h-72 overflow-y-auto outline-none",
|
|
3299
|
+
children: visible.length === 0 ? /* @__PURE__ */ jsx("div", { className: "px-3 py-4 text-sm text-foreground-secondary text-center", children: "No items" }) : visible.map((v, idx) => /* @__PURE__ */ jsx(
|
|
3300
|
+
TreeNodeRow,
|
|
3218
3301
|
{
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
{
|
|
3234
|
-
d: "M4 10l4.5 4.5L16 6",
|
|
3235
|
-
stroke: hoveredItem === item.key ? "#fff" : colors_default.PALETTE["prussian-blue"],
|
|
3236
|
-
strokeWidth: "2",
|
|
3237
|
-
strokeLinecap: "round",
|
|
3238
|
-
strokeLinejoin: "round"
|
|
3239
|
-
}
|
|
3240
|
-
) })
|
|
3241
|
-
]
|
|
3302
|
+
node: v.node,
|
|
3303
|
+
depth: v.depth,
|
|
3304
|
+
isParent: v.isParent,
|
|
3305
|
+
isExpanded: expanded.has(v.node.key),
|
|
3306
|
+
isActive: idx === activeIndex,
|
|
3307
|
+
isSelected: value === v.node.key,
|
|
3308
|
+
parentsSelectable,
|
|
3309
|
+
onActivate: () => {
|
|
3310
|
+
if (v.node.disabled) return;
|
|
3311
|
+
if (v.isParent && !parentsSelectable) toggleExpand(v.node.key);
|
|
3312
|
+
else selectKey(v.node.key);
|
|
3313
|
+
},
|
|
3314
|
+
onToggle: () => toggleExpand(v.node.key),
|
|
3315
|
+
onHover: () => setActiveIndex(idx)
|
|
3242
3316
|
},
|
|
3243
|
-
|
|
3244
|
-
))
|
|
3317
|
+
v.node.key
|
|
3318
|
+
))
|
|
3245
3319
|
}
|
|
3246
|
-
)
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
}
|
|
3250
|
-
),
|
|
3251
|
-
/* @__PURE__ */ jsx("div", { className: "text-
|
|
3320
|
+
)
|
|
3321
|
+
}
|
|
3322
|
+
) })
|
|
3323
|
+
] })
|
|
3324
|
+
] }),
|
|
3325
|
+
hasError && /* @__PURE__ */ jsx("div", { id: errorId, className: "text-xs text-status-error ml-1", children: errorMessage })
|
|
3252
3326
|
] });
|
|
3253
3327
|
}
|
|
3328
|
+
function TreeNodeRow({
|
|
3329
|
+
node,
|
|
3330
|
+
depth,
|
|
3331
|
+
isParent: isParent2,
|
|
3332
|
+
isExpanded,
|
|
3333
|
+
isActive,
|
|
3334
|
+
isSelected,
|
|
3335
|
+
parentsSelectable,
|
|
3336
|
+
onActivate,
|
|
3337
|
+
onToggle,
|
|
3338
|
+
onHover
|
|
3339
|
+
}) {
|
|
3340
|
+
const disabled = node.disabled;
|
|
3341
|
+
return /* @__PURE__ */ jsxs(
|
|
3342
|
+
"div",
|
|
3343
|
+
{
|
|
3344
|
+
id: `tree-opt-${node.key}`,
|
|
3345
|
+
role: "treeitem",
|
|
3346
|
+
"aria-selected": isSelected,
|
|
3347
|
+
"aria-expanded": isParent2 ? isExpanded : void 0,
|
|
3348
|
+
"aria-disabled": disabled || void 0,
|
|
3349
|
+
"data-active": isActive ? "" : void 0,
|
|
3350
|
+
onMouseEnter: onHover,
|
|
3351
|
+
className: `flex items-center gap-1 rounded-md px-1 py-1.5 select-none cursor-pointer transition-colors duration-100 ${disabled ? "opacity-40 cursor-not-allowed" : isActive ? "bg-accent text-accent-fg" : isSelected ? "bg-surface-raised" : "hover:bg-surface-raised"}`,
|
|
3352
|
+
style: { paddingLeft: depth * 16 + 4 },
|
|
3353
|
+
children: [
|
|
3354
|
+
isParent2 ? /* @__PURE__ */ jsx(
|
|
3355
|
+
"button",
|
|
3356
|
+
{
|
|
3357
|
+
type: "button",
|
|
3358
|
+
onClick: (e) => {
|
|
3359
|
+
e.stopPropagation();
|
|
3360
|
+
onToggle();
|
|
3361
|
+
},
|
|
3362
|
+
"aria-label": isExpanded ? "Collapse" : "Expand",
|
|
3363
|
+
tabIndex: -1,
|
|
3364
|
+
className: "w-5 h-5 inline-flex items-center justify-center rounded hover:bg-black/10 focus:outline-none",
|
|
3365
|
+
children: /* @__PURE__ */ jsx(
|
|
3366
|
+
"svg",
|
|
3367
|
+
{
|
|
3368
|
+
viewBox: "0 0 24 24",
|
|
3369
|
+
fill: "none",
|
|
3370
|
+
stroke: "currentColor",
|
|
3371
|
+
strokeWidth: 2.5,
|
|
3372
|
+
className: `h-3 w-3 transition-transform duration-150 ${isExpanded ? "rotate-0" : "-rotate-90"}`,
|
|
3373
|
+
"aria-hidden": "true",
|
|
3374
|
+
children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19 9l-7 7-7-7" })
|
|
3375
|
+
}
|
|
3376
|
+
)
|
|
3377
|
+
}
|
|
3378
|
+
) : /* @__PURE__ */ jsx("span", { className: "w-5 h-5 inline-block", "aria-hidden": "true" }),
|
|
3379
|
+
/* @__PURE__ */ jsxs(
|
|
3380
|
+
"button",
|
|
3381
|
+
{
|
|
3382
|
+
type: "button",
|
|
3383
|
+
onClick: onActivate,
|
|
3384
|
+
disabled,
|
|
3385
|
+
tabIndex: -1,
|
|
3386
|
+
className: "flex-1 flex items-center gap-2 text-sm text-left focus:outline-none disabled:cursor-not-allowed",
|
|
3387
|
+
children: [
|
|
3388
|
+
node.icon,
|
|
3389
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: node.label }),
|
|
3390
|
+
isParent2 && !parentsSelectable && /* @__PURE__ */ jsx("span", { className: "ml-auto text-xs text-foreground-muted", children: "parent" })
|
|
3391
|
+
]
|
|
3392
|
+
}
|
|
3393
|
+
),
|
|
3394
|
+
isSelected && /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true", className: "ml-1", children: /* @__PURE__ */ jsx("path", { d: "M4 10l4.5 4.5L16 6", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
|
|
3395
|
+
]
|
|
3396
|
+
}
|
|
3397
|
+
);
|
|
3398
|
+
}
|
|
3254
3399
|
function FileInput({
|
|
3255
3400
|
allowMultiple = false,
|
|
3256
3401
|
onChange,
|
|
@@ -3358,295 +3503,285 @@ function FileInput({
|
|
|
3358
3503
|
)
|
|
3359
3504
|
);
|
|
3360
3505
|
}
|
|
3361
|
-
var
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
const
|
|
3381
|
-
const
|
|
3382
|
-
|
|
3383
|
-
}
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3506
|
+
var MONTH_NAMES = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
3507
|
+
var WEEKDAY_SHORT = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
3508
|
+
function isSameDay(a, b) {
|
|
3509
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
3510
|
+
}
|
|
3511
|
+
function startOfMonth(d) {
|
|
3512
|
+
return new Date(d.getFullYear(), d.getMonth(), 1);
|
|
3513
|
+
}
|
|
3514
|
+
function addDays(d, n) {
|
|
3515
|
+
const c = new Date(d);
|
|
3516
|
+
c.setDate(c.getDate() + n);
|
|
3517
|
+
return c;
|
|
3518
|
+
}
|
|
3519
|
+
function addMonths(d, n) {
|
|
3520
|
+
const c = new Date(d);
|
|
3521
|
+
c.setMonth(c.getMonth() + n);
|
|
3522
|
+
return c;
|
|
3523
|
+
}
|
|
3524
|
+
function defaultFormat(d) {
|
|
3525
|
+
const y = d.getFullYear().toString().padStart(4, "0");
|
|
3526
|
+
const m = (d.getMonth() + 1).toString().padStart(2, "0");
|
|
3527
|
+
const day = d.getDate().toString().padStart(2, "0");
|
|
3528
|
+
return `${y}-${m}-${day}`;
|
|
3529
|
+
}
|
|
3530
|
+
function buildGrid(viewMonth, weekStartsOn) {
|
|
3531
|
+
const first = startOfMonth(viewMonth);
|
|
3532
|
+
const startOffset = (first.getDay() - weekStartsOn + 7) % 7;
|
|
3533
|
+
const gridStart = addDays(first, -startOffset);
|
|
3534
|
+
const cells = [];
|
|
3535
|
+
for (let i = 0; i < 42; i++) {
|
|
3536
|
+
const d = addDays(gridStart, i);
|
|
3537
|
+
cells.push({ date: d, outside: d.getMonth() !== viewMonth.getMonth() });
|
|
3390
3538
|
}
|
|
3391
|
-
|
|
3539
|
+
const rows = [];
|
|
3540
|
+
for (let r = 0; r < 6; r++) rows.push(cells.slice(r * 7, r * 7 + 7));
|
|
3541
|
+
return rows;
|
|
3392
3542
|
}
|
|
3393
|
-
|
|
3394
|
-
var DoubleChevronRight2 = ({ color = colors_default.PALETTE["prussian-blue"] }) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: color, strokeWidth: 2, className: "w-4 h-4", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M13 5l7 7-7 7M5 5l7 7-7 7" }) });
|
|
3395
|
-
var ChevronDown2 = ({ color = colors_default.PALETTE["prussian-blue"] }) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: color, strokeWidth: 2, className: "w-4 h-4", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19 9l-7 7-7-7" }) });
|
|
3396
|
-
function DatePickerBase({
|
|
3543
|
+
function DatePicker({
|
|
3397
3544
|
value,
|
|
3398
3545
|
onChange,
|
|
3399
|
-
layout,
|
|
3400
3546
|
label,
|
|
3547
|
+
placeholder = "Select a date\u2026",
|
|
3401
3548
|
htmlFor,
|
|
3402
|
-
name,
|
|
3403
|
-
|
|
3549
|
+
name: _name,
|
|
3550
|
+
layout = "horizontal",
|
|
3551
|
+
disabled,
|
|
3404
3552
|
errorMessage,
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3553
|
+
min,
|
|
3554
|
+
max,
|
|
3555
|
+
style,
|
|
3556
|
+
format = defaultFormat,
|
|
3557
|
+
weekStartsOn = 0,
|
|
3558
|
+
clearable = true
|
|
3408
3559
|
}) {
|
|
3409
|
-
const
|
|
3410
|
-
const
|
|
3411
|
-
const [
|
|
3412
|
-
const [
|
|
3413
|
-
const [
|
|
3414
|
-
const
|
|
3415
|
-
|
|
3416
|
-
if (!
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
};
|
|
3430
|
-
const
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
const isSelected = (d) => value.getDate() === d.getDate() && value.getMonth() === d.getMonth() && value.getFullYear() === d.getFullYear();
|
|
3435
|
-
const isDateDisabled = (d) => {
|
|
3436
|
-
if (disableBefore && d.getTime() < new Date(disableBefore).getTime()) return true;
|
|
3437
|
-
if (disableAfter && d.getTime() > new Date(disableAfter).getTime()) return true;
|
|
3560
|
+
const errorId = useId();
|
|
3561
|
+
const hasError = errorMessage != null;
|
|
3562
|
+
const [open, setOpen] = useState(false);
|
|
3563
|
+
const [viewMonth, setViewMonth] = useState(() => startOfMonth(value ?? /* @__PURE__ */ new Date()));
|
|
3564
|
+
const [focusDate, setFocusDate] = useState(() => value ?? /* @__PURE__ */ new Date());
|
|
3565
|
+
const gridRef = useRef(null);
|
|
3566
|
+
useEffect(() => {
|
|
3567
|
+
if (!open) return;
|
|
3568
|
+
const target = value ?? /* @__PURE__ */ new Date();
|
|
3569
|
+
setViewMonth(startOfMonth(target));
|
|
3570
|
+
setFocusDate(target);
|
|
3571
|
+
}, [open, value]);
|
|
3572
|
+
useEffect(() => {
|
|
3573
|
+
if (!open) return;
|
|
3574
|
+
const cell = gridRef.current?.querySelector(`[data-day="${defaultFormat(focusDate)}"]`);
|
|
3575
|
+
cell?.focus();
|
|
3576
|
+
}, [open, focusDate]);
|
|
3577
|
+
const weekdays = useMemo(() => {
|
|
3578
|
+
const ordered = WEEKDAY_SHORT.slice(weekStartsOn).concat(WEEKDAY_SHORT.slice(0, weekStartsOn));
|
|
3579
|
+
return ordered;
|
|
3580
|
+
}, [weekStartsOn]);
|
|
3581
|
+
const grid = useMemo(() => buildGrid(viewMonth, weekStartsOn), [viewMonth, weekStartsOn]);
|
|
3582
|
+
const isDisabled = (d) => {
|
|
3583
|
+
if (min && d < min) return true;
|
|
3584
|
+
if (max && d > max) return true;
|
|
3438
3585
|
return false;
|
|
3439
3586
|
};
|
|
3440
|
-
const
|
|
3441
|
-
|
|
3442
|
-
onChange(
|
|
3443
|
-
|
|
3444
|
-
setCurrentYear(d.getFullYear());
|
|
3445
|
-
setCurrentMonth(d.getMonth() + 1);
|
|
3587
|
+
const selectDate = (d) => {
|
|
3588
|
+
if (isDisabled(d)) return;
|
|
3589
|
+
onChange?.(d);
|
|
3590
|
+
setOpen(false);
|
|
3446
3591
|
};
|
|
3447
|
-
const
|
|
3448
|
-
const
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
if (
|
|
3454
|
-
|
|
3592
|
+
const onKey = (e) => {
|
|
3593
|
+
const next = (delta) => {
|
|
3594
|
+
const nd = addDays(focusDate, delta);
|
|
3595
|
+
setFocusDate(nd);
|
|
3596
|
+
if (nd.getMonth() !== viewMonth.getMonth()) setViewMonth(startOfMonth(nd));
|
|
3597
|
+
};
|
|
3598
|
+
if (e.key === "ArrowLeft") {
|
|
3599
|
+
e.preventDefault();
|
|
3600
|
+
next(-1);
|
|
3601
|
+
} else if (e.key === "ArrowRight") {
|
|
3602
|
+
e.preventDefault();
|
|
3603
|
+
next(1);
|
|
3604
|
+
} else if (e.key === "ArrowUp") {
|
|
3605
|
+
e.preventDefault();
|
|
3606
|
+
next(-7);
|
|
3607
|
+
} else if (e.key === "ArrowDown") {
|
|
3608
|
+
e.preventDefault();
|
|
3609
|
+
next(7);
|
|
3610
|
+
} else if (e.key === "PageUp") {
|
|
3611
|
+
e.preventDefault();
|
|
3612
|
+
const nm = addMonths(viewMonth, -1);
|
|
3613
|
+
setViewMonth(nm);
|
|
3614
|
+
setFocusDate((d) => addMonths(d, -1));
|
|
3615
|
+
} else if (e.key === "PageDown") {
|
|
3616
|
+
e.preventDefault();
|
|
3617
|
+
const nm = addMonths(viewMonth, 1);
|
|
3618
|
+
setViewMonth(nm);
|
|
3619
|
+
setFocusDate((d) => addMonths(d, 1));
|
|
3620
|
+
} else if (e.key === "Home") {
|
|
3621
|
+
e.preventDefault();
|
|
3622
|
+
const dow = (focusDate.getDay() - weekStartsOn + 7) % 7;
|
|
3623
|
+
setFocusDate(addDays(focusDate, -dow));
|
|
3624
|
+
} else if (e.key === "End") {
|
|
3625
|
+
e.preventDefault();
|
|
3626
|
+
const dow = (focusDate.getDay() - weekStartsOn + 7) % 7;
|
|
3627
|
+
setFocusDate(addDays(focusDate, 6 - dow));
|
|
3628
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
3629
|
+
e.preventDefault();
|
|
3630
|
+
selectDate(focusDate);
|
|
3631
|
+
} else if (e.key === "Escape") {
|
|
3632
|
+
e.preventDefault();
|
|
3633
|
+
setOpen(false);
|
|
3455
3634
|
}
|
|
3456
|
-
return ordered;
|
|
3457
3635
|
};
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
return () => document.removeEventListener("mousedown", clickAway);
|
|
3464
|
-
}, []);
|
|
3465
|
-
useEffect(() => {
|
|
3466
|
-
const bbox = pickerRef.current?.getBoundingClientRect();
|
|
3467
|
-
if (bbox && (bbox.y > window.innerHeight - 220 || bbox.bottom > window.innerHeight - 400)) {
|
|
3468
|
-
setCloseToBottom(true);
|
|
3469
|
-
} else setCloseToBottom(false);
|
|
3470
|
-
}, []);
|
|
3471
|
-
return /* @__PURE__ */ jsxs("div", { className: "w-full", children: [
|
|
3472
|
-
/* @__PURE__ */ jsxs("div", { className: `flex relative ${layout === "vertical" ? "flex-col" : "flex-row items-center gap-2"}`, children: [
|
|
3473
|
-
label && /* @__PURE__ */ jsx("label", { className: "text-md font-bold ml-1 max-content text-prussian-blue dark:text-white", children: label }),
|
|
3474
|
-
/* @__PURE__ */ jsxs(
|
|
3475
|
-
"div",
|
|
3636
|
+
const displayValue = value ? format(value) : "";
|
|
3637
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
3638
|
+
/* @__PURE__ */ jsxs("div", { className: `flex ${layout === "vertical" ? "flex-col gap-1" : "flex-row items-center gap-2"}`, children: [
|
|
3639
|
+
label && /* @__PURE__ */ jsx(
|
|
3640
|
+
"label",
|
|
3476
3641
|
{
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
children: [
|
|
3481
|
-
/* @__PURE__ */ jsx(
|
|
3482
|
-
"div",
|
|
3483
|
-
{
|
|
3484
|
-
onClick: toggle,
|
|
3485
|
-
className: `h-7 focus:outline-none text-prussian-blue ${disabled ? "cursor-not-allowed" : "cursor-pointer"} ${!style.width ? "min-w-[240px]" : ""} flex items-center gap-1`,
|
|
3486
|
-
children: formatDate(value)
|
|
3487
|
-
}
|
|
3488
|
-
),
|
|
3489
|
-
/* @__PURE__ */ jsx(
|
|
3490
|
-
"div",
|
|
3491
|
-
{
|
|
3492
|
-
onClick: toggle,
|
|
3493
|
-
className: `transition-all duration-300 ml-2 ${isExpanded ? "rotate-180" : "rotate-0 w-4 h-4"}`,
|
|
3494
|
-
children: /* @__PURE__ */ jsx(ChevronDown2, {})
|
|
3495
|
-
}
|
|
3496
|
-
)
|
|
3497
|
-
]
|
|
3642
|
+
className: "text-sm font-medium ml-1 max-content select-none text-foreground",
|
|
3643
|
+
htmlFor,
|
|
3644
|
+
children: label
|
|
3498
3645
|
}
|
|
3499
3646
|
),
|
|
3500
|
-
/* @__PURE__ */
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3647
|
+
/* @__PURE__ */ jsxs(Popover.Root, { open: open && !disabled, onOpenChange: (o) => !disabled && setOpen(o), children: [
|
|
3648
|
+
/* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
3649
|
+
"button",
|
|
3650
|
+
{
|
|
3651
|
+
id: htmlFor,
|
|
3652
|
+
type: "button",
|
|
3653
|
+
disabled,
|
|
3654
|
+
style,
|
|
3655
|
+
"aria-invalid": hasError || void 0,
|
|
3656
|
+
"aria-describedby": hasError ? errorId : void 0,
|
|
3657
|
+
"aria-haspopup": "dialog",
|
|
3658
|
+
"aria-expanded": open,
|
|
3659
|
+
className: `flex items-center justify-between h-9 rounded-lg border px-3 cursor-pointer select-none focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${hasError ? "border-status-error" : "border-border"} ${disabled ? "cursor-not-allowed bg-surface-raised text-foreground-muted" : "bg-surface text-foreground"} ${!style?.width ? "min-w-[200px]" : ""}`,
|
|
3660
|
+
children: [
|
|
3661
|
+
/* @__PURE__ */ jsx("span", { className: `text-sm truncate ${displayValue ? "" : "text-foreground-muted"}`, children: displayValue || placeholder }),
|
|
3662
|
+
/* @__PURE__ */ jsx(CalendarIcon, {})
|
|
3663
|
+
]
|
|
3664
|
+
}
|
|
3665
|
+
) }),
|
|
3666
|
+
/* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsxs(
|
|
3667
|
+
Popover.Content,
|
|
3668
|
+
{
|
|
3669
|
+
align: "start",
|
|
3670
|
+
sideOffset: 4,
|
|
3671
|
+
className: "bg-surface text-foreground border border-border rounded-lg shadow-md z-50 p-3 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",
|
|
3672
|
+
onOpenAutoFocus: (e) => {
|
|
3673
|
+
e.preventDefault();
|
|
3674
|
+
},
|
|
3675
|
+
children: [
|
|
3676
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-2", children: [
|
|
3677
|
+
/* @__PURE__ */ jsx(
|
|
3678
|
+
"button",
|
|
3679
|
+
{
|
|
3680
|
+
type: "button",
|
|
3681
|
+
onClick: () => setViewMonth(addMonths(viewMonth, -1)),
|
|
3682
|
+
"aria-label": "Previous month",
|
|
3683
|
+
className: "w-7 h-7 inline-flex items-center justify-center rounded-md hover:bg-surface-raised focus:outline-none focus-visible:ring-2 focus-visible:ring-accent transition-colors",
|
|
3684
|
+
children: /* @__PURE__ */ jsx(ChevronLeft, {})
|
|
3685
|
+
}
|
|
3686
|
+
),
|
|
3687
|
+
/* @__PURE__ */ jsxs("div", { className: "text-sm font-semibold select-none", children: [
|
|
3688
|
+
MONTH_NAMES[viewMonth.getMonth()],
|
|
3689
|
+
" ",
|
|
3690
|
+
viewMonth.getFullYear()
|
|
3691
|
+
] }),
|
|
3692
|
+
/* @__PURE__ */ jsx(
|
|
3693
|
+
"button",
|
|
3694
|
+
{
|
|
3695
|
+
type: "button",
|
|
3696
|
+
onClick: () => setViewMonth(addMonths(viewMonth, 1)),
|
|
3697
|
+
"aria-label": "Next month",
|
|
3698
|
+
className: "w-7 h-7 inline-flex items-center justify-center rounded-md hover:bg-surface-raised focus:outline-none focus-visible:ring-2 focus-visible:ring-accent transition-colors",
|
|
3699
|
+
children: /* @__PURE__ */ jsx(ChevronRight3, {})
|
|
3700
|
+
}
|
|
3701
|
+
)
|
|
3513
3702
|
] }),
|
|
3514
|
-
/* @__PURE__ */
|
|
3515
|
-
|
|
3516
|
-
] }),
|
|
3517
|
-
/* @__PURE__ */ jsx("div", { className: "flex gap-3 p-2", children: renderCalendar().map((weekDay, index) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2", children: [
|
|
3518
|
-
/* @__PURE__ */ jsx("div", { className: "text-center font-bold text-sm text-prussian-blue", children: weekDay[0] ? DAYS[weekDay[0].getDay()] : "" }),
|
|
3519
|
-
weekDay.map((day) => /* @__PURE__ */ jsx(
|
|
3520
|
-
"div",
|
|
3703
|
+
/* @__PURE__ */ jsxs(
|
|
3704
|
+
"table",
|
|
3521
3705
|
{
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3706
|
+
ref: gridRef,
|
|
3707
|
+
role: "grid",
|
|
3708
|
+
"aria-label": `${MONTH_NAMES[viewMonth.getMonth()]} ${viewMonth.getFullYear()}`,
|
|
3709
|
+
onKeyDown: onKey,
|
|
3710
|
+
className: "border-separate border-spacing-0",
|
|
3711
|
+
children: [
|
|
3712
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: weekdays.map((w) => /* @__PURE__ */ jsx("th", { scope: "col", className: "text-[11px] font-medium text-foreground-muted uppercase tracking-wide w-8 h-8", children: w }, w)) }) }),
|
|
3713
|
+
/* @__PURE__ */ jsx("tbody", { children: grid.map((row, ri) => /* @__PURE__ */ jsx("tr", { children: row.map(({ date, outside }) => {
|
|
3714
|
+
const dis = isDisabled(date);
|
|
3715
|
+
const sel = value ? isSameDay(date, value) : false;
|
|
3716
|
+
const focused = isSameDay(date, focusDate);
|
|
3717
|
+
const today = isSameDay(date, /* @__PURE__ */ new Date());
|
|
3718
|
+
return /* @__PURE__ */ jsx("td", { role: "gridcell", className: "p-0", children: /* @__PURE__ */ jsx(
|
|
3719
|
+
"button",
|
|
3720
|
+
{
|
|
3721
|
+
type: "button",
|
|
3722
|
+
disabled: dis,
|
|
3723
|
+
tabIndex: focused ? 0 : -1,
|
|
3724
|
+
"data-day": defaultFormat(date),
|
|
3725
|
+
"aria-label": defaultFormat(date),
|
|
3726
|
+
"aria-selected": sel || void 0,
|
|
3727
|
+
onClick: () => selectDate(date),
|
|
3728
|
+
className: [
|
|
3729
|
+
"w-8 h-8 rounded-md text-xs font-medium transition-colors duration-100",
|
|
3730
|
+
"focus:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-1 focus-visible:ring-offset-surface",
|
|
3731
|
+
"disabled:opacity-30 disabled:cursor-not-allowed",
|
|
3732
|
+
sel ? "bg-accent text-accent-fg" : today ? "bg-surface-raised text-foreground ring-1 ring-inset ring-accent" : outside ? "text-foreground-muted hover:bg-surface-raised" : "text-foreground hover:bg-surface-raised"
|
|
3733
|
+
].join(" "),
|
|
3734
|
+
children: date.getDate()
|
|
3735
|
+
}
|
|
3736
|
+
) }, defaultFormat(date));
|
|
3737
|
+
}) }, ri)) })
|
|
3738
|
+
]
|
|
3739
|
+
}
|
|
3740
|
+
),
|
|
3741
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-2 flex items-center justify-between gap-2 border-t border-border pt-2", children: [
|
|
3742
|
+
/* @__PURE__ */ jsx(
|
|
3743
|
+
"button",
|
|
3744
|
+
{
|
|
3745
|
+
type: "button",
|
|
3746
|
+
onClick: () => selectDate(/* @__PURE__ */ new Date()),
|
|
3747
|
+
className: "text-xs text-accent hover:underline focus:outline-none focus-visible:ring-2 focus-visible:ring-accent rounded-sm px-1",
|
|
3748
|
+
children: "Today"
|
|
3749
|
+
}
|
|
3750
|
+
),
|
|
3751
|
+
clearable && value && /* @__PURE__ */ jsx(
|
|
3752
|
+
"button",
|
|
3753
|
+
{
|
|
3754
|
+
type: "button",
|
|
3755
|
+
onClick: () => {
|
|
3756
|
+
onChange?.(null);
|
|
3757
|
+
setOpen(false);
|
|
3758
|
+
},
|
|
3759
|
+
className: "text-xs text-foreground-secondary hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-accent rounded-sm px-1",
|
|
3760
|
+
children: "Clear"
|
|
3761
|
+
}
|
|
3762
|
+
)
|
|
3763
|
+
] })
|
|
3764
|
+
]
|
|
3765
|
+
}
|
|
3766
|
+
) })
|
|
3767
|
+
] })
|
|
3544
3768
|
] }),
|
|
3545
|
-
/* @__PURE__ */ jsx("div", { className: "text-
|
|
3769
|
+
hasError && /* @__PURE__ */ jsx("div", { id: errorId, className: "text-xs text-status-error ml-1", children: errorMessage })
|
|
3546
3770
|
] });
|
|
3547
3771
|
}
|
|
3548
|
-
function
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
upperLimit = (/* @__PURE__ */ new Date()).getFullYear(),
|
|
3553
|
-
errorMessage,
|
|
3554
|
-
label,
|
|
3555
|
-
layout,
|
|
3556
|
-
style = {}
|
|
3557
|
-
}) {
|
|
3558
|
-
const pickerRef = useRef(null);
|
|
3559
|
-
const calendarRef = useRef(null);
|
|
3560
|
-
const valueRefs = useRef([]);
|
|
3561
|
-
const [isExpanded, setExpanded] = useState(false);
|
|
3562
|
-
const [isCloseToBottom, setCloseToBottom] = useState(false);
|
|
3563
|
-
const innerValues = useMemo(() => {
|
|
3564
|
-
const vals = [];
|
|
3565
|
-
for (let i = lowerLimit; i <= upperLimit; i++) vals.push(i);
|
|
3566
|
-
return vals;
|
|
3567
|
-
}, [lowerLimit, upperLimit]);
|
|
3568
|
-
useEffect(() => {
|
|
3569
|
-
const clickAway = (e) => {
|
|
3570
|
-
if (pickerRef.current && !pickerRef.current.contains(e.target) && calendarRef.current && !calendarRef.current.contains(e.target)) setExpanded(false);
|
|
3571
|
-
};
|
|
3572
|
-
document.addEventListener("mousedown", clickAway);
|
|
3573
|
-
return () => document.removeEventListener("mousedown", clickAway);
|
|
3574
|
-
}, []);
|
|
3575
|
-
useEffect(() => {
|
|
3576
|
-
const bbox = pickerRef.current?.getBoundingClientRect();
|
|
3577
|
-
if (bbox && bbox.y > window.innerHeight - 220) setCloseToBottom(true);
|
|
3578
|
-
else setCloseToBottom(false);
|
|
3579
|
-
}, []);
|
|
3580
|
-
useEffect(() => {
|
|
3581
|
-
if (!isExpanded) return;
|
|
3582
|
-
const t = setTimeout(() => {
|
|
3583
|
-
const node = valueRefs.current.find((n) => n.value === value);
|
|
3584
|
-
node?.ref.scrollIntoView({ block: "end", inline: "nearest", behavior: "smooth" });
|
|
3585
|
-
}, 150);
|
|
3586
|
-
return () => clearTimeout(t);
|
|
3587
|
-
}, [isExpanded, value]);
|
|
3588
|
-
const navigate = (delta) => {
|
|
3589
|
-
const next = value + delta;
|
|
3590
|
-
if (next < lowerLimit || next > upperLimit) return;
|
|
3591
|
-
onChange({ target: { value: next } });
|
|
3592
|
-
const node = valueRefs.current.find((n) => n.value === next);
|
|
3593
|
-
node?.ref.scrollIntoView({ block: "end", inline: "nearest", behavior: "smooth" });
|
|
3594
|
-
};
|
|
3595
|
-
return /* @__PURE__ */ jsxs("div", { className: "mt-2", children: [
|
|
3596
|
-
/* @__PURE__ */ jsxs("div", { className: `flex relative ${layout === "vertical" ? "flex-col" : "flex-row items-center gap-2"}`, children: [
|
|
3597
|
-
label && /* @__PURE__ */ jsx("label", { className: "text-md font-bold ml-1 max-content text-prussian-blue dark:text-white", children: label }),
|
|
3598
|
-
/* @__PURE__ */ jsxs(
|
|
3599
|
-
"div",
|
|
3600
|
-
{
|
|
3601
|
-
style,
|
|
3602
|
-
ref: pickerRef,
|
|
3603
|
-
className: "flex items-center justify-between relative h-9 bg-white rounded-lg p-2 cursor-pointer",
|
|
3604
|
-
children: [
|
|
3605
|
-
/* @__PURE__ */ jsx(
|
|
3606
|
-
"div",
|
|
3607
|
-
{
|
|
3608
|
-
onClick: () => setExpanded((p) => !p),
|
|
3609
|
-
className: `h-7 ${!style.width ? "min-w-[240px]" : ""} focus:outline-none text-prussian-blue cursor-pointer flex items-center gap-1`,
|
|
3610
|
-
children: innerValues.includes(value) ? value : "N/A"
|
|
3611
|
-
}
|
|
3612
|
-
),
|
|
3613
|
-
/* @__PURE__ */ jsx("div", { onClick: () => setExpanded((p) => !p), className: `transition-all duration-300 ml-2 ${isExpanded ? "rotate-180" : "rotate-0 w-4 h-4"}`, children: /* @__PURE__ */ jsx(ChevronDown2, {}) })
|
|
3614
|
-
]
|
|
3615
|
-
}
|
|
3616
|
-
),
|
|
3617
|
-
/* @__PURE__ */ jsxs(
|
|
3618
|
-
"div",
|
|
3619
|
-
{
|
|
3620
|
-
style: { width: style.width },
|
|
3621
|
-
ref: calendarRef,
|
|
3622
|
-
className: `${!style.width ? "w-[280px]" : ""} bg-ice absolute z-10 ${isCloseToBottom ? "bottom-[40px]" : "top-10"} rounded-lg shadow-md transition-all duration-150 right-0 overflow-hidden ${isExpanded ? "h-max scale-100" : "scale-0 pointer-events-none"}`,
|
|
3623
|
-
children: [
|
|
3624
|
-
/* @__PURE__ */ jsx("div", { onClick: () => navigate(-1), className: "flex items-center justify-center rotate-180 transition-all duration-300 hover:bg-ice-dark cursor-pointer rounded-br-lg rounded-bl-lg", children: /* @__PURE__ */ jsx(ChevronDown2, {}) }),
|
|
3625
|
-
/* @__PURE__ */ jsx("div", { className: "h-8 overflow-hidden", children: innerValues.map((val) => /* @__PURE__ */ jsx(
|
|
3626
|
-
"div",
|
|
3627
|
-
{
|
|
3628
|
-
ref: (ref) => {
|
|
3629
|
-
if (!valueRefs.current.find((n) => n.value === val) && ref)
|
|
3630
|
-
valueRefs.current.push({ value: val, ref });
|
|
3631
|
-
},
|
|
3632
|
-
className: "font-bold text-center text-lg",
|
|
3633
|
-
children: val
|
|
3634
|
-
},
|
|
3635
|
-
val
|
|
3636
|
-
)) }),
|
|
3637
|
-
/* @__PURE__ */ jsx("div", { onClick: () => navigate(1), className: "flex items-center justify-center transition-all hover:bg-ice-dark cursor-pointer rounded-br-lg rounded-bl-lg", children: /* @__PURE__ */ jsx(ChevronDown2, {}) })
|
|
3638
|
-
]
|
|
3639
|
-
}
|
|
3640
|
-
)
|
|
3641
|
-
] }),
|
|
3642
|
-
/* @__PURE__ */ jsx("div", { className: "text-center text-error dark:text-prussian-blue min-h-0", children: errorMessage })
|
|
3772
|
+
function CalendarIcon() {
|
|
3773
|
+
return /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1.75, className: "w-4 h-4 flex-shrink-0", "aria-hidden": "true", children: [
|
|
3774
|
+
/* @__PURE__ */ jsx("rect", { x: "3", y: "5", width: "18", height: "16", rx: "2" }),
|
|
3775
|
+
/* @__PURE__ */ jsx("path", { d: "M3 9h18M8 3v4M16 3v4", strokeLinecap: "round" })
|
|
3643
3776
|
] });
|
|
3644
3777
|
}
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3778
|
+
function ChevronLeft() {
|
|
3779
|
+
return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, className: "w-4 h-4", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M15 19l-7-7 7-7" }) });
|
|
3780
|
+
}
|
|
3781
|
+
function ChevronRight3() {
|
|
3782
|
+
return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, className: "w-4 h-4", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M9 5l7 7-7 7" }) });
|
|
3783
|
+
}
|
|
3649
3784
|
|
|
3650
|
-
export { AppShell, AutoComplete, Button, Catalog, CatalogCarousel, CatalogGrid, Checkbox, ContextMenu, Drawer, Dropdown, DropdownPill, FadingBase, FileInput, GridCard, icons_default as Icon, IconButton, List2 as List, LoadingSpinner, MenuBar, MenuBarItem, Modal, NotificationProvider, NumberInput, OpaqueGridCard, Password, Portal, ScalableContainer, SearchInput_default as SearchInput, Sidebar, SkeletonBox, SkeletonCard, SkeletonCircle, SkeletonText, Switch, Table, Tabs,
|
|
3785
|
+
export { AppShell, AutoComplete, Button, Catalog, CatalogCarousel, CatalogGrid, Checkbox, ContextMenu, Drawer, Dropdown, DropdownPill, FadingBase, FileInput, GridCard, icons_default as Icon, IconButton, List2 as List, LoadingSpinner, MenuBar, MenuBarItem, Modal, NotificationProvider, NumberInput, OpaqueGridCard, Password, Portal, ScalableContainer, SearchInput_default as SearchInput, Sidebar, SkeletonBox, SkeletonCard, SkeletonCircle, SkeletonText, Switch, Table, Tabs, DatePicker as Temporal, TextInput, ThemeProvider, ThemeSwitch, ToggleButton, Tooltip, TooltipProvider, TopBar, Tree, TreeSelect, Wizard, useNotification };
|
|
3651
3786
|
//# sourceMappingURL=index.js.map
|
|
3652
3787
|
//# sourceMappingURL=index.js.map
|