@vesture/react 0.2.0 → 0.2.2
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 +600 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +143 -1
- package/dist/index.js +1492 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1712,6 +1712,1492 @@ function DataGrid({
|
|
|
1712
1712
|
] });
|
|
1713
1713
|
}
|
|
1714
1714
|
|
|
1715
|
+
// src/components/Calendar/Calendar.tsx
|
|
1716
|
+
import { useEffect as useEffect2, useMemo as useMemo3, useRef as useRef4, useState as useState9 } from "react";
|
|
1717
|
+
|
|
1718
|
+
// src/components/Calendar/Calendar.css.ts
|
|
1719
|
+
var dayButton = "Calendar_dayButton__1uy43my8";
|
|
1720
|
+
var dayCell = "Calendar_dayCell__1uy43my7";
|
|
1721
|
+
var grid = "Calendar_grid__1uy43my4";
|
|
1722
|
+
var header = "Calendar_header__1uy43my1";
|
|
1723
|
+
var monthLabel = "Calendar_monthLabel__1uy43my2";
|
|
1724
|
+
var navButton = "Calendar_navButton__1uy43my3";
|
|
1725
|
+
var root2 = "Calendar_root__1uy43my0";
|
|
1726
|
+
var weekRow = "Calendar_weekRow__1uy43my5";
|
|
1727
|
+
var weekdayCell = "Calendar_weekdayCell__1uy43my6";
|
|
1728
|
+
|
|
1729
|
+
// src/components/Calendar/Calendar.tsx
|
|
1730
|
+
import { jsx as jsx35, jsxs as jsxs18 } from "react/jsx-runtime";
|
|
1731
|
+
function startOfMonth(date) {
|
|
1732
|
+
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
1733
|
+
}
|
|
1734
|
+
function endOfMonth(date) {
|
|
1735
|
+
return new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
1736
|
+
}
|
|
1737
|
+
function addDays(date, amount) {
|
|
1738
|
+
const next = new Date(date);
|
|
1739
|
+
next.setDate(next.getDate() + amount);
|
|
1740
|
+
return next;
|
|
1741
|
+
}
|
|
1742
|
+
function addMonths(date, amount) {
|
|
1743
|
+
const next = new Date(date);
|
|
1744
|
+
next.setMonth(next.getMonth() + amount);
|
|
1745
|
+
return next;
|
|
1746
|
+
}
|
|
1747
|
+
function isSameDay(a, b) {
|
|
1748
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
1749
|
+
}
|
|
1750
|
+
function isSameMonth(a, b) {
|
|
1751
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
|
|
1752
|
+
}
|
|
1753
|
+
function clampToMidnight(date) {
|
|
1754
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
1755
|
+
}
|
|
1756
|
+
function startOfWeek(date, weekStartsOn) {
|
|
1757
|
+
const diff = (date.getDay() - weekStartsOn + 7) % 7;
|
|
1758
|
+
return addDays(date, -diff);
|
|
1759
|
+
}
|
|
1760
|
+
function endOfWeek(date, weekStartsOn) {
|
|
1761
|
+
return addDays(startOfWeek(date, weekStartsOn), 6);
|
|
1762
|
+
}
|
|
1763
|
+
function dateKey(date) {
|
|
1764
|
+
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`;
|
|
1765
|
+
}
|
|
1766
|
+
function getCalendarWeeks(month, weekStartsOn) {
|
|
1767
|
+
const gridStart = startOfWeek(startOfMonth(month), weekStartsOn);
|
|
1768
|
+
const gridEnd = endOfWeek(endOfMonth(month), weekStartsOn);
|
|
1769
|
+
const weeks = [];
|
|
1770
|
+
let cursor = gridStart;
|
|
1771
|
+
while (cursor <= gridEnd) {
|
|
1772
|
+
const week = [];
|
|
1773
|
+
for (let i = 0; i < 7; i++) {
|
|
1774
|
+
week.push(cursor);
|
|
1775
|
+
cursor = addDays(cursor, 1);
|
|
1776
|
+
}
|
|
1777
|
+
weeks.push(week);
|
|
1778
|
+
}
|
|
1779
|
+
return weeks;
|
|
1780
|
+
}
|
|
1781
|
+
function isDateDisabledBy(date, minDate, maxDate, isDateDisabled) {
|
|
1782
|
+
const target = clampToMidnight(date);
|
|
1783
|
+
if (minDate && target < clampToMidnight(minDate)) return true;
|
|
1784
|
+
if (maxDate && target > clampToMidnight(maxDate)) return true;
|
|
1785
|
+
if (isDateDisabled?.(target)) return true;
|
|
1786
|
+
return false;
|
|
1787
|
+
}
|
|
1788
|
+
function findEnabledDate(date, direction2, minDate, maxDate, isDateDisabled) {
|
|
1789
|
+
let cursor = date;
|
|
1790
|
+
for (let i = 0; i < 366; i++) {
|
|
1791
|
+
if (!isDateDisabledBy(cursor, minDate, maxDate, isDateDisabled)) {
|
|
1792
|
+
return cursor;
|
|
1793
|
+
}
|
|
1794
|
+
cursor = addDays(cursor, direction2);
|
|
1795
|
+
}
|
|
1796
|
+
return null;
|
|
1797
|
+
}
|
|
1798
|
+
function getFocusableDate(month, value, minDate, maxDate, isDateDisabled) {
|
|
1799
|
+
if (value && isSameMonth(value, month) && !isDateDisabledBy(value, minDate, maxDate, isDateDisabled)) {
|
|
1800
|
+
return clampToMidnight(value);
|
|
1801
|
+
}
|
|
1802
|
+
const today = clampToMidnight(/* @__PURE__ */ new Date());
|
|
1803
|
+
if (isSameMonth(today, month) && !isDateDisabledBy(today, minDate, maxDate, isDateDisabled)) {
|
|
1804
|
+
return today;
|
|
1805
|
+
}
|
|
1806
|
+
const firstEnabled = findEnabledDate(
|
|
1807
|
+
startOfMonth(month),
|
|
1808
|
+
1,
|
|
1809
|
+
minDate,
|
|
1810
|
+
maxDate,
|
|
1811
|
+
isDateDisabled
|
|
1812
|
+
);
|
|
1813
|
+
if (firstEnabled && isSameMonth(firstEnabled, month)) {
|
|
1814
|
+
return firstEnabled;
|
|
1815
|
+
}
|
|
1816
|
+
return startOfMonth(month);
|
|
1817
|
+
}
|
|
1818
|
+
function Calendar({
|
|
1819
|
+
value: controlledValue,
|
|
1820
|
+
defaultValue = null,
|
|
1821
|
+
onChange,
|
|
1822
|
+
month: controlledMonth,
|
|
1823
|
+
onMonthChange,
|
|
1824
|
+
minDate,
|
|
1825
|
+
maxDate,
|
|
1826
|
+
isDateDisabled,
|
|
1827
|
+
weekStartsOn = 1,
|
|
1828
|
+
locale = "en-US",
|
|
1829
|
+
rangeEnd
|
|
1830
|
+
}) {
|
|
1831
|
+
const [uncontrolledValue, setUncontrolledValue] = useState9(
|
|
1832
|
+
defaultValue
|
|
1833
|
+
);
|
|
1834
|
+
const value = controlledValue !== void 0 ? controlledValue : uncontrolledValue;
|
|
1835
|
+
const setValue = (next) => {
|
|
1836
|
+
if (controlledValue === void 0) {
|
|
1837
|
+
setUncontrolledValue(next);
|
|
1838
|
+
}
|
|
1839
|
+
onChange?.(next);
|
|
1840
|
+
};
|
|
1841
|
+
const [uncontrolledMonth, setUncontrolledMonth] = useState9(
|
|
1842
|
+
() => startOfMonth(controlledMonth ?? value ?? /* @__PURE__ */ new Date())
|
|
1843
|
+
);
|
|
1844
|
+
const month = controlledMonth !== void 0 ? startOfMonth(controlledMonth) : uncontrolledMonth;
|
|
1845
|
+
const setMonth = (next) => {
|
|
1846
|
+
const normalized = startOfMonth(next);
|
|
1847
|
+
if (controlledMonth === void 0) {
|
|
1848
|
+
setUncontrolledMonth(normalized);
|
|
1849
|
+
}
|
|
1850
|
+
onMonthChange?.(normalized);
|
|
1851
|
+
};
|
|
1852
|
+
const [rovingDate, setRovingDate] = useState9(
|
|
1853
|
+
() => getFocusableDate(month, value, minDate, maxDate, isDateDisabled)
|
|
1854
|
+
);
|
|
1855
|
+
const shouldFocusRef = useRef4(false);
|
|
1856
|
+
const dayRefs = useRef4(/* @__PURE__ */ new Map());
|
|
1857
|
+
useEffect2(() => {
|
|
1858
|
+
setRovingDate((prev) => {
|
|
1859
|
+
if (isSameMonth(prev, month)) return prev;
|
|
1860
|
+
return getFocusableDate(month, value, minDate, maxDate, isDateDisabled);
|
|
1861
|
+
});
|
|
1862
|
+
}, [month]);
|
|
1863
|
+
useEffect2(() => {
|
|
1864
|
+
if (!shouldFocusRef.current) return;
|
|
1865
|
+
shouldFocusRef.current = false;
|
|
1866
|
+
dayRefs.current.get(dateKey(rovingDate))?.focus();
|
|
1867
|
+
}, [rovingDate, month]);
|
|
1868
|
+
const weeks = useMemo3(
|
|
1869
|
+
() => getCalendarWeeks(month, weekStartsOn),
|
|
1870
|
+
[month, weekStartsOn]
|
|
1871
|
+
);
|
|
1872
|
+
const today = useMemo3(() => clampToMidnight(/* @__PURE__ */ new Date()), []);
|
|
1873
|
+
const monthLabelFormatter = useMemo3(
|
|
1874
|
+
() => new Intl.DateTimeFormat(locale, { month: "long", year: "numeric" }),
|
|
1875
|
+
[locale]
|
|
1876
|
+
);
|
|
1877
|
+
const weekdayFormatter = useMemo3(
|
|
1878
|
+
() => new Intl.DateTimeFormat(locale, { weekday: "short" }),
|
|
1879
|
+
[locale]
|
|
1880
|
+
);
|
|
1881
|
+
const handleDayClick = (date, disabled, inMonth) => {
|
|
1882
|
+
if (disabled) return;
|
|
1883
|
+
if (!inMonth) {
|
|
1884
|
+
setMonth(startOfMonth(date));
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
const normalized = clampToMidnight(date);
|
|
1888
|
+
setValue(normalized);
|
|
1889
|
+
setRovingDate(normalized);
|
|
1890
|
+
};
|
|
1891
|
+
const handleKeyDown = (event, date) => {
|
|
1892
|
+
let targetRaw;
|
|
1893
|
+
let direction2;
|
|
1894
|
+
switch (event.key) {
|
|
1895
|
+
case "ArrowLeft":
|
|
1896
|
+
targetRaw = addDays(date, -1);
|
|
1897
|
+
direction2 = -1;
|
|
1898
|
+
break;
|
|
1899
|
+
case "ArrowRight":
|
|
1900
|
+
targetRaw = addDays(date, 1);
|
|
1901
|
+
direction2 = 1;
|
|
1902
|
+
break;
|
|
1903
|
+
case "ArrowUp":
|
|
1904
|
+
targetRaw = addDays(date, -7);
|
|
1905
|
+
direction2 = -1;
|
|
1906
|
+
break;
|
|
1907
|
+
case "ArrowDown":
|
|
1908
|
+
targetRaw = addDays(date, 7);
|
|
1909
|
+
direction2 = 1;
|
|
1910
|
+
break;
|
|
1911
|
+
case "Home":
|
|
1912
|
+
targetRaw = startOfWeek(date, weekStartsOn);
|
|
1913
|
+
direction2 = -1;
|
|
1914
|
+
break;
|
|
1915
|
+
case "End":
|
|
1916
|
+
targetRaw = endOfWeek(date, weekStartsOn);
|
|
1917
|
+
direction2 = 1;
|
|
1918
|
+
break;
|
|
1919
|
+
case "PageUp":
|
|
1920
|
+
targetRaw = addMonths(date, -1);
|
|
1921
|
+
direction2 = -1;
|
|
1922
|
+
break;
|
|
1923
|
+
case "PageDown":
|
|
1924
|
+
targetRaw = addMonths(date, 1);
|
|
1925
|
+
direction2 = 1;
|
|
1926
|
+
break;
|
|
1927
|
+
default:
|
|
1928
|
+
return;
|
|
1929
|
+
}
|
|
1930
|
+
event.preventDefault();
|
|
1931
|
+
const target = findEnabledDate(
|
|
1932
|
+
targetRaw,
|
|
1933
|
+
direction2,
|
|
1934
|
+
minDate,
|
|
1935
|
+
maxDate,
|
|
1936
|
+
isDateDisabled
|
|
1937
|
+
);
|
|
1938
|
+
if (!target) return;
|
|
1939
|
+
shouldFocusRef.current = true;
|
|
1940
|
+
setRovingDate(target);
|
|
1941
|
+
if (!isSameMonth(target, month)) {
|
|
1942
|
+
setMonth(startOfMonth(target));
|
|
1943
|
+
}
|
|
1944
|
+
};
|
|
1945
|
+
const monthLabelText = monthLabelFormatter.format(month);
|
|
1946
|
+
const clampedValue = value ? clampToMidnight(value) : null;
|
|
1947
|
+
const clampedRangeEnd = rangeEnd ? clampToMidnight(rangeEnd) : null;
|
|
1948
|
+
return /* @__PURE__ */ jsxs18("div", { className: root2, role: "application", "aria-label": monthLabelText, children: [
|
|
1949
|
+
/* @__PURE__ */ jsxs18("div", { className: header, children: [
|
|
1950
|
+
/* @__PURE__ */ jsx35(
|
|
1951
|
+
"button",
|
|
1952
|
+
{
|
|
1953
|
+
type: "button",
|
|
1954
|
+
className: navButton,
|
|
1955
|
+
onClick: () => setMonth(addMonths(month, -1)),
|
|
1956
|
+
"aria-label": "Previous month",
|
|
1957
|
+
children: "\u2039"
|
|
1958
|
+
}
|
|
1959
|
+
),
|
|
1960
|
+
/* @__PURE__ */ jsx35("span", { className: monthLabel, children: monthLabelText }),
|
|
1961
|
+
/* @__PURE__ */ jsx35(
|
|
1962
|
+
"button",
|
|
1963
|
+
{
|
|
1964
|
+
type: "button",
|
|
1965
|
+
className: navButton,
|
|
1966
|
+
onClick: () => setMonth(addMonths(month, 1)),
|
|
1967
|
+
"aria-label": "Next month",
|
|
1968
|
+
children: "\u203A"
|
|
1969
|
+
}
|
|
1970
|
+
)
|
|
1971
|
+
] }),
|
|
1972
|
+
/* @__PURE__ */ jsxs18("div", { className: grid, role: "grid", "aria-label": monthLabelText, children: [
|
|
1973
|
+
/* @__PURE__ */ jsx35("div", { className: weekRow, role: "row", children: weeks[0].map((date) => /* @__PURE__ */ jsx35(
|
|
1974
|
+
"div",
|
|
1975
|
+
{
|
|
1976
|
+
className: weekdayCell,
|
|
1977
|
+
role: "columnheader",
|
|
1978
|
+
children: weekdayFormatter.format(date)
|
|
1979
|
+
},
|
|
1980
|
+
dateKey(date)
|
|
1981
|
+
)) }),
|
|
1982
|
+
weeks.map((week, weekIndex) => /* @__PURE__ */ jsx35("div", { className: weekRow, role: "row", children: week.map((date) => {
|
|
1983
|
+
const inMonth = isSameMonth(date, month);
|
|
1984
|
+
const disabled = isDateDisabledBy(
|
|
1985
|
+
date,
|
|
1986
|
+
minDate,
|
|
1987
|
+
maxDate,
|
|
1988
|
+
isDateDisabled
|
|
1989
|
+
);
|
|
1990
|
+
const isRangeEndDay = clampedRangeEnd ? isSameDay(date, clampedRangeEnd) : false;
|
|
1991
|
+
const selected = (clampedValue ? isSameDay(date, clampedValue) : false) || isRangeEndDay;
|
|
1992
|
+
const inRange = Boolean(
|
|
1993
|
+
clampedValue && clampedRangeEnd && date > clampedValue && date < clampedRangeEnd
|
|
1994
|
+
);
|
|
1995
|
+
const isToday = isSameDay(date, today);
|
|
1996
|
+
const tabIndex = inMonth && !disabled && isSameDay(date, rovingDate) ? 0 : -1;
|
|
1997
|
+
return /* @__PURE__ */ jsx35("div", { className: dayCell, role: "gridcell", children: /* @__PURE__ */ jsx35(
|
|
1998
|
+
"button",
|
|
1999
|
+
{
|
|
2000
|
+
type: "button",
|
|
2001
|
+
ref: (el) => {
|
|
2002
|
+
if (el) {
|
|
2003
|
+
dayRefs.current.set(dateKey(date), el);
|
|
2004
|
+
} else {
|
|
2005
|
+
dayRefs.current.delete(dateKey(date));
|
|
2006
|
+
}
|
|
2007
|
+
},
|
|
2008
|
+
className: dayButton,
|
|
2009
|
+
"data-outside": !inMonth || void 0,
|
|
2010
|
+
"data-today": isToday || void 0,
|
|
2011
|
+
"data-selected": selected || void 0,
|
|
2012
|
+
"data-in-range": inRange || void 0,
|
|
2013
|
+
disabled,
|
|
2014
|
+
tabIndex,
|
|
2015
|
+
"aria-selected": selected || void 0,
|
|
2016
|
+
"aria-current": isToday ? "date" : void 0,
|
|
2017
|
+
"aria-disabled": disabled || void 0,
|
|
2018
|
+
"aria-label": date.toDateString(),
|
|
2019
|
+
onClick: () => handleDayClick(date, disabled, inMonth),
|
|
2020
|
+
onKeyDown: inMonth ? (e) => handleKeyDown(e, date) : void 0,
|
|
2021
|
+
children: date.getDate()
|
|
2022
|
+
}
|
|
2023
|
+
) }, dateKey(date));
|
|
2024
|
+
}) }, weekIndex))
|
|
2025
|
+
] })
|
|
2026
|
+
] });
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
// src/components/DatePicker/DatePicker.tsx
|
|
2030
|
+
import { useEffect as useEffect3, useRef as useRef5, useState as useState10 } from "react";
|
|
2031
|
+
import {
|
|
2032
|
+
FloatingFocusManager as FloatingFocusManager4,
|
|
2033
|
+
FloatingPortal as FloatingPortal5,
|
|
2034
|
+
autoUpdate as autoUpdate4,
|
|
2035
|
+
flip as flip4,
|
|
2036
|
+
offset as offset4,
|
|
2037
|
+
shift as shift4,
|
|
2038
|
+
useDismiss as useDismiss5,
|
|
2039
|
+
useFloating as useFloating5,
|
|
2040
|
+
useInteractions as useInteractions5,
|
|
2041
|
+
useRole as useRole5
|
|
2042
|
+
} from "@floating-ui/react";
|
|
2043
|
+
|
|
2044
|
+
// src/components/DatePicker/DatePicker.css.ts
|
|
2045
|
+
var dateInput = "DatePicker_dateInput__d7uy1a1";
|
|
2046
|
+
var iconButton2 = "DatePicker_iconButton__d7uy1a2";
|
|
2047
|
+
var popover2 = "DatePicker_popover__d7uy1a3";
|
|
2048
|
+
var wrapper6 = "DatePicker_wrapper__d7uy1a0";
|
|
2049
|
+
|
|
2050
|
+
// src/components/DatePicker/DatePicker.tsx
|
|
2051
|
+
import { jsx as jsx36, jsxs as jsxs19 } from "react/jsx-runtime";
|
|
2052
|
+
function startOfMonth2(date) {
|
|
2053
|
+
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
2054
|
+
}
|
|
2055
|
+
function clampToMidnight2(date) {
|
|
2056
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
2057
|
+
}
|
|
2058
|
+
function isDisabled(date, minDate, maxDate, isDateDisabled) {
|
|
2059
|
+
const target = clampToMidnight2(date);
|
|
2060
|
+
if (minDate && target < clampToMidnight2(minDate)) return true;
|
|
2061
|
+
if (maxDate && target > clampToMidnight2(maxDate)) return true;
|
|
2062
|
+
if (isDateDisabled?.(target)) return true;
|
|
2063
|
+
return false;
|
|
2064
|
+
}
|
|
2065
|
+
function getDatePartOrder(locale) {
|
|
2066
|
+
const parts = new Intl.DateTimeFormat(locale).formatToParts(
|
|
2067
|
+
new Date(2e3, 0, 2)
|
|
2068
|
+
);
|
|
2069
|
+
return parts.filter(
|
|
2070
|
+
(part) => part.type === "month" || part.type === "day" || part.type === "year"
|
|
2071
|
+
).map((part) => part.type);
|
|
2072
|
+
}
|
|
2073
|
+
function getDatePlaceholder(locale) {
|
|
2074
|
+
const parts = new Intl.DateTimeFormat(locale).formatToParts(
|
|
2075
|
+
new Date(2e3, 0, 2)
|
|
2076
|
+
);
|
|
2077
|
+
return parts.map((part) => {
|
|
2078
|
+
switch (part.type) {
|
|
2079
|
+
case "month":
|
|
2080
|
+
return "MM";
|
|
2081
|
+
case "day":
|
|
2082
|
+
return "DD";
|
|
2083
|
+
case "year":
|
|
2084
|
+
return "YYYY";
|
|
2085
|
+
default:
|
|
2086
|
+
return part.value;
|
|
2087
|
+
}
|
|
2088
|
+
}).join("");
|
|
2089
|
+
}
|
|
2090
|
+
function formatDate(date, locale) {
|
|
2091
|
+
return new Intl.DateTimeFormat(locale).format(date);
|
|
2092
|
+
}
|
|
2093
|
+
function parseDate(text, locale) {
|
|
2094
|
+
const numbers = text.match(/\d+/g);
|
|
2095
|
+
if (!numbers || numbers.length < 3) return null;
|
|
2096
|
+
const order = getDatePartOrder(locale);
|
|
2097
|
+
if (order.length < 3) return null;
|
|
2098
|
+
const values = {};
|
|
2099
|
+
order.forEach((type, i) => {
|
|
2100
|
+
values[type] = Number.parseInt(numbers[i], 10);
|
|
2101
|
+
});
|
|
2102
|
+
const { month, day, year } = values;
|
|
2103
|
+
if (!month || !day || !year) return null;
|
|
2104
|
+
const fullYear = year < 100 ? 2e3 + year : year;
|
|
2105
|
+
const date = new Date(fullYear, month - 1, day);
|
|
2106
|
+
if (date.getFullYear() !== fullYear || date.getMonth() !== month - 1 || date.getDate() !== day) {
|
|
2107
|
+
return null;
|
|
2108
|
+
}
|
|
2109
|
+
return date;
|
|
2110
|
+
}
|
|
2111
|
+
function DatePicker({
|
|
2112
|
+
value: controlledValue,
|
|
2113
|
+
defaultValue = null,
|
|
2114
|
+
onChange,
|
|
2115
|
+
minDate,
|
|
2116
|
+
maxDate,
|
|
2117
|
+
isDateDisabled,
|
|
2118
|
+
weekStartsOn = 1,
|
|
2119
|
+
locale = "en-US",
|
|
2120
|
+
placeholder,
|
|
2121
|
+
disabled = false,
|
|
2122
|
+
open: controlledOpen,
|
|
2123
|
+
onOpenChange
|
|
2124
|
+
}) {
|
|
2125
|
+
const [uncontrolledValue, setUncontrolledValue] = useState10(
|
|
2126
|
+
defaultValue
|
|
2127
|
+
);
|
|
2128
|
+
const value = controlledValue !== void 0 ? controlledValue : uncontrolledValue;
|
|
2129
|
+
const setValue = (next) => {
|
|
2130
|
+
if (controlledValue === void 0) {
|
|
2131
|
+
setUncontrolledValue(next);
|
|
2132
|
+
}
|
|
2133
|
+
onChange?.(next);
|
|
2134
|
+
};
|
|
2135
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState10(false);
|
|
2136
|
+
const open = controlledOpen ?? uncontrolledOpen;
|
|
2137
|
+
const setOpen = onOpenChange ?? setUncontrolledOpen;
|
|
2138
|
+
const [month, setMonth] = useState10(
|
|
2139
|
+
() => startOfMonth2(value ?? /* @__PURE__ */ new Date())
|
|
2140
|
+
);
|
|
2141
|
+
const [inputText, setInputText] = useState10(
|
|
2142
|
+
() => value ? formatDate(value, locale) : ""
|
|
2143
|
+
);
|
|
2144
|
+
const inputRef = useRef5(null);
|
|
2145
|
+
useEffect3(() => {
|
|
2146
|
+
setInputText(value ? formatDate(value, locale) : "");
|
|
2147
|
+
}, [value, locale]);
|
|
2148
|
+
useEffect3(() => {
|
|
2149
|
+
if (open && value) {
|
|
2150
|
+
setMonth(startOfMonth2(value));
|
|
2151
|
+
}
|
|
2152
|
+
}, [open]);
|
|
2153
|
+
const { refs, floatingStyles, context } = useFloating5({
|
|
2154
|
+
open,
|
|
2155
|
+
onOpenChange: setOpen,
|
|
2156
|
+
placement: "bottom-start",
|
|
2157
|
+
whileElementsMounted: autoUpdate4,
|
|
2158
|
+
middleware: [offset4(8), flip4(), shift4({ padding: 8 })]
|
|
2159
|
+
});
|
|
2160
|
+
const { getReferenceProps, getFloatingProps } = useInteractions5([
|
|
2161
|
+
useDismiss5(context),
|
|
2162
|
+
useRole5(context, { role: "dialog" })
|
|
2163
|
+
]);
|
|
2164
|
+
const revertInputText = () => {
|
|
2165
|
+
setInputText(value ? formatDate(value, locale) : "");
|
|
2166
|
+
};
|
|
2167
|
+
const commitTypedValue = () => {
|
|
2168
|
+
const trimmed = inputText.trim();
|
|
2169
|
+
if (!trimmed) {
|
|
2170
|
+
if (value !== null) {
|
|
2171
|
+
setValue(null);
|
|
2172
|
+
}
|
|
2173
|
+
return;
|
|
2174
|
+
}
|
|
2175
|
+
const parsed = parseDate(trimmed, locale);
|
|
2176
|
+
if (!parsed || isDisabled(parsed, minDate, maxDate, isDateDisabled)) {
|
|
2177
|
+
revertInputText();
|
|
2178
|
+
return;
|
|
2179
|
+
}
|
|
2180
|
+
setValue(parsed);
|
|
2181
|
+
setMonth(startOfMonth2(parsed));
|
|
2182
|
+
setInputText(formatDate(parsed, locale));
|
|
2183
|
+
};
|
|
2184
|
+
const handleInputKeyDown = (event) => {
|
|
2185
|
+
if (event.key === "Enter") {
|
|
2186
|
+
event.preventDefault();
|
|
2187
|
+
commitTypedValue();
|
|
2188
|
+
}
|
|
2189
|
+
};
|
|
2190
|
+
const handleCalendarChange = (date) => {
|
|
2191
|
+
setValue(date);
|
|
2192
|
+
setMonth(startOfMonth2(date));
|
|
2193
|
+
setOpen(false);
|
|
2194
|
+
};
|
|
2195
|
+
const placeholderText = placeholder ?? getDatePlaceholder(locale);
|
|
2196
|
+
return /* @__PURE__ */ jsxs19("div", { className: wrapper6, ref: refs.setReference, children: [
|
|
2197
|
+
/* @__PURE__ */ jsx36(
|
|
2198
|
+
"input",
|
|
2199
|
+
{
|
|
2200
|
+
ref: inputRef,
|
|
2201
|
+
type: "text",
|
|
2202
|
+
className: dateInput,
|
|
2203
|
+
value: inputText,
|
|
2204
|
+
placeholder: placeholderText,
|
|
2205
|
+
disabled,
|
|
2206
|
+
onChange: (e) => setInputText(e.target.value),
|
|
2207
|
+
onBlur: commitTypedValue,
|
|
2208
|
+
onKeyDown: handleInputKeyDown,
|
|
2209
|
+
"aria-label": "Date"
|
|
2210
|
+
}
|
|
2211
|
+
),
|
|
2212
|
+
/* @__PURE__ */ jsx36(
|
|
2213
|
+
"button",
|
|
2214
|
+
{
|
|
2215
|
+
type: "button",
|
|
2216
|
+
className: iconButton2,
|
|
2217
|
+
disabled,
|
|
2218
|
+
"aria-label": open ? "Close calendar" : "Open calendar",
|
|
2219
|
+
...getReferenceProps({
|
|
2220
|
+
onClick: () => {
|
|
2221
|
+
if (disabled) return;
|
|
2222
|
+
setOpen(!open);
|
|
2223
|
+
}
|
|
2224
|
+
}),
|
|
2225
|
+
children: /* @__PURE__ */ jsxs19(
|
|
2226
|
+
"svg",
|
|
2227
|
+
{
|
|
2228
|
+
width: "16",
|
|
2229
|
+
height: "16",
|
|
2230
|
+
viewBox: "0 0 16 16",
|
|
2231
|
+
fill: "none",
|
|
2232
|
+
"aria-hidden": "true",
|
|
2233
|
+
children: [
|
|
2234
|
+
/* @__PURE__ */ jsx36(
|
|
2235
|
+
"rect",
|
|
2236
|
+
{
|
|
2237
|
+
x: "1.5",
|
|
2238
|
+
y: "2.5",
|
|
2239
|
+
width: "13",
|
|
2240
|
+
height: "12",
|
|
2241
|
+
rx: "1.5",
|
|
2242
|
+
stroke: "currentColor",
|
|
2243
|
+
strokeWidth: "1.3"
|
|
2244
|
+
}
|
|
2245
|
+
),
|
|
2246
|
+
/* @__PURE__ */ jsx36("path", { d: "M1.5 6h13", stroke: "currentColor", strokeWidth: "1.3" }),
|
|
2247
|
+
/* @__PURE__ */ jsx36(
|
|
2248
|
+
"path",
|
|
2249
|
+
{
|
|
2250
|
+
d: "M4.5 1v3M11.5 1v3",
|
|
2251
|
+
stroke: "currentColor",
|
|
2252
|
+
strokeWidth: "1.3",
|
|
2253
|
+
strokeLinecap: "round"
|
|
2254
|
+
}
|
|
2255
|
+
)
|
|
2256
|
+
]
|
|
2257
|
+
}
|
|
2258
|
+
)
|
|
2259
|
+
}
|
|
2260
|
+
),
|
|
2261
|
+
open ? /* @__PURE__ */ jsx36(FloatingPortal5, { children: /* @__PURE__ */ jsx36(
|
|
2262
|
+
FloatingFocusManager4,
|
|
2263
|
+
{
|
|
2264
|
+
context,
|
|
2265
|
+
modal: false,
|
|
2266
|
+
returnFocus: inputRef,
|
|
2267
|
+
children: /* @__PURE__ */ jsx36(
|
|
2268
|
+
"div",
|
|
2269
|
+
{
|
|
2270
|
+
ref: refs.setFloating,
|
|
2271
|
+
className: popover2,
|
|
2272
|
+
style: floatingStyles,
|
|
2273
|
+
...getFloatingProps(),
|
|
2274
|
+
children: /* @__PURE__ */ jsx36(
|
|
2275
|
+
Calendar,
|
|
2276
|
+
{
|
|
2277
|
+
value,
|
|
2278
|
+
onChange: handleCalendarChange,
|
|
2279
|
+
month,
|
|
2280
|
+
onMonthChange: setMonth,
|
|
2281
|
+
minDate,
|
|
2282
|
+
maxDate,
|
|
2283
|
+
isDateDisabled,
|
|
2284
|
+
weekStartsOn,
|
|
2285
|
+
locale
|
|
2286
|
+
}
|
|
2287
|
+
)
|
|
2288
|
+
}
|
|
2289
|
+
)
|
|
2290
|
+
}
|
|
2291
|
+
) }) : null
|
|
2292
|
+
] });
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
// src/components/DateRangePicker/DateRangePicker.tsx
|
|
2296
|
+
import { useEffect as useEffect4, useState as useState11 } from "react";
|
|
2297
|
+
import {
|
|
2298
|
+
FloatingFocusManager as FloatingFocusManager5,
|
|
2299
|
+
FloatingPortal as FloatingPortal6,
|
|
2300
|
+
autoUpdate as autoUpdate5,
|
|
2301
|
+
flip as flip5,
|
|
2302
|
+
offset as offset5,
|
|
2303
|
+
shift as shift5,
|
|
2304
|
+
useDismiss as useDismiss6,
|
|
2305
|
+
useFloating as useFloating6,
|
|
2306
|
+
useInteractions as useInteractions6,
|
|
2307
|
+
useRole as useRole6
|
|
2308
|
+
} from "@floating-ui/react";
|
|
2309
|
+
|
|
2310
|
+
// src/components/DateRangePicker/DateRangePicker.css.ts
|
|
2311
|
+
var dateInput2 = "DateRangePicker_dateInput__11t25r41";
|
|
2312
|
+
var iconButton3 = "DateRangePicker_iconButton__11t25r43";
|
|
2313
|
+
var popover3 = "DateRangePicker_popover__11t25r44";
|
|
2314
|
+
var separator2 = "DateRangePicker_separator__11t25r42";
|
|
2315
|
+
var wrapper7 = "DateRangePicker_wrapper__11t25r40";
|
|
2316
|
+
|
|
2317
|
+
// src/components/DateRangePicker/DateRangePicker.tsx
|
|
2318
|
+
import { jsx as jsx37, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
2319
|
+
function startOfMonth3(date) {
|
|
2320
|
+
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
2321
|
+
}
|
|
2322
|
+
function clampToMidnight3(date) {
|
|
2323
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
2324
|
+
}
|
|
2325
|
+
function compareDates(a, b) {
|
|
2326
|
+
const x = clampToMidnight3(a).getTime();
|
|
2327
|
+
const y = clampToMidnight3(b).getTime();
|
|
2328
|
+
if (x < y) return -1;
|
|
2329
|
+
if (x > y) return 1;
|
|
2330
|
+
return 0;
|
|
2331
|
+
}
|
|
2332
|
+
function isDisabled2(date, minDate, maxDate, isDateDisabled) {
|
|
2333
|
+
const target = clampToMidnight3(date);
|
|
2334
|
+
if (minDate && target < clampToMidnight3(minDate)) return true;
|
|
2335
|
+
if (maxDate && target > clampToMidnight3(maxDate)) return true;
|
|
2336
|
+
if (isDateDisabled?.(target)) return true;
|
|
2337
|
+
return false;
|
|
2338
|
+
}
|
|
2339
|
+
function getDatePartOrder2(locale) {
|
|
2340
|
+
const parts = new Intl.DateTimeFormat(locale).formatToParts(
|
|
2341
|
+
new Date(2e3, 0, 2)
|
|
2342
|
+
);
|
|
2343
|
+
return parts.filter(
|
|
2344
|
+
(part) => part.type === "month" || part.type === "day" || part.type === "year"
|
|
2345
|
+
).map((part) => part.type);
|
|
2346
|
+
}
|
|
2347
|
+
function getDatePlaceholder2(locale) {
|
|
2348
|
+
const parts = new Intl.DateTimeFormat(locale).formatToParts(
|
|
2349
|
+
new Date(2e3, 0, 2)
|
|
2350
|
+
);
|
|
2351
|
+
return parts.map((part) => {
|
|
2352
|
+
switch (part.type) {
|
|
2353
|
+
case "month":
|
|
2354
|
+
return "MM";
|
|
2355
|
+
case "day":
|
|
2356
|
+
return "DD";
|
|
2357
|
+
case "year":
|
|
2358
|
+
return "YYYY";
|
|
2359
|
+
default:
|
|
2360
|
+
return part.value;
|
|
2361
|
+
}
|
|
2362
|
+
}).join("");
|
|
2363
|
+
}
|
|
2364
|
+
function formatDate2(date, locale) {
|
|
2365
|
+
return new Intl.DateTimeFormat(locale).format(date);
|
|
2366
|
+
}
|
|
2367
|
+
function parseDate2(text, locale) {
|
|
2368
|
+
const numbers = text.match(/\d+/g);
|
|
2369
|
+
if (!numbers || numbers.length < 3) return null;
|
|
2370
|
+
const order = getDatePartOrder2(locale);
|
|
2371
|
+
if (order.length < 3) return null;
|
|
2372
|
+
const values = {};
|
|
2373
|
+
order.forEach((type, i) => {
|
|
2374
|
+
values[type] = Number.parseInt(numbers[i], 10);
|
|
2375
|
+
});
|
|
2376
|
+
const { month, day, year } = values;
|
|
2377
|
+
if (!month || !day || !year) return null;
|
|
2378
|
+
const fullYear = year < 100 ? 2e3 + year : year;
|
|
2379
|
+
const date = new Date(fullYear, month - 1, day);
|
|
2380
|
+
if (date.getFullYear() !== fullYear || date.getMonth() !== month - 1 || date.getDate() !== day) {
|
|
2381
|
+
return null;
|
|
2382
|
+
}
|
|
2383
|
+
return date;
|
|
2384
|
+
}
|
|
2385
|
+
var EMPTY_RANGE = { start: null, end: null };
|
|
2386
|
+
function DateRangePicker({
|
|
2387
|
+
value: controlledValue,
|
|
2388
|
+
defaultValue = EMPTY_RANGE,
|
|
2389
|
+
onChange,
|
|
2390
|
+
minDate,
|
|
2391
|
+
maxDate,
|
|
2392
|
+
isDateDisabled,
|
|
2393
|
+
weekStartsOn = 1,
|
|
2394
|
+
locale = "en-US",
|
|
2395
|
+
startPlaceholder,
|
|
2396
|
+
endPlaceholder,
|
|
2397
|
+
disabled = false,
|
|
2398
|
+
open: controlledOpen,
|
|
2399
|
+
onOpenChange
|
|
2400
|
+
}) {
|
|
2401
|
+
const [uncontrolledValue, setUncontrolledValue] = useState11(defaultValue);
|
|
2402
|
+
const value = controlledValue !== void 0 ? controlledValue : uncontrolledValue;
|
|
2403
|
+
const setValue = (next) => {
|
|
2404
|
+
if (controlledValue === void 0) {
|
|
2405
|
+
setUncontrolledValue(next);
|
|
2406
|
+
}
|
|
2407
|
+
onChange?.(next);
|
|
2408
|
+
};
|
|
2409
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState11(false);
|
|
2410
|
+
const open = controlledOpen ?? uncontrolledOpen;
|
|
2411
|
+
const setOpen = onOpenChange ?? setUncontrolledOpen;
|
|
2412
|
+
const [month, setMonth] = useState11(
|
|
2413
|
+
() => startOfMonth3(value.start ?? /* @__PURE__ */ new Date())
|
|
2414
|
+
);
|
|
2415
|
+
const [startText, setStartText] = useState11(
|
|
2416
|
+
() => value.start ? formatDate2(value.start, locale) : ""
|
|
2417
|
+
);
|
|
2418
|
+
const [endText, setEndText] = useState11(
|
|
2419
|
+
() => value.end ? formatDate2(value.end, locale) : ""
|
|
2420
|
+
);
|
|
2421
|
+
useEffect4(() => {
|
|
2422
|
+
setStartText(value.start ? formatDate2(value.start, locale) : "");
|
|
2423
|
+
}, [value.start, locale]);
|
|
2424
|
+
useEffect4(() => {
|
|
2425
|
+
setEndText(value.end ? formatDate2(value.end, locale) : "");
|
|
2426
|
+
}, [value.end, locale]);
|
|
2427
|
+
useEffect4(() => {
|
|
2428
|
+
if (open && value.start) {
|
|
2429
|
+
setMonth(startOfMonth3(value.start));
|
|
2430
|
+
}
|
|
2431
|
+
}, [open]);
|
|
2432
|
+
const { refs, floatingStyles, context } = useFloating6({
|
|
2433
|
+
open,
|
|
2434
|
+
onOpenChange: setOpen,
|
|
2435
|
+
placement: "bottom-start",
|
|
2436
|
+
whileElementsMounted: autoUpdate5,
|
|
2437
|
+
middleware: [offset5(8), flip5(), shift5({ padding: 8 })]
|
|
2438
|
+
});
|
|
2439
|
+
const { getReferenceProps, getFloatingProps } = useInteractions6([
|
|
2440
|
+
useDismiss6(context),
|
|
2441
|
+
useRole6(context, { role: "dialog" })
|
|
2442
|
+
]);
|
|
2443
|
+
const revertStartText = () => {
|
|
2444
|
+
setStartText(value.start ? formatDate2(value.start, locale) : "");
|
|
2445
|
+
};
|
|
2446
|
+
const revertEndText = () => {
|
|
2447
|
+
setEndText(value.end ? formatDate2(value.end, locale) : "");
|
|
2448
|
+
};
|
|
2449
|
+
const commitStartText = () => {
|
|
2450
|
+
const trimmed = startText.trim();
|
|
2451
|
+
if (!trimmed) {
|
|
2452
|
+
if (value.start !== null) {
|
|
2453
|
+
setValue({ start: null, end: value.end });
|
|
2454
|
+
}
|
|
2455
|
+
return;
|
|
2456
|
+
}
|
|
2457
|
+
const parsed = parseDate2(trimmed, locale);
|
|
2458
|
+
if (!parsed || isDisabled2(parsed, minDate, maxDate, isDateDisabled) || value.end && compareDates(parsed, value.end) > 0) {
|
|
2459
|
+
revertStartText();
|
|
2460
|
+
return;
|
|
2461
|
+
}
|
|
2462
|
+
setValue({ start: parsed, end: value.end });
|
|
2463
|
+
setMonth(startOfMonth3(parsed));
|
|
2464
|
+
};
|
|
2465
|
+
const commitEndText = () => {
|
|
2466
|
+
const trimmed = endText.trim();
|
|
2467
|
+
if (!trimmed) {
|
|
2468
|
+
if (value.end !== null) {
|
|
2469
|
+
setValue({ start: value.start, end: null });
|
|
2470
|
+
}
|
|
2471
|
+
return;
|
|
2472
|
+
}
|
|
2473
|
+
const parsed = parseDate2(trimmed, locale);
|
|
2474
|
+
if (!parsed || isDisabled2(parsed, minDate, maxDate, isDateDisabled) || value.start && compareDates(parsed, value.start) < 0) {
|
|
2475
|
+
revertEndText();
|
|
2476
|
+
return;
|
|
2477
|
+
}
|
|
2478
|
+
setValue({ start: value.start, end: parsed });
|
|
2479
|
+
setMonth(startOfMonth3(parsed));
|
|
2480
|
+
};
|
|
2481
|
+
const handleStartKeyDown = (event) => {
|
|
2482
|
+
if (event.key === "Enter") {
|
|
2483
|
+
event.preventDefault();
|
|
2484
|
+
commitStartText();
|
|
2485
|
+
}
|
|
2486
|
+
};
|
|
2487
|
+
const handleEndKeyDown = (event) => {
|
|
2488
|
+
if (event.key === "Enter") {
|
|
2489
|
+
event.preventDefault();
|
|
2490
|
+
commitEndText();
|
|
2491
|
+
}
|
|
2492
|
+
};
|
|
2493
|
+
const handleCalendarChange = (date) => {
|
|
2494
|
+
const { start, end } = value;
|
|
2495
|
+
if (!start || start && end) {
|
|
2496
|
+
setValue({ start: date, end: null });
|
|
2497
|
+
setMonth(startOfMonth3(date));
|
|
2498
|
+
return;
|
|
2499
|
+
}
|
|
2500
|
+
if (compareDates(date, start) < 0) {
|
|
2501
|
+
setValue({ start: date, end: start });
|
|
2502
|
+
} else {
|
|
2503
|
+
setValue({ start, end: date });
|
|
2504
|
+
}
|
|
2505
|
+
setOpen(false);
|
|
2506
|
+
};
|
|
2507
|
+
const startPlaceholderText = startPlaceholder ?? getDatePlaceholder2(locale);
|
|
2508
|
+
const endPlaceholderText = endPlaceholder ?? getDatePlaceholder2(locale);
|
|
2509
|
+
return /* @__PURE__ */ jsxs20(
|
|
2510
|
+
"div",
|
|
2511
|
+
{
|
|
2512
|
+
className: wrapper7,
|
|
2513
|
+
"data-disabled": disabled || void 0,
|
|
2514
|
+
ref: refs.setReference,
|
|
2515
|
+
children: [
|
|
2516
|
+
/* @__PURE__ */ jsx37(
|
|
2517
|
+
"input",
|
|
2518
|
+
{
|
|
2519
|
+
type: "text",
|
|
2520
|
+
className: dateInput2,
|
|
2521
|
+
value: startText,
|
|
2522
|
+
placeholder: startPlaceholderText,
|
|
2523
|
+
disabled,
|
|
2524
|
+
onChange: (e) => setStartText(e.target.value),
|
|
2525
|
+
onBlur: commitStartText,
|
|
2526
|
+
onKeyDown: handleStartKeyDown,
|
|
2527
|
+
"aria-label": "Start date"
|
|
2528
|
+
}
|
|
2529
|
+
),
|
|
2530
|
+
/* @__PURE__ */ jsx37("span", { className: separator2, "aria-hidden": "true", children: "\u2013" }),
|
|
2531
|
+
/* @__PURE__ */ jsx37(
|
|
2532
|
+
"input",
|
|
2533
|
+
{
|
|
2534
|
+
type: "text",
|
|
2535
|
+
className: dateInput2,
|
|
2536
|
+
value: endText,
|
|
2537
|
+
placeholder: endPlaceholderText,
|
|
2538
|
+
disabled,
|
|
2539
|
+
onChange: (e) => setEndText(e.target.value),
|
|
2540
|
+
onBlur: commitEndText,
|
|
2541
|
+
onKeyDown: handleEndKeyDown,
|
|
2542
|
+
"aria-label": "End date"
|
|
2543
|
+
}
|
|
2544
|
+
),
|
|
2545
|
+
/* @__PURE__ */ jsx37(
|
|
2546
|
+
"button",
|
|
2547
|
+
{
|
|
2548
|
+
type: "button",
|
|
2549
|
+
className: iconButton3,
|
|
2550
|
+
disabled,
|
|
2551
|
+
"aria-label": open ? "Close calendar" : "Open calendar",
|
|
2552
|
+
...getReferenceProps({
|
|
2553
|
+
onClick: () => {
|
|
2554
|
+
if (disabled) return;
|
|
2555
|
+
setOpen(!open);
|
|
2556
|
+
}
|
|
2557
|
+
}),
|
|
2558
|
+
children: /* @__PURE__ */ jsxs20(
|
|
2559
|
+
"svg",
|
|
2560
|
+
{
|
|
2561
|
+
width: "16",
|
|
2562
|
+
height: "16",
|
|
2563
|
+
viewBox: "0 0 16 16",
|
|
2564
|
+
fill: "none",
|
|
2565
|
+
"aria-hidden": "true",
|
|
2566
|
+
children: [
|
|
2567
|
+
/* @__PURE__ */ jsx37(
|
|
2568
|
+
"rect",
|
|
2569
|
+
{
|
|
2570
|
+
x: "1.5",
|
|
2571
|
+
y: "2.5",
|
|
2572
|
+
width: "13",
|
|
2573
|
+
height: "12",
|
|
2574
|
+
rx: "1.5",
|
|
2575
|
+
stroke: "currentColor",
|
|
2576
|
+
strokeWidth: "1.3"
|
|
2577
|
+
}
|
|
2578
|
+
),
|
|
2579
|
+
/* @__PURE__ */ jsx37("path", { d: "M1.5 6h13", stroke: "currentColor", strokeWidth: "1.3" }),
|
|
2580
|
+
/* @__PURE__ */ jsx37(
|
|
2581
|
+
"path",
|
|
2582
|
+
{
|
|
2583
|
+
d: "M4.5 1v3M11.5 1v3",
|
|
2584
|
+
stroke: "currentColor",
|
|
2585
|
+
strokeWidth: "1.3",
|
|
2586
|
+
strokeLinecap: "round"
|
|
2587
|
+
}
|
|
2588
|
+
)
|
|
2589
|
+
]
|
|
2590
|
+
}
|
|
2591
|
+
)
|
|
2592
|
+
}
|
|
2593
|
+
),
|
|
2594
|
+
open ? /* @__PURE__ */ jsx37(FloatingPortal6, { children: /* @__PURE__ */ jsx37(FloatingFocusManager5, { context, modal: false, children: /* @__PURE__ */ jsx37(
|
|
2595
|
+
"div",
|
|
2596
|
+
{
|
|
2597
|
+
ref: refs.setFloating,
|
|
2598
|
+
className: popover3,
|
|
2599
|
+
style: floatingStyles,
|
|
2600
|
+
...getFloatingProps(),
|
|
2601
|
+
children: /* @__PURE__ */ jsx37(
|
|
2602
|
+
Calendar,
|
|
2603
|
+
{
|
|
2604
|
+
value: value.start,
|
|
2605
|
+
rangeEnd: value.end,
|
|
2606
|
+
onChange: handleCalendarChange,
|
|
2607
|
+
month,
|
|
2608
|
+
onMonthChange: setMonth,
|
|
2609
|
+
minDate,
|
|
2610
|
+
maxDate,
|
|
2611
|
+
isDateDisabled,
|
|
2612
|
+
weekStartsOn,
|
|
2613
|
+
locale
|
|
2614
|
+
}
|
|
2615
|
+
)
|
|
2616
|
+
}
|
|
2617
|
+
) }) }) : null
|
|
2618
|
+
]
|
|
2619
|
+
}
|
|
2620
|
+
);
|
|
2621
|
+
}
|
|
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
|
+
...rest
|
|
2658
|
+
}, ref) {
|
|
2659
|
+
const [uncontrolledValue, setUncontrolledValue] = useState12(defaultValue);
|
|
2660
|
+
const value = controlledValue !== void 0 ? controlledValue : uncontrolledValue;
|
|
2661
|
+
const setValue = (next) => {
|
|
2662
|
+
if (controlledValue === void 0) {
|
|
2663
|
+
setUncontrolledValue(next);
|
|
2664
|
+
}
|
|
2665
|
+
onChange?.(next);
|
|
2666
|
+
};
|
|
2667
|
+
const [inputText, setInputText] = useState12(() => formatValue(value));
|
|
2668
|
+
useEffect5(() => {
|
|
2669
|
+
setInputText(formatValue(value));
|
|
2670
|
+
}, [value]);
|
|
2671
|
+
const inputRef = useRef6(null);
|
|
2672
|
+
const mergedRef = useMergeRefs5([inputRef, ref]);
|
|
2673
|
+
const commitTypedValue = () => {
|
|
2674
|
+
const trimmed = inputText.trim();
|
|
2675
|
+
if (!trimmed) {
|
|
2676
|
+
if (value !== null) setValue(null);
|
|
2677
|
+
return;
|
|
2678
|
+
}
|
|
2679
|
+
const parsed = Number(trimmed);
|
|
2680
|
+
if (Number.isNaN(parsed)) {
|
|
2681
|
+
setInputText(formatValue(value));
|
|
2682
|
+
return;
|
|
2683
|
+
}
|
|
2684
|
+
const clamped = clamp(parsed, min, max);
|
|
2685
|
+
setValue(clamped);
|
|
2686
|
+
setInputText(formatValue(clamped));
|
|
2687
|
+
};
|
|
2688
|
+
const step2 = (direction2) => {
|
|
2689
|
+
if (disabled) return;
|
|
2690
|
+
const base2 = value ?? min ?? 0;
|
|
2691
|
+
const next = clamp(base2 + direction2 * step, min, max);
|
|
2692
|
+
setValue(next);
|
|
2693
|
+
setInputText(formatValue(next));
|
|
2694
|
+
inputRef.current?.focus();
|
|
2695
|
+
};
|
|
2696
|
+
const handleKeyDown = (event) => {
|
|
2697
|
+
if (event.key === "Enter") {
|
|
2698
|
+
event.preventDefault();
|
|
2699
|
+
commitTypedValue();
|
|
2700
|
+
return;
|
|
2701
|
+
}
|
|
2702
|
+
if (event.key === "ArrowUp") {
|
|
2703
|
+
event.preventDefault();
|
|
2704
|
+
step2(1);
|
|
2705
|
+
return;
|
|
2706
|
+
}
|
|
2707
|
+
if (event.key === "ArrowDown") {
|
|
2708
|
+
event.preventDefault();
|
|
2709
|
+
step2(-1);
|
|
2710
|
+
return;
|
|
2711
|
+
}
|
|
2712
|
+
if (event.key === "Home" && min !== void 0) {
|
|
2713
|
+
event.preventDefault();
|
|
2714
|
+
setValue(min);
|
|
2715
|
+
setInputText(formatValue(min));
|
|
2716
|
+
return;
|
|
2717
|
+
}
|
|
2718
|
+
if (event.key === "End" && max !== void 0) {
|
|
2719
|
+
event.preventDefault();
|
|
2720
|
+
setValue(max);
|
|
2721
|
+
setInputText(formatValue(max));
|
|
2722
|
+
}
|
|
2723
|
+
};
|
|
2724
|
+
const handleBlur = (_event) => {
|
|
2725
|
+
commitTypedValue();
|
|
2726
|
+
};
|
|
2727
|
+
const classes = [wrapper8, className].filter(Boolean).join(" ");
|
|
2728
|
+
return /* @__PURE__ */ jsxs21("span", { className: classes, "data-disabled": disabled || void 0, children: [
|
|
2729
|
+
/* @__PURE__ */ jsx38(
|
|
2730
|
+
"input",
|
|
2731
|
+
{
|
|
2732
|
+
ref: mergedRef,
|
|
2733
|
+
id,
|
|
2734
|
+
name,
|
|
2735
|
+
type: "text",
|
|
2736
|
+
inputMode: "decimal",
|
|
2737
|
+
className: input2,
|
|
2738
|
+
value: inputText,
|
|
2739
|
+
placeholder,
|
|
2740
|
+
disabled,
|
|
2741
|
+
role: "spinbutton",
|
|
2742
|
+
"aria-valuenow": value ?? void 0,
|
|
2743
|
+
"aria-valuemin": min,
|
|
2744
|
+
"aria-valuemax": max,
|
|
2745
|
+
"aria-invalid": invalid || void 0,
|
|
2746
|
+
onChange: (e) => setInputText(e.target.value),
|
|
2747
|
+
onBlur: handleBlur,
|
|
2748
|
+
onKeyDown: handleKeyDown,
|
|
2749
|
+
...rest
|
|
2750
|
+
}
|
|
2751
|
+
),
|
|
2752
|
+
/* @__PURE__ */ jsxs21("span", { className: stepperGroup, children: [
|
|
2753
|
+
/* @__PURE__ */ jsx38(
|
|
2754
|
+
"button",
|
|
2755
|
+
{
|
|
2756
|
+
type: "button",
|
|
2757
|
+
tabIndex: -1,
|
|
2758
|
+
className: stepButton,
|
|
2759
|
+
disabled: disabled || max !== void 0 && value !== null && value >= max,
|
|
2760
|
+
"aria-label": "Increment",
|
|
2761
|
+
onClick: () => step2(1),
|
|
2762
|
+
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" }) })
|
|
2763
|
+
}
|
|
2764
|
+
),
|
|
2765
|
+
/* @__PURE__ */ jsx38(
|
|
2766
|
+
"button",
|
|
2767
|
+
{
|
|
2768
|
+
type: "button",
|
|
2769
|
+
tabIndex: -1,
|
|
2770
|
+
className: stepButton,
|
|
2771
|
+
disabled: disabled || min !== void 0 && value !== null && value <= min,
|
|
2772
|
+
"aria-label": "Decrement",
|
|
2773
|
+
onClick: () => step2(-1),
|
|
2774
|
+
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" }) })
|
|
2775
|
+
}
|
|
2776
|
+
)
|
|
2777
|
+
] })
|
|
2778
|
+
] });
|
|
2779
|
+
});
|
|
2780
|
+
|
|
2781
|
+
// src/components/Slider/Slider.tsx
|
|
2782
|
+
import { useRef as useRef7, useState as useState13 } from "react";
|
|
2783
|
+
|
|
2784
|
+
// src/components/Slider/Slider.css.ts
|
|
2785
|
+
var range2 = "Slider_range__2gl56i2";
|
|
2786
|
+
var root3 = "Slider_root__2gl56i0";
|
|
2787
|
+
var thumb = "Slider_thumb__2gl56i3";
|
|
2788
|
+
var track3 = "Slider_track__2gl56i1";
|
|
2789
|
+
|
|
2790
|
+
// src/components/Slider/Slider.tsx
|
|
2791
|
+
import { jsx as jsx39, jsxs as jsxs22 } from "react/jsx-runtime";
|
|
2792
|
+
function isRange(value) {
|
|
2793
|
+
return Array.isArray(value);
|
|
2794
|
+
}
|
|
2795
|
+
function clampToStep(raw, min, max, step) {
|
|
2796
|
+
const stepped = Math.round((raw - min) / step) * step + min;
|
|
2797
|
+
return Math.min(max, Math.max(min, Math.round(stepped * 1e6) / 1e6));
|
|
2798
|
+
}
|
|
2799
|
+
function percentOf(value, min, max) {
|
|
2800
|
+
if (max === min) return 0;
|
|
2801
|
+
return (value - min) / (max - min) * 100;
|
|
2802
|
+
}
|
|
2803
|
+
function Slider({
|
|
2804
|
+
value: controlledValue,
|
|
2805
|
+
defaultValue = 0,
|
|
2806
|
+
onChange,
|
|
2807
|
+
min = 0,
|
|
2808
|
+
max = 100,
|
|
2809
|
+
step = 1,
|
|
2810
|
+
disabled = false,
|
|
2811
|
+
className,
|
|
2812
|
+
formatValue: formatValue2 = (v) => String(v),
|
|
2813
|
+
...rest
|
|
2814
|
+
}) {
|
|
2815
|
+
const ariaLabel = rest["aria-label"];
|
|
2816
|
+
const [uncontrolledValue, setUncontrolledValue] = useState13(defaultValue);
|
|
2817
|
+
const value = controlledValue !== void 0 ? controlledValue : uncontrolledValue;
|
|
2818
|
+
const setValue = (next) => {
|
|
2819
|
+
if (controlledValue === void 0) {
|
|
2820
|
+
setUncontrolledValue(next);
|
|
2821
|
+
}
|
|
2822
|
+
onChange?.(next);
|
|
2823
|
+
};
|
|
2824
|
+
const trackRef = useRef7(null);
|
|
2825
|
+
const dragThumbIndex = useRef7(null);
|
|
2826
|
+
const isDragging = useRef7(false);
|
|
2827
|
+
const valueFromClientX = (clientX) => {
|
|
2828
|
+
const trackEl = trackRef.current;
|
|
2829
|
+
if (!trackEl) return min;
|
|
2830
|
+
const rect = trackEl.getBoundingClientRect();
|
|
2831
|
+
const ratio = rect.width === 0 ? 0 : (clientX - rect.left) / rect.width;
|
|
2832
|
+
return clampToStep(min + ratio * (max - min), min, max, step);
|
|
2833
|
+
};
|
|
2834
|
+
const setThumbValue = (index, raw) => {
|
|
2835
|
+
if (index === null) {
|
|
2836
|
+
setValue(clampToStep(raw, min, max, step));
|
|
2837
|
+
return;
|
|
2838
|
+
}
|
|
2839
|
+
if (!isRange(value)) return;
|
|
2840
|
+
const [start, end] = value;
|
|
2841
|
+
if (index === 0) {
|
|
2842
|
+
setValue([Math.min(raw, end), end]);
|
|
2843
|
+
} else {
|
|
2844
|
+
setValue([start, Math.max(raw, start)]);
|
|
2845
|
+
}
|
|
2846
|
+
};
|
|
2847
|
+
const handlePointerMove = (event) => {
|
|
2848
|
+
if (!isDragging.current) return;
|
|
2849
|
+
setThumbValue(dragThumbIndex.current, valueFromClientX(event.clientX));
|
|
2850
|
+
};
|
|
2851
|
+
const handlePointerUp = () => {
|
|
2852
|
+
isDragging.current = false;
|
|
2853
|
+
dragThumbIndex.current = null;
|
|
2854
|
+
window.removeEventListener("pointermove", handlePointerMove);
|
|
2855
|
+
window.removeEventListener("pointerup", handlePointerUp);
|
|
2856
|
+
};
|
|
2857
|
+
const startDrag = (index) => (event) => {
|
|
2858
|
+
if (disabled) return;
|
|
2859
|
+
event.preventDefault();
|
|
2860
|
+
isDragging.current = true;
|
|
2861
|
+
dragThumbIndex.current = index;
|
|
2862
|
+
setThumbValue(index, valueFromClientX(event.clientX));
|
|
2863
|
+
window.addEventListener("pointermove", handlePointerMove);
|
|
2864
|
+
window.addEventListener("pointerup", handlePointerUp);
|
|
2865
|
+
};
|
|
2866
|
+
const handleTrackPointerDown = (event) => {
|
|
2867
|
+
if (disabled) return;
|
|
2868
|
+
if (!isRange(value)) {
|
|
2869
|
+
startDrag(null)(event);
|
|
2870
|
+
return;
|
|
2871
|
+
}
|
|
2872
|
+
const target = valueFromClientX(event.clientX);
|
|
2873
|
+
const [start, end] = value;
|
|
2874
|
+
const nearestIndex = Math.abs(target - start) <= Math.abs(target - end) ? 0 : 1;
|
|
2875
|
+
startDrag(nearestIndex)(event);
|
|
2876
|
+
};
|
|
2877
|
+
const handleThumbKeyDown = (index) => (event) => {
|
|
2878
|
+
if (disabled) return;
|
|
2879
|
+
const current2 = index === null ? value : value[index];
|
|
2880
|
+
let next = null;
|
|
2881
|
+
switch (event.key) {
|
|
2882
|
+
case "ArrowRight":
|
|
2883
|
+
case "ArrowUp":
|
|
2884
|
+
next = clampToStep(current2 + step, min, max, step);
|
|
2885
|
+
break;
|
|
2886
|
+
case "ArrowLeft":
|
|
2887
|
+
case "ArrowDown":
|
|
2888
|
+
next = clampToStep(current2 - step, min, max, step);
|
|
2889
|
+
break;
|
|
2890
|
+
case "Home":
|
|
2891
|
+
next = min;
|
|
2892
|
+
break;
|
|
2893
|
+
case "End":
|
|
2894
|
+
next = max;
|
|
2895
|
+
break;
|
|
2896
|
+
case "PageUp":
|
|
2897
|
+
next = clampToStep(current2 + step * 10, min, max, step);
|
|
2898
|
+
break;
|
|
2899
|
+
case "PageDown":
|
|
2900
|
+
next = clampToStep(current2 - step * 10, min, max, step);
|
|
2901
|
+
break;
|
|
2902
|
+
default:
|
|
2903
|
+
return;
|
|
2904
|
+
}
|
|
2905
|
+
event.preventDefault();
|
|
2906
|
+
setThumbValue(index, next);
|
|
2907
|
+
};
|
|
2908
|
+
const renderThumb = (index, current2, label3) => /* @__PURE__ */ jsx39(
|
|
2909
|
+
"span",
|
|
2910
|
+
{
|
|
2911
|
+
role: "slider",
|
|
2912
|
+
tabIndex: disabled ? -1 : 0,
|
|
2913
|
+
"aria-label": label3,
|
|
2914
|
+
"aria-valuemin": min,
|
|
2915
|
+
"aria-valuemax": max,
|
|
2916
|
+
"aria-valuenow": current2,
|
|
2917
|
+
"aria-valuetext": formatValue2(current2),
|
|
2918
|
+
"aria-disabled": disabled || void 0,
|
|
2919
|
+
className: thumb,
|
|
2920
|
+
style: { left: `${percentOf(current2, min, max)}%` },
|
|
2921
|
+
onPointerDown: (event) => {
|
|
2922
|
+
event.stopPropagation();
|
|
2923
|
+
startDrag(index)(event);
|
|
2924
|
+
},
|
|
2925
|
+
onKeyDown: handleThumbKeyDown(index)
|
|
2926
|
+
},
|
|
2927
|
+
index ?? "single"
|
|
2928
|
+
);
|
|
2929
|
+
const classes = [root3, className].filter(Boolean).join(" ");
|
|
2930
|
+
return /* @__PURE__ */ jsx39("span", { className: classes, "data-disabled": disabled || void 0, children: /* @__PURE__ */ jsxs22("span", { ref: trackRef, className: track3, onPointerDown: handleTrackPointerDown, children: [
|
|
2931
|
+
isRange(value) ? /* @__PURE__ */ jsx39(
|
|
2932
|
+
"span",
|
|
2933
|
+
{
|
|
2934
|
+
className: range2,
|
|
2935
|
+
style: {
|
|
2936
|
+
left: `${percentOf(value[0], min, max)}%`,
|
|
2937
|
+
right: `${100 - percentOf(value[1], min, max)}%`
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
) : /* @__PURE__ */ jsx39("span", { className: range2, style: { left: 0, right: `${100 - percentOf(value, min, max)}%` } }),
|
|
2941
|
+
isRange(value) ? [
|
|
2942
|
+
renderThumb(0, value[0], Array.isArray(ariaLabel) ? ariaLabel[0] : ariaLabel),
|
|
2943
|
+
renderThumb(1, value[1], Array.isArray(ariaLabel) ? ariaLabel[1] : ariaLabel)
|
|
2944
|
+
] : renderThumb(null, value, typeof ariaLabel === "string" ? ariaLabel : void 0)
|
|
2945
|
+
] }) });
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2948
|
+
// src/components/Combobox/Combobox.tsx
|
|
2949
|
+
import { useEffect as useEffect6, useId as useId2, useRef as useRef8, useState as useState14 } from "react";
|
|
2950
|
+
import {
|
|
2951
|
+
FloatingPortal as FloatingPortal7,
|
|
2952
|
+
autoUpdate as autoUpdate6,
|
|
2953
|
+
flip as flip6,
|
|
2954
|
+
offset as offset6,
|
|
2955
|
+
shift as shift6,
|
|
2956
|
+
useDismiss as useDismiss7,
|
|
2957
|
+
useFloating as useFloating7,
|
|
2958
|
+
useInteractions as useInteractions7,
|
|
2959
|
+
useRole as useRole7
|
|
2960
|
+
} from "@floating-ui/react";
|
|
2961
|
+
|
|
2962
|
+
// src/components/Combobox/Combobox.css.ts
|
|
2963
|
+
var chip = "Combobox_chip__26nhic2";
|
|
2964
|
+
var chipRemove = "Combobox_chipRemove__26nhic3";
|
|
2965
|
+
var chipsWrapper = "Combobox_chipsWrapper__26nhic1";
|
|
2966
|
+
var emptyState2 = "Combobox_emptyState__26nhic7";
|
|
2967
|
+
var inputEl = "Combobox_inputEl__26nhic4";
|
|
2968
|
+
var listbox = "Combobox_listbox__26nhic5";
|
|
2969
|
+
var option = "Combobox_option__26nhic6";
|
|
2970
|
+
var wrapper9 = "Combobox_wrapper__26nhic0";
|
|
2971
|
+
|
|
2972
|
+
// src/components/Combobox/Combobox.tsx
|
|
2973
|
+
import { jsx as jsx40, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
2974
|
+
function defaultFilter(options, inputText) {
|
|
2975
|
+
const query = inputText.trim().toLowerCase();
|
|
2976
|
+
if (!query) return options;
|
|
2977
|
+
return options.filter((opt) => opt.label.toLowerCase().includes(query));
|
|
2978
|
+
}
|
|
2979
|
+
function labelFor(options, value) {
|
|
2980
|
+
if (!value) return "";
|
|
2981
|
+
return options.find((opt) => opt.value === value)?.label ?? "";
|
|
2982
|
+
}
|
|
2983
|
+
function Combobox({
|
|
2984
|
+
options,
|
|
2985
|
+
multiple = false,
|
|
2986
|
+
value: controlledValue,
|
|
2987
|
+
defaultValue,
|
|
2988
|
+
onChange,
|
|
2989
|
+
onInputChange,
|
|
2990
|
+
filterOptions = defaultFilter,
|
|
2991
|
+
placeholder,
|
|
2992
|
+
noOptionsMessage = "No options",
|
|
2993
|
+
disabled = false,
|
|
2994
|
+
invalid,
|
|
2995
|
+
loading = false,
|
|
2996
|
+
id,
|
|
2997
|
+
className,
|
|
2998
|
+
...rest
|
|
2999
|
+
}) {
|
|
3000
|
+
const fallbackDefault = multiple ? [] : null;
|
|
3001
|
+
const [uncontrolledValue, setUncontrolledValue] = useState14(
|
|
3002
|
+
defaultValue !== void 0 ? defaultValue : fallbackDefault
|
|
3003
|
+
);
|
|
3004
|
+
const value = controlledValue !== void 0 ? controlledValue : uncontrolledValue;
|
|
3005
|
+
const setValue = (next) => {
|
|
3006
|
+
if (controlledValue === void 0) {
|
|
3007
|
+
setUncontrolledValue(next);
|
|
3008
|
+
}
|
|
3009
|
+
onChange?.(next);
|
|
3010
|
+
};
|
|
3011
|
+
const selectedValues = multiple ? value ?? [] : [];
|
|
3012
|
+
const singleValue = multiple ? null : value;
|
|
3013
|
+
const [open, setOpen] = useState14(false);
|
|
3014
|
+
const [inputText, setInputText] = useState14(() => multiple ? "" : labelFor(options, singleValue));
|
|
3015
|
+
const [activeIndex, setActiveIndex] = useState14(null);
|
|
3016
|
+
useEffect6(() => {
|
|
3017
|
+
if (!multiple) {
|
|
3018
|
+
setInputText(labelFor(options, singleValue));
|
|
3019
|
+
}
|
|
3020
|
+
}, [singleValue, multiple]);
|
|
3021
|
+
const inputRef = useRef8(null);
|
|
3022
|
+
const listboxId = useId2();
|
|
3023
|
+
const filteredOptions = filterOptions(options, multiple ? inputText : open ? inputText : "");
|
|
3024
|
+
const { refs, floatingStyles, context } = useFloating7({
|
|
3025
|
+
open,
|
|
3026
|
+
onOpenChange: setOpen,
|
|
3027
|
+
placement: "bottom-start",
|
|
3028
|
+
whileElementsMounted: autoUpdate6,
|
|
3029
|
+
middleware: [offset6(4), flip6(), shift6({ padding: 8 })]
|
|
3030
|
+
});
|
|
3031
|
+
const { getReferenceProps, getFloatingProps } = useInteractions7([
|
|
3032
|
+
useDismiss7(context),
|
|
3033
|
+
useRole7(context, { role: "listbox" })
|
|
3034
|
+
]);
|
|
3035
|
+
const openList = () => {
|
|
3036
|
+
if (disabled) return;
|
|
3037
|
+
setOpen(true);
|
|
3038
|
+
setActiveIndex(null);
|
|
3039
|
+
};
|
|
3040
|
+
const closeList = () => {
|
|
3041
|
+
setOpen(false);
|
|
3042
|
+
setActiveIndex(null);
|
|
3043
|
+
};
|
|
3044
|
+
const selectOption = (opt) => {
|
|
3045
|
+
if (opt.disabled) return;
|
|
3046
|
+
if (multiple) {
|
|
3047
|
+
const next = selectedValues.includes(opt.value) ? selectedValues.filter((v) => v !== opt.value) : [...selectedValues, opt.value];
|
|
3048
|
+
setValue(next);
|
|
3049
|
+
setInputText("");
|
|
3050
|
+
onInputChange?.("");
|
|
3051
|
+
inputRef.current?.focus();
|
|
3052
|
+
return;
|
|
3053
|
+
}
|
|
3054
|
+
setValue(opt.value);
|
|
3055
|
+
setInputText(opt.label);
|
|
3056
|
+
closeList();
|
|
3057
|
+
};
|
|
3058
|
+
const removeChip = (optionValue) => {
|
|
3059
|
+
setValue(selectedValues.filter((v) => v !== optionValue));
|
|
3060
|
+
inputRef.current?.focus();
|
|
3061
|
+
};
|
|
3062
|
+
const handleInputChange = (text) => {
|
|
3063
|
+
setInputText(text);
|
|
3064
|
+
onInputChange?.(text);
|
|
3065
|
+
setOpen(true);
|
|
3066
|
+
setActiveIndex(null);
|
|
3067
|
+
};
|
|
3068
|
+
const moveActiveIndex = (direction2) => {
|
|
3069
|
+
if (filteredOptions.length === 0) return;
|
|
3070
|
+
let next = activeIndex ?? (direction2 === 1 ? -1 : filteredOptions.length);
|
|
3071
|
+
for (let step = 0; step < filteredOptions.length; step++) {
|
|
3072
|
+
next = (next + direction2 + filteredOptions.length) % filteredOptions.length;
|
|
3073
|
+
if (!filteredOptions[next]?.disabled) {
|
|
3074
|
+
setActiveIndex(next);
|
|
3075
|
+
return;
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
};
|
|
3079
|
+
const handleKeyDown = (event) => {
|
|
3080
|
+
if (disabled) return;
|
|
3081
|
+
switch (event.key) {
|
|
3082
|
+
case "ArrowDown":
|
|
3083
|
+
event.preventDefault();
|
|
3084
|
+
if (!open) {
|
|
3085
|
+
openList();
|
|
3086
|
+
} else {
|
|
3087
|
+
moveActiveIndex(1);
|
|
3088
|
+
}
|
|
3089
|
+
return;
|
|
3090
|
+
case "ArrowUp":
|
|
3091
|
+
event.preventDefault();
|
|
3092
|
+
if (open) moveActiveIndex(-1);
|
|
3093
|
+
return;
|
|
3094
|
+
case "Enter": {
|
|
3095
|
+
if (!open) return;
|
|
3096
|
+
event.preventDefault();
|
|
3097
|
+
const active = activeIndex !== null ? filteredOptions[activeIndex] : void 0;
|
|
3098
|
+
if (active) selectOption(active);
|
|
3099
|
+
return;
|
|
3100
|
+
}
|
|
3101
|
+
case "Escape":
|
|
3102
|
+
if (open) {
|
|
3103
|
+
event.preventDefault();
|
|
3104
|
+
closeList();
|
|
3105
|
+
if (!multiple) setInputText(labelFor(options, singleValue));
|
|
3106
|
+
}
|
|
3107
|
+
return;
|
|
3108
|
+
case "Backspace":
|
|
3109
|
+
if (multiple && inputText === "" && selectedValues.length > 0) {
|
|
3110
|
+
removeChip(selectedValues[selectedValues.length - 1]);
|
|
3111
|
+
}
|
|
3112
|
+
return;
|
|
3113
|
+
default:
|
|
3114
|
+
}
|
|
3115
|
+
};
|
|
3116
|
+
const handleBlur = () => {
|
|
3117
|
+
if (!multiple) {
|
|
3118
|
+
setInputText(labelFor(options, singleValue));
|
|
3119
|
+
}
|
|
3120
|
+
closeList();
|
|
3121
|
+
};
|
|
3122
|
+
const classes = [wrapper9, className].filter(Boolean).join(" ");
|
|
3123
|
+
const activeOptionId = activeIndex !== null ? `${listboxId}-option-${activeIndex}` : void 0;
|
|
3124
|
+
return /* @__PURE__ */ jsxs23("span", { className: classes, ref: refs.setReference, "data-disabled": disabled || void 0, children: [
|
|
3125
|
+
multiple && selectedValues.length > 0 ? /* @__PURE__ */ jsx40("span", { className: chipsWrapper, children: selectedValues.map((val) => /* @__PURE__ */ jsxs23("span", { className: chip, children: [
|
|
3126
|
+
labelFor(options, val),
|
|
3127
|
+
/* @__PURE__ */ jsx40(
|
|
3128
|
+
"button",
|
|
3129
|
+
{
|
|
3130
|
+
type: "button",
|
|
3131
|
+
className: chipRemove,
|
|
3132
|
+
"aria-label": `Remove ${labelFor(options, val)}`,
|
|
3133
|
+
disabled,
|
|
3134
|
+
onClick: () => removeChip(val),
|
|
3135
|
+
children: "\xD7"
|
|
3136
|
+
}
|
|
3137
|
+
)
|
|
3138
|
+
] }, val)) }) : null,
|
|
3139
|
+
/* @__PURE__ */ jsx40(
|
|
3140
|
+
"input",
|
|
3141
|
+
{
|
|
3142
|
+
ref: inputRef,
|
|
3143
|
+
id,
|
|
3144
|
+
type: "text",
|
|
3145
|
+
role: "combobox",
|
|
3146
|
+
className: inputEl,
|
|
3147
|
+
value: inputText,
|
|
3148
|
+
placeholder,
|
|
3149
|
+
disabled,
|
|
3150
|
+
autoComplete: "off",
|
|
3151
|
+
"aria-autocomplete": "list",
|
|
3152
|
+
"aria-expanded": open,
|
|
3153
|
+
"aria-controls": listboxId,
|
|
3154
|
+
"aria-invalid": invalid || void 0,
|
|
3155
|
+
"aria-activedescendant": activeOptionId,
|
|
3156
|
+
...getReferenceProps({
|
|
3157
|
+
...rest,
|
|
3158
|
+
onFocus: openList,
|
|
3159
|
+
onBlur: handleBlur,
|
|
3160
|
+
onChange: (e) => handleInputChange(e.target.value),
|
|
3161
|
+
onKeyDown: handleKeyDown
|
|
3162
|
+
})
|
|
3163
|
+
}
|
|
3164
|
+
),
|
|
3165
|
+
open ? /* @__PURE__ */ jsx40(FloatingPortal7, { children: /* @__PURE__ */ jsx40(
|
|
3166
|
+
"div",
|
|
3167
|
+
{
|
|
3168
|
+
ref: refs.setFloating,
|
|
3169
|
+
id: listboxId,
|
|
3170
|
+
role: "listbox",
|
|
3171
|
+
"aria-multiselectable": multiple || void 0,
|
|
3172
|
+
className: listbox,
|
|
3173
|
+
style: floatingStyles,
|
|
3174
|
+
...getFloatingProps(),
|
|
3175
|
+
children: loading ? /* @__PURE__ */ jsx40("div", { className: emptyState2, children: "Loading\u2026" }) : filteredOptions.length === 0 ? /* @__PURE__ */ jsx40("div", { className: emptyState2, children: noOptionsMessage }) : filteredOptions.map((opt, index) => {
|
|
3176
|
+
const isSelected = multiple ? selectedValues.includes(opt.value) : opt.value === singleValue;
|
|
3177
|
+
return /* @__PURE__ */ jsx40(
|
|
3178
|
+
"div",
|
|
3179
|
+
{
|
|
3180
|
+
id: `${listboxId}-option-${index}`,
|
|
3181
|
+
role: "option",
|
|
3182
|
+
"aria-selected": isSelected,
|
|
3183
|
+
"aria-disabled": opt.disabled || void 0,
|
|
3184
|
+
"data-active": activeIndex === index || void 0,
|
|
3185
|
+
className: option,
|
|
3186
|
+
onMouseDown: (event) => {
|
|
3187
|
+
event.preventDefault();
|
|
3188
|
+
selectOption(opt);
|
|
3189
|
+
},
|
|
3190
|
+
onMouseEnter: () => setActiveIndex(index),
|
|
3191
|
+
children: opt.label
|
|
3192
|
+
},
|
|
3193
|
+
opt.value
|
|
3194
|
+
);
|
|
3195
|
+
})
|
|
3196
|
+
}
|
|
3197
|
+
) }) : null
|
|
3198
|
+
] });
|
|
3199
|
+
}
|
|
3200
|
+
|
|
1715
3201
|
// src/index.ts
|
|
1716
3202
|
import { vars as vars2, defaultThemeClass, defaultThemeVars } from "@vesture/tokens";
|
|
1717
3203
|
export {
|
|
@@ -1725,20 +3211,26 @@ export {
|
|
|
1725
3211
|
Breadcrumbs2 as Breadcrumbs,
|
|
1726
3212
|
BreadcrumbsItem,
|
|
1727
3213
|
Button,
|
|
3214
|
+
Calendar,
|
|
1728
3215
|
Card,
|
|
1729
3216
|
Checkbox,
|
|
3217
|
+
Combobox,
|
|
1730
3218
|
DataGrid,
|
|
3219
|
+
DatePicker,
|
|
3220
|
+
DateRangePicker,
|
|
1731
3221
|
Divider,
|
|
1732
3222
|
DropdownMenu2 as DropdownMenu,
|
|
1733
3223
|
DropdownMenuItem,
|
|
1734
3224
|
Input,
|
|
1735
3225
|
Label,
|
|
1736
3226
|
Modal,
|
|
3227
|
+
NumberInput,
|
|
1737
3228
|
Pagination,
|
|
1738
3229
|
Popover,
|
|
1739
3230
|
Progress,
|
|
1740
3231
|
Radio,
|
|
1741
3232
|
Select,
|
|
3233
|
+
Slider,
|
|
1742
3234
|
Spinner,
|
|
1743
3235
|
Stack,
|
|
1744
3236
|
Switch,
|