@vesture/react 0.2.1 → 0.2.3
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.css +277 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +70 -2
- package/dist/index.js +589 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2620,6 +2620,592 @@ function DateRangePicker({
|
|
|
2620
2620
|
);
|
|
2621
2621
|
}
|
|
2622
2622
|
|
|
2623
|
+
// src/components/NumberInput/NumberInput.tsx
|
|
2624
|
+
import { forwardRef as forwardRef14, useEffect as useEffect5, useRef as useRef6, useState as useState12 } from "react";
|
|
2625
|
+
import { useMergeRefs as useMergeRefs5 } from "@floating-ui/react";
|
|
2626
|
+
|
|
2627
|
+
// src/components/NumberInput/NumberInput.css.ts
|
|
2628
|
+
var input2 = "NumberInput_input__1vx30yr1";
|
|
2629
|
+
var stepButton = "NumberInput_stepButton__1vx30yr3";
|
|
2630
|
+
var stepperGroup = "NumberInput_stepperGroup__1vx30yr2";
|
|
2631
|
+
var wrapper8 = "NumberInput_wrapper__1vx30yr0";
|
|
2632
|
+
|
|
2633
|
+
// src/components/NumberInput/NumberInput.tsx
|
|
2634
|
+
import { jsx as jsx38, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
2635
|
+
function clamp(value, min, max) {
|
|
2636
|
+
let result = value;
|
|
2637
|
+
if (min !== void 0) result = Math.max(min, result);
|
|
2638
|
+
if (max !== void 0) result = Math.min(max, result);
|
|
2639
|
+
return result;
|
|
2640
|
+
}
|
|
2641
|
+
function formatValue(value) {
|
|
2642
|
+
return value === null ? "" : String(value);
|
|
2643
|
+
}
|
|
2644
|
+
var NumberInput = forwardRef14(function NumberInput2({
|
|
2645
|
+
value: controlledValue,
|
|
2646
|
+
defaultValue = null,
|
|
2647
|
+
onChange,
|
|
2648
|
+
min,
|
|
2649
|
+
max,
|
|
2650
|
+
step = 1,
|
|
2651
|
+
disabled = false,
|
|
2652
|
+
invalid,
|
|
2653
|
+
placeholder,
|
|
2654
|
+
id,
|
|
2655
|
+
name,
|
|
2656
|
+
className,
|
|
2657
|
+
style,
|
|
2658
|
+
...rest
|
|
2659
|
+
}, ref) {
|
|
2660
|
+
const [uncontrolledValue, setUncontrolledValue] = useState12(defaultValue);
|
|
2661
|
+
const value = controlledValue !== void 0 ? controlledValue : uncontrolledValue;
|
|
2662
|
+
const setValue = (next) => {
|
|
2663
|
+
if (controlledValue === void 0) {
|
|
2664
|
+
setUncontrolledValue(next);
|
|
2665
|
+
}
|
|
2666
|
+
onChange?.(next);
|
|
2667
|
+
};
|
|
2668
|
+
const [inputText, setInputText] = useState12(() => formatValue(value));
|
|
2669
|
+
useEffect5(() => {
|
|
2670
|
+
setInputText(formatValue(value));
|
|
2671
|
+
}, [value]);
|
|
2672
|
+
const inputRef = useRef6(null);
|
|
2673
|
+
const mergedRef = useMergeRefs5([inputRef, ref]);
|
|
2674
|
+
const commitTypedValue = () => {
|
|
2675
|
+
const trimmed = inputText.trim();
|
|
2676
|
+
if (!trimmed) {
|
|
2677
|
+
if (value !== null) setValue(null);
|
|
2678
|
+
return;
|
|
2679
|
+
}
|
|
2680
|
+
const parsed = Number(trimmed);
|
|
2681
|
+
if (Number.isNaN(parsed)) {
|
|
2682
|
+
setInputText(formatValue(value));
|
|
2683
|
+
return;
|
|
2684
|
+
}
|
|
2685
|
+
const clamped = clamp(parsed, min, max);
|
|
2686
|
+
setValue(clamped);
|
|
2687
|
+
setInputText(formatValue(clamped));
|
|
2688
|
+
};
|
|
2689
|
+
const step2 = (direction2) => {
|
|
2690
|
+
if (disabled) return;
|
|
2691
|
+
const base2 = value ?? min ?? 0;
|
|
2692
|
+
const next = clamp(base2 + direction2 * step, min, max);
|
|
2693
|
+
setValue(next);
|
|
2694
|
+
setInputText(formatValue(next));
|
|
2695
|
+
inputRef.current?.focus();
|
|
2696
|
+
};
|
|
2697
|
+
const handleKeyDown = (event) => {
|
|
2698
|
+
if (event.key === "Enter") {
|
|
2699
|
+
event.preventDefault();
|
|
2700
|
+
commitTypedValue();
|
|
2701
|
+
return;
|
|
2702
|
+
}
|
|
2703
|
+
if (event.key === "ArrowUp") {
|
|
2704
|
+
event.preventDefault();
|
|
2705
|
+
step2(1);
|
|
2706
|
+
return;
|
|
2707
|
+
}
|
|
2708
|
+
if (event.key === "ArrowDown") {
|
|
2709
|
+
event.preventDefault();
|
|
2710
|
+
step2(-1);
|
|
2711
|
+
return;
|
|
2712
|
+
}
|
|
2713
|
+
if (event.key === "Home" && min !== void 0) {
|
|
2714
|
+
event.preventDefault();
|
|
2715
|
+
setValue(min);
|
|
2716
|
+
setInputText(formatValue(min));
|
|
2717
|
+
return;
|
|
2718
|
+
}
|
|
2719
|
+
if (event.key === "End" && max !== void 0) {
|
|
2720
|
+
event.preventDefault();
|
|
2721
|
+
setValue(max);
|
|
2722
|
+
setInputText(formatValue(max));
|
|
2723
|
+
}
|
|
2724
|
+
};
|
|
2725
|
+
const handleBlur = (_event) => {
|
|
2726
|
+
commitTypedValue();
|
|
2727
|
+
};
|
|
2728
|
+
const classes = [wrapper8, className].filter(Boolean).join(" ");
|
|
2729
|
+
return /* @__PURE__ */ jsxs21("span", { className: classes, style, "data-disabled": disabled || void 0, children: [
|
|
2730
|
+
/* @__PURE__ */ jsx38(
|
|
2731
|
+
"input",
|
|
2732
|
+
{
|
|
2733
|
+
ref: mergedRef,
|
|
2734
|
+
id,
|
|
2735
|
+
name,
|
|
2736
|
+
type: "text",
|
|
2737
|
+
inputMode: "decimal",
|
|
2738
|
+
className: input2,
|
|
2739
|
+
value: inputText,
|
|
2740
|
+
placeholder,
|
|
2741
|
+
disabled,
|
|
2742
|
+
role: "spinbutton",
|
|
2743
|
+
"aria-valuenow": value ?? void 0,
|
|
2744
|
+
"aria-valuemin": min,
|
|
2745
|
+
"aria-valuemax": max,
|
|
2746
|
+
"aria-invalid": invalid || void 0,
|
|
2747
|
+
onChange: (e) => setInputText(e.target.value),
|
|
2748
|
+
onBlur: handleBlur,
|
|
2749
|
+
onKeyDown: handleKeyDown,
|
|
2750
|
+
...rest
|
|
2751
|
+
}
|
|
2752
|
+
),
|
|
2753
|
+
/* @__PURE__ */ jsxs21("span", { className: stepperGroup, children: [
|
|
2754
|
+
/* @__PURE__ */ jsx38(
|
|
2755
|
+
"button",
|
|
2756
|
+
{
|
|
2757
|
+
type: "button",
|
|
2758
|
+
tabIndex: -1,
|
|
2759
|
+
className: stepButton,
|
|
2760
|
+
disabled: disabled || max !== void 0 && value !== null && value >= max,
|
|
2761
|
+
"aria-label": "Increment",
|
|
2762
|
+
onClick: () => step2(1),
|
|
2763
|
+
children: /* @__PURE__ */ jsx38("svg", { width: "8", height: "8", viewBox: "0 0 8 8", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx38("path", { d: "M1 5l3-3 3 3", stroke: "currentColor", strokeWidth: "1.3", strokeLinecap: "round", strokeLinejoin: "round" }) })
|
|
2764
|
+
}
|
|
2765
|
+
),
|
|
2766
|
+
/* @__PURE__ */ jsx38(
|
|
2767
|
+
"button",
|
|
2768
|
+
{
|
|
2769
|
+
type: "button",
|
|
2770
|
+
tabIndex: -1,
|
|
2771
|
+
className: stepButton,
|
|
2772
|
+
disabled: disabled || min !== void 0 && value !== null && value <= min,
|
|
2773
|
+
"aria-label": "Decrement",
|
|
2774
|
+
onClick: () => step2(-1),
|
|
2775
|
+
children: /* @__PURE__ */ jsx38("svg", { width: "8", height: "8", viewBox: "0 0 8 8", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx38("path", { d: "M1 3l3 3 3-3", stroke: "currentColor", strokeWidth: "1.3", strokeLinecap: "round", strokeLinejoin: "round" }) })
|
|
2776
|
+
}
|
|
2777
|
+
)
|
|
2778
|
+
] })
|
|
2779
|
+
] });
|
|
2780
|
+
});
|
|
2781
|
+
|
|
2782
|
+
// src/components/Slider/Slider.tsx
|
|
2783
|
+
import { useRef as useRef7, useState as useState13 } from "react";
|
|
2784
|
+
|
|
2785
|
+
// src/components/Slider/Slider.css.ts
|
|
2786
|
+
var range2 = "Slider_range__2gl56i2";
|
|
2787
|
+
var root3 = "Slider_root__2gl56i0";
|
|
2788
|
+
var thumb = "Slider_thumb__2gl56i3";
|
|
2789
|
+
var track3 = "Slider_track__2gl56i1";
|
|
2790
|
+
|
|
2791
|
+
// src/components/Slider/Slider.tsx
|
|
2792
|
+
import { jsx as jsx39, jsxs as jsxs22 } from "react/jsx-runtime";
|
|
2793
|
+
function isRange(value) {
|
|
2794
|
+
return Array.isArray(value);
|
|
2795
|
+
}
|
|
2796
|
+
function clampToStep(raw, min, max, step) {
|
|
2797
|
+
const stepped = Math.round((raw - min) / step) * step + min;
|
|
2798
|
+
return Math.min(max, Math.max(min, Math.round(stepped * 1e6) / 1e6));
|
|
2799
|
+
}
|
|
2800
|
+
function percentOf(value, min, max) {
|
|
2801
|
+
if (max === min) return 0;
|
|
2802
|
+
return (value - min) / (max - min) * 100;
|
|
2803
|
+
}
|
|
2804
|
+
function Slider({
|
|
2805
|
+
value: controlledValue,
|
|
2806
|
+
defaultValue = 0,
|
|
2807
|
+
onChange,
|
|
2808
|
+
min = 0,
|
|
2809
|
+
max = 100,
|
|
2810
|
+
step = 1,
|
|
2811
|
+
disabled = false,
|
|
2812
|
+
id,
|
|
2813
|
+
className,
|
|
2814
|
+
style,
|
|
2815
|
+
formatValue: formatValue2 = (v) => String(v),
|
|
2816
|
+
...rest
|
|
2817
|
+
}) {
|
|
2818
|
+
const ariaLabel = rest["aria-label"];
|
|
2819
|
+
const [uncontrolledValue, setUncontrolledValue] = useState13(defaultValue);
|
|
2820
|
+
const value = controlledValue !== void 0 ? controlledValue : uncontrolledValue;
|
|
2821
|
+
const setValue = (next) => {
|
|
2822
|
+
if (controlledValue === void 0) {
|
|
2823
|
+
setUncontrolledValue(next);
|
|
2824
|
+
}
|
|
2825
|
+
onChange?.(next);
|
|
2826
|
+
};
|
|
2827
|
+
const trackRef = useRef7(null);
|
|
2828
|
+
const thumbRefs = useRef7({ single: null, 0: null, 1: null });
|
|
2829
|
+
const dragThumbIndex = useRef7(null);
|
|
2830
|
+
const isDragging = useRef7(false);
|
|
2831
|
+
const valueFromClientX = (clientX) => {
|
|
2832
|
+
const trackEl = trackRef.current;
|
|
2833
|
+
if (!trackEl) return min;
|
|
2834
|
+
const rect = trackEl.getBoundingClientRect();
|
|
2835
|
+
const ratio = rect.width === 0 ? 0 : (clientX - rect.left) / rect.width;
|
|
2836
|
+
return clampToStep(min + ratio * (max - min), min, max, step);
|
|
2837
|
+
};
|
|
2838
|
+
const setThumbValue = (index, raw) => {
|
|
2839
|
+
if (index === null) {
|
|
2840
|
+
setValue(clampToStep(raw, min, max, step));
|
|
2841
|
+
return;
|
|
2842
|
+
}
|
|
2843
|
+
if (!isRange(value)) return;
|
|
2844
|
+
const [start, end] = value;
|
|
2845
|
+
if (index === 0) {
|
|
2846
|
+
setValue([Math.min(raw, end), end]);
|
|
2847
|
+
} else {
|
|
2848
|
+
setValue([start, Math.max(raw, start)]);
|
|
2849
|
+
}
|
|
2850
|
+
};
|
|
2851
|
+
const handlePointerMove = (event) => {
|
|
2852
|
+
if (!isDragging.current) return;
|
|
2853
|
+
setThumbValue(dragThumbIndex.current, valueFromClientX(event.clientX));
|
|
2854
|
+
};
|
|
2855
|
+
const handlePointerUp = () => {
|
|
2856
|
+
isDragging.current = false;
|
|
2857
|
+
dragThumbIndex.current = null;
|
|
2858
|
+
window.removeEventListener("pointermove", handlePointerMove);
|
|
2859
|
+
window.removeEventListener("pointerup", handlePointerUp);
|
|
2860
|
+
};
|
|
2861
|
+
const startDrag = (index) => (event) => {
|
|
2862
|
+
if (disabled) return;
|
|
2863
|
+
event.preventDefault();
|
|
2864
|
+
thumbRefs.current[index ?? "single"]?.focus();
|
|
2865
|
+
isDragging.current = true;
|
|
2866
|
+
dragThumbIndex.current = index;
|
|
2867
|
+
setThumbValue(index, valueFromClientX(event.clientX));
|
|
2868
|
+
window.addEventListener("pointermove", handlePointerMove);
|
|
2869
|
+
window.addEventListener("pointerup", handlePointerUp);
|
|
2870
|
+
};
|
|
2871
|
+
const handleTrackPointerDown = (event) => {
|
|
2872
|
+
if (disabled) return;
|
|
2873
|
+
if (!isRange(value)) {
|
|
2874
|
+
startDrag(null)(event);
|
|
2875
|
+
return;
|
|
2876
|
+
}
|
|
2877
|
+
const target = valueFromClientX(event.clientX);
|
|
2878
|
+
const [start, end] = value;
|
|
2879
|
+
const nearestIndex = Math.abs(target - start) <= Math.abs(target - end) ? 0 : 1;
|
|
2880
|
+
startDrag(nearestIndex)(event);
|
|
2881
|
+
};
|
|
2882
|
+
const handleThumbKeyDown = (index) => (event) => {
|
|
2883
|
+
if (disabled) return;
|
|
2884
|
+
const current2 = index === null ? value : value[index];
|
|
2885
|
+
let next = null;
|
|
2886
|
+
switch (event.key) {
|
|
2887
|
+
case "ArrowRight":
|
|
2888
|
+
case "ArrowUp":
|
|
2889
|
+
next = clampToStep(current2 + step, min, max, step);
|
|
2890
|
+
break;
|
|
2891
|
+
case "ArrowLeft":
|
|
2892
|
+
case "ArrowDown":
|
|
2893
|
+
next = clampToStep(current2 - step, min, max, step);
|
|
2894
|
+
break;
|
|
2895
|
+
case "Home":
|
|
2896
|
+
next = min;
|
|
2897
|
+
break;
|
|
2898
|
+
case "End":
|
|
2899
|
+
next = max;
|
|
2900
|
+
break;
|
|
2901
|
+
case "PageUp":
|
|
2902
|
+
next = clampToStep(current2 + step * 10, min, max, step);
|
|
2903
|
+
break;
|
|
2904
|
+
case "PageDown":
|
|
2905
|
+
next = clampToStep(current2 - step * 10, min, max, step);
|
|
2906
|
+
break;
|
|
2907
|
+
default:
|
|
2908
|
+
return;
|
|
2909
|
+
}
|
|
2910
|
+
event.preventDefault();
|
|
2911
|
+
setThumbValue(index, next);
|
|
2912
|
+
};
|
|
2913
|
+
const renderThumb = (index, current2, label3) => /* @__PURE__ */ jsx39(
|
|
2914
|
+
"span",
|
|
2915
|
+
{
|
|
2916
|
+
ref: (node) => {
|
|
2917
|
+
thumbRefs.current[index ?? "single"] = node;
|
|
2918
|
+
},
|
|
2919
|
+
role: "slider",
|
|
2920
|
+
tabIndex: disabled ? -1 : 0,
|
|
2921
|
+
"aria-label": label3,
|
|
2922
|
+
"aria-valuemin": min,
|
|
2923
|
+
"aria-valuemax": max,
|
|
2924
|
+
"aria-valuenow": current2,
|
|
2925
|
+
"aria-valuetext": formatValue2(current2),
|
|
2926
|
+
"aria-disabled": disabled || void 0,
|
|
2927
|
+
className: thumb,
|
|
2928
|
+
style: { left: `${percentOf(current2, min, max)}%` },
|
|
2929
|
+
onPointerDown: (event) => {
|
|
2930
|
+
event.stopPropagation();
|
|
2931
|
+
startDrag(index)(event);
|
|
2932
|
+
},
|
|
2933
|
+
onKeyDown: handleThumbKeyDown(index)
|
|
2934
|
+
},
|
|
2935
|
+
index ?? "single"
|
|
2936
|
+
);
|
|
2937
|
+
const classes = [root3, className].filter(Boolean).join(" ");
|
|
2938
|
+
return /* @__PURE__ */ jsx39("span", { id, className: classes, style, "data-disabled": disabled || void 0, children: /* @__PURE__ */ jsxs22("span", { ref: trackRef, className: track3, onPointerDown: handleTrackPointerDown, children: [
|
|
2939
|
+
isRange(value) ? /* @__PURE__ */ jsx39(
|
|
2940
|
+
"span",
|
|
2941
|
+
{
|
|
2942
|
+
className: range2,
|
|
2943
|
+
style: {
|
|
2944
|
+
left: `${percentOf(value[0], min, max)}%`,
|
|
2945
|
+
right: `${100 - percentOf(value[1], min, max)}%`
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
) : /* @__PURE__ */ jsx39("span", { className: range2, style: { left: 0, right: `${100 - percentOf(value, min, max)}%` } }),
|
|
2949
|
+
isRange(value) ? [
|
|
2950
|
+
renderThumb(0, value[0], Array.isArray(ariaLabel) ? ariaLabel[0] : ariaLabel),
|
|
2951
|
+
renderThumb(1, value[1], Array.isArray(ariaLabel) ? ariaLabel[1] : ariaLabel)
|
|
2952
|
+
] : renderThumb(null, value, typeof ariaLabel === "string" ? ariaLabel : void 0)
|
|
2953
|
+
] }) });
|
|
2954
|
+
}
|
|
2955
|
+
|
|
2956
|
+
// src/components/Combobox/Combobox.tsx
|
|
2957
|
+
import { useEffect as useEffect6, useId as useId2, useRef as useRef8, useState as useState14 } from "react";
|
|
2958
|
+
import {
|
|
2959
|
+
FloatingPortal as FloatingPortal7,
|
|
2960
|
+
autoUpdate as autoUpdate6,
|
|
2961
|
+
flip as flip6,
|
|
2962
|
+
offset as offset6,
|
|
2963
|
+
shift as shift6,
|
|
2964
|
+
useDismiss as useDismiss7,
|
|
2965
|
+
useFloating as useFloating7,
|
|
2966
|
+
useInteractions as useInteractions7,
|
|
2967
|
+
useRole as useRole7
|
|
2968
|
+
} from "@floating-ui/react";
|
|
2969
|
+
|
|
2970
|
+
// src/components/Combobox/Combobox.css.ts
|
|
2971
|
+
var chip = "Combobox_chip__26nhic2";
|
|
2972
|
+
var chipRemove = "Combobox_chipRemove__26nhic3";
|
|
2973
|
+
var chipsWrapper = "Combobox_chipsWrapper__26nhic1";
|
|
2974
|
+
var emptyState2 = "Combobox_emptyState__26nhic7";
|
|
2975
|
+
var inputEl = "Combobox_inputEl__26nhic4";
|
|
2976
|
+
var listbox = "Combobox_listbox__26nhic5";
|
|
2977
|
+
var option = "Combobox_option__26nhic6";
|
|
2978
|
+
var wrapper9 = "Combobox_wrapper__26nhic0";
|
|
2979
|
+
|
|
2980
|
+
// src/components/Combobox/Combobox.tsx
|
|
2981
|
+
import { jsx as jsx40, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
2982
|
+
function defaultFilter(options, inputText) {
|
|
2983
|
+
const query = inputText.trim().toLowerCase();
|
|
2984
|
+
if (!query) return options;
|
|
2985
|
+
return options.filter((opt) => opt.label.toLowerCase().includes(query));
|
|
2986
|
+
}
|
|
2987
|
+
function labelFor(options, value) {
|
|
2988
|
+
if (!value) return "";
|
|
2989
|
+
return options.find((opt) => opt.value === value)?.label ?? "";
|
|
2990
|
+
}
|
|
2991
|
+
function Combobox({
|
|
2992
|
+
options,
|
|
2993
|
+
multiple = false,
|
|
2994
|
+
value: controlledValue,
|
|
2995
|
+
defaultValue,
|
|
2996
|
+
onChange,
|
|
2997
|
+
onInputChange,
|
|
2998
|
+
filterOptions = defaultFilter,
|
|
2999
|
+
placeholder,
|
|
3000
|
+
noOptionsMessage = "No options",
|
|
3001
|
+
disabled = false,
|
|
3002
|
+
invalid,
|
|
3003
|
+
loading = false,
|
|
3004
|
+
id,
|
|
3005
|
+
className,
|
|
3006
|
+
...rest
|
|
3007
|
+
}) {
|
|
3008
|
+
const fallbackDefault = multiple ? [] : null;
|
|
3009
|
+
const [uncontrolledValue, setUncontrolledValue] = useState14(
|
|
3010
|
+
defaultValue !== void 0 ? defaultValue : fallbackDefault
|
|
3011
|
+
);
|
|
3012
|
+
const value = controlledValue !== void 0 ? controlledValue : uncontrolledValue;
|
|
3013
|
+
const setValue = (next) => {
|
|
3014
|
+
if (controlledValue === void 0) {
|
|
3015
|
+
setUncontrolledValue(next);
|
|
3016
|
+
}
|
|
3017
|
+
onChange?.(next);
|
|
3018
|
+
};
|
|
3019
|
+
const selectedValues = multiple ? value ?? [] : [];
|
|
3020
|
+
const singleValue = multiple ? null : value;
|
|
3021
|
+
const [open, setOpen] = useState14(false);
|
|
3022
|
+
const [inputText, setInputText] = useState14(() => multiple ? "" : labelFor(options, singleValue));
|
|
3023
|
+
const [activeIndex, setActiveIndex] = useState14(null);
|
|
3024
|
+
useEffect6(() => {
|
|
3025
|
+
if (!multiple) {
|
|
3026
|
+
setInputText(labelFor(options, singleValue));
|
|
3027
|
+
}
|
|
3028
|
+
}, [singleValue, multiple]);
|
|
3029
|
+
const inputRef = useRef8(null);
|
|
3030
|
+
const listboxId = useId2();
|
|
3031
|
+
const filteredOptions = filterOptions(options, multiple ? inputText : open ? inputText : "");
|
|
3032
|
+
const { refs, floatingStyles, context } = useFloating7({
|
|
3033
|
+
open,
|
|
3034
|
+
onOpenChange: setOpen,
|
|
3035
|
+
placement: "bottom-start",
|
|
3036
|
+
whileElementsMounted: autoUpdate6,
|
|
3037
|
+
middleware: [offset6(4), flip6(), shift6({ padding: 8 })]
|
|
3038
|
+
});
|
|
3039
|
+
const { getReferenceProps, getFloatingProps } = useInteractions7([
|
|
3040
|
+
useDismiss7(context),
|
|
3041
|
+
useRole7(context, { role: "listbox" })
|
|
3042
|
+
]);
|
|
3043
|
+
const openList = () => {
|
|
3044
|
+
if (disabled) return;
|
|
3045
|
+
setOpen(true);
|
|
3046
|
+
setActiveIndex(null);
|
|
3047
|
+
};
|
|
3048
|
+
const closeList = () => {
|
|
3049
|
+
setOpen(false);
|
|
3050
|
+
setActiveIndex(null);
|
|
3051
|
+
};
|
|
3052
|
+
const selectOption = (opt) => {
|
|
3053
|
+
if (opt.disabled) return;
|
|
3054
|
+
if (multiple) {
|
|
3055
|
+
const next = selectedValues.includes(opt.value) ? selectedValues.filter((v) => v !== opt.value) : [...selectedValues, opt.value];
|
|
3056
|
+
setValue(next);
|
|
3057
|
+
setInputText("");
|
|
3058
|
+
onInputChange?.("");
|
|
3059
|
+
inputRef.current?.focus();
|
|
3060
|
+
return;
|
|
3061
|
+
}
|
|
3062
|
+
setValue(opt.value);
|
|
3063
|
+
setInputText(opt.label);
|
|
3064
|
+
closeList();
|
|
3065
|
+
};
|
|
3066
|
+
const removeChip = (optionValue) => {
|
|
3067
|
+
setValue(selectedValues.filter((v) => v !== optionValue));
|
|
3068
|
+
inputRef.current?.focus();
|
|
3069
|
+
};
|
|
3070
|
+
const handleInputChange = (text) => {
|
|
3071
|
+
setInputText(text);
|
|
3072
|
+
onInputChange?.(text);
|
|
3073
|
+
setOpen(true);
|
|
3074
|
+
setActiveIndex(null);
|
|
3075
|
+
};
|
|
3076
|
+
const moveActiveIndex = (direction2) => {
|
|
3077
|
+
if (filteredOptions.length === 0) return;
|
|
3078
|
+
let next = activeIndex ?? (direction2 === 1 ? -1 : filteredOptions.length);
|
|
3079
|
+
for (let step = 0; step < filteredOptions.length; step++) {
|
|
3080
|
+
next = (next + direction2 + filteredOptions.length) % filteredOptions.length;
|
|
3081
|
+
if (!filteredOptions[next]?.disabled) {
|
|
3082
|
+
setActiveIndex(next);
|
|
3083
|
+
return;
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
};
|
|
3087
|
+
const handleKeyDown = (event) => {
|
|
3088
|
+
if (disabled) return;
|
|
3089
|
+
switch (event.key) {
|
|
3090
|
+
case "ArrowDown":
|
|
3091
|
+
event.preventDefault();
|
|
3092
|
+
if (!open) {
|
|
3093
|
+
openList();
|
|
3094
|
+
} else {
|
|
3095
|
+
moveActiveIndex(1);
|
|
3096
|
+
}
|
|
3097
|
+
return;
|
|
3098
|
+
case "ArrowUp":
|
|
3099
|
+
event.preventDefault();
|
|
3100
|
+
if (open) moveActiveIndex(-1);
|
|
3101
|
+
return;
|
|
3102
|
+
case "Enter": {
|
|
3103
|
+
if (!open) return;
|
|
3104
|
+
event.preventDefault();
|
|
3105
|
+
const active = activeIndex !== null ? filteredOptions[activeIndex] : void 0;
|
|
3106
|
+
if (active) selectOption(active);
|
|
3107
|
+
return;
|
|
3108
|
+
}
|
|
3109
|
+
case "Escape":
|
|
3110
|
+
if (open) {
|
|
3111
|
+
event.preventDefault();
|
|
3112
|
+
closeList();
|
|
3113
|
+
if (!multiple) setInputText(labelFor(options, singleValue));
|
|
3114
|
+
}
|
|
3115
|
+
return;
|
|
3116
|
+
case "Backspace":
|
|
3117
|
+
if (multiple && inputText === "" && selectedValues.length > 0) {
|
|
3118
|
+
removeChip(selectedValues[selectedValues.length - 1]);
|
|
3119
|
+
}
|
|
3120
|
+
return;
|
|
3121
|
+
default:
|
|
3122
|
+
}
|
|
3123
|
+
};
|
|
3124
|
+
const handleBlur = () => {
|
|
3125
|
+
if (!multiple) {
|
|
3126
|
+
setInputText(labelFor(options, singleValue));
|
|
3127
|
+
}
|
|
3128
|
+
closeList();
|
|
3129
|
+
};
|
|
3130
|
+
const classes = [wrapper9, className].filter(Boolean).join(" ");
|
|
3131
|
+
const activeOptionId = activeIndex !== null ? `${listboxId}-option-${activeIndex}` : void 0;
|
|
3132
|
+
return /* @__PURE__ */ jsxs23("span", { className: classes, ref: refs.setReference, "data-disabled": disabled || void 0, children: [
|
|
3133
|
+
multiple && selectedValues.length > 0 ? /* @__PURE__ */ jsx40("span", { className: chipsWrapper, children: selectedValues.map((val) => /* @__PURE__ */ jsxs23("span", { className: chip, children: [
|
|
3134
|
+
labelFor(options, val),
|
|
3135
|
+
/* @__PURE__ */ jsx40(
|
|
3136
|
+
"button",
|
|
3137
|
+
{
|
|
3138
|
+
type: "button",
|
|
3139
|
+
className: chipRemove,
|
|
3140
|
+
"aria-label": `Remove ${labelFor(options, val)}`,
|
|
3141
|
+
disabled,
|
|
3142
|
+
onClick: () => removeChip(val),
|
|
3143
|
+
children: "\xD7"
|
|
3144
|
+
}
|
|
3145
|
+
)
|
|
3146
|
+
] }, val)) }) : null,
|
|
3147
|
+
/* @__PURE__ */ jsx40(
|
|
3148
|
+
"input",
|
|
3149
|
+
{
|
|
3150
|
+
ref: inputRef,
|
|
3151
|
+
id,
|
|
3152
|
+
type: "text",
|
|
3153
|
+
role: "combobox",
|
|
3154
|
+
className: inputEl,
|
|
3155
|
+
value: inputText,
|
|
3156
|
+
placeholder,
|
|
3157
|
+
disabled,
|
|
3158
|
+
autoComplete: "off",
|
|
3159
|
+
"aria-autocomplete": "list",
|
|
3160
|
+
"aria-expanded": open,
|
|
3161
|
+
"aria-controls": listboxId,
|
|
3162
|
+
"aria-invalid": invalid || void 0,
|
|
3163
|
+
"aria-activedescendant": activeOptionId,
|
|
3164
|
+
...getReferenceProps({
|
|
3165
|
+
...rest,
|
|
3166
|
+
onFocus: openList,
|
|
3167
|
+
onBlur: handleBlur,
|
|
3168
|
+
onChange: (e) => handleInputChange(e.target.value),
|
|
3169
|
+
onKeyDown: handleKeyDown
|
|
3170
|
+
})
|
|
3171
|
+
}
|
|
3172
|
+
),
|
|
3173
|
+
open ? /* @__PURE__ */ jsx40(FloatingPortal7, { children: /* @__PURE__ */ jsx40(
|
|
3174
|
+
"div",
|
|
3175
|
+
{
|
|
3176
|
+
ref: refs.setFloating,
|
|
3177
|
+
id: listboxId,
|
|
3178
|
+
role: "listbox",
|
|
3179
|
+
"aria-multiselectable": multiple || void 0,
|
|
3180
|
+
className: listbox,
|
|
3181
|
+
style: floatingStyles,
|
|
3182
|
+
...getFloatingProps(),
|
|
3183
|
+
children: loading ? /* @__PURE__ */ jsx40("div", { className: emptyState2, children: "Loading\u2026" }) : filteredOptions.length === 0 ? /* @__PURE__ */ jsx40("div", { className: emptyState2, children: noOptionsMessage }) : filteredOptions.map((opt, index) => {
|
|
3184
|
+
const isSelected = multiple ? selectedValues.includes(opt.value) : opt.value === singleValue;
|
|
3185
|
+
return /* @__PURE__ */ jsx40(
|
|
3186
|
+
"div",
|
|
3187
|
+
{
|
|
3188
|
+
id: `${listboxId}-option-${index}`,
|
|
3189
|
+
role: "option",
|
|
3190
|
+
"aria-selected": isSelected,
|
|
3191
|
+
"aria-disabled": opt.disabled || void 0,
|
|
3192
|
+
"data-active": activeIndex === index || void 0,
|
|
3193
|
+
className: option,
|
|
3194
|
+
onMouseDown: (event) => {
|
|
3195
|
+
event.preventDefault();
|
|
3196
|
+
selectOption(opt);
|
|
3197
|
+
},
|
|
3198
|
+
onMouseEnter: () => setActiveIndex(index),
|
|
3199
|
+
children: opt.label
|
|
3200
|
+
},
|
|
3201
|
+
opt.value
|
|
3202
|
+
);
|
|
3203
|
+
})
|
|
3204
|
+
}
|
|
3205
|
+
) }) : null
|
|
3206
|
+
] });
|
|
3207
|
+
}
|
|
3208
|
+
|
|
2623
3209
|
// src/index.ts
|
|
2624
3210
|
import { vars as vars2, defaultThemeClass, defaultThemeVars } from "@vesture/tokens";
|
|
2625
3211
|
export {
|
|
@@ -2636,6 +3222,7 @@ export {
|
|
|
2636
3222
|
Calendar,
|
|
2637
3223
|
Card,
|
|
2638
3224
|
Checkbox,
|
|
3225
|
+
Combobox,
|
|
2639
3226
|
DataGrid,
|
|
2640
3227
|
DatePicker,
|
|
2641
3228
|
DateRangePicker,
|
|
@@ -2645,11 +3232,13 @@ export {
|
|
|
2645
3232
|
Input,
|
|
2646
3233
|
Label,
|
|
2647
3234
|
Modal,
|
|
3235
|
+
NumberInput,
|
|
2648
3236
|
Pagination,
|
|
2649
3237
|
Popover,
|
|
2650
3238
|
Progress,
|
|
2651
3239
|
Radio,
|
|
2652
3240
|
Select,
|
|
3241
|
+
Slider,
|
|
2653
3242
|
Spinner,
|
|
2654
3243
|
Stack,
|
|
2655
3244
|
Switch,
|