shadcn-ui-react 0.7.11 → 0.7.12
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 +382 -243
- package/dist/index.d.cts +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.js +382 -243
- package/dist/style.css +17 -83
- 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);
|
|
@@ -7741,8 +7825,7 @@ var SelectContent = React46.forwardRef(
|
|
|
7741
7825
|
role: "listbox",
|
|
7742
7826
|
"data-side": side,
|
|
7743
7827
|
className: cn(
|
|
7744
|
-
"min-w-32 rounded-md border border-border bg-popover text-popover-foreground shadow-md",
|
|
7745
|
-
"overflow-hidden",
|
|
7828
|
+
"min-w-32 overflow-hidden rounded-md border border-border bg-popover text-popover-foreground shadow-md",
|
|
7746
7829
|
className
|
|
7747
7830
|
),
|
|
7748
7831
|
style: __spreadValues(__spreadValues({}, contentStyle), style),
|
|
@@ -7752,20 +7835,13 @@ var SelectContent = React46.forwardRef(
|
|
|
7752
7835
|
ref: scrollRef,
|
|
7753
7836
|
"data-select-scroll-content": true,
|
|
7754
7837
|
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"
|
|
7838
|
+
"max-h-full overflow-x-hidden overflow-y-auto overscroll-contain px-1 py-1",
|
|
7839
|
+
"scrollbar-gutter-stable"
|
|
7764
7840
|
),
|
|
7765
7841
|
style: {
|
|
7766
7842
|
maxHeight: contentStyle.maxHeight,
|
|
7767
7843
|
overflowX: "hidden",
|
|
7768
|
-
overflowY: "
|
|
7844
|
+
overflowY: "auto",
|
|
7769
7845
|
overscrollBehavior: "contain",
|
|
7770
7846
|
scrollbarGutter: "stable",
|
|
7771
7847
|
WebkitOverflowScrolling: "touch"
|
|
@@ -7773,6 +7849,9 @@ var SelectContent = React46.forwardRef(
|
|
|
7773
7849
|
onWheel: (event) => {
|
|
7774
7850
|
event.stopPropagation();
|
|
7775
7851
|
},
|
|
7852
|
+
onTouchMove: (event) => {
|
|
7853
|
+
event.stopPropagation();
|
|
7854
|
+
},
|
|
7776
7855
|
children
|
|
7777
7856
|
}
|
|
7778
7857
|
)
|
|
@@ -7848,7 +7927,7 @@ var SelectItem = React46.forwardRef(
|
|
|
7848
7927
|
const labelText = textValue != null ? textValue : getNodeText(children);
|
|
7849
7928
|
const isSelected = selectedValue === value;
|
|
7850
7929
|
const isActive = activeValue === value;
|
|
7851
|
-
React46.
|
|
7930
|
+
React46.useLayoutEffect(() => {
|
|
7852
7931
|
registerItem({
|
|
7853
7932
|
id: itemId,
|
|
7854
7933
|
value,
|
|
@@ -7865,9 +7944,9 @@ var SelectItem = React46.forwardRef(
|
|
|
7865
7944
|
unregisterItem,
|
|
7866
7945
|
itemId,
|
|
7867
7946
|
value,
|
|
7868
|
-
children,
|
|
7869
7947
|
labelText,
|
|
7870
|
-
disabled
|
|
7948
|
+
disabled,
|
|
7949
|
+
children
|
|
7871
7950
|
]);
|
|
7872
7951
|
const handleItemRef = React46.useCallback(
|
|
7873
7952
|
(node) => {
|
|
@@ -7940,15 +8019,25 @@ SelectSeparator.displayName = "SelectSeparator";
|
|
|
7940
8019
|
|
|
7941
8020
|
// src/components/searchable-select.tsx
|
|
7942
8021
|
var React47 = __toESM(require("react"), 1);
|
|
8022
|
+
var import_react_dom2 = require("react-dom");
|
|
7943
8023
|
var import_react_icons10 = require("@radix-ui/react-icons");
|
|
7944
8024
|
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
7945
8025
|
function normalizeText(value) {
|
|
7946
8026
|
return String(value != null ? value : "").normalize("NFD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().trim();
|
|
7947
8027
|
}
|
|
7948
8028
|
function getLabelText(value) {
|
|
8029
|
+
if (value === null || value === void 0 || typeof value === "boolean") {
|
|
8030
|
+
return "";
|
|
8031
|
+
}
|
|
7949
8032
|
if (typeof value === "string" || typeof value === "number") {
|
|
7950
8033
|
return String(value);
|
|
7951
8034
|
}
|
|
8035
|
+
if (Array.isArray(value)) {
|
|
8036
|
+
return value.map(getLabelText).join("");
|
|
8037
|
+
}
|
|
8038
|
+
if (React47.isValidElement(value)) {
|
|
8039
|
+
return getLabelText(value.props.children);
|
|
8040
|
+
}
|
|
7952
8041
|
return "";
|
|
7953
8042
|
}
|
|
7954
8043
|
function getOptionText(item) {
|
|
@@ -7967,6 +8056,10 @@ function getNextEnabledIndex2(items, currentIndex, direction) {
|
|
|
7967
8056
|
}
|
|
7968
8057
|
return -1;
|
|
7969
8058
|
}
|
|
8059
|
+
function areStylesEqual2(previous, next) {
|
|
8060
|
+
if (!previous) return false;
|
|
8061
|
+
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;
|
|
8062
|
+
}
|
|
7970
8063
|
function SearchableSelectBase({
|
|
7971
8064
|
items,
|
|
7972
8065
|
value,
|
|
@@ -7990,6 +8083,8 @@ function SearchableSelectBase({
|
|
|
7990
8083
|
}) {
|
|
7991
8084
|
const rootRef = React47.useRef(null);
|
|
7992
8085
|
const inputRef = React47.useRef(null);
|
|
8086
|
+
const contentRef = React47.useRef(null);
|
|
8087
|
+
const rafRef = React47.useRef(null);
|
|
7993
8088
|
const listboxId = React47.useId();
|
|
7994
8089
|
const sizeClasses = getFormSizeClasses(size, customSize);
|
|
7995
8090
|
const triggerSizeClass = getFormControlSizeClass(variant, sizeClasses);
|
|
@@ -8002,9 +8097,14 @@ function SearchableSelectBase({
|
|
|
8002
8097
|
const selectedText = React47.useMemo(() => {
|
|
8003
8098
|
return getOptionText(selectedItem);
|
|
8004
8099
|
}, [selectedItem]);
|
|
8100
|
+
const [mounted, setMounted] = React47.useState(false);
|
|
8005
8101
|
const [open, setOpen] = React47.useState(false);
|
|
8006
8102
|
const [inputValue, setInputValue] = React47.useState(selectedText);
|
|
8007
8103
|
const [activeIndex, setActiveIndex] = React47.useState(-1);
|
|
8104
|
+
const [contentStyle, setContentStyle] = React47.useState();
|
|
8105
|
+
React47.useLayoutEffect(() => {
|
|
8106
|
+
setMounted(true);
|
|
8107
|
+
}, []);
|
|
8008
8108
|
React47.useEffect(() => {
|
|
8009
8109
|
if (!open) {
|
|
8010
8110
|
setInputValue(selectedText);
|
|
@@ -8021,17 +8121,110 @@ function SearchableSelectBase({
|
|
|
8021
8121
|
return haystack.includes(query);
|
|
8022
8122
|
});
|
|
8023
8123
|
}, [inputValue, items]);
|
|
8124
|
+
const updatePosition = React47.useCallback(() => {
|
|
8125
|
+
const root = rootRef.current;
|
|
8126
|
+
if (!root) return;
|
|
8127
|
+
const rect = root.getBoundingClientRect();
|
|
8128
|
+
const viewportPadding = 8;
|
|
8129
|
+
const sideOffset = 6;
|
|
8130
|
+
const preferredMaxHeight = 288;
|
|
8131
|
+
const minUsefulHeight = 140;
|
|
8132
|
+
const availableBelow = window.innerHeight - rect.bottom - viewportPadding - sideOffset;
|
|
8133
|
+
const availableAbove = rect.top - viewportPadding - sideOffset;
|
|
8134
|
+
const shouldOpenBelow = availableBelow >= Math.min(preferredMaxHeight, minUsefulHeight) || availableBelow >= availableAbove;
|
|
8135
|
+
const availableHeight = shouldOpenBelow ? availableBelow : availableAbove;
|
|
8136
|
+
const contentMaxHeight = Math.max(
|
|
8137
|
+
96,
|
|
8138
|
+
Math.min(preferredMaxHeight, availableHeight)
|
|
8139
|
+
);
|
|
8140
|
+
const nextStyle = {
|
|
8141
|
+
position: "fixed",
|
|
8142
|
+
zIndex: 9999,
|
|
8143
|
+
left: Math.max(viewportPadding, rect.left),
|
|
8144
|
+
width: rect.width,
|
|
8145
|
+
minWidth: rect.width,
|
|
8146
|
+
maxWidth: `calc(100vw - ${viewportPadding * 2}px)`,
|
|
8147
|
+
maxHeight: contentMaxHeight
|
|
8148
|
+
};
|
|
8149
|
+
if (shouldOpenBelow) {
|
|
8150
|
+
nextStyle.top = rect.bottom + sideOffset;
|
|
8151
|
+
nextStyle.bottom = void 0;
|
|
8152
|
+
} else {
|
|
8153
|
+
nextStyle.bottom = window.innerHeight - rect.top + sideOffset;
|
|
8154
|
+
nextStyle.top = void 0;
|
|
8155
|
+
}
|
|
8156
|
+
setContentStyle(
|
|
8157
|
+
(previousStyle) => areStylesEqual2(previousStyle, nextStyle) ? previousStyle : nextStyle
|
|
8158
|
+
);
|
|
8159
|
+
}, []);
|
|
8160
|
+
const scheduleUpdatePosition = React47.useCallback(() => {
|
|
8161
|
+
if (rafRef.current) {
|
|
8162
|
+
cancelAnimationFrame(rafRef.current);
|
|
8163
|
+
}
|
|
8164
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
8165
|
+
rafRef.current = null;
|
|
8166
|
+
updatePosition();
|
|
8167
|
+
});
|
|
8168
|
+
}, [updatePosition]);
|
|
8169
|
+
const openDropdown = React47.useCallback(() => {
|
|
8170
|
+
if (disabled) return;
|
|
8171
|
+
if (!open) {
|
|
8172
|
+
setInputValue("");
|
|
8173
|
+
setOpen(true);
|
|
8174
|
+
}
|
|
8175
|
+
requestAnimationFrame(() => {
|
|
8176
|
+
var _a;
|
|
8177
|
+
(_a = inputRef.current) == null ? void 0 : _a.focus({ preventScroll: true });
|
|
8178
|
+
});
|
|
8179
|
+
}, [disabled, open]);
|
|
8180
|
+
React47.useLayoutEffect(() => {
|
|
8181
|
+
if (!open) {
|
|
8182
|
+
setContentStyle(void 0);
|
|
8183
|
+
}
|
|
8184
|
+
}, [open]);
|
|
8185
|
+
React47.useLayoutEffect(() => {
|
|
8186
|
+
var _a, _b;
|
|
8187
|
+
if (!open) return;
|
|
8188
|
+
updatePosition();
|
|
8189
|
+
scheduleUpdatePosition();
|
|
8190
|
+
const handleResizeOrScroll = () => {
|
|
8191
|
+
scheduleUpdatePosition();
|
|
8192
|
+
};
|
|
8193
|
+
window.addEventListener("resize", handleResizeOrScroll);
|
|
8194
|
+
window.addEventListener("scroll", handleResizeOrScroll, true);
|
|
8195
|
+
(_a = window.visualViewport) == null ? void 0 : _a.addEventListener("resize", handleResizeOrScroll);
|
|
8196
|
+
(_b = window.visualViewport) == null ? void 0 : _b.addEventListener("scroll", handleResizeOrScroll);
|
|
8197
|
+
return () => {
|
|
8198
|
+
var _a2, _b2;
|
|
8199
|
+
window.removeEventListener("resize", handleResizeOrScroll);
|
|
8200
|
+
window.removeEventListener("scroll", handleResizeOrScroll, true);
|
|
8201
|
+
(_a2 = window.visualViewport) == null ? void 0 : _a2.removeEventListener(
|
|
8202
|
+
"resize",
|
|
8203
|
+
handleResizeOrScroll
|
|
8204
|
+
);
|
|
8205
|
+
(_b2 = window.visualViewport) == null ? void 0 : _b2.removeEventListener(
|
|
8206
|
+
"scroll",
|
|
8207
|
+
handleResizeOrScroll
|
|
8208
|
+
);
|
|
8209
|
+
if (rafRef.current) {
|
|
8210
|
+
cancelAnimationFrame(rafRef.current);
|
|
8211
|
+
rafRef.current = null;
|
|
8212
|
+
}
|
|
8213
|
+
};
|
|
8214
|
+
}, [open, scheduleUpdatePosition, updatePosition]);
|
|
8024
8215
|
React47.useEffect(() => {
|
|
8025
8216
|
if (!open) return;
|
|
8026
8217
|
const firstEnabledIndex = filteredItems.findIndex((item) => !item.disabled);
|
|
8027
|
-
setActiveIndex(
|
|
8218
|
+
setActiveIndex(
|
|
8219
|
+
(previousIndex) => previousIndex === firstEnabledIndex ? previousIndex : firstEnabledIndex
|
|
8220
|
+
);
|
|
8028
8221
|
}, [filteredItems, open]);
|
|
8029
8222
|
React47.useEffect(() => {
|
|
8030
8223
|
if (!open) return;
|
|
8031
8224
|
const handlePointerDown = (event) => {
|
|
8032
|
-
var _a;
|
|
8225
|
+
var _a, _b;
|
|
8033
8226
|
const target = event.target;
|
|
8034
|
-
if (target && ((_a = rootRef.current) == null ? void 0 : _a.contains(target))) {
|
|
8227
|
+
if (target && (((_a = rootRef.current) == null ? void 0 : _a.contains(target)) || ((_b = contentRef.current) == null ? void 0 : _b.contains(target)))) {
|
|
8035
8228
|
return;
|
|
8036
8229
|
}
|
|
8037
8230
|
setOpen(false);
|
|
@@ -8057,6 +8250,99 @@ function SearchableSelectBase({
|
|
|
8057
8250
|
},
|
|
8058
8251
|
[isControlled, onValueChange]
|
|
8059
8252
|
);
|
|
8253
|
+
const dropdown = open && mounted && contentStyle ? (0, import_react_dom2.createPortal)(
|
|
8254
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
8255
|
+
"div",
|
|
8256
|
+
{
|
|
8257
|
+
ref: contentRef,
|
|
8258
|
+
className: cn(
|
|
8259
|
+
"overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground shadow-xl",
|
|
8260
|
+
contentClassName
|
|
8261
|
+
),
|
|
8262
|
+
style: __spreadProps(__spreadValues({}, contentStyle), {
|
|
8263
|
+
maxHeight: contentStyle.maxHeight
|
|
8264
|
+
}),
|
|
8265
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
8266
|
+
"div",
|
|
8267
|
+
{
|
|
8268
|
+
id: listboxId,
|
|
8269
|
+
role: "listbox",
|
|
8270
|
+
className: "max-h-full overflow-x-hidden overflow-y-auto overscroll-contain p-1 scrollbar-gutter-stable",
|
|
8271
|
+
style: {
|
|
8272
|
+
maxHeight: contentStyle.maxHeight,
|
|
8273
|
+
overflowX: "hidden",
|
|
8274
|
+
overflowY: "auto",
|
|
8275
|
+
overscrollBehavior: "contain",
|
|
8276
|
+
scrollbarGutter: "stable",
|
|
8277
|
+
WebkitOverflowScrolling: "touch"
|
|
8278
|
+
},
|
|
8279
|
+
onWheel: (event) => {
|
|
8280
|
+
event.stopPropagation();
|
|
8281
|
+
},
|
|
8282
|
+
onTouchMove: (event) => {
|
|
8283
|
+
event.stopPropagation();
|
|
8284
|
+
},
|
|
8285
|
+
children: filteredItems.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
8286
|
+
"div",
|
|
8287
|
+
{
|
|
8288
|
+
className: cn(
|
|
8289
|
+
"px-3 py-6 text-center text-muted-foreground",
|
|
8290
|
+
sizeClasses.message
|
|
8291
|
+
),
|
|
8292
|
+
children: emptyText
|
|
8293
|
+
}
|
|
8294
|
+
) : filteredItems.map((item, index) => {
|
|
8295
|
+
const isSelected = item.value === currentValue;
|
|
8296
|
+
const isActive = index === activeIndex;
|
|
8297
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
8298
|
+
"div",
|
|
8299
|
+
{
|
|
8300
|
+
id: `${listboxId}-option-${index}`,
|
|
8301
|
+
role: "option",
|
|
8302
|
+
"aria-selected": isSelected,
|
|
8303
|
+
"aria-disabled": item.disabled,
|
|
8304
|
+
tabIndex: -1,
|
|
8305
|
+
onMouseMove: () => {
|
|
8306
|
+
if (!item.disabled) {
|
|
8307
|
+
setActiveIndex(index);
|
|
8308
|
+
}
|
|
8309
|
+
},
|
|
8310
|
+
onPointerDown: (event) => {
|
|
8311
|
+
event.preventDefault();
|
|
8312
|
+
event.stopPropagation();
|
|
8313
|
+
if (!item.disabled) {
|
|
8314
|
+
selectItem(item);
|
|
8315
|
+
}
|
|
8316
|
+
},
|
|
8317
|
+
className: cn(
|
|
8318
|
+
"relative flex w-full select-none items-center gap-2 rounded-lg px-3 text-left outline-none transition",
|
|
8319
|
+
sizeClasses.selectItem,
|
|
8320
|
+
item.disabled ? "pointer-events-none opacity-50" : "cursor-pointer",
|
|
8321
|
+
isActive && !item.disabled && "bg-accent text-accent-foreground",
|
|
8322
|
+
!isActive && !item.disabled && "hover:bg-accent/70 hover:text-accent-foreground",
|
|
8323
|
+
isSelected && "font-medium",
|
|
8324
|
+
itemClassName
|
|
8325
|
+
),
|
|
8326
|
+
children: [
|
|
8327
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "min-w-0 flex-1 truncate", children: item.label }),
|
|
8328
|
+
isSelected ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
8329
|
+
import_react_icons10.CheckIcon,
|
|
8330
|
+
{
|
|
8331
|
+
"aria-hidden": "true",
|
|
8332
|
+
className: "h-4 w-4 shrink-0 text-primary"
|
|
8333
|
+
}
|
|
8334
|
+
) : null
|
|
8335
|
+
]
|
|
8336
|
+
},
|
|
8337
|
+
item.value
|
|
8338
|
+
);
|
|
8339
|
+
})
|
|
8340
|
+
}
|
|
8341
|
+
)
|
|
8342
|
+
}
|
|
8343
|
+
),
|
|
8344
|
+
document.body
|
|
8345
|
+
) : null;
|
|
8060
8346
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { ref: rootRef, className: "relative w-full", children: [
|
|
8061
8347
|
name ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
8062
8348
|
"input",
|
|
@@ -8079,13 +8365,10 @@ function SearchableSelectBase({
|
|
|
8079
8365
|
disabled && "cursor-not-allowed opacity-50",
|
|
8080
8366
|
triggerClassName
|
|
8081
8367
|
) : triggerClassName,
|
|
8082
|
-
onPointerDown: () => {
|
|
8083
|
-
if (disabled) return;
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
var _a;
|
|
8087
|
-
(_a = inputRef.current) == null ? void 0 : _a.focus({ preventScroll: true });
|
|
8088
|
-
});
|
|
8368
|
+
onPointerDown: (event) => {
|
|
8369
|
+
if (disabled || event.button !== 0 || event.ctrlKey) return;
|
|
8370
|
+
event.preventDefault();
|
|
8371
|
+
openDropdown();
|
|
8089
8372
|
},
|
|
8090
8373
|
children: [
|
|
8091
8374
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
@@ -8104,11 +8387,7 @@ function SearchableSelectBase({
|
|
|
8104
8387
|
spellCheck: false,
|
|
8105
8388
|
disabled,
|
|
8106
8389
|
onFocus: () => {
|
|
8107
|
-
|
|
8108
|
-
requestAnimationFrame(() => {
|
|
8109
|
-
var _a;
|
|
8110
|
-
(_a = inputRef.current) == null ? void 0 : _a.select();
|
|
8111
|
-
});
|
|
8390
|
+
openDropdown();
|
|
8112
8391
|
},
|
|
8113
8392
|
onChange: (event) => {
|
|
8114
8393
|
setInputValue(event.target.value);
|
|
@@ -8191,86 +8470,7 @@ function SearchableSelectBase({
|
|
|
8191
8470
|
]
|
|
8192
8471
|
}
|
|
8193
8472
|
),
|
|
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
|
-
)
|
|
8473
|
+
dropdown
|
|
8274
8474
|
] });
|
|
8275
8475
|
}
|
|
8276
8476
|
var SearchableSelect = React47.memo(
|
|
@@ -8285,7 +8485,7 @@ var FormSelect = ({
|
|
|
8285
8485
|
rules,
|
|
8286
8486
|
shouldUnregister,
|
|
8287
8487
|
defaultValue,
|
|
8288
|
-
placeholder = "
|
|
8488
|
+
placeholder = "Select an option",
|
|
8289
8489
|
label,
|
|
8290
8490
|
requiredLabel,
|
|
8291
8491
|
className,
|
|
@@ -8301,7 +8501,6 @@ var FormSelect = ({
|
|
|
8301
8501
|
getOptionLabel = getDefaultOptionLabel,
|
|
8302
8502
|
getOptionDisabled,
|
|
8303
8503
|
getOptionData,
|
|
8304
|
-
children,
|
|
8305
8504
|
onChange,
|
|
8306
8505
|
onChangeItem,
|
|
8307
8506
|
disabled,
|
|
@@ -8310,17 +8509,14 @@ var FormSelect = ({
|
|
|
8310
8509
|
variant = "outline",
|
|
8311
8510
|
invalid,
|
|
8312
8511
|
searchable = false,
|
|
8313
|
-
searchPlaceholder = "
|
|
8314
|
-
emptyText = "No
|
|
8315
|
-
classNameDefault = true
|
|
8316
|
-
position
|
|
8512
|
+
searchPlaceholder = "Search\u2026",
|
|
8513
|
+
emptyText = "No results",
|
|
8514
|
+
classNameDefault = true
|
|
8317
8515
|
}) => {
|
|
8318
8516
|
const form = (0, import_react_hook_form5.useFormContext)();
|
|
8319
8517
|
const controllerControl = control != null ? control : form == null ? void 0 : form.control;
|
|
8320
8518
|
const sizeClasses = getFormSizeClasses(size, customSize);
|
|
8321
8519
|
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
8520
|
const normalizedOptions = React48.useMemo(() => {
|
|
8325
8521
|
if (options) return options;
|
|
8326
8522
|
return (items != null ? items : []).map((item) => {
|
|
@@ -8361,15 +8557,11 @@ var FormSelect = ({
|
|
|
8361
8557
|
onChange == null ? void 0 : onChange(value);
|
|
8362
8558
|
onChangeItem == null ? void 0 : onChangeItem((_a2 = nextOption == null ? void 0 : nextOption.data) != null ? _a2 : null);
|
|
8363
8559
|
};
|
|
8364
|
-
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(FormItem, { children: [
|
|
8560
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(FormItem, { className: itemClassName, children: [
|
|
8365
8561
|
label ? /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
|
|
8366
8562
|
FormLabel,
|
|
8367
8563
|
{
|
|
8368
|
-
className: cn(
|
|
8369
|
-
"flex items-center gap-0.5",
|
|
8370
|
-
sizeClasses.label,
|
|
8371
|
-
labelClassName
|
|
8372
|
-
),
|
|
8564
|
+
className: cn("flex items-center gap-0.5", labelClassName),
|
|
8373
8565
|
children: [
|
|
8374
8566
|
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { children: label }),
|
|
8375
8567
|
requiredLabel ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
@@ -8385,7 +8577,7 @@ var FormSelect = ({
|
|
|
8385
8577
|
]
|
|
8386
8578
|
}
|
|
8387
8579
|
) : null,
|
|
8388
|
-
searchable ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
8580
|
+
searchable ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(FormControl, { children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
8389
8581
|
SearchableSelect,
|
|
8390
8582
|
{
|
|
8391
8583
|
items: normalizedOptions,
|
|
@@ -8408,74 +8600,34 @@ var FormSelect = ({
|
|
|
8408
8600
|
var _a2;
|
|
8409
8601
|
field.onChange(value);
|
|
8410
8602
|
onChange == null ? void 0 : onChange(value);
|
|
8411
|
-
onChangeItem == null ? void 0 : onChangeItem(
|
|
8603
|
+
onChangeItem == null ? void 0 : onChangeItem(
|
|
8604
|
+
(_a2 = option == null ? void 0 : option.data) != null ? _a2 : null
|
|
8605
|
+
);
|
|
8412
8606
|
field.onBlur();
|
|
8413
8607
|
}
|
|
8414
8608
|
}
|
|
8415
|
-
) : /* @__PURE__ */ (0, import_jsx_runtime26.
|
|
8609
|
+
) }) : /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
8416
8610
|
Select2,
|
|
8417
8611
|
{
|
|
8418
8612
|
value: (_b = field.value) != null ? _b : "",
|
|
8419
8613
|
onValueChange: handleValueChange,
|
|
8420
8614
|
onOpenChange: (nextOpen) => {
|
|
8421
|
-
if (!nextOpen)
|
|
8422
|
-
field.onBlur();
|
|
8423
|
-
}
|
|
8615
|
+
if (!nextOpen) field.onBlur();
|
|
8424
8616
|
},
|
|
8425
8617
|
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
|
-
]
|
|
8618
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(FormControl, { children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
8619
|
+
SelectTrigger,
|
|
8620
|
+
{
|
|
8621
|
+
className: classNameDefault ? cn(
|
|
8622
|
+
formControlBase,
|
|
8623
|
+
formInputVariants[variant],
|
|
8624
|
+
triggerSizeClass,
|
|
8625
|
+
hasError && formControlErrorClass,
|
|
8626
|
+
className
|
|
8627
|
+
) : className,
|
|
8628
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(SelectValue, { placeholder })
|
|
8629
|
+
}
|
|
8630
|
+
) })
|
|
8479
8631
|
}
|
|
8480
8632
|
),
|
|
8481
8633
|
fieldError ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
@@ -10207,7 +10359,7 @@ var import_lucide_react9 = require("lucide-react");
|
|
|
10207
10359
|
var import_jsx_runtime54 = require("react/jsx-runtime");
|
|
10208
10360
|
function UiSelect({
|
|
10209
10361
|
label,
|
|
10210
|
-
placeholder,
|
|
10362
|
+
placeholder = "Select an option",
|
|
10211
10363
|
value,
|
|
10212
10364
|
defaultValue,
|
|
10213
10365
|
onChange,
|
|
@@ -10225,7 +10377,6 @@ function UiSelect({
|
|
|
10225
10377
|
size = "md",
|
|
10226
10378
|
customSize,
|
|
10227
10379
|
variant = "outline",
|
|
10228
|
-
classNameDefault = true,
|
|
10229
10380
|
errorMessage,
|
|
10230
10381
|
htmlFormItemId,
|
|
10231
10382
|
position
|
|
@@ -10235,20 +10386,16 @@ function UiSelect({
|
|
|
10235
10386
|
const messageId = `${triggerId}-message`;
|
|
10236
10387
|
const hasError = Boolean(errorMessage);
|
|
10237
10388
|
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: [
|
|
10389
|
+
return /* @__PURE__ */ (0, import_jsx_runtime54.jsxs)("div", { className: cn("w-full space-y-0.5", selectClassName), children: [
|
|
10242
10390
|
label ? /* @__PURE__ */ (0, import_jsx_runtime54.jsxs)(
|
|
10243
10391
|
Label3,
|
|
10244
10392
|
{
|
|
10393
|
+
htmlFor: triggerId,
|
|
10245
10394
|
className: cn(
|
|
10246
|
-
"
|
|
10247
|
-
sizeClasses.label,
|
|
10395
|
+
"flex items-center gap-0.5 text-sm font-medium -mt-0.75 -pt-1.5",
|
|
10248
10396
|
hasError && "text-destructive",
|
|
10249
10397
|
labelClassName
|
|
10250
10398
|
),
|
|
10251
|
-
htmlFor: triggerId,
|
|
10252
10399
|
children: [
|
|
10253
10400
|
/* @__PURE__ */ (0, import_jsx_runtime54.jsx)("span", { children: label }),
|
|
10254
10401
|
requiredLabel ? /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(
|
|
@@ -10271,6 +10418,10 @@ function UiSelect({
|
|
|
10271
10418
|
defaultValue,
|
|
10272
10419
|
onValueChange: onChange,
|
|
10273
10420
|
disabled,
|
|
10421
|
+
size,
|
|
10422
|
+
customSize,
|
|
10423
|
+
variant,
|
|
10424
|
+
invalid: hasError,
|
|
10274
10425
|
children: [
|
|
10275
10426
|
/* @__PURE__ */ (0, import_jsx_runtime54.jsx)(
|
|
10276
10427
|
SelectTrigger,
|
|
@@ -10278,13 +10429,7 @@ function UiSelect({
|
|
|
10278
10429
|
id: triggerId,
|
|
10279
10430
|
"aria-invalid": hasError || void 0,
|
|
10280
10431
|
"aria-describedby": errorMessage ? messageId : void 0,
|
|
10281
|
-
className
|
|
10282
|
-
formControlBase,
|
|
10283
|
-
formInputVariants[variant],
|
|
10284
|
-
triggerSizeClass,
|
|
10285
|
-
hasError && formControlErrorClass,
|
|
10286
|
-
className
|
|
10287
|
-
) : className,
|
|
10432
|
+
className,
|
|
10288
10433
|
children: /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(SelectValue, { placeholder })
|
|
10289
10434
|
}
|
|
10290
10435
|
),
|
|
@@ -10294,17 +10439,11 @@ function UiSelect({
|
|
|
10294
10439
|
position,
|
|
10295
10440
|
sideOffset: 6,
|
|
10296
10441
|
className: cn(
|
|
10297
|
-
|
|
10298
|
-
contentViewport,
|
|
10299
|
-
"w-(--radix-select-trigger-width) min-w-(--radix-select-trigger-width) overflow-hidden!",
|
|
10442
|
+
"z-50 overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground shadow-xl outline-none",
|
|
10300
10443
|
contentClassName
|
|
10301
10444
|
),
|
|
10302
|
-
onWheelCapture: (event) =>
|
|
10303
|
-
|
|
10304
|
-
},
|
|
10305
|
-
onTouchMoveCapture: (event) => {
|
|
10306
|
-
event.stopPropagation();
|
|
10307
|
-
},
|
|
10445
|
+
onWheelCapture: (event) => event.stopPropagation(),
|
|
10446
|
+
onTouchMoveCapture: (event) => event.stopPropagation(),
|
|
10308
10447
|
children: children != null ? children : items == null ? void 0 : items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(
|
|
10309
10448
|
SelectItem,
|
|
10310
10449
|
{
|