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.js
CHANGED
|
@@ -6271,7 +6271,7 @@ import { cva as cva5 } from "class-variance-authority";
|
|
|
6271
6271
|
import * as React42 from "react";
|
|
6272
6272
|
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
6273
6273
|
var labelVariants = cva5(
|
|
6274
|
-
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70
|
|
6274
|
+
"text-sm font-medium leading-none text-label peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
6275
6275
|
);
|
|
6276
6276
|
var Label3 = React42.forwardRef((_a, ref) => {
|
|
6277
6277
|
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
@@ -6924,7 +6924,9 @@ var SelectContext = React46.createContext(null);
|
|
|
6924
6924
|
function useSelectContext(componentName) {
|
|
6925
6925
|
const context = React46.useContext(SelectContext);
|
|
6926
6926
|
if (!context) {
|
|
6927
|
-
throw new Error(
|
|
6927
|
+
throw new Error(
|
|
6928
|
+
`${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.`
|
|
6929
|
+
);
|
|
6928
6930
|
}
|
|
6929
6931
|
return context;
|
|
6930
6932
|
}
|
|
@@ -6939,11 +6941,15 @@ function useControllableState({
|
|
|
6939
6941
|
const setValue = React46.useCallback(
|
|
6940
6942
|
(nextValue) => {
|
|
6941
6943
|
if (!isControlled) {
|
|
6942
|
-
setInternalValue(
|
|
6944
|
+
setInternalValue(
|
|
6945
|
+
(previousValue) => Object.is(previousValue, nextValue) ? previousValue : nextValue
|
|
6946
|
+
);
|
|
6947
|
+
}
|
|
6948
|
+
if (!Object.is(currentValue, nextValue)) {
|
|
6949
|
+
onChange == null ? void 0 : onChange(nextValue);
|
|
6943
6950
|
}
|
|
6944
|
-
onChange == null ? void 0 : onChange(nextValue);
|
|
6945
6951
|
},
|
|
6946
|
-
[isControlled, onChange]
|
|
6952
|
+
[currentValue, isControlled, onChange]
|
|
6947
6953
|
);
|
|
6948
6954
|
return [currentValue, setValue];
|
|
6949
6955
|
}
|
|
@@ -6990,6 +6996,31 @@ function getNextItemValue(items, currentValue, direction) {
|
|
|
6990
6996
|
const nextIndex = direction === "next" ? (currentIndex + 1) % enabledItems.length : (currentIndex - 1 + enabledItems.length) % enabledItems.length;
|
|
6991
6997
|
return (_c = enabledItems[nextIndex]) == null ? void 0 : _c.value;
|
|
6992
6998
|
}
|
|
6999
|
+
function areRegisteredItemsEqual(previous, next) {
|
|
7000
|
+
return Boolean(
|
|
7001
|
+
previous && previous.id === next.id && previous.value === next.value && previous.textValue === next.textValue && previous.disabled === next.disabled && previous.label === next.label
|
|
7002
|
+
);
|
|
7003
|
+
}
|
|
7004
|
+
function areStylesEqual(previous, next) {
|
|
7005
|
+
if (!previous) return false;
|
|
7006
|
+
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;
|
|
7007
|
+
}
|
|
7008
|
+
function scrollItemIntoView(container, item) {
|
|
7009
|
+
if (!container || !item) return;
|
|
7010
|
+
const containerRect = container.getBoundingClientRect();
|
|
7011
|
+
const itemRect = item.getBoundingClientRect();
|
|
7012
|
+
const itemTop = itemRect.top - containerRect.top + container.scrollTop;
|
|
7013
|
+
const itemBottom = itemTop + itemRect.height;
|
|
7014
|
+
const visibleTop = container.scrollTop;
|
|
7015
|
+
const visibleBottom = visibleTop + container.clientHeight;
|
|
7016
|
+
if (itemTop < visibleTop) {
|
|
7017
|
+
container.scrollTop = itemTop;
|
|
7018
|
+
return;
|
|
7019
|
+
}
|
|
7020
|
+
if (itemBottom > visibleBottom) {
|
|
7021
|
+
container.scrollTop = itemBottom - container.clientHeight;
|
|
7022
|
+
}
|
|
7023
|
+
}
|
|
6993
7024
|
function Select2({
|
|
6994
7025
|
value,
|
|
6995
7026
|
defaultValue = "",
|
|
@@ -7028,17 +7059,28 @@ function Select2({
|
|
|
7028
7059
|
() => Array.from(itemsRef.current.values()),
|
|
7029
7060
|
[itemsVersion]
|
|
7030
7061
|
);
|
|
7031
|
-
const selectedItem =
|
|
7062
|
+
const selectedItem = React46.useMemo(
|
|
7063
|
+
() => items.find((item) => item.value === currentValue),
|
|
7064
|
+
[currentValue, items]
|
|
7065
|
+
);
|
|
7032
7066
|
const registerItem = React46.useCallback((item) => {
|
|
7067
|
+
const previousItem = itemsRef.current.get(item.value);
|
|
7068
|
+
if (previousItem && previousItem.id === item.id) {
|
|
7069
|
+
previousItem.label = item.label;
|
|
7070
|
+
previousItem.textValue = item.textValue;
|
|
7071
|
+
previousItem.disabled = item.disabled;
|
|
7072
|
+
if (!areRegisteredItemsEqual(previousItem, item)) {
|
|
7073
|
+
forceItemsUpdate();
|
|
7074
|
+
}
|
|
7075
|
+
return;
|
|
7076
|
+
}
|
|
7033
7077
|
itemsRef.current.set(item.value, item);
|
|
7034
7078
|
forceItemsUpdate();
|
|
7035
7079
|
}, []);
|
|
7036
7080
|
const unregisterItem = React46.useCallback((value2, id) => {
|
|
7037
7081
|
const currentItem = itemsRef.current.get(value2);
|
|
7038
7082
|
if (!currentItem || currentItem.id !== id) return;
|
|
7039
|
-
itemsRef.current.
|
|
7040
|
-
ref: null
|
|
7041
|
-
}));
|
|
7083
|
+
itemsRef.current.delete(value2);
|
|
7042
7084
|
forceItemsUpdate();
|
|
7043
7085
|
}, []);
|
|
7044
7086
|
const updateItemRef = React46.useCallback(
|
|
@@ -7046,10 +7088,7 @@ function Select2({
|
|
|
7046
7088
|
const currentItem = itemsRef.current.get(value2);
|
|
7047
7089
|
if (!currentItem || currentItem.id !== id) return;
|
|
7048
7090
|
if (currentItem.ref === node) return;
|
|
7049
|
-
|
|
7050
|
-
ref: node
|
|
7051
|
-
}));
|
|
7052
|
-
forceItemsUpdate();
|
|
7091
|
+
currentItem.ref = node;
|
|
7053
7092
|
},
|
|
7054
7093
|
[]
|
|
7055
7094
|
);
|
|
@@ -7067,7 +7106,7 @@ function Select2({
|
|
|
7067
7106
|
setIsOpen(false);
|
|
7068
7107
|
requestAnimationFrame(() => {
|
|
7069
7108
|
var _a;
|
|
7070
|
-
(_a = triggerRef.current) == null ? void 0 : _a.focus();
|
|
7109
|
+
(_a = triggerRef.current) == null ? void 0 : _a.focus({ preventScroll: true });
|
|
7071
7110
|
});
|
|
7072
7111
|
},
|
|
7073
7112
|
[disabled, setCurrentValue, setIsOpen]
|
|
@@ -7079,21 +7118,24 @@ function Select2({
|
|
|
7079
7118
|
(item) => item.value === currentValue && !item.disabled
|
|
7080
7119
|
);
|
|
7081
7120
|
const firstEnabledItem = getEnabledItems(items)[0];
|
|
7082
|
-
|
|
7121
|
+
const nextActiveValue = (_a = selectedEnabledItem == null ? void 0 : selectedEnabledItem.value) != null ? _a : firstEnabledItem == null ? void 0 : firstEnabledItem.value;
|
|
7122
|
+
setActiveValue(
|
|
7123
|
+
(previousValue) => previousValue === nextActiveValue ? previousValue : nextActiveValue
|
|
7124
|
+
);
|
|
7083
7125
|
}, [currentValue, isOpen, items]);
|
|
7084
7126
|
React46.useEffect(() => {
|
|
7085
7127
|
if (!isOpen) return;
|
|
7086
7128
|
const handlePointerDown = (event) => {
|
|
7087
7129
|
var _a, _b;
|
|
7088
7130
|
const target = event.target;
|
|
7089
|
-
if (((_a = triggerRef.current) == null ? void 0 : _a.contains(target)) || ((_b = contentRef.current) == null ? void 0 : _b.contains(target))) {
|
|
7131
|
+
if (target && (((_a = triggerRef.current) == null ? void 0 : _a.contains(target)) || ((_b = contentRef.current) == null ? void 0 : _b.contains(target)))) {
|
|
7090
7132
|
return;
|
|
7091
7133
|
}
|
|
7092
7134
|
setIsOpen(false);
|
|
7093
7135
|
};
|
|
7094
|
-
document.addEventListener("pointerdown", handlePointerDown);
|
|
7136
|
+
document.addEventListener("pointerdown", handlePointerDown, true);
|
|
7095
7137
|
return () => {
|
|
7096
|
-
document.removeEventListener("pointerdown", handlePointerDown);
|
|
7138
|
+
document.removeEventListener("pointerdown", handlePointerDown, true);
|
|
7097
7139
|
};
|
|
7098
7140
|
}, [isOpen, setIsOpen]);
|
|
7099
7141
|
const contextValue = React46.useMemo(
|
|
@@ -7143,7 +7185,8 @@ function Select2({
|
|
|
7143
7185
|
type: "hidden",
|
|
7144
7186
|
name,
|
|
7145
7187
|
value: currentValue,
|
|
7146
|
-
required
|
|
7188
|
+
required,
|
|
7189
|
+
disabled
|
|
7147
7190
|
}
|
|
7148
7191
|
) : null
|
|
7149
7192
|
] });
|
|
@@ -7159,7 +7202,8 @@ var SelectTrigger = React46.forwardRef(
|
|
|
7159
7202
|
invalid,
|
|
7160
7203
|
disabled,
|
|
7161
7204
|
onClick,
|
|
7162
|
-
onKeyDown
|
|
7205
|
+
onKeyDown,
|
|
7206
|
+
onPointerDown
|
|
7163
7207
|
} = _b, props = __objRest(_b, [
|
|
7164
7208
|
"className",
|
|
7165
7209
|
"children",
|
|
@@ -7169,7 +7213,8 @@ var SelectTrigger = React46.forwardRef(
|
|
|
7169
7213
|
"invalid",
|
|
7170
7214
|
"disabled",
|
|
7171
7215
|
"onClick",
|
|
7172
|
-
"onKeyDown"
|
|
7216
|
+
"onKeyDown",
|
|
7217
|
+
"onPointerDown"
|
|
7173
7218
|
]);
|
|
7174
7219
|
const context = useSelectContext("SelectTrigger");
|
|
7175
7220
|
const resolvedVariant = variant != null ? variant : context.variant;
|
|
@@ -7295,16 +7340,27 @@ var SelectTrigger = React46.forwardRef(
|
|
|
7295
7340
|
disabled: resolvedDisabled,
|
|
7296
7341
|
className: cn(
|
|
7297
7342
|
formControlBase,
|
|
7298
|
-
"whitespace-nowrap ring-offset-background
|
|
7343
|
+
"relative flex w-full items-center justify-between gap-2 overflow-hidden whitespace-nowrap ring-offset-background",
|
|
7299
7344
|
formInputVariants[resolvedVariant],
|
|
7300
7345
|
controlSizeClass,
|
|
7301
7346
|
resolvedInvalid && formControlErrorClass,
|
|
7302
7347
|
className
|
|
7303
7348
|
),
|
|
7349
|
+
onPointerDown: (event) => {
|
|
7350
|
+
onPointerDown == null ? void 0 : onPointerDown(event);
|
|
7351
|
+
if (event.defaultPrevented || resolvedDisabled || event.button !== 0 || event.ctrlKey) {
|
|
7352
|
+
return;
|
|
7353
|
+
}
|
|
7354
|
+
event.preventDefault();
|
|
7355
|
+
},
|
|
7304
7356
|
onClick: (event) => {
|
|
7305
7357
|
onClick == null ? void 0 : onClick(event);
|
|
7306
7358
|
if (!event.defaultPrevented && !resolvedDisabled) {
|
|
7307
7359
|
context.setOpen(!context.open);
|
|
7360
|
+
requestAnimationFrame(() => {
|
|
7361
|
+
var _a2;
|
|
7362
|
+
(_a2 = context.triggerRef.current) == null ? void 0 : _a2.focus({ preventScroll: true });
|
|
7363
|
+
});
|
|
7308
7364
|
}
|
|
7309
7365
|
},
|
|
7310
7366
|
onKeyDown: handleKeyDown
|
|
@@ -7320,13 +7376,25 @@ var SelectTrigger = React46.forwardRef(
|
|
|
7320
7376
|
SelectTrigger.displayName = "SelectTrigger";
|
|
7321
7377
|
var SelectValue = React46.forwardRef(
|
|
7322
7378
|
(_a, ref) => {
|
|
7323
|
-
var _b = _a, { className, placeholder, children } = _b, props = __objRest(_b, ["className", "placeholder", "children"]);
|
|
7324
|
-
var _a2
|
|
7379
|
+
var _b = _a, { className, placeholder = "Select an option", children } = _b, props = __objRest(_b, ["className", "placeholder", "children"]);
|
|
7380
|
+
var _a2;
|
|
7325
7381
|
const context = useSelectContext("SelectValue");
|
|
7326
|
-
|
|
7382
|
+
const hasValue = Boolean(context.selectedItem) || children !== void 0;
|
|
7383
|
+
return /* @__PURE__ */ jsx24(
|
|
7384
|
+
"span",
|
|
7385
|
+
__spreadProps(__spreadValues({
|
|
7386
|
+
ref,
|
|
7387
|
+
className: cn(
|
|
7388
|
+
"min-w-0 flex-1 truncate text-left",
|
|
7389
|
+
!hasValue && "text-muted-foreground",
|
|
7390
|
+
className
|
|
7391
|
+
)
|
|
7392
|
+
}, props), {
|
|
7393
|
+
children: hasValue ? children != null ? children : (_a2 = context.selectedItem) == null ? void 0 : _a2.label : placeholder
|
|
7394
|
+
})
|
|
7395
|
+
);
|
|
7327
7396
|
}
|
|
7328
7397
|
);
|
|
7329
|
-
SelectValue.displayName = "SelectValue";
|
|
7330
7398
|
var SelectContent = React46.forwardRef(
|
|
7331
7399
|
(_a, ref) => {
|
|
7332
7400
|
var _b = _a, {
|
|
@@ -7347,22 +7415,33 @@ var SelectContent = React46.forwardRef(
|
|
|
7347
7415
|
const context = useSelectContext("SelectContent");
|
|
7348
7416
|
const scrollRef = React46.useRef(null);
|
|
7349
7417
|
const rafRef = React46.useRef(null);
|
|
7418
|
+
const lockedSideRef = React46.useRef(null);
|
|
7350
7419
|
const [mounted, setMounted] = React46.useState(false);
|
|
7351
7420
|
const [side, setSide] = React46.useState("bottom");
|
|
7352
7421
|
const [contentStyle, setContentStyle] = React46.useState();
|
|
7353
|
-
React46.
|
|
7422
|
+
React46.useLayoutEffect(() => {
|
|
7354
7423
|
setMounted(true);
|
|
7355
7424
|
}, []);
|
|
7425
|
+
React46.useLayoutEffect(() => {
|
|
7426
|
+
if (!context.open) {
|
|
7427
|
+
lockedSideRef.current = null;
|
|
7428
|
+
setContentStyle(void 0);
|
|
7429
|
+
}
|
|
7430
|
+
}, [context.open]);
|
|
7356
7431
|
const updatePosition = React46.useCallback(() => {
|
|
7357
7432
|
const trigger = context.triggerRef.current;
|
|
7358
7433
|
if (!trigger) return;
|
|
7359
7434
|
const rect = trigger.getBoundingClientRect();
|
|
7360
7435
|
const viewportPadding = 8;
|
|
7361
|
-
const preferredMaxHeight =
|
|
7436
|
+
const preferredMaxHeight = 288;
|
|
7362
7437
|
const minUsefulHeight = 140;
|
|
7363
7438
|
const availableBelow = window.innerHeight - rect.bottom - viewportPadding - sideOffset;
|
|
7364
7439
|
const availableAbove = rect.top - viewportPadding - sideOffset;
|
|
7365
|
-
const
|
|
7440
|
+
const calculatedSide = availableBelow >= Math.min(preferredMaxHeight, minUsefulHeight) || availableBelow >= availableAbove ? "bottom" : "top";
|
|
7441
|
+
if (!lockedSideRef.current) {
|
|
7442
|
+
lockedSideRef.current = calculatedSide;
|
|
7443
|
+
}
|
|
7444
|
+
const nextSide = lockedSideRef.current;
|
|
7366
7445
|
const availableHeight = nextSide === "bottom" ? availableBelow : availableAbove;
|
|
7367
7446
|
const contentMaxHeight = Math.max(
|
|
7368
7447
|
80,
|
|
@@ -7378,14 +7457,17 @@ var SelectContent = React46.forwardRef(
|
|
|
7378
7457
|
};
|
|
7379
7458
|
if (align === "start") {
|
|
7380
7459
|
baseStyle.left = rect.left;
|
|
7460
|
+
baseStyle.right = void 0;
|
|
7381
7461
|
baseStyle.transform = void 0;
|
|
7382
7462
|
}
|
|
7383
7463
|
if (align === "center") {
|
|
7384
7464
|
baseStyle.left = rect.left + rect.width / 2;
|
|
7465
|
+
baseStyle.right = void 0;
|
|
7385
7466
|
baseStyle.transform = "translateX(-50%)";
|
|
7386
7467
|
}
|
|
7387
7468
|
if (align === "end") {
|
|
7388
7469
|
baseStyle.left = rect.right;
|
|
7470
|
+
baseStyle.right = void 0;
|
|
7389
7471
|
baseStyle.transform = "translateX(-100%)";
|
|
7390
7472
|
}
|
|
7391
7473
|
if (nextSide === "bottom") {
|
|
@@ -7395,14 +7477,19 @@ var SelectContent = React46.forwardRef(
|
|
|
7395
7477
|
baseStyle.bottom = window.innerHeight - rect.top + sideOffset;
|
|
7396
7478
|
baseStyle.top = void 0;
|
|
7397
7479
|
}
|
|
7398
|
-
setSide(
|
|
7399
|
-
|
|
7480
|
+
setSide(
|
|
7481
|
+
(previousSide) => previousSide === nextSide ? previousSide : nextSide
|
|
7482
|
+
);
|
|
7483
|
+
setContentStyle(
|
|
7484
|
+
(previousStyle) => areStylesEqual(previousStyle, baseStyle) ? previousStyle : baseStyle
|
|
7485
|
+
);
|
|
7400
7486
|
}, [align, context.triggerRef, sideOffset]);
|
|
7401
7487
|
const scheduleUpdatePosition = React46.useCallback(() => {
|
|
7402
7488
|
if (rafRef.current) {
|
|
7403
7489
|
cancelAnimationFrame(rafRef.current);
|
|
7404
7490
|
}
|
|
7405
7491
|
rafRef.current = requestAnimationFrame(() => {
|
|
7492
|
+
rafRef.current = null;
|
|
7406
7493
|
updatePosition();
|
|
7407
7494
|
});
|
|
7408
7495
|
}, [updatePosition]);
|
|
@@ -7441,13 +7528,10 @@ var SelectContent = React46.forwardRef(
|
|
|
7441
7528
|
React46.useLayoutEffect(() => {
|
|
7442
7529
|
if (!context.open) return;
|
|
7443
7530
|
const frame = requestAnimationFrame(() => {
|
|
7444
|
-
var _a2;
|
|
7445
7531
|
const activeItem = context.items.find(
|
|
7446
7532
|
(item) => item.value === context.activeValue
|
|
7447
7533
|
);
|
|
7448
|
-
(
|
|
7449
|
-
block: "nearest"
|
|
7450
|
-
});
|
|
7534
|
+
scrollItemIntoView(scrollRef.current, activeItem == null ? void 0 : activeItem.ref);
|
|
7451
7535
|
});
|
|
7452
7536
|
return () => {
|
|
7453
7537
|
cancelAnimationFrame(frame);
|
|
@@ -7465,8 +7549,7 @@ var SelectContent = React46.forwardRef(
|
|
|
7465
7549
|
role: "listbox",
|
|
7466
7550
|
"data-side": side,
|
|
7467
7551
|
className: cn(
|
|
7468
|
-
"min-w-32 rounded-md border border-border bg-popover text-popover-foreground shadow-md",
|
|
7469
|
-
"overflow-hidden",
|
|
7552
|
+
"min-w-32 overflow-hidden rounded-md border border-border bg-popover text-popover-foreground shadow-md",
|
|
7470
7553
|
className
|
|
7471
7554
|
),
|
|
7472
7555
|
style: __spreadValues(__spreadValues({}, contentStyle), style),
|
|
@@ -7476,20 +7559,13 @@ var SelectContent = React46.forwardRef(
|
|
|
7476
7559
|
ref: scrollRef,
|
|
7477
7560
|
"data-select-scroll-content": true,
|
|
7478
7561
|
className: cn(
|
|
7479
|
-
"max-h-full px-1 py-1",
|
|
7480
|
-
"
|
|
7481
|
-
"[scrollbar-gutter:stable]",
|
|
7482
|
-
"[scrollbar-width:thin]",
|
|
7483
|
-
"[&::-webkit-scrollbar]:!block",
|
|
7484
|
-
"[&::-webkit-scrollbar]:!w-2",
|
|
7485
|
-
"[&::-webkit-scrollbar-track]:!bg-transparent",
|
|
7486
|
-
"[&::-webkit-scrollbar-thumb]:!rounded-full",
|
|
7487
|
-
"[&::-webkit-scrollbar-thumb]:!bg-border"
|
|
7562
|
+
"max-h-full overflow-x-hidden overflow-y-auto overscroll-contain px-1 py-1",
|
|
7563
|
+
"scrollbar-gutter-stable"
|
|
7488
7564
|
),
|
|
7489
7565
|
style: {
|
|
7490
7566
|
maxHeight: contentStyle.maxHeight,
|
|
7491
7567
|
overflowX: "hidden",
|
|
7492
|
-
overflowY: "
|
|
7568
|
+
overflowY: "auto",
|
|
7493
7569
|
overscrollBehavior: "contain",
|
|
7494
7570
|
scrollbarGutter: "stable",
|
|
7495
7571
|
WebkitOverflowScrolling: "touch"
|
|
@@ -7497,6 +7573,9 @@ var SelectContent = React46.forwardRef(
|
|
|
7497
7573
|
onWheel: (event) => {
|
|
7498
7574
|
event.stopPropagation();
|
|
7499
7575
|
},
|
|
7576
|
+
onTouchMove: (event) => {
|
|
7577
|
+
event.stopPropagation();
|
|
7578
|
+
},
|
|
7500
7579
|
children
|
|
7501
7580
|
}
|
|
7502
7581
|
)
|
|
@@ -7572,7 +7651,7 @@ var SelectItem = React46.forwardRef(
|
|
|
7572
7651
|
const labelText = textValue != null ? textValue : getNodeText(children);
|
|
7573
7652
|
const isSelected = selectedValue === value;
|
|
7574
7653
|
const isActive = activeValue === value;
|
|
7575
|
-
React46.
|
|
7654
|
+
React46.useLayoutEffect(() => {
|
|
7576
7655
|
registerItem({
|
|
7577
7656
|
id: itemId,
|
|
7578
7657
|
value,
|
|
@@ -7589,9 +7668,9 @@ var SelectItem = React46.forwardRef(
|
|
|
7589
7668
|
unregisterItem,
|
|
7590
7669
|
itemId,
|
|
7591
7670
|
value,
|
|
7592
|
-
children,
|
|
7593
7671
|
labelText,
|
|
7594
|
-
disabled
|
|
7672
|
+
disabled,
|
|
7673
|
+
children
|
|
7595
7674
|
]);
|
|
7596
7675
|
const handleItemRef = React46.useCallback(
|
|
7597
7676
|
(node) => {
|
|
@@ -7664,15 +7743,25 @@ SelectSeparator.displayName = "SelectSeparator";
|
|
|
7664
7743
|
|
|
7665
7744
|
// src/components/searchable-select.tsx
|
|
7666
7745
|
import * as React47 from "react";
|
|
7746
|
+
import { createPortal as createPortal2 } from "react-dom";
|
|
7667
7747
|
import { CaretSortIcon as CaretSortIcon2, CheckIcon as CheckIcon5, Cross2Icon as Cross2Icon2 } from "@radix-ui/react-icons";
|
|
7668
7748
|
import { jsx as jsx25, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
7669
7749
|
function normalizeText(value) {
|
|
7670
7750
|
return String(value != null ? value : "").normalize("NFD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().trim();
|
|
7671
7751
|
}
|
|
7672
7752
|
function getLabelText(value) {
|
|
7753
|
+
if (value === null || value === void 0 || typeof value === "boolean") {
|
|
7754
|
+
return "";
|
|
7755
|
+
}
|
|
7673
7756
|
if (typeof value === "string" || typeof value === "number") {
|
|
7674
7757
|
return String(value);
|
|
7675
7758
|
}
|
|
7759
|
+
if (Array.isArray(value)) {
|
|
7760
|
+
return value.map(getLabelText).join("");
|
|
7761
|
+
}
|
|
7762
|
+
if (React47.isValidElement(value)) {
|
|
7763
|
+
return getLabelText(value.props.children);
|
|
7764
|
+
}
|
|
7676
7765
|
return "";
|
|
7677
7766
|
}
|
|
7678
7767
|
function getOptionText(item) {
|
|
@@ -7691,6 +7780,10 @@ function getNextEnabledIndex2(items, currentIndex, direction) {
|
|
|
7691
7780
|
}
|
|
7692
7781
|
return -1;
|
|
7693
7782
|
}
|
|
7783
|
+
function areStylesEqual2(previous, next) {
|
|
7784
|
+
if (!previous) return false;
|
|
7785
|
+
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;
|
|
7786
|
+
}
|
|
7694
7787
|
function SearchableSelectBase({
|
|
7695
7788
|
items,
|
|
7696
7789
|
value,
|
|
@@ -7714,6 +7807,8 @@ function SearchableSelectBase({
|
|
|
7714
7807
|
}) {
|
|
7715
7808
|
const rootRef = React47.useRef(null);
|
|
7716
7809
|
const inputRef = React47.useRef(null);
|
|
7810
|
+
const contentRef = React47.useRef(null);
|
|
7811
|
+
const rafRef = React47.useRef(null);
|
|
7717
7812
|
const listboxId = React47.useId();
|
|
7718
7813
|
const sizeClasses = getFormSizeClasses(size, customSize);
|
|
7719
7814
|
const triggerSizeClass = getFormControlSizeClass(variant, sizeClasses);
|
|
@@ -7726,9 +7821,14 @@ function SearchableSelectBase({
|
|
|
7726
7821
|
const selectedText = React47.useMemo(() => {
|
|
7727
7822
|
return getOptionText(selectedItem);
|
|
7728
7823
|
}, [selectedItem]);
|
|
7824
|
+
const [mounted, setMounted] = React47.useState(false);
|
|
7729
7825
|
const [open, setOpen] = React47.useState(false);
|
|
7730
7826
|
const [inputValue, setInputValue] = React47.useState(selectedText);
|
|
7731
7827
|
const [activeIndex, setActiveIndex] = React47.useState(-1);
|
|
7828
|
+
const [contentStyle, setContentStyle] = React47.useState();
|
|
7829
|
+
React47.useLayoutEffect(() => {
|
|
7830
|
+
setMounted(true);
|
|
7831
|
+
}, []);
|
|
7732
7832
|
React47.useEffect(() => {
|
|
7733
7833
|
if (!open) {
|
|
7734
7834
|
setInputValue(selectedText);
|
|
@@ -7745,17 +7845,110 @@ function SearchableSelectBase({
|
|
|
7745
7845
|
return haystack.includes(query);
|
|
7746
7846
|
});
|
|
7747
7847
|
}, [inputValue, items]);
|
|
7848
|
+
const updatePosition = React47.useCallback(() => {
|
|
7849
|
+
const root = rootRef.current;
|
|
7850
|
+
if (!root) return;
|
|
7851
|
+
const rect = root.getBoundingClientRect();
|
|
7852
|
+
const viewportPadding = 8;
|
|
7853
|
+
const sideOffset = 6;
|
|
7854
|
+
const preferredMaxHeight = 288;
|
|
7855
|
+
const minUsefulHeight = 140;
|
|
7856
|
+
const availableBelow = window.innerHeight - rect.bottom - viewportPadding - sideOffset;
|
|
7857
|
+
const availableAbove = rect.top - viewportPadding - sideOffset;
|
|
7858
|
+
const shouldOpenBelow = availableBelow >= Math.min(preferredMaxHeight, minUsefulHeight) || availableBelow >= availableAbove;
|
|
7859
|
+
const availableHeight = shouldOpenBelow ? availableBelow : availableAbove;
|
|
7860
|
+
const contentMaxHeight = Math.max(
|
|
7861
|
+
96,
|
|
7862
|
+
Math.min(preferredMaxHeight, availableHeight)
|
|
7863
|
+
);
|
|
7864
|
+
const nextStyle = {
|
|
7865
|
+
position: "fixed",
|
|
7866
|
+
zIndex: 9999,
|
|
7867
|
+
left: Math.max(viewportPadding, rect.left),
|
|
7868
|
+
width: rect.width,
|
|
7869
|
+
minWidth: rect.width,
|
|
7870
|
+
maxWidth: `calc(100vw - ${viewportPadding * 2}px)`,
|
|
7871
|
+
maxHeight: contentMaxHeight
|
|
7872
|
+
};
|
|
7873
|
+
if (shouldOpenBelow) {
|
|
7874
|
+
nextStyle.top = rect.bottom + sideOffset;
|
|
7875
|
+
nextStyle.bottom = void 0;
|
|
7876
|
+
} else {
|
|
7877
|
+
nextStyle.bottom = window.innerHeight - rect.top + sideOffset;
|
|
7878
|
+
nextStyle.top = void 0;
|
|
7879
|
+
}
|
|
7880
|
+
setContentStyle(
|
|
7881
|
+
(previousStyle) => areStylesEqual2(previousStyle, nextStyle) ? previousStyle : nextStyle
|
|
7882
|
+
);
|
|
7883
|
+
}, []);
|
|
7884
|
+
const scheduleUpdatePosition = React47.useCallback(() => {
|
|
7885
|
+
if (rafRef.current) {
|
|
7886
|
+
cancelAnimationFrame(rafRef.current);
|
|
7887
|
+
}
|
|
7888
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
7889
|
+
rafRef.current = null;
|
|
7890
|
+
updatePosition();
|
|
7891
|
+
});
|
|
7892
|
+
}, [updatePosition]);
|
|
7893
|
+
const openDropdown = React47.useCallback(() => {
|
|
7894
|
+
if (disabled) return;
|
|
7895
|
+
if (!open) {
|
|
7896
|
+
setInputValue("");
|
|
7897
|
+
setOpen(true);
|
|
7898
|
+
}
|
|
7899
|
+
requestAnimationFrame(() => {
|
|
7900
|
+
var _a;
|
|
7901
|
+
(_a = inputRef.current) == null ? void 0 : _a.focus({ preventScroll: true });
|
|
7902
|
+
});
|
|
7903
|
+
}, [disabled, open]);
|
|
7904
|
+
React47.useLayoutEffect(() => {
|
|
7905
|
+
if (!open) {
|
|
7906
|
+
setContentStyle(void 0);
|
|
7907
|
+
}
|
|
7908
|
+
}, [open]);
|
|
7909
|
+
React47.useLayoutEffect(() => {
|
|
7910
|
+
var _a, _b;
|
|
7911
|
+
if (!open) return;
|
|
7912
|
+
updatePosition();
|
|
7913
|
+
scheduleUpdatePosition();
|
|
7914
|
+
const handleResizeOrScroll = () => {
|
|
7915
|
+
scheduleUpdatePosition();
|
|
7916
|
+
};
|
|
7917
|
+
window.addEventListener("resize", handleResizeOrScroll);
|
|
7918
|
+
window.addEventListener("scroll", handleResizeOrScroll, true);
|
|
7919
|
+
(_a = window.visualViewport) == null ? void 0 : _a.addEventListener("resize", handleResizeOrScroll);
|
|
7920
|
+
(_b = window.visualViewport) == null ? void 0 : _b.addEventListener("scroll", handleResizeOrScroll);
|
|
7921
|
+
return () => {
|
|
7922
|
+
var _a2, _b2;
|
|
7923
|
+
window.removeEventListener("resize", handleResizeOrScroll);
|
|
7924
|
+
window.removeEventListener("scroll", handleResizeOrScroll, true);
|
|
7925
|
+
(_a2 = window.visualViewport) == null ? void 0 : _a2.removeEventListener(
|
|
7926
|
+
"resize",
|
|
7927
|
+
handleResizeOrScroll
|
|
7928
|
+
);
|
|
7929
|
+
(_b2 = window.visualViewport) == null ? void 0 : _b2.removeEventListener(
|
|
7930
|
+
"scroll",
|
|
7931
|
+
handleResizeOrScroll
|
|
7932
|
+
);
|
|
7933
|
+
if (rafRef.current) {
|
|
7934
|
+
cancelAnimationFrame(rafRef.current);
|
|
7935
|
+
rafRef.current = null;
|
|
7936
|
+
}
|
|
7937
|
+
};
|
|
7938
|
+
}, [open, scheduleUpdatePosition, updatePosition]);
|
|
7748
7939
|
React47.useEffect(() => {
|
|
7749
7940
|
if (!open) return;
|
|
7750
7941
|
const firstEnabledIndex = filteredItems.findIndex((item) => !item.disabled);
|
|
7751
|
-
setActiveIndex(
|
|
7942
|
+
setActiveIndex(
|
|
7943
|
+
(previousIndex) => previousIndex === firstEnabledIndex ? previousIndex : firstEnabledIndex
|
|
7944
|
+
);
|
|
7752
7945
|
}, [filteredItems, open]);
|
|
7753
7946
|
React47.useEffect(() => {
|
|
7754
7947
|
if (!open) return;
|
|
7755
7948
|
const handlePointerDown = (event) => {
|
|
7756
|
-
var _a;
|
|
7949
|
+
var _a, _b;
|
|
7757
7950
|
const target = event.target;
|
|
7758
|
-
if (target && ((_a = rootRef.current) == null ? void 0 : _a.contains(target))) {
|
|
7951
|
+
if (target && (((_a = rootRef.current) == null ? void 0 : _a.contains(target)) || ((_b = contentRef.current) == null ? void 0 : _b.contains(target)))) {
|
|
7759
7952
|
return;
|
|
7760
7953
|
}
|
|
7761
7954
|
setOpen(false);
|
|
@@ -7781,6 +7974,99 @@ function SearchableSelectBase({
|
|
|
7781
7974
|
},
|
|
7782
7975
|
[isControlled, onValueChange]
|
|
7783
7976
|
);
|
|
7977
|
+
const dropdown = open && mounted && contentStyle ? createPortal2(
|
|
7978
|
+
/* @__PURE__ */ jsx25(
|
|
7979
|
+
"div",
|
|
7980
|
+
{
|
|
7981
|
+
ref: contentRef,
|
|
7982
|
+
className: cn(
|
|
7983
|
+
"overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground shadow-xl",
|
|
7984
|
+
contentClassName
|
|
7985
|
+
),
|
|
7986
|
+
style: __spreadProps(__spreadValues({}, contentStyle), {
|
|
7987
|
+
maxHeight: contentStyle.maxHeight
|
|
7988
|
+
}),
|
|
7989
|
+
children: /* @__PURE__ */ jsx25(
|
|
7990
|
+
"div",
|
|
7991
|
+
{
|
|
7992
|
+
id: listboxId,
|
|
7993
|
+
role: "listbox",
|
|
7994
|
+
className: "max-h-full overflow-x-hidden overflow-y-auto overscroll-contain p-1 scrollbar-gutter-stable",
|
|
7995
|
+
style: {
|
|
7996
|
+
maxHeight: contentStyle.maxHeight,
|
|
7997
|
+
overflowX: "hidden",
|
|
7998
|
+
overflowY: "auto",
|
|
7999
|
+
overscrollBehavior: "contain",
|
|
8000
|
+
scrollbarGutter: "stable",
|
|
8001
|
+
WebkitOverflowScrolling: "touch"
|
|
8002
|
+
},
|
|
8003
|
+
onWheel: (event) => {
|
|
8004
|
+
event.stopPropagation();
|
|
8005
|
+
},
|
|
8006
|
+
onTouchMove: (event) => {
|
|
8007
|
+
event.stopPropagation();
|
|
8008
|
+
},
|
|
8009
|
+
children: filteredItems.length === 0 ? /* @__PURE__ */ jsx25(
|
|
8010
|
+
"div",
|
|
8011
|
+
{
|
|
8012
|
+
className: cn(
|
|
8013
|
+
"px-3 py-6 text-center text-muted-foreground",
|
|
8014
|
+
sizeClasses.message
|
|
8015
|
+
),
|
|
8016
|
+
children: emptyText
|
|
8017
|
+
}
|
|
8018
|
+
) : filteredItems.map((item, index) => {
|
|
8019
|
+
const isSelected = item.value === currentValue;
|
|
8020
|
+
const isActive = index === activeIndex;
|
|
8021
|
+
return /* @__PURE__ */ jsxs15(
|
|
8022
|
+
"div",
|
|
8023
|
+
{
|
|
8024
|
+
id: `${listboxId}-option-${index}`,
|
|
8025
|
+
role: "option",
|
|
8026
|
+
"aria-selected": isSelected,
|
|
8027
|
+
"aria-disabled": item.disabled,
|
|
8028
|
+
tabIndex: -1,
|
|
8029
|
+
onMouseMove: () => {
|
|
8030
|
+
if (!item.disabled) {
|
|
8031
|
+
setActiveIndex(index);
|
|
8032
|
+
}
|
|
8033
|
+
},
|
|
8034
|
+
onPointerDown: (event) => {
|
|
8035
|
+
event.preventDefault();
|
|
8036
|
+
event.stopPropagation();
|
|
8037
|
+
if (!item.disabled) {
|
|
8038
|
+
selectItem(item);
|
|
8039
|
+
}
|
|
8040
|
+
},
|
|
8041
|
+
className: cn(
|
|
8042
|
+
"relative flex w-full select-none items-center gap-2 rounded-lg px-3 text-left outline-none transition",
|
|
8043
|
+
sizeClasses.selectItem,
|
|
8044
|
+
item.disabled ? "pointer-events-none opacity-50" : "cursor-pointer",
|
|
8045
|
+
isActive && !item.disabled && "bg-accent text-accent-foreground",
|
|
8046
|
+
!isActive && !item.disabled && "hover:bg-accent/70 hover:text-accent-foreground",
|
|
8047
|
+
isSelected && "font-medium",
|
|
8048
|
+
itemClassName
|
|
8049
|
+
),
|
|
8050
|
+
children: [
|
|
8051
|
+
/* @__PURE__ */ jsx25("span", { className: "min-w-0 flex-1 truncate", children: item.label }),
|
|
8052
|
+
isSelected ? /* @__PURE__ */ jsx25(
|
|
8053
|
+
CheckIcon5,
|
|
8054
|
+
{
|
|
8055
|
+
"aria-hidden": "true",
|
|
8056
|
+
className: "h-4 w-4 shrink-0 text-primary"
|
|
8057
|
+
}
|
|
8058
|
+
) : null
|
|
8059
|
+
]
|
|
8060
|
+
},
|
|
8061
|
+
item.value
|
|
8062
|
+
);
|
|
8063
|
+
})
|
|
8064
|
+
}
|
|
8065
|
+
)
|
|
8066
|
+
}
|
|
8067
|
+
),
|
|
8068
|
+
document.body
|
|
8069
|
+
) : null;
|
|
7784
8070
|
return /* @__PURE__ */ jsxs15("div", { ref: rootRef, className: "relative w-full", children: [
|
|
7785
8071
|
name ? /* @__PURE__ */ jsx25(
|
|
7786
8072
|
"input",
|
|
@@ -7803,13 +8089,10 @@ function SearchableSelectBase({
|
|
|
7803
8089
|
disabled && "cursor-not-allowed opacity-50",
|
|
7804
8090
|
triggerClassName
|
|
7805
8091
|
) : triggerClassName,
|
|
7806
|
-
onPointerDown: () => {
|
|
7807
|
-
if (disabled) return;
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
var _a;
|
|
7811
|
-
(_a = inputRef.current) == null ? void 0 : _a.focus({ preventScroll: true });
|
|
7812
|
-
});
|
|
8092
|
+
onPointerDown: (event) => {
|
|
8093
|
+
if (disabled || event.button !== 0 || event.ctrlKey) return;
|
|
8094
|
+
event.preventDefault();
|
|
8095
|
+
openDropdown();
|
|
7813
8096
|
},
|
|
7814
8097
|
children: [
|
|
7815
8098
|
/* @__PURE__ */ jsx25(
|
|
@@ -7828,11 +8111,7 @@ function SearchableSelectBase({
|
|
|
7828
8111
|
spellCheck: false,
|
|
7829
8112
|
disabled,
|
|
7830
8113
|
onFocus: () => {
|
|
7831
|
-
|
|
7832
|
-
requestAnimationFrame(() => {
|
|
7833
|
-
var _a;
|
|
7834
|
-
(_a = inputRef.current) == null ? void 0 : _a.select();
|
|
7835
|
-
});
|
|
8114
|
+
openDropdown();
|
|
7836
8115
|
},
|
|
7837
8116
|
onChange: (event) => {
|
|
7838
8117
|
setInputValue(event.target.value);
|
|
@@ -7915,86 +8194,7 @@ function SearchableSelectBase({
|
|
|
7915
8194
|
]
|
|
7916
8195
|
}
|
|
7917
8196
|
),
|
|
7918
|
-
|
|
7919
|
-
"div",
|
|
7920
|
-
{
|
|
7921
|
-
className: cn(
|
|
7922
|
-
"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",
|
|
7923
|
-
!open && "pointer-events-none invisible opacity-0",
|
|
7924
|
-
open && "visible opacity-100",
|
|
7925
|
-
contentClassName
|
|
7926
|
-
),
|
|
7927
|
-
children: /* @__PURE__ */ jsx25(
|
|
7928
|
-
"div",
|
|
7929
|
-
{
|
|
7930
|
-
id: listboxId,
|
|
7931
|
-
role: "listbox",
|
|
7932
|
-
className: "max-h-72 overflow-y-auto overscroll-contain p-1 [scrollbar-gutter:stable]",
|
|
7933
|
-
onWheelCapture: (event) => {
|
|
7934
|
-
event.stopPropagation();
|
|
7935
|
-
},
|
|
7936
|
-
onTouchMoveCapture: (event) => {
|
|
7937
|
-
event.stopPropagation();
|
|
7938
|
-
},
|
|
7939
|
-
children: filteredItems.length === 0 ? /* @__PURE__ */ jsx25(
|
|
7940
|
-
"div",
|
|
7941
|
-
{
|
|
7942
|
-
className: cn(
|
|
7943
|
-
"px-3 py-6 text-center text-muted-foreground",
|
|
7944
|
-
sizeClasses.message
|
|
7945
|
-
),
|
|
7946
|
-
children: emptyText
|
|
7947
|
-
}
|
|
7948
|
-
) : filteredItems.map((item, index) => {
|
|
7949
|
-
const isSelected = item.value === currentValue;
|
|
7950
|
-
const isActive = index === activeIndex;
|
|
7951
|
-
return /* @__PURE__ */ jsxs15(
|
|
7952
|
-
"div",
|
|
7953
|
-
{
|
|
7954
|
-
id: `${listboxId}-option-${index}`,
|
|
7955
|
-
role: "option",
|
|
7956
|
-
"aria-selected": isSelected,
|
|
7957
|
-
"aria-disabled": item.disabled,
|
|
7958
|
-
tabIndex: -1,
|
|
7959
|
-
onMouseMove: () => {
|
|
7960
|
-
if (!item.disabled) {
|
|
7961
|
-
setActiveIndex(index);
|
|
7962
|
-
}
|
|
7963
|
-
},
|
|
7964
|
-
onPointerDown: (event) => {
|
|
7965
|
-
event.preventDefault();
|
|
7966
|
-
event.stopPropagation();
|
|
7967
|
-
if (!item.disabled) {
|
|
7968
|
-
selectItem(item);
|
|
7969
|
-
}
|
|
7970
|
-
},
|
|
7971
|
-
className: cn(
|
|
7972
|
-
"relative flex w-full select-none items-center gap-2 rounded-lg px-3 text-left outline-none transition",
|
|
7973
|
-
sizeClasses.selectItem,
|
|
7974
|
-
item.disabled ? "pointer-events-none opacity-50" : "cursor-pointer",
|
|
7975
|
-
isActive && !item.disabled && "bg-accent text-accent-foreground",
|
|
7976
|
-
!isActive && !item.disabled && "hover:bg-accent/70 hover:text-accent-foreground",
|
|
7977
|
-
isSelected && "font-medium",
|
|
7978
|
-
itemClassName
|
|
7979
|
-
),
|
|
7980
|
-
children: [
|
|
7981
|
-
/* @__PURE__ */ jsx25("span", { className: "min-w-0 flex-1 truncate", children: item.label }),
|
|
7982
|
-
isSelected ? /* @__PURE__ */ jsx25(
|
|
7983
|
-
CheckIcon5,
|
|
7984
|
-
{
|
|
7985
|
-
"aria-hidden": "true",
|
|
7986
|
-
className: "h-4 w-4 shrink-0 text-primary"
|
|
7987
|
-
}
|
|
7988
|
-
) : null
|
|
7989
|
-
]
|
|
7990
|
-
},
|
|
7991
|
-
item.value
|
|
7992
|
-
);
|
|
7993
|
-
})
|
|
7994
|
-
}
|
|
7995
|
-
)
|
|
7996
|
-
}
|
|
7997
|
-
)
|
|
8197
|
+
dropdown
|
|
7998
8198
|
] });
|
|
7999
8199
|
}
|
|
8000
8200
|
var SearchableSelect = React47.memo(
|
|
@@ -8009,7 +8209,7 @@ var FormSelect = ({
|
|
|
8009
8209
|
rules,
|
|
8010
8210
|
shouldUnregister,
|
|
8011
8211
|
defaultValue,
|
|
8012
|
-
placeholder = "
|
|
8212
|
+
placeholder = "Select an option",
|
|
8013
8213
|
label,
|
|
8014
8214
|
requiredLabel,
|
|
8015
8215
|
className,
|
|
@@ -8025,7 +8225,6 @@ var FormSelect = ({
|
|
|
8025
8225
|
getOptionLabel = getDefaultOptionLabel,
|
|
8026
8226
|
getOptionDisabled,
|
|
8027
8227
|
getOptionData,
|
|
8028
|
-
children,
|
|
8029
8228
|
onChange,
|
|
8030
8229
|
onChangeItem,
|
|
8031
8230
|
disabled,
|
|
@@ -8034,17 +8233,14 @@ var FormSelect = ({
|
|
|
8034
8233
|
variant = "outline",
|
|
8035
8234
|
invalid,
|
|
8036
8235
|
searchable = false,
|
|
8037
|
-
searchPlaceholder = "
|
|
8038
|
-
emptyText = "No
|
|
8039
|
-
classNameDefault = true
|
|
8040
|
-
position
|
|
8236
|
+
searchPlaceholder = "Search\u2026",
|
|
8237
|
+
emptyText = "No results",
|
|
8238
|
+
classNameDefault = true
|
|
8041
8239
|
}) => {
|
|
8042
8240
|
const form = useFormContext4();
|
|
8043
8241
|
const controllerControl = control != null ? control : form == null ? void 0 : form.control;
|
|
8044
8242
|
const sizeClasses = getFormSizeClasses(size, customSize);
|
|
8045
8243
|
const triggerSizeClass = getFormControlSizeClass(variant, sizeClasses);
|
|
8046
|
-
const contentBase = "z-50 rounded-xl border border-border bg-popover text-popover-foreground shadow-xl outline-none";
|
|
8047
|
-
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]";
|
|
8048
8244
|
const normalizedOptions = React48.useMemo(() => {
|
|
8049
8245
|
if (options) return options;
|
|
8050
8246
|
return (items != null ? items : []).map((item) => {
|
|
@@ -8085,15 +8281,11 @@ var FormSelect = ({
|
|
|
8085
8281
|
onChange == null ? void 0 : onChange(value);
|
|
8086
8282
|
onChangeItem == null ? void 0 : onChangeItem((_a2 = nextOption == null ? void 0 : nextOption.data) != null ? _a2 : null);
|
|
8087
8283
|
};
|
|
8088
|
-
return /* @__PURE__ */ jsxs16(FormItem, { children: [
|
|
8284
|
+
return /* @__PURE__ */ jsxs16(FormItem, { className: itemClassName, children: [
|
|
8089
8285
|
label ? /* @__PURE__ */ jsxs16(
|
|
8090
8286
|
FormLabel,
|
|
8091
8287
|
{
|
|
8092
|
-
className: cn(
|
|
8093
|
-
"flex items-center gap-0.5",
|
|
8094
|
-
sizeClasses.label,
|
|
8095
|
-
labelClassName
|
|
8096
|
-
),
|
|
8288
|
+
className: cn("flex items-center gap-0.5", labelClassName),
|
|
8097
8289
|
children: [
|
|
8098
8290
|
/* @__PURE__ */ jsx26("span", { children: label }),
|
|
8099
8291
|
requiredLabel ? /* @__PURE__ */ jsx26(
|
|
@@ -8109,7 +8301,7 @@ var FormSelect = ({
|
|
|
8109
8301
|
]
|
|
8110
8302
|
}
|
|
8111
8303
|
) : null,
|
|
8112
|
-
searchable ? /* @__PURE__ */ jsx26(
|
|
8304
|
+
searchable ? /* @__PURE__ */ jsx26(FormControl, { children: /* @__PURE__ */ jsx26(
|
|
8113
8305
|
SearchableSelect,
|
|
8114
8306
|
{
|
|
8115
8307
|
items: normalizedOptions,
|
|
@@ -8132,74 +8324,34 @@ var FormSelect = ({
|
|
|
8132
8324
|
var _a2;
|
|
8133
8325
|
field.onChange(value);
|
|
8134
8326
|
onChange == null ? void 0 : onChange(value);
|
|
8135
|
-
onChangeItem == null ? void 0 : onChangeItem(
|
|
8327
|
+
onChangeItem == null ? void 0 : onChangeItem(
|
|
8328
|
+
(_a2 = option == null ? void 0 : option.data) != null ? _a2 : null
|
|
8329
|
+
);
|
|
8136
8330
|
field.onBlur();
|
|
8137
8331
|
}
|
|
8138
8332
|
}
|
|
8139
|
-
) : /* @__PURE__ */
|
|
8333
|
+
) }) : /* @__PURE__ */ jsx26(
|
|
8140
8334
|
Select2,
|
|
8141
8335
|
{
|
|
8142
8336
|
value: (_b = field.value) != null ? _b : "",
|
|
8143
8337
|
onValueChange: handleValueChange,
|
|
8144
8338
|
onOpenChange: (nextOpen) => {
|
|
8145
|
-
if (!nextOpen)
|
|
8146
|
-
field.onBlur();
|
|
8147
|
-
}
|
|
8339
|
+
if (!nextOpen) field.onBlur();
|
|
8148
8340
|
},
|
|
8149
8341
|
disabled,
|
|
8150
|
-
children:
|
|
8151
|
-
|
|
8152
|
-
|
|
8153
|
-
|
|
8154
|
-
|
|
8155
|
-
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
|
|
8163
|
-
) }),
|
|
8164
|
-
/* @__PURE__ */ jsx26(
|
|
8165
|
-
SelectContent,
|
|
8166
|
-
{
|
|
8167
|
-
position,
|
|
8168
|
-
sideOffset: 6,
|
|
8169
|
-
className: cn(
|
|
8170
|
-
contentBase,
|
|
8171
|
-
contentViewport,
|
|
8172
|
-
"w-(--radix-select-trigger-width) min-w-(--radix-select-trigger-width) overflow-hidden!",
|
|
8173
|
-
contentClassName
|
|
8174
|
-
),
|
|
8175
|
-
onWheelCapture: (event) => {
|
|
8176
|
-
event.stopPropagation();
|
|
8177
|
-
},
|
|
8178
|
-
onTouchMoveCapture: (event) => {
|
|
8179
|
-
event.stopPropagation();
|
|
8180
|
-
},
|
|
8181
|
-
children: children ? children : normalizedOptions.length > 0 ? normalizedOptions.map((option) => /* @__PURE__ */ jsx26(
|
|
8182
|
-
SelectItem,
|
|
8183
|
-
{
|
|
8184
|
-
value: option.value,
|
|
8185
|
-
disabled: option.disabled,
|
|
8186
|
-
className: cn(sizeClasses.selectItem, itemClassName),
|
|
8187
|
-
children: option.label
|
|
8188
|
-
},
|
|
8189
|
-
option.value
|
|
8190
|
-
)) : /* @__PURE__ */ jsx26(
|
|
8191
|
-
"div",
|
|
8192
|
-
{
|
|
8193
|
-
className: cn(
|
|
8194
|
-
"px-3 py-2 text-muted-foreground",
|
|
8195
|
-
sizeClasses.message
|
|
8196
|
-
),
|
|
8197
|
-
children: emptyText
|
|
8198
|
-
}
|
|
8199
|
-
)
|
|
8200
|
-
}
|
|
8201
|
-
)
|
|
8202
|
-
]
|
|
8342
|
+
children: /* @__PURE__ */ jsx26(FormControl, { children: /* @__PURE__ */ jsx26(
|
|
8343
|
+
SelectTrigger,
|
|
8344
|
+
{
|
|
8345
|
+
className: classNameDefault ? cn(
|
|
8346
|
+
formControlBase,
|
|
8347
|
+
formInputVariants[variant],
|
|
8348
|
+
triggerSizeClass,
|
|
8349
|
+
hasError && formControlErrorClass,
|
|
8350
|
+
className
|
|
8351
|
+
) : className,
|
|
8352
|
+
children: /* @__PURE__ */ jsx26(SelectValue, { placeholder })
|
|
8353
|
+
}
|
|
8354
|
+
) })
|
|
8203
8355
|
}
|
|
8204
8356
|
),
|
|
8205
8357
|
fieldError ? /* @__PURE__ */ jsx26(
|
|
@@ -9967,7 +10119,7 @@ import { Asterisk as Asterisk5 } from "lucide-react";
|
|
|
9967
10119
|
import { jsx as jsx54, jsxs as jsxs27 } from "react/jsx-runtime";
|
|
9968
10120
|
function UiSelect({
|
|
9969
10121
|
label,
|
|
9970
|
-
placeholder,
|
|
10122
|
+
placeholder = "Select an option",
|
|
9971
10123
|
value,
|
|
9972
10124
|
defaultValue,
|
|
9973
10125
|
onChange,
|
|
@@ -9985,7 +10137,6 @@ function UiSelect({
|
|
|
9985
10137
|
size = "md",
|
|
9986
10138
|
customSize,
|
|
9987
10139
|
variant = "outline",
|
|
9988
|
-
classNameDefault = true,
|
|
9989
10140
|
errorMessage,
|
|
9990
10141
|
htmlFormItemId,
|
|
9991
10142
|
position
|
|
@@ -9995,20 +10146,16 @@ function UiSelect({
|
|
|
9995
10146
|
const messageId = `${triggerId}-message`;
|
|
9996
10147
|
const hasError = Boolean(errorMessage);
|
|
9997
10148
|
const sizeClasses = getFormSizeClasses(size, customSize);
|
|
9998
|
-
|
|
9999
|
-
const contentBase = "z-50 rounded-xl border border-border bg-popover text-popover-foreground shadow-xl outline-none";
|
|
10000
|
-
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]";
|
|
10001
|
-
return /* @__PURE__ */ jsxs27("div", { className: cn("w-full space-y-2", selectClassName), children: [
|
|
10149
|
+
return /* @__PURE__ */ jsxs27("div", { className: cn("w-full space-y-0.5", selectClassName), children: [
|
|
10002
10150
|
label ? /* @__PURE__ */ jsxs27(
|
|
10003
10151
|
Label3,
|
|
10004
10152
|
{
|
|
10153
|
+
htmlFor: triggerId,
|
|
10005
10154
|
className: cn(
|
|
10006
|
-
"
|
|
10007
|
-
sizeClasses.label,
|
|
10155
|
+
"flex items-center gap-0.5 text-sm font-medium -mt-0.75 -pt-1.5",
|
|
10008
10156
|
hasError && "text-destructive",
|
|
10009
10157
|
labelClassName
|
|
10010
10158
|
),
|
|
10011
|
-
htmlFor: triggerId,
|
|
10012
10159
|
children: [
|
|
10013
10160
|
/* @__PURE__ */ jsx54("span", { children: label }),
|
|
10014
10161
|
requiredLabel ? /* @__PURE__ */ jsx54(
|
|
@@ -10031,6 +10178,10 @@ function UiSelect({
|
|
|
10031
10178
|
defaultValue,
|
|
10032
10179
|
onValueChange: onChange,
|
|
10033
10180
|
disabled,
|
|
10181
|
+
size,
|
|
10182
|
+
customSize,
|
|
10183
|
+
variant,
|
|
10184
|
+
invalid: hasError,
|
|
10034
10185
|
children: [
|
|
10035
10186
|
/* @__PURE__ */ jsx54(
|
|
10036
10187
|
SelectTrigger,
|
|
@@ -10038,13 +10189,7 @@ function UiSelect({
|
|
|
10038
10189
|
id: triggerId,
|
|
10039
10190
|
"aria-invalid": hasError || void 0,
|
|
10040
10191
|
"aria-describedby": errorMessage ? messageId : void 0,
|
|
10041
|
-
className
|
|
10042
|
-
formControlBase,
|
|
10043
|
-
formInputVariants[variant],
|
|
10044
|
-
triggerSizeClass,
|
|
10045
|
-
hasError && formControlErrorClass,
|
|
10046
|
-
className
|
|
10047
|
-
) : className,
|
|
10192
|
+
className,
|
|
10048
10193
|
children: /* @__PURE__ */ jsx54(SelectValue, { placeholder })
|
|
10049
10194
|
}
|
|
10050
10195
|
),
|
|
@@ -10054,17 +10199,11 @@ function UiSelect({
|
|
|
10054
10199
|
position,
|
|
10055
10200
|
sideOffset: 6,
|
|
10056
10201
|
className: cn(
|
|
10057
|
-
|
|
10058
|
-
contentViewport,
|
|
10059
|
-
"w-(--radix-select-trigger-width) min-w-(--radix-select-trigger-width) overflow-hidden!",
|
|
10202
|
+
"z-50 overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground shadow-xl outline-none",
|
|
10060
10203
|
contentClassName
|
|
10061
10204
|
),
|
|
10062
|
-
onWheelCapture: (event) =>
|
|
10063
|
-
|
|
10064
|
-
},
|
|
10065
|
-
onTouchMoveCapture: (event) => {
|
|
10066
|
-
event.stopPropagation();
|
|
10067
|
-
},
|
|
10205
|
+
onWheelCapture: (event) => event.stopPropagation(),
|
|
10206
|
+
onTouchMoveCapture: (event) => event.stopPropagation(),
|
|
10068
10207
|
children: children != null ? children : items == null ? void 0 : items.map((item) => /* @__PURE__ */ jsx54(
|
|
10069
10208
|
SelectItem,
|
|
10070
10209
|
{
|