shadcn-ui-react 0.7.11 → 0.7.13
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 +386 -245
- package/dist/index.d.cts +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.js +386 -245
- package/dist/style.css +81 -88
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6558,7 +6558,7 @@ var import_class_variance_authority5 = require("class-variance-authority");
|
|
|
6558
6558
|
var React42 = __toESM(require("react"), 1);
|
|
6559
6559
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
6560
6560
|
var labelVariants = (0, import_class_variance_authority5.cva)(
|
|
6561
|
-
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70
|
|
6561
|
+
"text-sm font-medium leading-none text-label peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
6562
6562
|
);
|
|
6563
6563
|
var Label3 = React42.forwardRef((_a, ref) => {
|
|
6564
6564
|
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
@@ -7200,7 +7200,9 @@ var SelectContext = React46.createContext(null);
|
|
|
7200
7200
|
function useSelectContext(componentName) {
|
|
7201
7201
|
const context = React46.useContext(SelectContext);
|
|
7202
7202
|
if (!context) {
|
|
7203
|
-
throw new Error(
|
|
7203
|
+
throw new Error(
|
|
7204
|
+
`${componentName} must be used within <Select />. Aseg\xFArate de importar Select, SelectTrigger, SelectContent, SelectValue y SelectItem desde el mismo archivo "../select", sin mezclar Radix ni otra versi\xF3n del componente.`
|
|
7205
|
+
);
|
|
7204
7206
|
}
|
|
7205
7207
|
return context;
|
|
7206
7208
|
}
|
|
@@ -7215,11 +7217,15 @@ function useControllableState({
|
|
|
7215
7217
|
const setValue = React46.useCallback(
|
|
7216
7218
|
(nextValue) => {
|
|
7217
7219
|
if (!isControlled) {
|
|
7218
|
-
setInternalValue(
|
|
7220
|
+
setInternalValue(
|
|
7221
|
+
(previousValue) => Object.is(previousValue, nextValue) ? previousValue : nextValue
|
|
7222
|
+
);
|
|
7223
|
+
}
|
|
7224
|
+
if (!Object.is(currentValue, nextValue)) {
|
|
7225
|
+
onChange == null ? void 0 : onChange(nextValue);
|
|
7219
7226
|
}
|
|
7220
|
-
onChange == null ? void 0 : onChange(nextValue);
|
|
7221
7227
|
},
|
|
7222
|
-
[isControlled, onChange]
|
|
7228
|
+
[currentValue, isControlled, onChange]
|
|
7223
7229
|
);
|
|
7224
7230
|
return [currentValue, setValue];
|
|
7225
7231
|
}
|
|
@@ -7266,6 +7272,31 @@ function getNextItemValue(items, currentValue, direction) {
|
|
|
7266
7272
|
const nextIndex = direction === "next" ? (currentIndex + 1) % enabledItems.length : (currentIndex - 1 + enabledItems.length) % enabledItems.length;
|
|
7267
7273
|
return (_c = enabledItems[nextIndex]) == null ? void 0 : _c.value;
|
|
7268
7274
|
}
|
|
7275
|
+
function areRegisteredItemsEqual(previous, next) {
|
|
7276
|
+
return Boolean(
|
|
7277
|
+
previous && previous.id === next.id && previous.value === next.value && previous.textValue === next.textValue && previous.disabled === next.disabled && previous.label === next.label
|
|
7278
|
+
);
|
|
7279
|
+
}
|
|
7280
|
+
function areStylesEqual(previous, next) {
|
|
7281
|
+
if (!previous) return false;
|
|
7282
|
+
return previous.position === next.position && previous.zIndex === next.zIndex && previous.width === next.width && previous.minWidth === next.minWidth && previous.maxWidth === next.maxWidth && previous.maxHeight === next.maxHeight && previous.left === next.left && previous.right === next.right && previous.top === next.top && previous.bottom === next.bottom && previous.transform === next.transform;
|
|
7283
|
+
}
|
|
7284
|
+
function scrollItemIntoView(container, item) {
|
|
7285
|
+
if (!container || !item) return;
|
|
7286
|
+
const containerRect = container.getBoundingClientRect();
|
|
7287
|
+
const itemRect = item.getBoundingClientRect();
|
|
7288
|
+
const itemTop = itemRect.top - containerRect.top + container.scrollTop;
|
|
7289
|
+
const itemBottom = itemTop + itemRect.height;
|
|
7290
|
+
const visibleTop = container.scrollTop;
|
|
7291
|
+
const visibleBottom = visibleTop + container.clientHeight;
|
|
7292
|
+
if (itemTop < visibleTop) {
|
|
7293
|
+
container.scrollTop = itemTop;
|
|
7294
|
+
return;
|
|
7295
|
+
}
|
|
7296
|
+
if (itemBottom > visibleBottom) {
|
|
7297
|
+
container.scrollTop = itemBottom - container.clientHeight;
|
|
7298
|
+
}
|
|
7299
|
+
}
|
|
7269
7300
|
function Select2({
|
|
7270
7301
|
value,
|
|
7271
7302
|
defaultValue = "",
|
|
@@ -7304,17 +7335,28 @@ function Select2({
|
|
|
7304
7335
|
() => Array.from(itemsRef.current.values()),
|
|
7305
7336
|
[itemsVersion]
|
|
7306
7337
|
);
|
|
7307
|
-
const selectedItem =
|
|
7338
|
+
const selectedItem = React46.useMemo(
|
|
7339
|
+
() => items.find((item) => item.value === currentValue),
|
|
7340
|
+
[currentValue, items]
|
|
7341
|
+
);
|
|
7308
7342
|
const registerItem = React46.useCallback((item) => {
|
|
7343
|
+
const previousItem = itemsRef.current.get(item.value);
|
|
7344
|
+
if (previousItem && previousItem.id === item.id) {
|
|
7345
|
+
previousItem.label = item.label;
|
|
7346
|
+
previousItem.textValue = item.textValue;
|
|
7347
|
+
previousItem.disabled = item.disabled;
|
|
7348
|
+
if (!areRegisteredItemsEqual(previousItem, item)) {
|
|
7349
|
+
forceItemsUpdate();
|
|
7350
|
+
}
|
|
7351
|
+
return;
|
|
7352
|
+
}
|
|
7309
7353
|
itemsRef.current.set(item.value, item);
|
|
7310
7354
|
forceItemsUpdate();
|
|
7311
7355
|
}, []);
|
|
7312
7356
|
const unregisterItem = React46.useCallback((value2, id) => {
|
|
7313
7357
|
const currentItem = itemsRef.current.get(value2);
|
|
7314
7358
|
if (!currentItem || currentItem.id !== id) return;
|
|
7315
|
-
itemsRef.current.
|
|
7316
|
-
ref: null
|
|
7317
|
-
}));
|
|
7359
|
+
itemsRef.current.delete(value2);
|
|
7318
7360
|
forceItemsUpdate();
|
|
7319
7361
|
}, []);
|
|
7320
7362
|
const updateItemRef = React46.useCallback(
|
|
@@ -7322,10 +7364,7 @@ function Select2({
|
|
|
7322
7364
|
const currentItem = itemsRef.current.get(value2);
|
|
7323
7365
|
if (!currentItem || currentItem.id !== id) return;
|
|
7324
7366
|
if (currentItem.ref === node) return;
|
|
7325
|
-
|
|
7326
|
-
ref: node
|
|
7327
|
-
}));
|
|
7328
|
-
forceItemsUpdate();
|
|
7367
|
+
currentItem.ref = node;
|
|
7329
7368
|
},
|
|
7330
7369
|
[]
|
|
7331
7370
|
);
|
|
@@ -7343,7 +7382,7 @@ function Select2({
|
|
|
7343
7382
|
setIsOpen(false);
|
|
7344
7383
|
requestAnimationFrame(() => {
|
|
7345
7384
|
var _a;
|
|
7346
|
-
(_a = triggerRef.current) == null ? void 0 : _a.focus();
|
|
7385
|
+
(_a = triggerRef.current) == null ? void 0 : _a.focus({ preventScroll: true });
|
|
7347
7386
|
});
|
|
7348
7387
|
},
|
|
7349
7388
|
[disabled, setCurrentValue, setIsOpen]
|
|
@@ -7355,21 +7394,24 @@ function Select2({
|
|
|
7355
7394
|
(item) => item.value === currentValue && !item.disabled
|
|
7356
7395
|
);
|
|
7357
7396
|
const firstEnabledItem = getEnabledItems(items)[0];
|
|
7358
|
-
|
|
7397
|
+
const nextActiveValue = (_a = selectedEnabledItem == null ? void 0 : selectedEnabledItem.value) != null ? _a : firstEnabledItem == null ? void 0 : firstEnabledItem.value;
|
|
7398
|
+
setActiveValue(
|
|
7399
|
+
(previousValue) => previousValue === nextActiveValue ? previousValue : nextActiveValue
|
|
7400
|
+
);
|
|
7359
7401
|
}, [currentValue, isOpen, items]);
|
|
7360
7402
|
React46.useEffect(() => {
|
|
7361
7403
|
if (!isOpen) return;
|
|
7362
7404
|
const handlePointerDown = (event) => {
|
|
7363
7405
|
var _a, _b;
|
|
7364
7406
|
const target = event.target;
|
|
7365
|
-
if (((_a = triggerRef.current) == null ? void 0 : _a.contains(target)) || ((_b = contentRef.current) == null ? void 0 : _b.contains(target))) {
|
|
7407
|
+
if (target && (((_a = triggerRef.current) == null ? void 0 : _a.contains(target)) || ((_b = contentRef.current) == null ? void 0 : _b.contains(target)))) {
|
|
7366
7408
|
return;
|
|
7367
7409
|
}
|
|
7368
7410
|
setIsOpen(false);
|
|
7369
7411
|
};
|
|
7370
|
-
document.addEventListener("pointerdown", handlePointerDown);
|
|
7412
|
+
document.addEventListener("pointerdown", handlePointerDown, true);
|
|
7371
7413
|
return () => {
|
|
7372
|
-
document.removeEventListener("pointerdown", handlePointerDown);
|
|
7414
|
+
document.removeEventListener("pointerdown", handlePointerDown, true);
|
|
7373
7415
|
};
|
|
7374
7416
|
}, [isOpen, setIsOpen]);
|
|
7375
7417
|
const contextValue = React46.useMemo(
|
|
@@ -7419,7 +7461,8 @@ function Select2({
|
|
|
7419
7461
|
type: "hidden",
|
|
7420
7462
|
name,
|
|
7421
7463
|
value: currentValue,
|
|
7422
|
-
required
|
|
7464
|
+
required,
|
|
7465
|
+
disabled
|
|
7423
7466
|
}
|
|
7424
7467
|
) : null
|
|
7425
7468
|
] });
|
|
@@ -7435,7 +7478,8 @@ var SelectTrigger = React46.forwardRef(
|
|
|
7435
7478
|
invalid,
|
|
7436
7479
|
disabled,
|
|
7437
7480
|
onClick,
|
|
7438
|
-
onKeyDown
|
|
7481
|
+
onKeyDown,
|
|
7482
|
+
onPointerDown
|
|
7439
7483
|
} = _b, props = __objRest(_b, [
|
|
7440
7484
|
"className",
|
|
7441
7485
|
"children",
|
|
@@ -7445,7 +7489,8 @@ var SelectTrigger = React46.forwardRef(
|
|
|
7445
7489
|
"invalid",
|
|
7446
7490
|
"disabled",
|
|
7447
7491
|
"onClick",
|
|
7448
|
-
"onKeyDown"
|
|
7492
|
+
"onKeyDown",
|
|
7493
|
+
"onPointerDown"
|
|
7449
7494
|
]);
|
|
7450
7495
|
const context = useSelectContext("SelectTrigger");
|
|
7451
7496
|
const resolvedVariant = variant != null ? variant : context.variant;
|
|
@@ -7571,16 +7616,27 @@ var SelectTrigger = React46.forwardRef(
|
|
|
7571
7616
|
disabled: resolvedDisabled,
|
|
7572
7617
|
className: cn(
|
|
7573
7618
|
formControlBase,
|
|
7574
|
-
"whitespace-nowrap ring-offset-background
|
|
7619
|
+
"relative flex w-full items-center justify-between gap-2 overflow-hidden whitespace-nowrap ring-offset-background",
|
|
7575
7620
|
formInputVariants[resolvedVariant],
|
|
7576
7621
|
controlSizeClass,
|
|
7577
7622
|
resolvedInvalid && formControlErrorClass,
|
|
7578
7623
|
className
|
|
7579
7624
|
),
|
|
7625
|
+
onPointerDown: (event) => {
|
|
7626
|
+
onPointerDown == null ? void 0 : onPointerDown(event);
|
|
7627
|
+
if (event.defaultPrevented || resolvedDisabled || event.button !== 0 || event.ctrlKey) {
|
|
7628
|
+
return;
|
|
7629
|
+
}
|
|
7630
|
+
event.preventDefault();
|
|
7631
|
+
},
|
|
7580
7632
|
onClick: (event) => {
|
|
7581
7633
|
onClick == null ? void 0 : onClick(event);
|
|
7582
7634
|
if (!event.defaultPrevented && !resolvedDisabled) {
|
|
7583
7635
|
context.setOpen(!context.open);
|
|
7636
|
+
requestAnimationFrame(() => {
|
|
7637
|
+
var _a2;
|
|
7638
|
+
(_a2 = context.triggerRef.current) == null ? void 0 : _a2.focus({ preventScroll: true });
|
|
7639
|
+
});
|
|
7584
7640
|
}
|
|
7585
7641
|
},
|
|
7586
7642
|
onKeyDown: handleKeyDown
|
|
@@ -7596,13 +7652,25 @@ var SelectTrigger = React46.forwardRef(
|
|
|
7596
7652
|
SelectTrigger.displayName = "SelectTrigger";
|
|
7597
7653
|
var SelectValue = React46.forwardRef(
|
|
7598
7654
|
(_a, ref) => {
|
|
7599
|
-
var _b = _a, { className, placeholder, children } = _b, props = __objRest(_b, ["className", "placeholder", "children"]);
|
|
7600
|
-
var _a2
|
|
7655
|
+
var _b = _a, { className, placeholder = "Select an option", children } = _b, props = __objRest(_b, ["className", "placeholder", "children"]);
|
|
7656
|
+
var _a2;
|
|
7601
7657
|
const context = useSelectContext("SelectValue");
|
|
7602
|
-
|
|
7658
|
+
const hasValue = Boolean(context.selectedItem) || children !== void 0;
|
|
7659
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
7660
|
+
"span",
|
|
7661
|
+
__spreadProps(__spreadValues({
|
|
7662
|
+
ref,
|
|
7663
|
+
className: cn(
|
|
7664
|
+
"min-w-0 flex-1 truncate text-left",
|
|
7665
|
+
!hasValue && "text-muted-foreground",
|
|
7666
|
+
className
|
|
7667
|
+
)
|
|
7668
|
+
}, props), {
|
|
7669
|
+
children: hasValue ? children != null ? children : (_a2 = context.selectedItem) == null ? void 0 : _a2.label : placeholder
|
|
7670
|
+
})
|
|
7671
|
+
);
|
|
7603
7672
|
}
|
|
7604
7673
|
);
|
|
7605
|
-
SelectValue.displayName = "SelectValue";
|
|
7606
7674
|
var SelectContent = React46.forwardRef(
|
|
7607
7675
|
(_a, ref) => {
|
|
7608
7676
|
var _b = _a, {
|
|
@@ -7623,22 +7691,33 @@ var SelectContent = React46.forwardRef(
|
|
|
7623
7691
|
const context = useSelectContext("SelectContent");
|
|
7624
7692
|
const scrollRef = React46.useRef(null);
|
|
7625
7693
|
const rafRef = React46.useRef(null);
|
|
7694
|
+
const lockedSideRef = React46.useRef(null);
|
|
7626
7695
|
const [mounted, setMounted] = React46.useState(false);
|
|
7627
7696
|
const [side, setSide] = React46.useState("bottom");
|
|
7628
7697
|
const [contentStyle, setContentStyle] = React46.useState();
|
|
7629
|
-
React46.
|
|
7698
|
+
React46.useLayoutEffect(() => {
|
|
7630
7699
|
setMounted(true);
|
|
7631
7700
|
}, []);
|
|
7701
|
+
React46.useLayoutEffect(() => {
|
|
7702
|
+
if (!context.open) {
|
|
7703
|
+
lockedSideRef.current = null;
|
|
7704
|
+
setContentStyle(void 0);
|
|
7705
|
+
}
|
|
7706
|
+
}, [context.open]);
|
|
7632
7707
|
const updatePosition = React46.useCallback(() => {
|
|
7633
7708
|
const trigger = context.triggerRef.current;
|
|
7634
7709
|
if (!trigger) return;
|
|
7635
7710
|
const rect = trigger.getBoundingClientRect();
|
|
7636
7711
|
const viewportPadding = 8;
|
|
7637
|
-
const preferredMaxHeight =
|
|
7712
|
+
const preferredMaxHeight = 288;
|
|
7638
7713
|
const minUsefulHeight = 140;
|
|
7639
7714
|
const availableBelow = window.innerHeight - rect.bottom - viewportPadding - sideOffset;
|
|
7640
7715
|
const availableAbove = rect.top - viewportPadding - sideOffset;
|
|
7641
|
-
const
|
|
7716
|
+
const calculatedSide = availableBelow >= Math.min(preferredMaxHeight, minUsefulHeight) || availableBelow >= availableAbove ? "bottom" : "top";
|
|
7717
|
+
if (!lockedSideRef.current) {
|
|
7718
|
+
lockedSideRef.current = calculatedSide;
|
|
7719
|
+
}
|
|
7720
|
+
const nextSide = lockedSideRef.current;
|
|
7642
7721
|
const availableHeight = nextSide === "bottom" ? availableBelow : availableAbove;
|
|
7643
7722
|
const contentMaxHeight = Math.max(
|
|
7644
7723
|
80,
|
|
@@ -7654,14 +7733,17 @@ var SelectContent = React46.forwardRef(
|
|
|
7654
7733
|
};
|
|
7655
7734
|
if (align === "start") {
|
|
7656
7735
|
baseStyle.left = rect.left;
|
|
7736
|
+
baseStyle.right = void 0;
|
|
7657
7737
|
baseStyle.transform = void 0;
|
|
7658
7738
|
}
|
|
7659
7739
|
if (align === "center") {
|
|
7660
7740
|
baseStyle.left = rect.left + rect.width / 2;
|
|
7741
|
+
baseStyle.right = void 0;
|
|
7661
7742
|
baseStyle.transform = "translateX(-50%)";
|
|
7662
7743
|
}
|
|
7663
7744
|
if (align === "end") {
|
|
7664
7745
|
baseStyle.left = rect.right;
|
|
7746
|
+
baseStyle.right = void 0;
|
|
7665
7747
|
baseStyle.transform = "translateX(-100%)";
|
|
7666
7748
|
}
|
|
7667
7749
|
if (nextSide === "bottom") {
|
|
@@ -7671,14 +7753,19 @@ var SelectContent = React46.forwardRef(
|
|
|
7671
7753
|
baseStyle.bottom = window.innerHeight - rect.top + sideOffset;
|
|
7672
7754
|
baseStyle.top = void 0;
|
|
7673
7755
|
}
|
|
7674
|
-
setSide(
|
|
7675
|
-
|
|
7756
|
+
setSide(
|
|
7757
|
+
(previousSide) => previousSide === nextSide ? previousSide : nextSide
|
|
7758
|
+
);
|
|
7759
|
+
setContentStyle(
|
|
7760
|
+
(previousStyle) => areStylesEqual(previousStyle, baseStyle) ? previousStyle : baseStyle
|
|
7761
|
+
);
|
|
7676
7762
|
}, [align, context.triggerRef, sideOffset]);
|
|
7677
7763
|
const scheduleUpdatePosition = React46.useCallback(() => {
|
|
7678
7764
|
if (rafRef.current) {
|
|
7679
7765
|
cancelAnimationFrame(rafRef.current);
|
|
7680
7766
|
}
|
|
7681
7767
|
rafRef.current = requestAnimationFrame(() => {
|
|
7768
|
+
rafRef.current = null;
|
|
7682
7769
|
updatePosition();
|
|
7683
7770
|
});
|
|
7684
7771
|
}, [updatePosition]);
|
|
@@ -7717,13 +7804,10 @@ var SelectContent = React46.forwardRef(
|
|
|
7717
7804
|
React46.useLayoutEffect(() => {
|
|
7718
7805
|
if (!context.open) return;
|
|
7719
7806
|
const frame = requestAnimationFrame(() => {
|
|
7720
|
-
var _a2;
|
|
7721
7807
|
const activeItem = context.items.find(
|
|
7722
7808
|
(item) => item.value === context.activeValue
|
|
7723
7809
|
);
|
|
7724
|
-
(
|
|
7725
|
-
block: "nearest"
|
|
7726
|
-
});
|
|
7810
|
+
scrollItemIntoView(scrollRef.current, activeItem == null ? void 0 : activeItem.ref);
|
|
7727
7811
|
});
|
|
7728
7812
|
return () => {
|
|
7729
7813
|
cancelAnimationFrame(frame);
|
|
@@ -7740,9 +7824,9 @@ var SelectContent = React46.forwardRef(
|
|
|
7740
7824
|
ref: composeRefs(ref, context.contentRef),
|
|
7741
7825
|
role: "listbox",
|
|
7742
7826
|
"data-side": side,
|
|
7827
|
+
"data-select-content": true,
|
|
7743
7828
|
className: cn(
|
|
7744
|
-
"min-w-32 rounded-md border border-border bg-popover text-popover-foreground shadow-md",
|
|
7745
|
-
"overflow-hidden",
|
|
7829
|
+
"pointer-events-auto min-w-32 overflow-hidden rounded-md border border-border bg-popover text-popover-foreground shadow-md",
|
|
7746
7830
|
className
|
|
7747
7831
|
),
|
|
7748
7832
|
style: __spreadValues(__spreadValues({}, contentStyle), style),
|
|
@@ -7752,20 +7836,13 @@ var SelectContent = React46.forwardRef(
|
|
|
7752
7836
|
ref: scrollRef,
|
|
7753
7837
|
"data-select-scroll-content": true,
|
|
7754
7838
|
className: cn(
|
|
7755
|
-
"max-h-full px-1 py-1",
|
|
7756
|
-
"
|
|
7757
|
-
"[scrollbar-gutter:stable]",
|
|
7758
|
-
"[scrollbar-width:thin]",
|
|
7759
|
-
"[&::-webkit-scrollbar]:!block",
|
|
7760
|
-
"[&::-webkit-scrollbar]:!w-2",
|
|
7761
|
-
"[&::-webkit-scrollbar-track]:!bg-transparent",
|
|
7762
|
-
"[&::-webkit-scrollbar-thumb]:!rounded-full",
|
|
7763
|
-
"[&::-webkit-scrollbar-thumb]:!bg-border"
|
|
7839
|
+
"max-h-full overflow-x-hidden overflow-y-auto overscroll-contain px-1 py-1",
|
|
7840
|
+
"scrollbar-gutter-stable"
|
|
7764
7841
|
),
|
|
7765
7842
|
style: {
|
|
7766
7843
|
maxHeight: contentStyle.maxHeight,
|
|
7767
7844
|
overflowX: "hidden",
|
|
7768
|
-
overflowY: "
|
|
7845
|
+
overflowY: "auto",
|
|
7769
7846
|
overscrollBehavior: "contain",
|
|
7770
7847
|
scrollbarGutter: "stable",
|
|
7771
7848
|
WebkitOverflowScrolling: "touch"
|
|
@@ -7773,6 +7850,9 @@ var SelectContent = React46.forwardRef(
|
|
|
7773
7850
|
onWheel: (event) => {
|
|
7774
7851
|
event.stopPropagation();
|
|
7775
7852
|
},
|
|
7853
|
+
onTouchMove: (event) => {
|
|
7854
|
+
event.stopPropagation();
|
|
7855
|
+
},
|
|
7776
7856
|
children
|
|
7777
7857
|
}
|
|
7778
7858
|
)
|
|
@@ -7848,7 +7928,7 @@ var SelectItem = React46.forwardRef(
|
|
|
7848
7928
|
const labelText = textValue != null ? textValue : getNodeText(children);
|
|
7849
7929
|
const isSelected = selectedValue === value;
|
|
7850
7930
|
const isActive = activeValue === value;
|
|
7851
|
-
React46.
|
|
7931
|
+
React46.useLayoutEffect(() => {
|
|
7852
7932
|
registerItem({
|
|
7853
7933
|
id: itemId,
|
|
7854
7934
|
value,
|
|
@@ -7865,9 +7945,9 @@ var SelectItem = React46.forwardRef(
|
|
|
7865
7945
|
unregisterItem,
|
|
7866
7946
|
itemId,
|
|
7867
7947
|
value,
|
|
7868
|
-
children,
|
|
7869
7948
|
labelText,
|
|
7870
|
-
disabled
|
|
7949
|
+
disabled,
|
|
7950
|
+
children
|
|
7871
7951
|
]);
|
|
7872
7952
|
const handleItemRef = React46.useCallback(
|
|
7873
7953
|
(node) => {
|
|
@@ -7940,15 +8020,25 @@ SelectSeparator.displayName = "SelectSeparator";
|
|
|
7940
8020
|
|
|
7941
8021
|
// src/components/searchable-select.tsx
|
|
7942
8022
|
var React47 = __toESM(require("react"), 1);
|
|
8023
|
+
var import_react_dom2 = require("react-dom");
|
|
7943
8024
|
var import_react_icons10 = require("@radix-ui/react-icons");
|
|
7944
8025
|
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
7945
8026
|
function normalizeText(value) {
|
|
7946
8027
|
return String(value != null ? value : "").normalize("NFD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().trim();
|
|
7947
8028
|
}
|
|
7948
8029
|
function getLabelText(value) {
|
|
8030
|
+
if (value === null || value === void 0 || typeof value === "boolean") {
|
|
8031
|
+
return "";
|
|
8032
|
+
}
|
|
7949
8033
|
if (typeof value === "string" || typeof value === "number") {
|
|
7950
8034
|
return String(value);
|
|
7951
8035
|
}
|
|
8036
|
+
if (Array.isArray(value)) {
|
|
8037
|
+
return value.map(getLabelText).join("");
|
|
8038
|
+
}
|
|
8039
|
+
if (React47.isValidElement(value)) {
|
|
8040
|
+
return getLabelText(value.props.children);
|
|
8041
|
+
}
|
|
7952
8042
|
return "";
|
|
7953
8043
|
}
|
|
7954
8044
|
function getOptionText(item) {
|
|
@@ -7967,6 +8057,10 @@ function getNextEnabledIndex2(items, currentIndex, direction) {
|
|
|
7967
8057
|
}
|
|
7968
8058
|
return -1;
|
|
7969
8059
|
}
|
|
8060
|
+
function areStylesEqual2(previous, next) {
|
|
8061
|
+
if (!previous) return false;
|
|
8062
|
+
return previous.position === next.position && previous.zIndex === next.zIndex && previous.width === next.width && previous.minWidth === next.minWidth && previous.maxWidth === next.maxWidth && previous.maxHeight === next.maxHeight && previous.left === next.left && previous.right === next.right && previous.top === next.top && previous.bottom === next.bottom && previous.transform === next.transform;
|
|
8063
|
+
}
|
|
7970
8064
|
function SearchableSelectBase({
|
|
7971
8065
|
items,
|
|
7972
8066
|
value,
|
|
@@ -7990,6 +8084,8 @@ function SearchableSelectBase({
|
|
|
7990
8084
|
}) {
|
|
7991
8085
|
const rootRef = React47.useRef(null);
|
|
7992
8086
|
const inputRef = React47.useRef(null);
|
|
8087
|
+
const contentRef = React47.useRef(null);
|
|
8088
|
+
const rafRef = React47.useRef(null);
|
|
7993
8089
|
const listboxId = React47.useId();
|
|
7994
8090
|
const sizeClasses = getFormSizeClasses(size, customSize);
|
|
7995
8091
|
const triggerSizeClass = getFormControlSizeClass(variant, sizeClasses);
|
|
@@ -8002,9 +8098,14 @@ function SearchableSelectBase({
|
|
|
8002
8098
|
const selectedText = React47.useMemo(() => {
|
|
8003
8099
|
return getOptionText(selectedItem);
|
|
8004
8100
|
}, [selectedItem]);
|
|
8101
|
+
const [mounted, setMounted] = React47.useState(false);
|
|
8005
8102
|
const [open, setOpen] = React47.useState(false);
|
|
8006
8103
|
const [inputValue, setInputValue] = React47.useState(selectedText);
|
|
8007
8104
|
const [activeIndex, setActiveIndex] = React47.useState(-1);
|
|
8105
|
+
const [contentStyle, setContentStyle] = React47.useState();
|
|
8106
|
+
React47.useLayoutEffect(() => {
|
|
8107
|
+
setMounted(true);
|
|
8108
|
+
}, []);
|
|
8008
8109
|
React47.useEffect(() => {
|
|
8009
8110
|
if (!open) {
|
|
8010
8111
|
setInputValue(selectedText);
|
|
@@ -8021,17 +8122,110 @@ function SearchableSelectBase({
|
|
|
8021
8122
|
return haystack.includes(query);
|
|
8022
8123
|
});
|
|
8023
8124
|
}, [inputValue, items]);
|
|
8125
|
+
const updatePosition = React47.useCallback(() => {
|
|
8126
|
+
const root = rootRef.current;
|
|
8127
|
+
if (!root) return;
|
|
8128
|
+
const rect = root.getBoundingClientRect();
|
|
8129
|
+
const viewportPadding = 8;
|
|
8130
|
+
const sideOffset = 6;
|
|
8131
|
+
const preferredMaxHeight = 288;
|
|
8132
|
+
const minUsefulHeight = 140;
|
|
8133
|
+
const availableBelow = window.innerHeight - rect.bottom - viewportPadding - sideOffset;
|
|
8134
|
+
const availableAbove = rect.top - viewportPadding - sideOffset;
|
|
8135
|
+
const shouldOpenBelow = availableBelow >= Math.min(preferredMaxHeight, minUsefulHeight) || availableBelow >= availableAbove;
|
|
8136
|
+
const availableHeight = shouldOpenBelow ? availableBelow : availableAbove;
|
|
8137
|
+
const contentMaxHeight = Math.max(
|
|
8138
|
+
96,
|
|
8139
|
+
Math.min(preferredMaxHeight, availableHeight)
|
|
8140
|
+
);
|
|
8141
|
+
const nextStyle = {
|
|
8142
|
+
position: "fixed",
|
|
8143
|
+
zIndex: 9999,
|
|
8144
|
+
left: Math.max(viewportPadding, rect.left),
|
|
8145
|
+
width: rect.width,
|
|
8146
|
+
minWidth: rect.width,
|
|
8147
|
+
maxWidth: `calc(100vw - ${viewportPadding * 2}px)`,
|
|
8148
|
+
maxHeight: contentMaxHeight
|
|
8149
|
+
};
|
|
8150
|
+
if (shouldOpenBelow) {
|
|
8151
|
+
nextStyle.top = rect.bottom + sideOffset;
|
|
8152
|
+
nextStyle.bottom = void 0;
|
|
8153
|
+
} else {
|
|
8154
|
+
nextStyle.bottom = window.innerHeight - rect.top + sideOffset;
|
|
8155
|
+
nextStyle.top = void 0;
|
|
8156
|
+
}
|
|
8157
|
+
setContentStyle(
|
|
8158
|
+
(previousStyle) => areStylesEqual2(previousStyle, nextStyle) ? previousStyle : nextStyle
|
|
8159
|
+
);
|
|
8160
|
+
}, []);
|
|
8161
|
+
const scheduleUpdatePosition = React47.useCallback(() => {
|
|
8162
|
+
if (rafRef.current) {
|
|
8163
|
+
cancelAnimationFrame(rafRef.current);
|
|
8164
|
+
}
|
|
8165
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
8166
|
+
rafRef.current = null;
|
|
8167
|
+
updatePosition();
|
|
8168
|
+
});
|
|
8169
|
+
}, [updatePosition]);
|
|
8170
|
+
const openDropdown = React47.useCallback(() => {
|
|
8171
|
+
if (disabled) return;
|
|
8172
|
+
if (!open) {
|
|
8173
|
+
setInputValue("");
|
|
8174
|
+
setOpen(true);
|
|
8175
|
+
}
|
|
8176
|
+
requestAnimationFrame(() => {
|
|
8177
|
+
var _a;
|
|
8178
|
+
(_a = inputRef.current) == null ? void 0 : _a.focus({ preventScroll: true });
|
|
8179
|
+
});
|
|
8180
|
+
}, [disabled, open]);
|
|
8181
|
+
React47.useLayoutEffect(() => {
|
|
8182
|
+
if (!open) {
|
|
8183
|
+
setContentStyle(void 0);
|
|
8184
|
+
}
|
|
8185
|
+
}, [open]);
|
|
8186
|
+
React47.useLayoutEffect(() => {
|
|
8187
|
+
var _a, _b;
|
|
8188
|
+
if (!open) return;
|
|
8189
|
+
updatePosition();
|
|
8190
|
+
scheduleUpdatePosition();
|
|
8191
|
+
const handleResizeOrScroll = () => {
|
|
8192
|
+
scheduleUpdatePosition();
|
|
8193
|
+
};
|
|
8194
|
+
window.addEventListener("resize", handleResizeOrScroll);
|
|
8195
|
+
window.addEventListener("scroll", handleResizeOrScroll, true);
|
|
8196
|
+
(_a = window.visualViewport) == null ? void 0 : _a.addEventListener("resize", handleResizeOrScroll);
|
|
8197
|
+
(_b = window.visualViewport) == null ? void 0 : _b.addEventListener("scroll", handleResizeOrScroll);
|
|
8198
|
+
return () => {
|
|
8199
|
+
var _a2, _b2;
|
|
8200
|
+
window.removeEventListener("resize", handleResizeOrScroll);
|
|
8201
|
+
window.removeEventListener("scroll", handleResizeOrScroll, true);
|
|
8202
|
+
(_a2 = window.visualViewport) == null ? void 0 : _a2.removeEventListener(
|
|
8203
|
+
"resize",
|
|
8204
|
+
handleResizeOrScroll
|
|
8205
|
+
);
|
|
8206
|
+
(_b2 = window.visualViewport) == null ? void 0 : _b2.removeEventListener(
|
|
8207
|
+
"scroll",
|
|
8208
|
+
handleResizeOrScroll
|
|
8209
|
+
);
|
|
8210
|
+
if (rafRef.current) {
|
|
8211
|
+
cancelAnimationFrame(rafRef.current);
|
|
8212
|
+
rafRef.current = null;
|
|
8213
|
+
}
|
|
8214
|
+
};
|
|
8215
|
+
}, [open, scheduleUpdatePosition, updatePosition]);
|
|
8024
8216
|
React47.useEffect(() => {
|
|
8025
8217
|
if (!open) return;
|
|
8026
8218
|
const firstEnabledIndex = filteredItems.findIndex((item) => !item.disabled);
|
|
8027
|
-
setActiveIndex(
|
|
8219
|
+
setActiveIndex(
|
|
8220
|
+
(previousIndex) => previousIndex === firstEnabledIndex ? previousIndex : firstEnabledIndex
|
|
8221
|
+
);
|
|
8028
8222
|
}, [filteredItems, open]);
|
|
8029
8223
|
React47.useEffect(() => {
|
|
8030
8224
|
if (!open) return;
|
|
8031
8225
|
const handlePointerDown = (event) => {
|
|
8032
|
-
var _a;
|
|
8226
|
+
var _a, _b;
|
|
8033
8227
|
const target = event.target;
|
|
8034
|
-
if (target && ((_a = rootRef.current) == null ? void 0 : _a.contains(target))) {
|
|
8228
|
+
if (target && (((_a = rootRef.current) == null ? void 0 : _a.contains(target)) || ((_b = contentRef.current) == null ? void 0 : _b.contains(target)))) {
|
|
8035
8229
|
return;
|
|
8036
8230
|
}
|
|
8037
8231
|
setOpen(false);
|
|
@@ -8057,6 +8251,100 @@ function SearchableSelectBase({
|
|
|
8057
8251
|
},
|
|
8058
8252
|
[isControlled, onValueChange]
|
|
8059
8253
|
);
|
|
8254
|
+
const dropdown = open && mounted && contentStyle ? (0, import_react_dom2.createPortal)(
|
|
8255
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
8256
|
+
"div",
|
|
8257
|
+
{
|
|
8258
|
+
ref: contentRef,
|
|
8259
|
+
"data-searchable-select-content": true,
|
|
8260
|
+
className: cn(
|
|
8261
|
+
"pointer-events-auto overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground shadow-xl",
|
|
8262
|
+
contentClassName
|
|
8263
|
+
),
|
|
8264
|
+
style: __spreadProps(__spreadValues({}, contentStyle), {
|
|
8265
|
+
maxHeight: contentStyle.maxHeight
|
|
8266
|
+
}),
|
|
8267
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
8268
|
+
"div",
|
|
8269
|
+
{
|
|
8270
|
+
id: listboxId,
|
|
8271
|
+
role: "listbox",
|
|
8272
|
+
className: "max-h-full overflow-x-hidden overflow-y-auto overscroll-contain p-1 scrollbar-gutter-stable",
|
|
8273
|
+
style: {
|
|
8274
|
+
maxHeight: contentStyle.maxHeight,
|
|
8275
|
+
overflowX: "hidden",
|
|
8276
|
+
overflowY: "auto",
|
|
8277
|
+
overscrollBehavior: "contain",
|
|
8278
|
+
scrollbarGutter: "stable",
|
|
8279
|
+
WebkitOverflowScrolling: "touch"
|
|
8280
|
+
},
|
|
8281
|
+
onWheel: (event) => {
|
|
8282
|
+
event.stopPropagation();
|
|
8283
|
+
},
|
|
8284
|
+
onTouchMove: (event) => {
|
|
8285
|
+
event.stopPropagation();
|
|
8286
|
+
},
|
|
8287
|
+
children: filteredItems.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
8288
|
+
"div",
|
|
8289
|
+
{
|
|
8290
|
+
className: cn(
|
|
8291
|
+
"px-3 py-6 text-center text-muted-foreground",
|
|
8292
|
+
sizeClasses.message
|
|
8293
|
+
),
|
|
8294
|
+
children: emptyText
|
|
8295
|
+
}
|
|
8296
|
+
) : filteredItems.map((item, index) => {
|
|
8297
|
+
const isSelected = item.value === currentValue;
|
|
8298
|
+
const isActive = index === activeIndex;
|
|
8299
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
8300
|
+
"div",
|
|
8301
|
+
{
|
|
8302
|
+
id: `${listboxId}-option-${index}`,
|
|
8303
|
+
role: "option",
|
|
8304
|
+
"aria-selected": isSelected,
|
|
8305
|
+
"aria-disabled": item.disabled,
|
|
8306
|
+
tabIndex: -1,
|
|
8307
|
+
onMouseMove: () => {
|
|
8308
|
+
if (!item.disabled) {
|
|
8309
|
+
setActiveIndex(index);
|
|
8310
|
+
}
|
|
8311
|
+
},
|
|
8312
|
+
onPointerDown: (event) => {
|
|
8313
|
+
event.preventDefault();
|
|
8314
|
+
event.stopPropagation();
|
|
8315
|
+
if (!item.disabled) {
|
|
8316
|
+
selectItem(item);
|
|
8317
|
+
}
|
|
8318
|
+
},
|
|
8319
|
+
className: cn(
|
|
8320
|
+
"relative flex w-full select-none items-center gap-2 rounded-lg px-3 text-left outline-none transition",
|
|
8321
|
+
sizeClasses.selectItem,
|
|
8322
|
+
item.disabled ? "pointer-events-none opacity-50" : "cursor-pointer",
|
|
8323
|
+
isActive && !item.disabled && "bg-accent text-accent-foreground",
|
|
8324
|
+
!isActive && !item.disabled && "hover:bg-accent/70 hover:text-accent-foreground",
|
|
8325
|
+
isSelected && "font-medium",
|
|
8326
|
+
itemClassName
|
|
8327
|
+
),
|
|
8328
|
+
children: [
|
|
8329
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "min-w-0 flex-1 truncate", children: item.label }),
|
|
8330
|
+
isSelected ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
8331
|
+
import_react_icons10.CheckIcon,
|
|
8332
|
+
{
|
|
8333
|
+
"aria-hidden": "true",
|
|
8334
|
+
className: "h-4 w-4 shrink-0 text-primary"
|
|
8335
|
+
}
|
|
8336
|
+
) : null
|
|
8337
|
+
]
|
|
8338
|
+
},
|
|
8339
|
+
item.value
|
|
8340
|
+
);
|
|
8341
|
+
})
|
|
8342
|
+
}
|
|
8343
|
+
)
|
|
8344
|
+
}
|
|
8345
|
+
),
|
|
8346
|
+
document.body
|
|
8347
|
+
) : null;
|
|
8060
8348
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { ref: rootRef, className: "relative w-full", children: [
|
|
8061
8349
|
name ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
8062
8350
|
"input",
|
|
@@ -8079,13 +8367,10 @@ function SearchableSelectBase({
|
|
|
8079
8367
|
disabled && "cursor-not-allowed opacity-50",
|
|
8080
8368
|
triggerClassName
|
|
8081
8369
|
) : triggerClassName,
|
|
8082
|
-
onPointerDown: () => {
|
|
8083
|
-
if (disabled) return;
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
var _a;
|
|
8087
|
-
(_a = inputRef.current) == null ? void 0 : _a.focus({ preventScroll: true });
|
|
8088
|
-
});
|
|
8370
|
+
onPointerDown: (event) => {
|
|
8371
|
+
if (disabled || event.button !== 0 || event.ctrlKey) return;
|
|
8372
|
+
event.preventDefault();
|
|
8373
|
+
openDropdown();
|
|
8089
8374
|
},
|
|
8090
8375
|
children: [
|
|
8091
8376
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
@@ -8104,11 +8389,7 @@ function SearchableSelectBase({
|
|
|
8104
8389
|
spellCheck: false,
|
|
8105
8390
|
disabled,
|
|
8106
8391
|
onFocus: () => {
|
|
8107
|
-
|
|
8108
|
-
requestAnimationFrame(() => {
|
|
8109
|
-
var _a;
|
|
8110
|
-
(_a = inputRef.current) == null ? void 0 : _a.select();
|
|
8111
|
-
});
|
|
8392
|
+
openDropdown();
|
|
8112
8393
|
},
|
|
8113
8394
|
onChange: (event) => {
|
|
8114
8395
|
setInputValue(event.target.value);
|
|
@@ -8191,86 +8472,7 @@ function SearchableSelectBase({
|
|
|
8191
8472
|
]
|
|
8192
8473
|
}
|
|
8193
8474
|
),
|
|
8194
|
-
|
|
8195
|
-
"div",
|
|
8196
|
-
{
|
|
8197
|
-
className: cn(
|
|
8198
|
-
"absolute left-0 top-full z-50 mt-1 w-full overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground shadow-xl transition",
|
|
8199
|
-
!open && "pointer-events-none invisible opacity-0",
|
|
8200
|
-
open && "visible opacity-100",
|
|
8201
|
-
contentClassName
|
|
8202
|
-
),
|
|
8203
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
8204
|
-
"div",
|
|
8205
|
-
{
|
|
8206
|
-
id: listboxId,
|
|
8207
|
-
role: "listbox",
|
|
8208
|
-
className: "max-h-72 overflow-y-auto overscroll-contain p-1 [scrollbar-gutter:stable]",
|
|
8209
|
-
onWheelCapture: (event) => {
|
|
8210
|
-
event.stopPropagation();
|
|
8211
|
-
},
|
|
8212
|
-
onTouchMoveCapture: (event) => {
|
|
8213
|
-
event.stopPropagation();
|
|
8214
|
-
},
|
|
8215
|
-
children: filteredItems.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
8216
|
-
"div",
|
|
8217
|
-
{
|
|
8218
|
-
className: cn(
|
|
8219
|
-
"px-3 py-6 text-center text-muted-foreground",
|
|
8220
|
-
sizeClasses.message
|
|
8221
|
-
),
|
|
8222
|
-
children: emptyText
|
|
8223
|
-
}
|
|
8224
|
-
) : filteredItems.map((item, index) => {
|
|
8225
|
-
const isSelected = item.value === currentValue;
|
|
8226
|
-
const isActive = index === activeIndex;
|
|
8227
|
-
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
8228
|
-
"div",
|
|
8229
|
-
{
|
|
8230
|
-
id: `${listboxId}-option-${index}`,
|
|
8231
|
-
role: "option",
|
|
8232
|
-
"aria-selected": isSelected,
|
|
8233
|
-
"aria-disabled": item.disabled,
|
|
8234
|
-
tabIndex: -1,
|
|
8235
|
-
onMouseMove: () => {
|
|
8236
|
-
if (!item.disabled) {
|
|
8237
|
-
setActiveIndex(index);
|
|
8238
|
-
}
|
|
8239
|
-
},
|
|
8240
|
-
onPointerDown: (event) => {
|
|
8241
|
-
event.preventDefault();
|
|
8242
|
-
event.stopPropagation();
|
|
8243
|
-
if (!item.disabled) {
|
|
8244
|
-
selectItem(item);
|
|
8245
|
-
}
|
|
8246
|
-
},
|
|
8247
|
-
className: cn(
|
|
8248
|
-
"relative flex w-full select-none items-center gap-2 rounded-lg px-3 text-left outline-none transition",
|
|
8249
|
-
sizeClasses.selectItem,
|
|
8250
|
-
item.disabled ? "pointer-events-none opacity-50" : "cursor-pointer",
|
|
8251
|
-
isActive && !item.disabled && "bg-accent text-accent-foreground",
|
|
8252
|
-
!isActive && !item.disabled && "hover:bg-accent/70 hover:text-accent-foreground",
|
|
8253
|
-
isSelected && "font-medium",
|
|
8254
|
-
itemClassName
|
|
8255
|
-
),
|
|
8256
|
-
children: [
|
|
8257
|
-
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "min-w-0 flex-1 truncate", children: item.label }),
|
|
8258
|
-
isSelected ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
8259
|
-
import_react_icons10.CheckIcon,
|
|
8260
|
-
{
|
|
8261
|
-
"aria-hidden": "true",
|
|
8262
|
-
className: "h-4 w-4 shrink-0 text-primary"
|
|
8263
|
-
}
|
|
8264
|
-
) : null
|
|
8265
|
-
]
|
|
8266
|
-
},
|
|
8267
|
-
item.value
|
|
8268
|
-
);
|
|
8269
|
-
})
|
|
8270
|
-
}
|
|
8271
|
-
)
|
|
8272
|
-
}
|
|
8273
|
-
)
|
|
8475
|
+
dropdown
|
|
8274
8476
|
] });
|
|
8275
8477
|
}
|
|
8276
8478
|
var SearchableSelect = React47.memo(
|
|
@@ -8285,7 +8487,7 @@ var FormSelect = ({
|
|
|
8285
8487
|
rules,
|
|
8286
8488
|
shouldUnregister,
|
|
8287
8489
|
defaultValue,
|
|
8288
|
-
placeholder = "
|
|
8490
|
+
placeholder = "Select an option",
|
|
8289
8491
|
label,
|
|
8290
8492
|
requiredLabel,
|
|
8291
8493
|
className,
|
|
@@ -8301,7 +8503,6 @@ var FormSelect = ({
|
|
|
8301
8503
|
getOptionLabel = getDefaultOptionLabel,
|
|
8302
8504
|
getOptionDisabled,
|
|
8303
8505
|
getOptionData,
|
|
8304
|
-
children,
|
|
8305
8506
|
onChange,
|
|
8306
8507
|
onChangeItem,
|
|
8307
8508
|
disabled,
|
|
@@ -8310,17 +8511,14 @@ var FormSelect = ({
|
|
|
8310
8511
|
variant = "outline",
|
|
8311
8512
|
invalid,
|
|
8312
8513
|
searchable = false,
|
|
8313
|
-
searchPlaceholder = "
|
|
8314
|
-
emptyText = "No
|
|
8315
|
-
classNameDefault = true
|
|
8316
|
-
position
|
|
8514
|
+
searchPlaceholder = "Search\u2026",
|
|
8515
|
+
emptyText = "No results",
|
|
8516
|
+
classNameDefault = true
|
|
8317
8517
|
}) => {
|
|
8318
8518
|
const form = (0, import_react_hook_form5.useFormContext)();
|
|
8319
8519
|
const controllerControl = control != null ? control : form == null ? void 0 : form.control;
|
|
8320
8520
|
const sizeClasses = getFormSizeClasses(size, customSize);
|
|
8321
8521
|
const triggerSizeClass = getFormControlSizeClass(variant, sizeClasses);
|
|
8322
|
-
const contentBase = "z-50 rounded-xl border border-border bg-popover text-popover-foreground shadow-xl outline-none";
|
|
8323
|
-
const contentViewport = "[&_[data-radix-select-viewport]]:max-h-72 [&_[data-radix-select-viewport]]:overflow-y-auto [&_[data-radix-select-viewport]]:overscroll-contain [&_[data-radix-select-viewport]]:[scrollbar-gutter:stable]";
|
|
8324
8522
|
const normalizedOptions = React48.useMemo(() => {
|
|
8325
8523
|
if (options) return options;
|
|
8326
8524
|
return (items != null ? items : []).map((item) => {
|
|
@@ -8361,15 +8559,11 @@ var FormSelect = ({
|
|
|
8361
8559
|
onChange == null ? void 0 : onChange(value);
|
|
8362
8560
|
onChangeItem == null ? void 0 : onChangeItem((_a2 = nextOption == null ? void 0 : nextOption.data) != null ? _a2 : null);
|
|
8363
8561
|
};
|
|
8364
|
-
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(FormItem, { children: [
|
|
8562
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(FormItem, { className: itemClassName, children: [
|
|
8365
8563
|
label ? /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
|
|
8366
8564
|
FormLabel,
|
|
8367
8565
|
{
|
|
8368
|
-
className: cn(
|
|
8369
|
-
"flex items-center gap-0.5",
|
|
8370
|
-
sizeClasses.label,
|
|
8371
|
-
labelClassName
|
|
8372
|
-
),
|
|
8566
|
+
className: cn("flex items-center gap-0.5", labelClassName),
|
|
8373
8567
|
children: [
|
|
8374
8568
|
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { children: label }),
|
|
8375
8569
|
requiredLabel ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
@@ -8385,7 +8579,7 @@ var FormSelect = ({
|
|
|
8385
8579
|
]
|
|
8386
8580
|
}
|
|
8387
8581
|
) : null,
|
|
8388
|
-
searchable ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
8582
|
+
searchable ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(FormControl, { children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
8389
8583
|
SearchableSelect,
|
|
8390
8584
|
{
|
|
8391
8585
|
items: normalizedOptions,
|
|
@@ -8408,74 +8602,34 @@ var FormSelect = ({
|
|
|
8408
8602
|
var _a2;
|
|
8409
8603
|
field.onChange(value);
|
|
8410
8604
|
onChange == null ? void 0 : onChange(value);
|
|
8411
|
-
onChangeItem == null ? void 0 : onChangeItem(
|
|
8605
|
+
onChangeItem == null ? void 0 : onChangeItem(
|
|
8606
|
+
(_a2 = option == null ? void 0 : option.data) != null ? _a2 : null
|
|
8607
|
+
);
|
|
8412
8608
|
field.onBlur();
|
|
8413
8609
|
}
|
|
8414
8610
|
}
|
|
8415
|
-
) : /* @__PURE__ */ (0, import_jsx_runtime26.
|
|
8611
|
+
) }) : /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
8416
8612
|
Select2,
|
|
8417
8613
|
{
|
|
8418
8614
|
value: (_b = field.value) != null ? _b : "",
|
|
8419
8615
|
onValueChange: handleValueChange,
|
|
8420
8616
|
onOpenChange: (nextOpen) => {
|
|
8421
|
-
if (!nextOpen)
|
|
8422
|
-
field.onBlur();
|
|
8423
|
-
}
|
|
8617
|
+
if (!nextOpen) field.onBlur();
|
|
8424
8618
|
},
|
|
8425
8619
|
disabled,
|
|
8426
|
-
children:
|
|
8427
|
-
|
|
8428
|
-
|
|
8429
|
-
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
) }),
|
|
8440
|
-
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
8441
|
-
SelectContent,
|
|
8442
|
-
{
|
|
8443
|
-
position,
|
|
8444
|
-
sideOffset: 6,
|
|
8445
|
-
className: cn(
|
|
8446
|
-
contentBase,
|
|
8447
|
-
contentViewport,
|
|
8448
|
-
"w-(--radix-select-trigger-width) min-w-(--radix-select-trigger-width) overflow-hidden!",
|
|
8449
|
-
contentClassName
|
|
8450
|
-
),
|
|
8451
|
-
onWheelCapture: (event) => {
|
|
8452
|
-
event.stopPropagation();
|
|
8453
|
-
},
|
|
8454
|
-
onTouchMoveCapture: (event) => {
|
|
8455
|
-
event.stopPropagation();
|
|
8456
|
-
},
|
|
8457
|
-
children: children ? children : normalizedOptions.length > 0 ? normalizedOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
8458
|
-
SelectItem,
|
|
8459
|
-
{
|
|
8460
|
-
value: option.value,
|
|
8461
|
-
disabled: option.disabled,
|
|
8462
|
-
className: cn(sizeClasses.selectItem, itemClassName),
|
|
8463
|
-
children: option.label
|
|
8464
|
-
},
|
|
8465
|
-
option.value
|
|
8466
|
-
)) : /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
8467
|
-
"div",
|
|
8468
|
-
{
|
|
8469
|
-
className: cn(
|
|
8470
|
-
"px-3 py-2 text-muted-foreground",
|
|
8471
|
-
sizeClasses.message
|
|
8472
|
-
),
|
|
8473
|
-
children: emptyText
|
|
8474
|
-
}
|
|
8475
|
-
)
|
|
8476
|
-
}
|
|
8477
|
-
)
|
|
8478
|
-
]
|
|
8620
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(FormControl, { children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
8621
|
+
SelectTrigger,
|
|
8622
|
+
{
|
|
8623
|
+
className: classNameDefault ? cn(
|
|
8624
|
+
formControlBase,
|
|
8625
|
+
formInputVariants[variant],
|
|
8626
|
+
triggerSizeClass,
|
|
8627
|
+
hasError && formControlErrorClass,
|
|
8628
|
+
className
|
|
8629
|
+
) : className,
|
|
8630
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(SelectValue, { placeholder })
|
|
8631
|
+
}
|
|
8632
|
+
) })
|
|
8479
8633
|
}
|
|
8480
8634
|
),
|
|
8481
8635
|
fieldError ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
@@ -9684,7 +9838,7 @@ var TableHead = React63.forwardRef((_a, ref) => {
|
|
|
9684
9838
|
__spreadValues({
|
|
9685
9839
|
ref,
|
|
9686
9840
|
className: cn(
|
|
9687
|
-
"h-10 px-2 text-left align-middle font-medium text-muted-foreground
|
|
9841
|
+
"h-10 px-2 text-left align-middle font-medium text-muted-foreground has-[[role=checkbox]]:pr-0 *:[[role=checkbox]]:translate-y-0.5",
|
|
9688
9842
|
className
|
|
9689
9843
|
)
|
|
9690
9844
|
}, props)
|
|
@@ -9698,7 +9852,7 @@ var TableCell = React63.forwardRef((_a, ref) => {
|
|
|
9698
9852
|
__spreadValues({
|
|
9699
9853
|
ref,
|
|
9700
9854
|
className: cn(
|
|
9701
|
-
"p-2 align-middle
|
|
9855
|
+
"p-2 align-middle has-[[role=checkbox]]:pr-0 *:[[role=checkbox]]:translate-y-0.5",
|
|
9702
9856
|
className
|
|
9703
9857
|
)
|
|
9704
9858
|
}, props)
|
|
@@ -10207,7 +10361,7 @@ var import_lucide_react9 = require("lucide-react");
|
|
|
10207
10361
|
var import_jsx_runtime54 = require("react/jsx-runtime");
|
|
10208
10362
|
function UiSelect({
|
|
10209
10363
|
label,
|
|
10210
|
-
placeholder,
|
|
10364
|
+
placeholder = "Select an option",
|
|
10211
10365
|
value,
|
|
10212
10366
|
defaultValue,
|
|
10213
10367
|
onChange,
|
|
@@ -10225,7 +10379,6 @@ function UiSelect({
|
|
|
10225
10379
|
size = "md",
|
|
10226
10380
|
customSize,
|
|
10227
10381
|
variant = "outline",
|
|
10228
|
-
classNameDefault = true,
|
|
10229
10382
|
errorMessage,
|
|
10230
10383
|
htmlFormItemId,
|
|
10231
10384
|
position
|
|
@@ -10235,20 +10388,16 @@ function UiSelect({
|
|
|
10235
10388
|
const messageId = `${triggerId}-message`;
|
|
10236
10389
|
const hasError = Boolean(errorMessage);
|
|
10237
10390
|
const sizeClasses = getFormSizeClasses(size, customSize);
|
|
10238
|
-
|
|
10239
|
-
const contentBase = "z-50 rounded-xl border border-border bg-popover text-popover-foreground shadow-xl outline-none";
|
|
10240
|
-
const contentViewport = "[&_[data-radix-select-viewport]]:max-h-72 [&_[data-radix-select-viewport]]:overflow-y-auto [&_[data-radix-select-viewport]]:overscroll-contain [&_[data-radix-select-viewport]]:[scrollbar-gutter:stable]";
|
|
10241
|
-
return /* @__PURE__ */ (0, import_jsx_runtime54.jsxs)("div", { className: cn("w-full space-y-2", selectClassName), children: [
|
|
10391
|
+
return /* @__PURE__ */ (0, import_jsx_runtime54.jsxs)("div", { className: cn("w-full space-y-0.5", selectClassName), children: [
|
|
10242
10392
|
label ? /* @__PURE__ */ (0, import_jsx_runtime54.jsxs)(
|
|
10243
10393
|
Label3,
|
|
10244
10394
|
{
|
|
10395
|
+
htmlFor: triggerId,
|
|
10245
10396
|
className: cn(
|
|
10246
|
-
"
|
|
10247
|
-
sizeClasses.label,
|
|
10397
|
+
"flex items-center gap-0.5 text-sm font-medium -mt-0.75 -pt-1.5",
|
|
10248
10398
|
hasError && "text-destructive",
|
|
10249
10399
|
labelClassName
|
|
10250
10400
|
),
|
|
10251
|
-
htmlFor: triggerId,
|
|
10252
10401
|
children: [
|
|
10253
10402
|
/* @__PURE__ */ (0, import_jsx_runtime54.jsx)("span", { children: label }),
|
|
10254
10403
|
requiredLabel ? /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(
|
|
@@ -10271,6 +10420,10 @@ function UiSelect({
|
|
|
10271
10420
|
defaultValue,
|
|
10272
10421
|
onValueChange: onChange,
|
|
10273
10422
|
disabled,
|
|
10423
|
+
size,
|
|
10424
|
+
customSize,
|
|
10425
|
+
variant,
|
|
10426
|
+
invalid: hasError,
|
|
10274
10427
|
children: [
|
|
10275
10428
|
/* @__PURE__ */ (0, import_jsx_runtime54.jsx)(
|
|
10276
10429
|
SelectTrigger,
|
|
@@ -10278,13 +10431,7 @@ function UiSelect({
|
|
|
10278
10431
|
id: triggerId,
|
|
10279
10432
|
"aria-invalid": hasError || void 0,
|
|
10280
10433
|
"aria-describedby": errorMessage ? messageId : void 0,
|
|
10281
|
-
className
|
|
10282
|
-
formControlBase,
|
|
10283
|
-
formInputVariants[variant],
|
|
10284
|
-
triggerSizeClass,
|
|
10285
|
-
hasError && formControlErrorClass,
|
|
10286
|
-
className
|
|
10287
|
-
) : className,
|
|
10434
|
+
className,
|
|
10288
10435
|
children: /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(SelectValue, { placeholder })
|
|
10289
10436
|
}
|
|
10290
10437
|
),
|
|
@@ -10294,17 +10441,11 @@ function UiSelect({
|
|
|
10294
10441
|
position,
|
|
10295
10442
|
sideOffset: 6,
|
|
10296
10443
|
className: cn(
|
|
10297
|
-
|
|
10298
|
-
contentViewport,
|
|
10299
|
-
"w-(--radix-select-trigger-width) min-w-(--radix-select-trigger-width) overflow-hidden!",
|
|
10444
|
+
"z-50 overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground shadow-xl outline-none",
|
|
10300
10445
|
contentClassName
|
|
10301
10446
|
),
|
|
10302
|
-
onWheelCapture: (event) =>
|
|
10303
|
-
|
|
10304
|
-
},
|
|
10305
|
-
onTouchMoveCapture: (event) => {
|
|
10306
|
-
event.stopPropagation();
|
|
10307
|
-
},
|
|
10447
|
+
onWheelCapture: (event) => event.stopPropagation(),
|
|
10448
|
+
onTouchMoveCapture: (event) => event.stopPropagation(),
|
|
10308
10449
|
children: children != null ? children : items == null ? void 0 : items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(
|
|
10309
10450
|
SelectItem,
|
|
10310
10451
|
{
|