@rufous/ui 0.2.79 → 0.2.81
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/main.cjs +966 -917
- package/dist/main.css +1 -1
- package/dist/main.js +976 -927
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1742,83 +1742,497 @@ var TextField = forwardRef3(({
|
|
|
1742
1742
|
TextField.displayName = "TextField";
|
|
1743
1743
|
|
|
1744
1744
|
// lib/TextFields/AddressLookup.tsx
|
|
1745
|
-
import
|
|
1745
|
+
import React70, { useState as useState5, useRef as useRef4, useEffect as useEffect5 } from "react";
|
|
1746
1746
|
import Axios from "axios";
|
|
1747
1747
|
import { Country, State, City } from "country-state-city";
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1748
|
+
|
|
1749
|
+
// lib/TextFields/Autocomplete.tsx
|
|
1750
|
+
import React69, {
|
|
1751
|
+
useState as useState4,
|
|
1752
|
+
useRef as useRef3,
|
|
1753
|
+
useEffect as useEffect4,
|
|
1754
|
+
useCallback
|
|
1755
|
+
} from "react";
|
|
1756
|
+
import ReactDOM2 from "react-dom";
|
|
1757
|
+
var ChevronDownIcon = () => /* @__PURE__ */ React69.createElement("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ React69.createElement("polyline", { points: "6 9 12 15 18 9" }));
|
|
1758
|
+
var CloseSmIcon = ({ size = 16 }) => /* @__PURE__ */ React69.createElement("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round" }, /* @__PURE__ */ React69.createElement("line", { x1: "18", y1: "6", x2: "6", y2: "18" }), /* @__PURE__ */ React69.createElement("line", { x1: "6", y1: "6", x2: "18", y2: "18" }));
|
|
1759
|
+
var CheckIcon = () => /* @__PURE__ */ React69.createElement("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ React69.createElement("polyline", { points: "20 6 9 17 4 12" }));
|
|
1760
|
+
function defaultGetLabel(option) {
|
|
1761
|
+
if (option === null || option === void 0) return "";
|
|
1762
|
+
if (typeof option === "string") return option;
|
|
1763
|
+
if (typeof option === "object" && "label" in option)
|
|
1764
|
+
return String(option.label);
|
|
1765
|
+
return String(option);
|
|
1766
|
+
}
|
|
1767
|
+
function defaultFilter(options, inputValue, getLabel) {
|
|
1768
|
+
if (!inputValue) return options;
|
|
1769
|
+
const q = inputValue.toLowerCase();
|
|
1770
|
+
return options.filter((o) => getLabel(o).toLowerCase().includes(q));
|
|
1771
|
+
}
|
|
1772
|
+
function AutocompleteInner(props, _ref) {
|
|
1773
|
+
const {
|
|
1774
|
+
options,
|
|
1775
|
+
value,
|
|
1776
|
+
onChange,
|
|
1777
|
+
inputValue: controlledInput,
|
|
1778
|
+
onInputChange,
|
|
1779
|
+
getOptionLabel = defaultGetLabel,
|
|
1780
|
+
isOptionEqualToValue,
|
|
1781
|
+
groupBy,
|
|
1782
|
+
filterOptions,
|
|
1783
|
+
renderOption,
|
|
1784
|
+
getOptionDisabled,
|
|
1785
|
+
multiple = false,
|
|
1786
|
+
freeSolo = false,
|
|
1787
|
+
clearable = true,
|
|
1788
|
+
loading = false,
|
|
1789
|
+
loadingText = "Loading\u2026",
|
|
1790
|
+
noOptionsText = "No options",
|
|
1791
|
+
limitTags,
|
|
1792
|
+
label,
|
|
1793
|
+
placeholder,
|
|
1794
|
+
variant = "outlined",
|
|
1795
|
+
size = "medium",
|
|
1796
|
+
error = false,
|
|
1797
|
+
helperText,
|
|
1798
|
+
fullWidth = false,
|
|
1799
|
+
disabled = false,
|
|
1800
|
+
required = false,
|
|
1801
|
+
className = "",
|
|
1802
|
+
style,
|
|
1803
|
+
sx,
|
|
1804
|
+
onOpen,
|
|
1805
|
+
onClose
|
|
1806
|
+
} = props;
|
|
1807
|
+
const [open, setOpen] = useState4(false);
|
|
1808
|
+
const [inputStr, setInputStr] = useState4("");
|
|
1809
|
+
const [focusedIdx, setFocusedIdx] = useState4(-1);
|
|
1810
|
+
const [popupStyle, setPopupStyle] = useState4({});
|
|
1765
1811
|
const containerRef = useRef3(null);
|
|
1766
|
-
const
|
|
1767
|
-
const
|
|
1768
|
-
const
|
|
1769
|
-
const
|
|
1812
|
+
const popupRef = useRef3(null);
|
|
1813
|
+
const inputRef = useRef3(null);
|
|
1814
|
+
const listRef = useRef3(null);
|
|
1815
|
+
const inputId = useRef3(`rf-ac-${Math.random().toString(36).slice(2, 9)}`).current;
|
|
1816
|
+
const sxClass = useSx(sx);
|
|
1817
|
+
const calcPopupStyle = useCallback(() => {
|
|
1818
|
+
if (!containerRef.current) return;
|
|
1819
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
1820
|
+
const POPUP_MAX_HEIGHT = 280;
|
|
1821
|
+
const GAP2 = 4;
|
|
1822
|
+
const viewportH = window.innerHeight;
|
|
1823
|
+
const viewportW = window.innerWidth;
|
|
1824
|
+
const spaceBelow = viewportH - rect.bottom - GAP2;
|
|
1825
|
+
const spaceAbove = rect.top - GAP2;
|
|
1826
|
+
const openUpward = spaceBelow < POPUP_MAX_HEIGHT && spaceAbove > spaceBelow;
|
|
1827
|
+
const minLeft = 8;
|
|
1828
|
+
const maxLeft = viewportW - rect.width - 8;
|
|
1829
|
+
const left = Math.min(Math.max(rect.left, minLeft), maxLeft);
|
|
1830
|
+
if (openUpward) {
|
|
1831
|
+
setPopupStyle({
|
|
1832
|
+
bottom: viewportH - rect.top + GAP2,
|
|
1833
|
+
top: "auto",
|
|
1834
|
+
left,
|
|
1835
|
+
width: rect.width
|
|
1836
|
+
});
|
|
1837
|
+
} else {
|
|
1838
|
+
setPopupStyle({
|
|
1839
|
+
top: rect.bottom + GAP2,
|
|
1840
|
+
bottom: "auto",
|
|
1841
|
+
left,
|
|
1842
|
+
width: rect.width
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
}, []);
|
|
1846
|
+
const activeInput = controlledInput !== void 0 ? controlledInput : inputStr;
|
|
1847
|
+
const selectedValues = multiple ? Array.isArray(value) ? value : [] : value != null ? [value] : [];
|
|
1848
|
+
const isEqual = useCallback(
|
|
1849
|
+
(a, b) => isOptionEqualToValue ? isOptionEqualToValue(a, b) : a === b,
|
|
1850
|
+
[isOptionEqualToValue]
|
|
1851
|
+
);
|
|
1852
|
+
const isSelected = useCallback(
|
|
1853
|
+
(opt) => selectedValues.some((v) => isEqual(opt, v)),
|
|
1854
|
+
[selectedValues, isEqual]
|
|
1855
|
+
);
|
|
1856
|
+
const filtered = filterOptions ? filterOptions(options, activeInput) : defaultFilter(options, activeInput, getOptionLabel);
|
|
1857
|
+
const flatEntries = [];
|
|
1858
|
+
if (groupBy) {
|
|
1859
|
+
const groups = {};
|
|
1860
|
+
const order = [];
|
|
1861
|
+
filtered.forEach((opt) => {
|
|
1862
|
+
const g = groupBy(opt);
|
|
1863
|
+
if (!groups[g]) {
|
|
1864
|
+
groups[g] = [];
|
|
1865
|
+
order.push(g);
|
|
1866
|
+
}
|
|
1867
|
+
groups[g].push(opt);
|
|
1868
|
+
});
|
|
1869
|
+
order.forEach((g) => {
|
|
1870
|
+
flatEntries.push({ kind: "group", label: g });
|
|
1871
|
+
groups[g].forEach((opt) => {
|
|
1872
|
+
flatEntries.push({ kind: "option", option: opt, flatIdx: flatEntries.filter((e) => e.kind === "option").length });
|
|
1873
|
+
});
|
|
1874
|
+
});
|
|
1875
|
+
} else {
|
|
1876
|
+
filtered.forEach((opt, i) => flatEntries.push({ kind: "option", option: opt, flatIdx: i }));
|
|
1877
|
+
}
|
|
1878
|
+
const selectableOptions = flatEntries.filter((e) => e.kind === "option");
|
|
1879
|
+
const openPopup = useCallback(() => {
|
|
1880
|
+
if (disabled) return;
|
|
1881
|
+
calcPopupStyle();
|
|
1882
|
+
setOpen(true);
|
|
1883
|
+
setFocusedIdx(-1);
|
|
1884
|
+
onOpen?.();
|
|
1885
|
+
}, [disabled, calcPopupStyle, onOpen]);
|
|
1886
|
+
const closePopup = useCallback((justSelected = false) => {
|
|
1887
|
+
setOpen(false);
|
|
1888
|
+
setFocusedIdx(-1);
|
|
1889
|
+
onClose?.();
|
|
1890
|
+
if (!justSelected && !freeSolo && !multiple && value == null) {
|
|
1891
|
+
setInputStr("");
|
|
1892
|
+
onInputChange?.("");
|
|
1893
|
+
}
|
|
1894
|
+
}, [freeSolo, multiple, value, onInputChange, onClose]);
|
|
1770
1895
|
useEffect4(() => {
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1896
|
+
if (!open) return;
|
|
1897
|
+
const handleOutside = (e) => {
|
|
1898
|
+
const target = e.target;
|
|
1899
|
+
const insideContainer = containerRef.current?.contains(target);
|
|
1900
|
+
const insidePopup = popupRef.current?.contains(target);
|
|
1901
|
+
if (!insideContainer && !insidePopup) {
|
|
1902
|
+
closePopup();
|
|
1774
1903
|
}
|
|
1775
1904
|
};
|
|
1776
|
-
document.addEventListener("mousedown",
|
|
1777
|
-
|
|
1778
|
-
|
|
1905
|
+
document.addEventListener("mousedown", handleOutside);
|
|
1906
|
+
window.addEventListener("scroll", calcPopupStyle, true);
|
|
1907
|
+
window.addEventListener("resize", calcPopupStyle);
|
|
1908
|
+
return () => {
|
|
1909
|
+
document.removeEventListener("mousedown", handleOutside);
|
|
1910
|
+
window.removeEventListener("scroll", calcPopupStyle, true);
|
|
1911
|
+
window.removeEventListener("resize", calcPopupStyle);
|
|
1912
|
+
};
|
|
1913
|
+
}, [open, closePopup, calcPopupStyle]);
|
|
1779
1914
|
useEffect4(() => {
|
|
1780
|
-
if (
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1915
|
+
if (controlledInput !== void 0) return;
|
|
1916
|
+
if (!multiple) {
|
|
1917
|
+
const v = value;
|
|
1918
|
+
setInputStr(v != null ? getOptionLabel(v) : "");
|
|
1919
|
+
}
|
|
1920
|
+
}, [value, multiple, getOptionLabel, controlledInput]);
|
|
1921
|
+
const selectOption = (opt) => {
|
|
1922
|
+
if (getOptionDisabled?.(opt)) return;
|
|
1923
|
+
if (multiple) {
|
|
1924
|
+
const already = isSelected(opt);
|
|
1925
|
+
const next = already ? selectedValues.filter((v) => !isEqual(v, opt)) : [...selectedValues, opt];
|
|
1926
|
+
onChange?.(next);
|
|
1927
|
+
setInputStr("");
|
|
1928
|
+
onInputChange?.("");
|
|
1929
|
+
inputRef.current?.focus();
|
|
1788
1930
|
} else {
|
|
1789
|
-
|
|
1931
|
+
onChange?.(opt);
|
|
1932
|
+
setInputStr(getOptionLabel(opt));
|
|
1933
|
+
onInputChange?.(getOptionLabel(opt));
|
|
1934
|
+
closePopup(true);
|
|
1790
1935
|
}
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1936
|
+
setFocusedIdx(-1);
|
|
1937
|
+
};
|
|
1938
|
+
const clearAll = (e) => {
|
|
1939
|
+
e.stopPropagation();
|
|
1940
|
+
onChange?.(multiple ? [] : null);
|
|
1941
|
+
setInputStr("");
|
|
1942
|
+
onInputChange?.("");
|
|
1943
|
+
inputRef.current?.focus();
|
|
1944
|
+
};
|
|
1945
|
+
const removeTag = (opt, e) => {
|
|
1946
|
+
e.stopPropagation();
|
|
1947
|
+
const next = selectedValues.filter((v) => !isEqual(v, opt));
|
|
1948
|
+
onChange?.(next);
|
|
1949
|
+
};
|
|
1950
|
+
const handleInputChange = (e) => {
|
|
1951
|
+
const v = e.target.value;
|
|
1952
|
+
setInputStr(v);
|
|
1953
|
+
onInputChange?.(v);
|
|
1954
|
+
if (!open) openPopup();
|
|
1955
|
+
};
|
|
1956
|
+
const handleKeyDown = (e) => {
|
|
1957
|
+
if (e.key === "ArrowDown") {
|
|
1958
|
+
e.preventDefault();
|
|
1959
|
+
if (!open) {
|
|
1960
|
+
openPopup();
|
|
1961
|
+
return;
|
|
1805
1962
|
}
|
|
1806
|
-
|
|
1807
|
-
|
|
1963
|
+
setFocusedIdx((i) => {
|
|
1964
|
+
const next = (i + 1) % selectableOptions.length;
|
|
1965
|
+
scrollOptionIntoView(next);
|
|
1966
|
+
return next;
|
|
1967
|
+
});
|
|
1968
|
+
} else if (e.key === "ArrowUp") {
|
|
1969
|
+
e.preventDefault();
|
|
1970
|
+
if (!open) {
|
|
1971
|
+
openPopup();
|
|
1972
|
+
return;
|
|
1973
|
+
}
|
|
1974
|
+
setFocusedIdx((i) => {
|
|
1975
|
+
const next = (i - 1 + selectableOptions.length) % selectableOptions.length;
|
|
1976
|
+
scrollOptionIntoView(next);
|
|
1977
|
+
return next;
|
|
1978
|
+
});
|
|
1979
|
+
} else if (e.key === "Enter") {
|
|
1980
|
+
e.preventDefault();
|
|
1981
|
+
if (!open) {
|
|
1982
|
+
openPopup();
|
|
1983
|
+
return;
|
|
1984
|
+
}
|
|
1985
|
+
if (focusedIdx >= 0 && focusedIdx < selectableOptions.length) {
|
|
1986
|
+
selectOption(selectableOptions[focusedIdx].option);
|
|
1987
|
+
} else if (freeSolo && activeInput) {
|
|
1988
|
+
onChange?.(activeInput);
|
|
1989
|
+
if (!multiple) closePopup();
|
|
1990
|
+
}
|
|
1991
|
+
} else if (e.key === "Escape") {
|
|
1992
|
+
closePopup();
|
|
1993
|
+
} else if (e.key === "Backspace" && multiple && !activeInput && selectedValues.length > 0) {
|
|
1994
|
+
removeTag(selectedValues[selectedValues.length - 1], { stopPropagation: () => {
|
|
1995
|
+
} });
|
|
1808
1996
|
}
|
|
1809
|
-
}
|
|
1810
|
-
const
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1997
|
+
};
|
|
1998
|
+
const scrollOptionIntoView = (idx) => {
|
|
1999
|
+
requestAnimationFrame(() => {
|
|
2000
|
+
const el = listRef.current?.querySelector(`[data-idx="${idx}"]`);
|
|
2001
|
+
el?.scrollIntoView({ block: "nearest" });
|
|
1814
2002
|
});
|
|
1815
2003
|
};
|
|
1816
|
-
const
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
2004
|
+
const hasClearable = clearable && !disabled && (multiple ? selectedValues.length > 0 : value != null);
|
|
2005
|
+
const visibleTags = multiple && limitTags != null ? selectedValues.slice(0, limitTags) : selectedValues;
|
|
2006
|
+
const hiddenCount = multiple && limitTags != null ? Math.max(0, selectedValues.length - limitTags) : 0;
|
|
2007
|
+
const isFloating = Boolean(
|
|
2008
|
+
open || activeInput || (multiple ? selectedValues.length > 0 : value != null)
|
|
2009
|
+
);
|
|
2010
|
+
const rootClasses = [
|
|
2011
|
+
"rf-text-field",
|
|
2012
|
+
`rf-text-field--${variant}`,
|
|
2013
|
+
`rf-text-field--${size}`,
|
|
2014
|
+
"rf-text-field--primary",
|
|
2015
|
+
error ? "rf-text-field--error" : "",
|
|
2016
|
+
fullWidth ? "rf-text-field--full-width" : "",
|
|
2017
|
+
disabled ? "rf-text-field--disabled" : "",
|
|
2018
|
+
isFloating ? "rf-text-field--floating" : "",
|
|
2019
|
+
label ? "rf-text-field--has-label" : "",
|
|
2020
|
+
"rf-text-field--adorned-end",
|
|
2021
|
+
"rf-autocomplete",
|
|
2022
|
+
sxClass,
|
|
2023
|
+
className
|
|
2024
|
+
].filter(Boolean).join(" ");
|
|
2025
|
+
const inputPlaceholder = placeholder || (variant === "outlined" ? " " : void 0);
|
|
2026
|
+
return /* @__PURE__ */ React69.createElement("div", { ref: containerRef, className: rootClasses, style }, /* @__PURE__ */ React69.createElement(
|
|
2027
|
+
"div",
|
|
2028
|
+
{
|
|
2029
|
+
className: "rf-text-field__wrapper",
|
|
2030
|
+
onClick: () => {
|
|
2031
|
+
if (!disabled) {
|
|
2032
|
+
inputRef.current?.focus();
|
|
2033
|
+
if (!open) openPopup();
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
},
|
|
2037
|
+
multiple && visibleTags.map((opt, i) => /* @__PURE__ */ React69.createElement("span", { key: i, className: "rf-autocomplete__tag" }, /* @__PURE__ */ React69.createElement("span", { style: { overflow: "hidden", textOverflow: "ellipsis" } }, getOptionLabel(opt)), /* @__PURE__ */ React69.createElement(
|
|
2038
|
+
"button",
|
|
2039
|
+
{
|
|
2040
|
+
type: "button",
|
|
2041
|
+
className: "rf-autocomplete__tag-delete",
|
|
2042
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2043
|
+
onClick: (e) => removeTag(opt, e),
|
|
2044
|
+
tabIndex: -1
|
|
2045
|
+
},
|
|
2046
|
+
/* @__PURE__ */ React69.createElement(CloseSmIcon, { size: 12 })
|
|
2047
|
+
))),
|
|
2048
|
+
hiddenCount > 0 && /* @__PURE__ */ React69.createElement("span", { className: "rf-autocomplete__tag-more" }, "+", hiddenCount, " more"),
|
|
2049
|
+
/* @__PURE__ */ React69.createElement(
|
|
2050
|
+
"input",
|
|
2051
|
+
{
|
|
2052
|
+
ref: inputRef,
|
|
2053
|
+
id: inputId,
|
|
2054
|
+
className: "rf-text-field__input",
|
|
2055
|
+
type: "text",
|
|
2056
|
+
value: activeInput,
|
|
2057
|
+
onChange: handleInputChange,
|
|
2058
|
+
onFocus: () => {
|
|
2059
|
+
if (!open) openPopup();
|
|
2060
|
+
},
|
|
2061
|
+
onKeyDown: handleKeyDown,
|
|
2062
|
+
placeholder: !multiple || selectedValues.length === 0 ? inputPlaceholder : void 0,
|
|
2063
|
+
disabled,
|
|
2064
|
+
autoComplete: "off",
|
|
2065
|
+
role: "combobox",
|
|
2066
|
+
"aria-expanded": open,
|
|
2067
|
+
"aria-haspopup": "listbox",
|
|
2068
|
+
"aria-autocomplete": "list"
|
|
2069
|
+
}
|
|
2070
|
+
),
|
|
2071
|
+
label && /* @__PURE__ */ React69.createElement("label", { htmlFor: inputId, className: "rf-text-field__label" }, label, required && /* @__PURE__ */ React69.createElement("span", { className: "rf-text-field__asterisk" }, " *")),
|
|
2072
|
+
variant === "outlined" && /* @__PURE__ */ React69.createElement("fieldset", { className: "rf-text-field__notch" }, label ? /* @__PURE__ */ React69.createElement("legend", { className: "rf-text-field__legend" }, /* @__PURE__ */ React69.createElement("span", null, label, required ? " *" : "")) : /* @__PURE__ */ React69.createElement("legend", { className: "rf-text-field__legend--empty" })),
|
|
2073
|
+
/* @__PURE__ */ React69.createElement("div", { className: "rf-autocomplete__endgroup" }, hasClearable && /* @__PURE__ */ React69.createElement(
|
|
2074
|
+
"button",
|
|
2075
|
+
{
|
|
2076
|
+
type: "button",
|
|
2077
|
+
className: "rf-autocomplete__icon-btn",
|
|
2078
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2079
|
+
onClick: clearAll,
|
|
2080
|
+
tabIndex: -1,
|
|
2081
|
+
"aria-label": "Clear"
|
|
2082
|
+
},
|
|
2083
|
+
/* @__PURE__ */ React69.createElement(CloseSmIcon, { size: 16 })
|
|
2084
|
+
), !freeSolo && /* @__PURE__ */ React69.createElement(
|
|
2085
|
+
"button",
|
|
2086
|
+
{
|
|
2087
|
+
type: "button",
|
|
2088
|
+
className: `rf-autocomplete__icon-btn rf-autocomplete__icon-btn--popup ${open ? "rf-autocomplete__icon-btn--open" : ""}`,
|
|
2089
|
+
onMouseDown: (e) => {
|
|
2090
|
+
e.preventDefault();
|
|
2091
|
+
open ? closePopup() : openPopup();
|
|
2092
|
+
},
|
|
2093
|
+
tabIndex: -1,
|
|
2094
|
+
"aria-label": open ? "Close" : "Open"
|
|
2095
|
+
},
|
|
2096
|
+
/* @__PURE__ */ React69.createElement(ChevronDownIcon, null)
|
|
2097
|
+
))
|
|
2098
|
+
), helperText && /* @__PURE__ */ React69.createElement("div", { className: `rf-text-field__helper-text${error ? " rf-text-field__helper-text--error" : ""}` }, helperText), open && !disabled && ReactDOM2.createPortal(
|
|
2099
|
+
/* @__PURE__ */ React69.createElement("div", { ref: popupRef, className: "rf-autocomplete__popup", role: "presentation", style: popupStyle }, loading ? /* @__PURE__ */ React69.createElement("div", { className: "rf-autocomplete__loading" }, /* @__PURE__ */ React69.createElement("span", { className: "rf-ac-spinner" }), loadingText) : flatEntries.length === 0 ? /* @__PURE__ */ React69.createElement("div", { className: "rf-autocomplete__no-options" }, noOptionsText) : /* @__PURE__ */ React69.createElement("ul", { ref: listRef, className: "rf-autocomplete__listbox", role: "listbox" }, groupBy ? (
|
|
2100
|
+
// Grouped render
|
|
2101
|
+
(() => {
|
|
2102
|
+
const rendered = [];
|
|
2103
|
+
let groupItems = [];
|
|
2104
|
+
let currentGroup = "";
|
|
2105
|
+
flatEntries.forEach((entry, ei) => {
|
|
2106
|
+
if (entry.kind === "group") {
|
|
2107
|
+
if (groupItems.length > 0) {
|
|
2108
|
+
rendered.push(
|
|
2109
|
+
/* @__PURE__ */ React69.createElement("li", { key: `g-${currentGroup}`, role: "presentation" }, /* @__PURE__ */ React69.createElement("div", { className: "rf-autocomplete__group-header" }, currentGroup), /* @__PURE__ */ React69.createElement("ul", { className: "rf-autocomplete__group-items", role: "group" }, groupItems))
|
|
2110
|
+
);
|
|
2111
|
+
groupItems = [];
|
|
2112
|
+
}
|
|
2113
|
+
currentGroup = entry.label;
|
|
2114
|
+
} else {
|
|
2115
|
+
const { option, flatIdx } = entry;
|
|
2116
|
+
groupItems.push(renderOptionItem(option, flatIdx));
|
|
2117
|
+
}
|
|
2118
|
+
if (ei === flatEntries.length - 1 && groupItems.length > 0) {
|
|
2119
|
+
rendered.push(
|
|
2120
|
+
/* @__PURE__ */ React69.createElement("li", { key: `g-${currentGroup}`, role: "presentation" }, /* @__PURE__ */ React69.createElement("div", { className: "rf-autocomplete__group-header" }, currentGroup), /* @__PURE__ */ React69.createElement("ul", { className: "rf-autocomplete__group-items", role: "group" }, groupItems))
|
|
2121
|
+
);
|
|
2122
|
+
}
|
|
2123
|
+
});
|
|
2124
|
+
return rendered;
|
|
2125
|
+
})()
|
|
2126
|
+
) : selectableOptions.map(({ option, flatIdx }) => renderOptionItem(option, flatIdx)))),
|
|
2127
|
+
document.body
|
|
2128
|
+
));
|
|
2129
|
+
function renderOptionItem(option, flatIdx) {
|
|
2130
|
+
const selected = isSelected(option);
|
|
2131
|
+
const focused = focusedIdx === flatIdx;
|
|
2132
|
+
const optDisabled = getOptionDisabled?.(option) ?? false;
|
|
2133
|
+
const label2 = getOptionLabel(option);
|
|
2134
|
+
return /* @__PURE__ */ React69.createElement(
|
|
2135
|
+
"li",
|
|
2136
|
+
{
|
|
2137
|
+
key: label2 + flatIdx,
|
|
2138
|
+
"data-idx": flatIdx,
|
|
2139
|
+
role: "option",
|
|
2140
|
+
"aria-selected": selected,
|
|
2141
|
+
"aria-disabled": optDisabled,
|
|
2142
|
+
className: [
|
|
2143
|
+
"rf-autocomplete__option",
|
|
2144
|
+
selected ? "rf-autocomplete__option--selected" : "",
|
|
2145
|
+
focused ? "rf-autocomplete__option--focused" : "",
|
|
2146
|
+
optDisabled ? "rf-autocomplete__option--disabled" : ""
|
|
2147
|
+
].filter(Boolean).join(" "),
|
|
2148
|
+
onMouseEnter: () => setFocusedIdx(flatIdx),
|
|
2149
|
+
onMouseLeave: () => setFocusedIdx(-1),
|
|
2150
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2151
|
+
onClick: () => selectOption(option)
|
|
2152
|
+
},
|
|
2153
|
+
renderOption ? renderOption(option, { selected, focused, index: flatIdx }) : /* @__PURE__ */ React69.createElement("span", { style: { flex: 1, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, label2),
|
|
2154
|
+
!renderOption && /* @__PURE__ */ React69.createElement("span", { className: "rf-autocomplete__option-check" }, /* @__PURE__ */ React69.createElement(CheckIcon, null))
|
|
2155
|
+
);
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
var Autocomplete = React69.forwardRef(AutocompleteInner);
|
|
2159
|
+
Autocomplete.displayName = "Autocomplete";
|
|
2160
|
+
|
|
2161
|
+
// lib/TextFields/AddressLookup.tsx
|
|
2162
|
+
var AddressLookup = ({
|
|
2163
|
+
value = {},
|
|
2164
|
+
onChange = () => {
|
|
2165
|
+
},
|
|
2166
|
+
label = "Address",
|
|
2167
|
+
error = {},
|
|
2168
|
+
size = "medium",
|
|
2169
|
+
sx = {},
|
|
2170
|
+
layout = "stack",
|
|
2171
|
+
required = false,
|
|
2172
|
+
token = ""
|
|
2173
|
+
}) => {
|
|
2174
|
+
const { theme } = useRufousTheme();
|
|
2175
|
+
const [suggestions, setSuggestions] = useState5([]);
|
|
2176
|
+
const [loading, setLoading] = useState5(false);
|
|
2177
|
+
const [showSuggestions, setShowSuggestions] = useState5(false);
|
|
2178
|
+
const debounceTimeout = useRef4(null);
|
|
2179
|
+
const containerRef = useRef4(null);
|
|
2180
|
+
const apiKey = token || "";
|
|
2181
|
+
const countries = Country.getAllCountries();
|
|
2182
|
+
const [states, setStates] = useState5([]);
|
|
2183
|
+
const [cities, setCities] = useState5([]);
|
|
2184
|
+
useEffect5(() => {
|
|
2185
|
+
const handleClickOutside = (event) => {
|
|
2186
|
+
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
2187
|
+
setShowSuggestions(false);
|
|
2188
|
+
}
|
|
2189
|
+
};
|
|
2190
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
2191
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
2192
|
+
}, []);
|
|
2193
|
+
useEffect5(() => {
|
|
2194
|
+
if (value.country) {
|
|
2195
|
+
const country = countries.find((c) => c.name === value.country);
|
|
2196
|
+
if (country) {
|
|
2197
|
+
const stateList = State.getStatesOfCountry(country.isoCode);
|
|
2198
|
+
setStates(stateList);
|
|
2199
|
+
} else {
|
|
2200
|
+
setStates([]);
|
|
2201
|
+
}
|
|
2202
|
+
} else {
|
|
2203
|
+
setStates([]);
|
|
2204
|
+
}
|
|
2205
|
+
}, [value.country]);
|
|
2206
|
+
useEffect5(() => {
|
|
2207
|
+
if (value.state && value.country) {
|
|
2208
|
+
const country = countries.find((c) => c.name === value.country);
|
|
2209
|
+
if (country) {
|
|
2210
|
+
const state = State.getStatesOfCountry(country.isoCode).find((s2) => s2.name === value.state);
|
|
2211
|
+
if (state) {
|
|
2212
|
+
const cityList = City.getCitiesOfState(country.isoCode, state.isoCode);
|
|
2213
|
+
setCities(cityList);
|
|
2214
|
+
} else {
|
|
2215
|
+
setCities([]);
|
|
2216
|
+
}
|
|
2217
|
+
} else {
|
|
2218
|
+
setCities([]);
|
|
2219
|
+
}
|
|
2220
|
+
} else {
|
|
2221
|
+
setCities([]);
|
|
2222
|
+
}
|
|
2223
|
+
}, [value.state, value.country]);
|
|
2224
|
+
const handleChange = (field, newVal) => {
|
|
2225
|
+
onChange({
|
|
2226
|
+
...value,
|
|
2227
|
+
[field]: newVal
|
|
2228
|
+
});
|
|
2229
|
+
};
|
|
2230
|
+
const fetchPlaceDetails = async (placeId, mainText = "") => {
|
|
2231
|
+
if (!apiKey) {
|
|
2232
|
+
console.warn("Google Places API Key (token) is missing.");
|
|
2233
|
+
return;
|
|
2234
|
+
}
|
|
2235
|
+
setLoading(true);
|
|
1822
2236
|
try {
|
|
1823
2237
|
const res = await Axios.get(
|
|
1824
2238
|
`https://places.googleapis.com/v1/places/${placeId}`,
|
|
@@ -1894,7 +2308,7 @@ var AddressLookup = ({
|
|
|
1894
2308
|
city: ""
|
|
1895
2309
|
});
|
|
1896
2310
|
};
|
|
1897
|
-
return /* @__PURE__ */
|
|
2311
|
+
return /* @__PURE__ */ React70.createElement("div", { className: "address-lookup-container", style: sx, ref: containerRef }, /* @__PURE__ */ React70.createElement("div", { className: `address-lookup-grid address-lookup-grid-${layout}` }, /* @__PURE__ */ React70.createElement("div", { className: "address-lookup-grid-item col-l1" }, /* @__PURE__ */ React70.createElement(
|
|
1898
2312
|
TextField,
|
|
1899
2313
|
{
|
|
1900
2314
|
label,
|
|
@@ -1926,7 +2340,7 @@ var AddressLookup = ({
|
|
|
1926
2340
|
},
|
|
1927
2341
|
onFocus: () => suggestions.length > 0 && setShowSuggestions(true)
|
|
1928
2342
|
}
|
|
1929
|
-
), loading && /* @__PURE__ */
|
|
2343
|
+
), loading && /* @__PURE__ */ React70.createElement("div", { className: "loading-indicator" }, /* @__PURE__ */ React70.createElement(circularProgress_default, { size: 20 })), showSuggestions && suggestions.length > 0 && /* @__PURE__ */ React70.createElement("div", { className: "autocomplete-dropdown" }, suggestions.map((option, idx) => /* @__PURE__ */ React70.createElement(
|
|
1930
2344
|
"div",
|
|
1931
2345
|
{
|
|
1932
2346
|
key: idx,
|
|
@@ -1937,9 +2351,9 @@ var AddressLookup = ({
|
|
|
1937
2351
|
fetchPlaceDetails(option.placePrediction.placeId, mainText);
|
|
1938
2352
|
}
|
|
1939
2353
|
},
|
|
1940
|
-
/* @__PURE__ */
|
|
1941
|
-
/* @__PURE__ */
|
|
1942
|
-
))), error.addressLine1 && /* @__PURE__ */
|
|
2354
|
+
/* @__PURE__ */ React70.createElement("div", { className: "autocomplete-main-text" }, option?.placePrediction?.structuredFormat?.mainText?.text),
|
|
2355
|
+
/* @__PURE__ */ React70.createElement("div", { className: "autocomplete-secondary-text" }, option?.placePrediction?.structuredFormat?.secondaryText?.text)
|
|
2356
|
+
))), error.addressLine1 && /* @__PURE__ */ React70.createElement("div", { className: "field-error-text" }, error.addressLine1)), layout === "compact" && /* @__PURE__ */ React70.createElement("div", { className: "address-lookup-grid-item col-l2" }, /* @__PURE__ */ React70.createElement(
|
|
1943
2357
|
TextField,
|
|
1944
2358
|
{
|
|
1945
2359
|
label: "Address Line 2",
|
|
@@ -1948,7 +2362,7 @@ var AddressLookup = ({
|
|
|
1948
2362
|
value: value.addressLine2 || "",
|
|
1949
2363
|
onChange: (e) => handleChange("addressLine2", e.target.value)
|
|
1950
2364
|
}
|
|
1951
|
-
)), layout !== "compact" && /* @__PURE__ */
|
|
2365
|
+
)), layout !== "compact" && /* @__PURE__ */ React70.createElement("div", { className: "address-lookup-grid-item col-l2" }, /* @__PURE__ */ React70.createElement(
|
|
1952
2366
|
TextField,
|
|
1953
2367
|
{
|
|
1954
2368
|
label: "Address Line 2",
|
|
@@ -1957,40 +2371,40 @@ var AddressLookup = ({
|
|
|
1957
2371
|
value: value.addressLine2 || "",
|
|
1958
2372
|
onChange: (e) => handleChange("addressLine2", e.target.value)
|
|
1959
2373
|
}
|
|
1960
|
-
)), /* @__PURE__ */
|
|
1961
|
-
|
|
2374
|
+
)), /* @__PURE__ */ React70.createElement("div", { className: "address-lookup-grid-item col-country" }, /* @__PURE__ */ React70.createElement(
|
|
2375
|
+
Autocomplete,
|
|
1962
2376
|
{
|
|
2377
|
+
options: countries.map((c) => c.name),
|
|
2378
|
+
value: value.country || null,
|
|
2379
|
+
onChange: (v) => handleCountryChange(v || ""),
|
|
1963
2380
|
label: "Country",
|
|
1964
|
-
name: "country",
|
|
1965
2381
|
fullWidth: true,
|
|
1966
|
-
value: value.country || "",
|
|
1967
2382
|
required,
|
|
1968
|
-
|
|
1969
|
-
list: "countries-list"
|
|
2383
|
+
error: !!error.country
|
|
1970
2384
|
}
|
|
1971
|
-
),
|
|
1972
|
-
|
|
2385
|
+
), error.country && /* @__PURE__ */ React70.createElement("div", { className: "field-error-text" }, error.country)), /* @__PURE__ */ React70.createElement("div", { className: "address-lookup-grid-item col-state" }, /* @__PURE__ */ React70.createElement(
|
|
2386
|
+
Autocomplete,
|
|
1973
2387
|
{
|
|
2388
|
+
options: states.map((s2) => s2.name),
|
|
2389
|
+
value: value.state || null,
|
|
2390
|
+
onChange: (v) => handleStateChange(v || ""),
|
|
1974
2391
|
label: "State",
|
|
1975
|
-
name: "state",
|
|
1976
2392
|
fullWidth: true,
|
|
1977
|
-
value: value.state || "",
|
|
1978
2393
|
required,
|
|
1979
|
-
|
|
1980
|
-
list: "states-list"
|
|
2394
|
+
error: !!error.state
|
|
1981
2395
|
}
|
|
1982
|
-
),
|
|
1983
|
-
|
|
2396
|
+
), error.state && /* @__PURE__ */ React70.createElement("div", { className: "field-error-text" }, error.state)), /* @__PURE__ */ React70.createElement("div", { className: "address-lookup-grid-item col-city" }, /* @__PURE__ */ React70.createElement(
|
|
2397
|
+
Autocomplete,
|
|
1984
2398
|
{
|
|
2399
|
+
options: cities.map((c) => c.name),
|
|
2400
|
+
value: value.city || null,
|
|
2401
|
+
onChange: (v) => handleChange("city", v || ""),
|
|
1985
2402
|
label: "City",
|
|
1986
|
-
name: "city",
|
|
1987
2403
|
fullWidth: true,
|
|
1988
|
-
value: value.city || "",
|
|
1989
2404
|
required,
|
|
1990
|
-
|
|
1991
|
-
list: "cities-list"
|
|
2405
|
+
error: !!error.city
|
|
1992
2406
|
}
|
|
1993
|
-
),
|
|
2407
|
+
), error.city && /* @__PURE__ */ React70.createElement("div", { className: "field-error-text" }, error.city)), /* @__PURE__ */ React70.createElement("div", { className: "address-lookup-grid-item col-pin" }, /* @__PURE__ */ React70.createElement(
|
|
1994
2408
|
TextField,
|
|
1995
2409
|
{
|
|
1996
2410
|
label: "Pincode",
|
|
@@ -2000,16 +2414,16 @@ var AddressLookup = ({
|
|
|
2000
2414
|
required,
|
|
2001
2415
|
onChange: (e) => handleChange("pincode", e.target.value)
|
|
2002
2416
|
}
|
|
2003
|
-
), error.pincode && /* @__PURE__ */
|
|
2417
|
+
), error.pincode && /* @__PURE__ */ React70.createElement("div", { className: "field-error-text" }, error.pincode))));
|
|
2004
2418
|
};
|
|
2005
2419
|
var AddressLookup_default = AddressLookup;
|
|
2006
2420
|
|
|
2007
2421
|
// lib/TextFields/DateField.tsx
|
|
2008
|
-
import
|
|
2009
|
-
useState as
|
|
2010
|
-
useRef as
|
|
2011
|
-
useEffect as
|
|
2012
|
-
useCallback
|
|
2422
|
+
import React71, {
|
|
2423
|
+
useState as useState6,
|
|
2424
|
+
useRef as useRef5,
|
|
2425
|
+
useEffect as useEffect6,
|
|
2426
|
+
useCallback as useCallback2
|
|
2013
2427
|
} from "react";
|
|
2014
2428
|
import { createPortal } from "react-dom";
|
|
2015
2429
|
var WEEKDAYS = ["SU", "MO", "TU", "WE", "TH", "FR", "SA"];
|
|
@@ -2078,6 +2492,13 @@ var parseMonthName = (name) => {
|
|
|
2078
2492
|
idx = MONTHS_SHORT.findIndex((m) => m.toLowerCase() === lower);
|
|
2079
2493
|
return idx;
|
|
2080
2494
|
};
|
|
2495
|
+
var strictDate = (yyyy, mm0, dd) => {
|
|
2496
|
+
if (dd < 1 || dd > 31 || mm0 < 0 || mm0 > 11) return null;
|
|
2497
|
+
const d = new Date(yyyy, mm0, dd);
|
|
2498
|
+
if (isNaN(d.getTime())) return null;
|
|
2499
|
+
if (d.getMonth() !== mm0 || d.getDate() !== dd) return null;
|
|
2500
|
+
return d;
|
|
2501
|
+
};
|
|
2081
2502
|
var parseDisplay = (str, fmt = "MM/DD/YYYY") => {
|
|
2082
2503
|
if (fmt === "DD MMM YYYY" || fmt === "DD MMMM YYYY") {
|
|
2083
2504
|
const parts2 = str.split(" ");
|
|
@@ -2085,9 +2506,8 @@ var parseDisplay = (str, fmt = "MM/DD/YYYY") => {
|
|
|
2085
2506
|
const dd2 = parseInt(parts2[0], 10);
|
|
2086
2507
|
const mm2 = parseMonthName(parts2[1]);
|
|
2087
2508
|
const yyyy2 = parseInt(parts2[2], 10);
|
|
2088
|
-
if (isNaN(dd2) ||
|
|
2089
|
-
|
|
2090
|
-
return isNaN(d2.getTime()) ? null : d2;
|
|
2509
|
+
if (isNaN(dd2) || isNaN(yyyy2) || yyyy2 < 1e3) return null;
|
|
2510
|
+
return strictDate(yyyy2, mm2, dd2);
|
|
2091
2511
|
}
|
|
2092
2512
|
if (fmt === "MMM DD, YYYY" || fmt === "MMMM DD, YYYY") {
|
|
2093
2513
|
const cleaned = str.replace(",", "");
|
|
@@ -2096,9 +2516,8 @@ var parseDisplay = (str, fmt = "MM/DD/YYYY") => {
|
|
|
2096
2516
|
const mm2 = parseMonthName(parts2[0]);
|
|
2097
2517
|
const dd2 = parseInt(parts2[1], 10);
|
|
2098
2518
|
const yyyy2 = parseInt(parts2[2], 10);
|
|
2099
|
-
if (
|
|
2100
|
-
|
|
2101
|
-
return isNaN(d2.getTime()) ? null : d2;
|
|
2519
|
+
if (isNaN(dd2) || isNaN(yyyy2) || yyyy2 < 1e3) return null;
|
|
2520
|
+
return strictDate(yyyy2, mm2, dd2);
|
|
2102
2521
|
}
|
|
2103
2522
|
const sep = str.includes("/") ? "/" : "-";
|
|
2104
2523
|
const parts = str.split(sep);
|
|
@@ -2120,10 +2539,8 @@ var parseDisplay = (str, fmt = "MM/DD/YYYY") => {
|
|
|
2120
2539
|
[mm, dd, yyyy] = nums;
|
|
2121
2540
|
break;
|
|
2122
2541
|
}
|
|
2123
|
-
if (!
|
|
2124
|
-
|
|
2125
|
-
if (isNaN(d.getTime())) return null;
|
|
2126
|
-
return d;
|
|
2542
|
+
if (!yyyy || yyyy < 1e3) return null;
|
|
2543
|
+
return strictDate(yyyy, mm - 1, dd);
|
|
2127
2544
|
};
|
|
2128
2545
|
var isoToDate = (iso) => {
|
|
2129
2546
|
if (!iso) return null;
|
|
@@ -2147,6 +2564,17 @@ var buildISO = (date, type, hour, minute, ampm) => {
|
|
|
2147
2564
|
if (ampm === "PM") h24 += 12;
|
|
2148
2565
|
return `${y}-${mo}-${d}T${String(h24).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
|
|
2149
2566
|
};
|
|
2567
|
+
var getDateWordCount = (fmt) => {
|
|
2568
|
+
switch (fmt) {
|
|
2569
|
+
case "DD MMM YYYY":
|
|
2570
|
+
case "MMM DD, YYYY":
|
|
2571
|
+
case "DD MMMM YYYY":
|
|
2572
|
+
case "MMMM DD, YYYY":
|
|
2573
|
+
return 3;
|
|
2574
|
+
default:
|
|
2575
|
+
return 1;
|
|
2576
|
+
}
|
|
2577
|
+
};
|
|
2150
2578
|
var parseTimeFromISO = (iso) => {
|
|
2151
2579
|
const timePart = iso.split("T")[1] || "";
|
|
2152
2580
|
const [hStr, mStr] = timePart.split(":");
|
|
@@ -2157,25 +2585,25 @@ var parseTimeFromISO = (iso) => {
|
|
|
2157
2585
|
if (h === 0) h = 12;
|
|
2158
2586
|
return { h, m, ampm };
|
|
2159
2587
|
};
|
|
2160
|
-
var CalendarIcon = () => /* @__PURE__ */
|
|
2161
|
-
var ChevUp = () => /* @__PURE__ */
|
|
2162
|
-
var ChevDown = () => /* @__PURE__ */
|
|
2588
|
+
var CalendarIcon = () => /* @__PURE__ */ React71.createElement("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ React71.createElement("rect", { x: "3", y: "4", width: "18", height: "18", rx: "2", ry: "2" }), /* @__PURE__ */ React71.createElement("line", { x1: "16", y1: "2", x2: "16", y2: "6" }), /* @__PURE__ */ React71.createElement("line", { x1: "8", y1: "2", x2: "8", y2: "6" }), /* @__PURE__ */ React71.createElement("line", { x1: "3", y1: "10", x2: "21", y2: "10" }));
|
|
2589
|
+
var ChevUp = () => /* @__PURE__ */ React71.createElement("svg", { width: "10", height: "7", viewBox: "0 0 10 7", fill: "currentColor" }, /* @__PURE__ */ React71.createElement("path", { d: "M5 0L10 7H0L5 0Z" }));
|
|
2590
|
+
var ChevDown = () => /* @__PURE__ */ React71.createElement("svg", { width: "10", height: "7", viewBox: "0 0 10 7", fill: "currentColor" }, /* @__PURE__ */ React71.createElement("path", { d: "M5 7L0 0H10L5 7Z" }));
|
|
2163
2591
|
var ITEM_H = 36;
|
|
2164
2592
|
var ScrollColumn = ({ items, selected, onSelect, infinite = true }) => {
|
|
2165
|
-
const listRef =
|
|
2166
|
-
const isInternalScroll =
|
|
2167
|
-
const scrollTimeout =
|
|
2593
|
+
const listRef = useRef5(null);
|
|
2594
|
+
const isInternalScroll = useRef5(false);
|
|
2595
|
+
const scrollTimeout = useRef5(null);
|
|
2168
2596
|
const MULTIPLIER = infinite ? 100 : 1;
|
|
2169
2597
|
const virtualItems = infinite ? Array(MULTIPLIER).fill(items).flat() : items;
|
|
2170
2598
|
const centerOffset = infinite ? Math.floor(MULTIPLIER / 2) * items.length : 0;
|
|
2171
2599
|
const VISUAL_OFFSET = 54;
|
|
2172
|
-
|
|
2600
|
+
useEffect6(() => {
|
|
2173
2601
|
if (listRef.current) {
|
|
2174
2602
|
const targetIndex = centerOffset + selected;
|
|
2175
2603
|
listRef.current.scrollTop = targetIndex * ITEM_H - (infinite ? VISUAL_OFFSET : 0);
|
|
2176
2604
|
}
|
|
2177
2605
|
}, [centerOffset, infinite, selected]);
|
|
2178
|
-
|
|
2606
|
+
useEffect6(() => {
|
|
2179
2607
|
if (listRef.current && !isInternalScroll.current) {
|
|
2180
2608
|
const targetIndex = centerOffset + selected;
|
|
2181
2609
|
listRef.current.scrollTo({
|
|
@@ -2207,15 +2635,15 @@ var ScrollColumn = ({ items, selected, onSelect, infinite = true }) => {
|
|
|
2207
2635
|
}
|
|
2208
2636
|
}, 100);
|
|
2209
2637
|
};
|
|
2210
|
-
return /* @__PURE__ */
|
|
2638
|
+
return /* @__PURE__ */ React71.createElement("div", { className: "rf-timescroll__col-wrapper" }, /* @__PURE__ */ React71.createElement(
|
|
2211
2639
|
"div",
|
|
2212
2640
|
{
|
|
2213
2641
|
className: "rf-timescroll__col",
|
|
2214
2642
|
ref: listRef,
|
|
2215
2643
|
onScroll: handleScroll
|
|
2216
2644
|
},
|
|
2217
|
-
!infinite && /* @__PURE__ */
|
|
2218
|
-
virtualItems.map((label, idx) => /* @__PURE__ */
|
|
2645
|
+
!infinite && /* @__PURE__ */ React71.createElement("div", { className: "rf-timescroll__spacer" }),
|
|
2646
|
+
virtualItems.map((label, idx) => /* @__PURE__ */ React71.createElement(
|
|
2219
2647
|
"div",
|
|
2220
2648
|
{
|
|
2221
2649
|
key: `${label}-${idx}`,
|
|
@@ -2223,8 +2651,8 @@ var ScrollColumn = ({ items, selected, onSelect, infinite = true }) => {
|
|
|
2223
2651
|
},
|
|
2224
2652
|
label
|
|
2225
2653
|
)),
|
|
2226
|
-
!infinite && /* @__PURE__ */
|
|
2227
|
-
), /* @__PURE__ */
|
|
2654
|
+
!infinite && /* @__PURE__ */ React71.createElement("div", { className: "rf-timescroll__spacer" })
|
|
2655
|
+
), /* @__PURE__ */ React71.createElement("div", { className: "rf-timescroll__mask rf-timescroll__mask--top" }), /* @__PURE__ */ React71.createElement("div", { className: "rf-timescroll__mask rf-timescroll__mask--bottom" }));
|
|
2228
2656
|
};
|
|
2229
2657
|
var SpinnerPanel = ({
|
|
2230
2658
|
hour,
|
|
@@ -2235,7 +2663,7 @@ var SpinnerPanel = ({
|
|
|
2235
2663
|
onHourInput,
|
|
2236
2664
|
onMinuteInput,
|
|
2237
2665
|
onAmpmToggle
|
|
2238
|
-
}) => /* @__PURE__ */
|
|
2666
|
+
}) => /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__time-row" }, /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__time-input-wrap" }, /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-date-picker__time-spin-btn", onMouseDown: (e) => e.preventDefault(), onClick: () => onHourChange(1) }, /* @__PURE__ */ React71.createElement(ChevUp, null)), /* @__PURE__ */ React71.createElement(
|
|
2239
2667
|
"input",
|
|
2240
2668
|
{
|
|
2241
2669
|
type: "number",
|
|
@@ -2246,7 +2674,7 @@ var SpinnerPanel = ({
|
|
|
2246
2674
|
onChange: onHourInput,
|
|
2247
2675
|
onMouseDown: (e) => e.stopPropagation()
|
|
2248
2676
|
}
|
|
2249
|
-
), /* @__PURE__ */
|
|
2677
|
+
), /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-date-picker__time-spin-btn", onMouseDown: (e) => e.preventDefault(), onClick: () => onHourChange(-1) }, /* @__PURE__ */ React71.createElement(ChevDown, null))), /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__time-colon" }, ":"), /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__time-input-wrap" }, /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-date-picker__time-spin-btn", onMouseDown: (e) => e.preventDefault(), onClick: () => onMinuteChange(1) }, /* @__PURE__ */ React71.createElement(ChevUp, null)), /* @__PURE__ */ React71.createElement(
|
|
2250
2678
|
"input",
|
|
2251
2679
|
{
|
|
2252
2680
|
type: "number",
|
|
@@ -2257,7 +2685,7 @@ var SpinnerPanel = ({
|
|
|
2257
2685
|
onChange: onMinuteInput,
|
|
2258
2686
|
onMouseDown: (e) => e.stopPropagation()
|
|
2259
2687
|
}
|
|
2260
|
-
), /* @__PURE__ */
|
|
2688
|
+
), /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-date-picker__time-spin-btn", onMouseDown: (e) => e.preventDefault(), onClick: () => onMinuteChange(-1) }, /* @__PURE__ */ React71.createElement(ChevDown, null))), /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__ampm" }, /* @__PURE__ */ React71.createElement(
|
|
2261
2689
|
"button",
|
|
2262
2690
|
{
|
|
2263
2691
|
type: "button",
|
|
@@ -2266,7 +2694,7 @@ var SpinnerPanel = ({
|
|
|
2266
2694
|
onClick: () => onAmpmToggle("AM")
|
|
2267
2695
|
},
|
|
2268
2696
|
"AM"
|
|
2269
|
-
), /* @__PURE__ */
|
|
2697
|
+
), /* @__PURE__ */ React71.createElement(
|
|
2270
2698
|
"button",
|
|
2271
2699
|
{
|
|
2272
2700
|
type: "button",
|
|
@@ -2288,7 +2716,7 @@ var CalendarBody = ({
|
|
|
2288
2716
|
onMonthSelect,
|
|
2289
2717
|
onYearSelect
|
|
2290
2718
|
}) => {
|
|
2291
|
-
const [pickerView, setPickerView] =
|
|
2719
|
+
const [pickerView, setPickerView] = useState6("calendar");
|
|
2292
2720
|
const handleMonthClick = () => {
|
|
2293
2721
|
setPickerView(pickerView === "month" ? "calendar" : "month");
|
|
2294
2722
|
};
|
|
@@ -2306,21 +2734,21 @@ var CalendarBody = ({
|
|
|
2306
2734
|
const currentYear = todayDate.getFullYear();
|
|
2307
2735
|
const yearStart = viewYear - 6;
|
|
2308
2736
|
const years = Array.from({ length: 16 }, (_, i) => yearStart + i);
|
|
2309
|
-
return /* @__PURE__ */
|
|
2737
|
+
return /* @__PURE__ */ React71.createElement(React71.Fragment, null, /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__header" }, /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__header-labels" }, /* @__PURE__ */ React71.createElement(
|
|
2310
2738
|
"span",
|
|
2311
2739
|
{
|
|
2312
2740
|
className: `rf-date-picker__month-label ${pickerView === "month" ? "rf-date-picker__month-label--active" : ""}`,
|
|
2313
2741
|
onClick: handleMonthClick
|
|
2314
2742
|
},
|
|
2315
2743
|
MONTHS[viewMonth]
|
|
2316
|
-
), /* @__PURE__ */
|
|
2744
|
+
), /* @__PURE__ */ React71.createElement(
|
|
2317
2745
|
"span",
|
|
2318
2746
|
{
|
|
2319
2747
|
className: `rf-date-picker__year-label ${pickerView === "year" ? "rf-date-picker__year-label--active" : ""}`,
|
|
2320
2748
|
onClick: handleYearClick
|
|
2321
2749
|
},
|
|
2322
2750
|
viewYear
|
|
2323
|
-
)), /* @__PURE__ */
|
|
2751
|
+
)), /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__nav" }, pickerView === "year" ? /* @__PURE__ */ React71.createElement(React71.Fragment, null, /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-date-picker__nav-btn", onClick: () => onYearSelect(viewYear - 16), "aria-label": "Previous years" }, "\u2039"), /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-date-picker__nav-btn", onClick: () => onYearSelect(viewYear + 16), "aria-label": "Next years" }, "\u203A")) : /* @__PURE__ */ React71.createElement(React71.Fragment, null, /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-date-picker__nav-btn", onClick: onPrev, "aria-label": "Previous month" }, "\u2039"), /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-date-picker__nav-btn", onClick: onNext, "aria-label": "Next month" }, "\u203A")))), pickerView === "month" && /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__month-grid" }, MONTHS_SHORT.map((m, idx) => /* @__PURE__ */ React71.createElement(
|
|
2324
2752
|
"button",
|
|
2325
2753
|
{
|
|
2326
2754
|
key: m,
|
|
@@ -2333,7 +2761,7 @@ var CalendarBody = ({
|
|
|
2333
2761
|
onClick: () => handleMonthPick(idx)
|
|
2334
2762
|
},
|
|
2335
2763
|
m
|
|
2336
|
-
))), pickerView === "year" && /* @__PURE__ */
|
|
2764
|
+
))), pickerView === "year" && /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__year-grid" }, years.map((y) => /* @__PURE__ */ React71.createElement(
|
|
2337
2765
|
"button",
|
|
2338
2766
|
{
|
|
2339
2767
|
key: y,
|
|
@@ -2346,12 +2774,12 @@ var CalendarBody = ({
|
|
|
2346
2774
|
onClick: () => handleYearPick(y)
|
|
2347
2775
|
},
|
|
2348
2776
|
y
|
|
2349
|
-
))), pickerView === "calendar" && /* @__PURE__ */
|
|
2350
|
-
if (day === null) return /* @__PURE__ */
|
|
2777
|
+
))), pickerView === "calendar" && /* @__PURE__ */ React71.createElement(React71.Fragment, null, /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__weekdays" }, WEEKDAYS.map((w) => /* @__PURE__ */ React71.createElement("div", { key: w, className: "rf-date-picker__weekday" }, w))), /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__grid" }, dayCells.map((day, idx) => {
|
|
2778
|
+
if (day === null) return /* @__PURE__ */ React71.createElement("div", { key: `e-${idx}`, className: "rf-date-picker__day rf-date-picker__day--empty" });
|
|
2351
2779
|
const cellDate = new Date(viewYear, viewMonth, day);
|
|
2352
2780
|
const isSelected = selectedDate ? isSameDay(cellDate, selectedDate) : false;
|
|
2353
2781
|
const isToday = isSameDay(cellDate, todayDate);
|
|
2354
|
-
return /* @__PURE__ */
|
|
2782
|
+
return /* @__PURE__ */ React71.createElement(
|
|
2355
2783
|
"button",
|
|
2356
2784
|
{
|
|
2357
2785
|
key: day,
|
|
@@ -2387,29 +2815,29 @@ var DateField = ({
|
|
|
2387
2815
|
sx
|
|
2388
2816
|
}) => {
|
|
2389
2817
|
const sxClass = useSx(sx);
|
|
2390
|
-
const [open, setOpen] =
|
|
2391
|
-
const [selectedDate, setSelectedDate] =
|
|
2392
|
-
const [hour, setHour] =
|
|
2818
|
+
const [open, setOpen] = useState6(false);
|
|
2819
|
+
const [selectedDate, setSelectedDate] = useState6(() => value ? isoToDate(value) : null);
|
|
2820
|
+
const [hour, setHour] = useState6(() => {
|
|
2393
2821
|
if (value && isDatetimeType(type)) return parseTimeFromISO(value).h;
|
|
2394
2822
|
return 12;
|
|
2395
2823
|
});
|
|
2396
|
-
const [minute, setMinute] =
|
|
2824
|
+
const [minute, setMinute] = useState6(() => {
|
|
2397
2825
|
if (value && isDatetimeType(type)) return parseTimeFromISO(value).m;
|
|
2398
2826
|
return 0;
|
|
2399
2827
|
});
|
|
2400
|
-
const [ampm, setAmpm] =
|
|
2828
|
+
const [ampm, setAmpm] = useState6(() => {
|
|
2401
2829
|
if (value && isDatetimeType(type)) return parseTimeFromISO(value).ampm;
|
|
2402
2830
|
return "AM";
|
|
2403
2831
|
});
|
|
2404
|
-
const [viewYear, setViewYear] =
|
|
2832
|
+
const [viewYear, setViewYear] = useState6(() => {
|
|
2405
2833
|
const base = value ? isoToDate(value) : null;
|
|
2406
2834
|
return base ? base.getFullYear() : today().getFullYear();
|
|
2407
2835
|
});
|
|
2408
|
-
const [viewMonth, setViewMonth] =
|
|
2836
|
+
const [viewMonth, setViewMonth] = useState6(() => {
|
|
2409
2837
|
const base = value ? isoToDate(value) : null;
|
|
2410
2838
|
return base ? base.getMonth() : today().getMonth();
|
|
2411
2839
|
});
|
|
2412
|
-
const [inputStr, setInputStr] =
|
|
2840
|
+
const [inputStr, setInputStr] = useState6(() => {
|
|
2413
2841
|
if (!value) return "";
|
|
2414
2842
|
const d = isoToDate(value);
|
|
2415
2843
|
if (!d) return "";
|
|
@@ -2423,12 +2851,17 @@ var DateField = ({
|
|
|
2423
2851
|
const HOURS = Array.from({ length: 12 }, (_, i) => String(i + 1).padStart(2, "0"));
|
|
2424
2852
|
const MINUTES = Array.from({ length: 60 }, (_, i) => String(i).padStart(2, "0"));
|
|
2425
2853
|
const AMPMS = ["AM", "PM"];
|
|
2426
|
-
const containerRef =
|
|
2427
|
-
const pickerRef =
|
|
2428
|
-
const [dropUp, setDropUp] =
|
|
2429
|
-
const inputId =
|
|
2430
|
-
|
|
2854
|
+
const containerRef = useRef5(null);
|
|
2855
|
+
const pickerRef = useRef5(null);
|
|
2856
|
+
const [dropUp, setDropUp] = useState6(false);
|
|
2857
|
+
const inputId = useRef5(`rf-df-${Math.random().toString(36).substring(2, 11)}`).current;
|
|
2858
|
+
const isInternalChange = useRef5(false);
|
|
2859
|
+
useEffect6(() => {
|
|
2431
2860
|
if (value === void 0) return;
|
|
2861
|
+
if (isInternalChange.current) {
|
|
2862
|
+
isInternalChange.current = false;
|
|
2863
|
+
return;
|
|
2864
|
+
}
|
|
2432
2865
|
if (!value) {
|
|
2433
2866
|
setSelectedDate(null);
|
|
2434
2867
|
setInputStr("");
|
|
@@ -2450,7 +2883,7 @@ var DateField = ({
|
|
|
2450
2883
|
setInputStr(str);
|
|
2451
2884
|
}
|
|
2452
2885
|
}, [value, type]);
|
|
2453
|
-
|
|
2886
|
+
useEffect6(() => {
|
|
2454
2887
|
if (!open) return;
|
|
2455
2888
|
const handler = (e) => {
|
|
2456
2889
|
const target = e.target;
|
|
@@ -2461,14 +2894,14 @@ var DateField = ({
|
|
|
2461
2894
|
document.addEventListener("mousedown", handler);
|
|
2462
2895
|
return () => document.removeEventListener("mousedown", handler);
|
|
2463
2896
|
}, [open]);
|
|
2464
|
-
|
|
2897
|
+
useEffect6(() => {
|
|
2465
2898
|
if (!open || !containerRef.current) return;
|
|
2466
2899
|
const rect = containerRef.current.getBoundingClientRect();
|
|
2467
2900
|
const spaceBelow = window.innerHeight - rect.bottom;
|
|
2468
2901
|
const pickerHeight = 400;
|
|
2469
2902
|
setDropUp(spaceBelow < pickerHeight && rect.top > pickerHeight);
|
|
2470
2903
|
}, [open]);
|
|
2471
|
-
const commitDate =
|
|
2904
|
+
const commitDate = useCallback2((d, h, m, ap) => {
|
|
2472
2905
|
setSelectedDate(d);
|
|
2473
2906
|
if (!d) {
|
|
2474
2907
|
setInputStr("");
|
|
@@ -2500,17 +2933,19 @@ var DateField = ({
|
|
|
2500
2933
|
const handleInputChange = (e) => {
|
|
2501
2934
|
const raw = e.target.value;
|
|
2502
2935
|
setInputStr(raw);
|
|
2503
|
-
const
|
|
2504
|
-
const
|
|
2936
|
+
const dateWordCount = getDateWordCount(dateFormat);
|
|
2937
|
+
const words = raw.split(" ");
|
|
2938
|
+
const datePart = words.slice(0, dateWordCount).join(" ");
|
|
2939
|
+
const timeParts = words.slice(dateWordCount);
|
|
2505
2940
|
const parsed = parseDisplay(datePart, dateFormat);
|
|
2506
2941
|
if (parsed) {
|
|
2507
2942
|
setSelectedDate(parsed);
|
|
2508
2943
|
setViewYear(parsed.getFullYear());
|
|
2509
2944
|
setViewMonth(parsed.getMonth());
|
|
2510
2945
|
let h = hour, m = minute, ap = ampm;
|
|
2511
|
-
if (isDatetimeType(type) &&
|
|
2512
|
-
const timePart =
|
|
2513
|
-
const periodPart =
|
|
2946
|
+
if (isDatetimeType(type) && timeParts.length >= 2) {
|
|
2947
|
+
const timePart = timeParts[0];
|
|
2948
|
+
const periodPart = timeParts[1]?.toUpperCase();
|
|
2514
2949
|
if (timePart?.includes(":")) {
|
|
2515
2950
|
const [hStr, mStr] = timePart.split(":");
|
|
2516
2951
|
const parsedH = parseInt(hStr, 10);
|
|
@@ -2529,9 +2964,11 @@ var DateField = ({
|
|
|
2529
2964
|
setAmpm(ap);
|
|
2530
2965
|
}
|
|
2531
2966
|
}
|
|
2967
|
+
isInternalChange.current = true;
|
|
2532
2968
|
onChange?.(buildISO(parsed, type, h, m, ap));
|
|
2533
2969
|
} else if (!raw) {
|
|
2534
2970
|
setSelectedDate(null);
|
|
2971
|
+
isInternalChange.current = true;
|
|
2535
2972
|
onChange?.("");
|
|
2536
2973
|
}
|
|
2537
2974
|
};
|
|
@@ -2615,7 +3052,7 @@ var DateField = ({
|
|
|
2615
3052
|
const inputPlaceholder = placeholder || (variant === "outlined" ? " " : void 0);
|
|
2616
3053
|
const todayDate = today();
|
|
2617
3054
|
const isSideVariant = type === "datetime-side" || type === "datetime-scroll";
|
|
2618
|
-
return /* @__PURE__ */
|
|
3055
|
+
return /* @__PURE__ */ React71.createElement("div", { ref: containerRef, className: rootClasses, style }, /* @__PURE__ */ React71.createElement("div", { className: "rf-date-field__anchor" }, /* @__PURE__ */ React71.createElement(
|
|
2619
3056
|
"div",
|
|
2620
3057
|
{
|
|
2621
3058
|
className: "rf-text-field__wrapper",
|
|
@@ -2624,7 +3061,7 @@ var DateField = ({
|
|
|
2624
3061
|
},
|
|
2625
3062
|
style: { cursor: disabled ? "default" : "pointer" }
|
|
2626
3063
|
},
|
|
2627
|
-
/* @__PURE__ */
|
|
3064
|
+
/* @__PURE__ */ React71.createElement(
|
|
2628
3065
|
"input",
|
|
2629
3066
|
{
|
|
2630
3067
|
id: inputId,
|
|
@@ -2640,7 +3077,7 @@ var DateField = ({
|
|
|
2640
3077
|
}
|
|
2641
3078
|
}
|
|
2642
3079
|
),
|
|
2643
|
-
/* @__PURE__ */
|
|
3080
|
+
/* @__PURE__ */ React71.createElement("div", { className: "rf-text-field__adornment rf-text-field__adornment--end" }, /* @__PURE__ */ React71.createElement(
|
|
2644
3081
|
"button",
|
|
2645
3082
|
{
|
|
2646
3083
|
type: "button",
|
|
@@ -2653,12 +3090,12 @@ var DateField = ({
|
|
|
2653
3090
|
},
|
|
2654
3091
|
"aria-label": "Pick date"
|
|
2655
3092
|
},
|
|
2656
|
-
/* @__PURE__ */
|
|
3093
|
+
/* @__PURE__ */ React71.createElement(CalendarIcon, null)
|
|
2657
3094
|
)),
|
|
2658
|
-
label && /* @__PURE__ */
|
|
2659
|
-
variant === "outlined" && /* @__PURE__ */
|
|
3095
|
+
label && /* @__PURE__ */ React71.createElement("label", { htmlFor: inputId, className: "rf-text-field__label" }, label, " ", required && /* @__PURE__ */ React71.createElement("span", { className: "rf-text-field__asterisk" }, "*")),
|
|
3096
|
+
variant === "outlined" && /* @__PURE__ */ React71.createElement("fieldset", { className: "rf-text-field__notch" }, label && /* @__PURE__ */ React71.createElement("legend", { className: "rf-text-field__legend" }, /* @__PURE__ */ React71.createElement("span", null, label, required ? " *" : "")))
|
|
2660
3097
|
), open && !disabled && createPortal(
|
|
2661
|
-
/* @__PURE__ */
|
|
3098
|
+
/* @__PURE__ */ React71.createElement(
|
|
2662
3099
|
"div",
|
|
2663
3100
|
{
|
|
2664
3101
|
ref: pickerRef,
|
|
@@ -2683,7 +3120,7 @@ var DateField = ({
|
|
|
2683
3120
|
})(),
|
|
2684
3121
|
onMouseDown: (e) => e.preventDefault()
|
|
2685
3122
|
},
|
|
2686
|
-
/* @__PURE__ */
|
|
3123
|
+
/* @__PURE__ */ React71.createElement("div", { className: isSideVariant ? "rf-date-picker__cal-col" : void 0 }, /* @__PURE__ */ React71.createElement(
|
|
2687
3124
|
CalendarBody,
|
|
2688
3125
|
{
|
|
2689
3126
|
viewMonth,
|
|
@@ -2697,7 +3134,7 @@ var DateField = ({
|
|
|
2697
3134
|
onMonthSelect: setViewMonth,
|
|
2698
3135
|
onYearSelect: setViewYear
|
|
2699
3136
|
}
|
|
2700
|
-
), type === "datetime" && /* @__PURE__ */
|
|
3137
|
+
), type === "datetime" && /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__time-section" }, /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__time-label" }, "Time"), /* @__PURE__ */ React71.createElement(
|
|
2701
3138
|
SpinnerPanel,
|
|
2702
3139
|
{
|
|
2703
3140
|
hour,
|
|
@@ -2709,8 +3146,8 @@ var DateField = ({
|
|
|
2709
3146
|
onMinuteInput: handleMinuteInput,
|
|
2710
3147
|
onAmpmToggle: handleAmpmToggle
|
|
2711
3148
|
}
|
|
2712
|
-
)), /* @__PURE__ */
|
|
2713
|
-
type === "datetime-side" && /* @__PURE__ */
|
|
3149
|
+
)), /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__divider" }), /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__footer" }, /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-date-picker__footer-btn", onClick: handleToday }, "Today"), /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-date-picker__footer-btn rf-date-picker__footer-btn--clear", onClick: handleClear }, "Clear"))),
|
|
3150
|
+
type === "datetime-side" && /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__side-panel" }, /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__side-label" }, "Time"), /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__side-spinner" }, /* @__PURE__ */ React71.createElement(
|
|
2714
3151
|
SpinnerPanel,
|
|
2715
3152
|
{
|
|
2716
3153
|
hour,
|
|
@@ -2722,22 +3159,22 @@ var DateField = ({
|
|
|
2722
3159
|
onMinuteInput: handleMinuteInput,
|
|
2723
3160
|
onAmpmToggle: handleAmpmToggle
|
|
2724
3161
|
}
|
|
2725
|
-
)), /* @__PURE__ */
|
|
2726
|
-
type === "datetime-scroll" && /* @__PURE__ */
|
|
3162
|
+
)), /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__side-time-display" }, String(hour).padStart(2, "0"), ":", String(minute).padStart(2, "0"), " ", ampm)),
|
|
3163
|
+
type === "datetime-scroll" && /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__side-panel" }, /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__side-label" }, "Time"), /* @__PURE__ */ React71.createElement("div", { className: "rf-timescroll" }, /* @__PURE__ */ React71.createElement(
|
|
2727
3164
|
ScrollColumn,
|
|
2728
3165
|
{
|
|
2729
3166
|
items: HOURS,
|
|
2730
3167
|
selected: hour - 1,
|
|
2731
3168
|
onSelect: handleScrollHour
|
|
2732
3169
|
}
|
|
2733
|
-
), /* @__PURE__ */
|
|
3170
|
+
), /* @__PURE__ */ React71.createElement("div", { className: "rf-timescroll__colon" }, ":"), /* @__PURE__ */ React71.createElement(
|
|
2734
3171
|
ScrollColumn,
|
|
2735
3172
|
{
|
|
2736
3173
|
items: MINUTES,
|
|
2737
3174
|
selected: minute,
|
|
2738
3175
|
onSelect: handleScrollMinute
|
|
2739
3176
|
}
|
|
2740
|
-
), /* @__PURE__ */
|
|
3177
|
+
), /* @__PURE__ */ React71.createElement(
|
|
2741
3178
|
ScrollColumn,
|
|
2742
3179
|
{
|
|
2743
3180
|
items: AMPMS,
|
|
@@ -2745,18 +3182,18 @@ var DateField = ({
|
|
|
2745
3182
|
onSelect: handleScrollAmpm,
|
|
2746
3183
|
infinite: false
|
|
2747
3184
|
}
|
|
2748
|
-
)), /* @__PURE__ */
|
|
3185
|
+
)), /* @__PURE__ */ React71.createElement("div", { className: "rf-date-picker__side-time-display" }, String(hour).padStart(2, "0"), ":", String(minute).padStart(2, "0"), " ", ampm))
|
|
2749
3186
|
),
|
|
2750
3187
|
document.body
|
|
2751
|
-
)), helperText && /* @__PURE__ */
|
|
3188
|
+
)), helperText && /* @__PURE__ */ React71.createElement("div", { className: "rf-text-field__helper-text" }, helperText));
|
|
2752
3189
|
};
|
|
2753
3190
|
DateField.displayName = "DateField";
|
|
2754
3191
|
|
|
2755
3192
|
// lib/TextFields/DateRangeField.tsx
|
|
2756
|
-
import
|
|
2757
|
-
useState as
|
|
2758
|
-
useRef as
|
|
2759
|
-
useEffect as
|
|
3193
|
+
import React72, {
|
|
3194
|
+
useState as useState7,
|
|
3195
|
+
useRef as useRef6,
|
|
3196
|
+
useEffect as useEffect7
|
|
2760
3197
|
} from "react";
|
|
2761
3198
|
var WEEKDAYS2 = ["SU", "MO", "TU", "WE", "TH", "FR", "SA"];
|
|
2762
3199
|
var MONTHS2 = [
|
|
@@ -2882,7 +3319,7 @@ var detectPreset = (start, end) => {
|
|
|
2882
3319
|
if (isSameDay2(start, new Date(2e3, 0, 1)) && isSameDay2(end, today2)) return "all";
|
|
2883
3320
|
return null;
|
|
2884
3321
|
};
|
|
2885
|
-
var CalendarIcon2 = () => /* @__PURE__ */
|
|
3322
|
+
var CalendarIcon2 = () => /* @__PURE__ */ React72.createElement("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ React72.createElement("rect", { x: "3", y: "4", width: "18", height: "18", rx: "2", ry: "2" }), /* @__PURE__ */ React72.createElement("line", { x1: "16", y1: "2", x2: "16", y2: "6" }), /* @__PURE__ */ React72.createElement("line", { x1: "8", y1: "2", x2: "8", y2: "6" }), /* @__PURE__ */ React72.createElement("line", { x1: "3", y1: "10", x2: "21", y2: "10" }));
|
|
2886
3323
|
var RangeCalendarBody = ({
|
|
2887
3324
|
viewYear,
|
|
2888
3325
|
viewMonth,
|
|
@@ -2907,7 +3344,7 @@ var RangeCalendarBody = ({
|
|
|
2907
3344
|
const hasRange = startDate != null && effectiveEnd != null && !isSameDay2(startDate, effectiveEnd);
|
|
2908
3345
|
const lo = startDate && effectiveEnd ? startDate <= effectiveEnd ? startDate : effectiveEnd : null;
|
|
2909
3346
|
const hi = startDate && effectiveEnd ? startDate <= effectiveEnd ? effectiveEnd : startDate : null;
|
|
2910
|
-
return /* @__PURE__ */
|
|
3347
|
+
return /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-calendar" }, /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-calendar__header" }, /* @__PURE__ */ React72.createElement(
|
|
2911
3348
|
"button",
|
|
2912
3349
|
{
|
|
2913
3350
|
type: "button",
|
|
@@ -2917,7 +3354,7 @@ var RangeCalendarBody = ({
|
|
|
2917
3354
|
"aria-label": "Previous month"
|
|
2918
3355
|
},
|
|
2919
3356
|
"\u2039"
|
|
2920
|
-
), /* @__PURE__ */
|
|
3357
|
+
), /* @__PURE__ */ React72.createElement("span", { className: "rf-dr-calendar__month-label" }, MONTHS2[viewMonth], " ", viewYear), /* @__PURE__ */ React72.createElement(
|
|
2921
3358
|
"button",
|
|
2922
3359
|
{
|
|
2923
3360
|
type: "button",
|
|
@@ -2927,9 +3364,9 @@ var RangeCalendarBody = ({
|
|
|
2927
3364
|
"aria-label": "Next month"
|
|
2928
3365
|
},
|
|
2929
3366
|
"\u203A"
|
|
2930
|
-
)), /* @__PURE__ */
|
|
3367
|
+
)), /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-calendar__weekdays" }, WEEKDAYS2.map((w) => /* @__PURE__ */ React72.createElement("div", { key: w, className: "rf-dr-calendar__weekday" }, w))), /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-calendar__grid" }, dayCells.map((day, idx) => {
|
|
2931
3368
|
if (day === null) {
|
|
2932
|
-
return /* @__PURE__ */
|
|
3369
|
+
return /* @__PURE__ */ React72.createElement("div", { key: `e-${idx}`, className: "rf-dr-calendar__cell rf-dr-calendar__cell--empty" });
|
|
2933
3370
|
}
|
|
2934
3371
|
const cellDate = new Date(viewYear, viewMonth, day);
|
|
2935
3372
|
const isStart = startDate ? isSameDay2(cellDate, startDate) : false;
|
|
@@ -2949,7 +3386,7 @@ var RangeCalendarBody = ({
|
|
|
2949
3386
|
isStart || isEnd ? "rf-dr-calendar__day--selected" : "",
|
|
2950
3387
|
isToday && !isStart && !isEnd ? "rf-dr-calendar__day--today" : ""
|
|
2951
3388
|
].filter(Boolean).join(" ");
|
|
2952
|
-
return /* @__PURE__ */
|
|
3389
|
+
return /* @__PURE__ */ React72.createElement(
|
|
2953
3390
|
"div",
|
|
2954
3391
|
{
|
|
2955
3392
|
key: day,
|
|
@@ -2957,7 +3394,7 @@ var RangeCalendarBody = ({
|
|
|
2957
3394
|
onMouseEnter: () => onDayHover(cellDate),
|
|
2958
3395
|
onMouseLeave: () => onDayHover(null)
|
|
2959
3396
|
},
|
|
2960
|
-
/* @__PURE__ */
|
|
3397
|
+
/* @__PURE__ */ React72.createElement(
|
|
2961
3398
|
"button",
|
|
2962
3399
|
{
|
|
2963
3400
|
type: "button",
|
|
@@ -2971,8 +3408,8 @@ var RangeCalendarBody = ({
|
|
|
2971
3408
|
};
|
|
2972
3409
|
var MiniCalendar = ({ selectedDate, todayDate, onSelect, onClose }) => {
|
|
2973
3410
|
const init = selectedDate ?? todayDate;
|
|
2974
|
-
const [viewYear, setViewYear] =
|
|
2975
|
-
const [viewMonth, setViewMonth] =
|
|
3411
|
+
const [viewYear, setViewYear] = useState7(init.getFullYear());
|
|
3412
|
+
const [viewMonth, setViewMonth] = useState7(init.getMonth());
|
|
2976
3413
|
const firstDay = new Date(viewYear, viewMonth, 1).getDay();
|
|
2977
3414
|
const daysInMonth = new Date(viewYear, viewMonth + 1, 0).getDate();
|
|
2978
3415
|
const dayCells = [
|
|
@@ -2991,807 +3428,419 @@ var MiniCalendar = ({ selectedDate, todayDate, onSelect, onClose }) => {
|
|
|
2991
3428
|
setViewYear((y) => y + 1);
|
|
2992
3429
|
} else setViewMonth((m) => m + 1);
|
|
2993
3430
|
};
|
|
2994
|
-
return /* @__PURE__ */
|
|
3431
|
+
return /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-mini-cal" }, /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-mini-cal__header" }, /* @__PURE__ */ React72.createElement("button", { type: "button", className: "rf-dr-calendar__nav-btn", onClick: prevMonth }, "\u2039"), /* @__PURE__ */ React72.createElement("span", { className: "rf-dr-calendar__month-label", style: { fontSize: "0.88rem" } }, MONTHS2[viewMonth], " ", viewYear), /* @__PURE__ */ React72.createElement("button", { type: "button", className: "rf-dr-calendar__nav-btn", onClick: nextMonth }, "\u203A")), /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-calendar__weekdays" }, WEEKDAYS2.map((w) => /* @__PURE__ */ React72.createElement("div", { key: w, className: "rf-dr-calendar__weekday" }, w))), /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-calendar__grid" }, dayCells.map((day, idx) => {
|
|
2995
3432
|
if (day === null) {
|
|
2996
|
-
return /* @__PURE__ */
|
|
2997
|
-
}
|
|
2998
|
-
const cellDate = new Date(viewYear, viewMonth, day);
|
|
2999
|
-
const isSel = selectedDate ? isSameDay2(cellDate, selectedDate) : false;
|
|
3000
|
-
const isToday = isSameDay2(cellDate, todayDate);
|
|
3001
|
-
return /* @__PURE__ */ React71.createElement("div", { key: day, className: "rf-dr-calendar__cell" }, /* @__PURE__ */ React71.createElement(
|
|
3002
|
-
"button",
|
|
3003
|
-
{
|
|
3004
|
-
type: "button",
|
|
3005
|
-
className: [
|
|
3006
|
-
"rf-dr-calendar__day",
|
|
3007
|
-
isSel ? "rf-dr-calendar__day--selected" : "",
|
|
3008
|
-
isToday && !isSel ? "rf-dr-calendar__day--today" : ""
|
|
3009
|
-
].filter(Boolean).join(" "),
|
|
3010
|
-
onClick: () => {
|
|
3011
|
-
onSelect(cellDate);
|
|
3012
|
-
onClose();
|
|
3013
|
-
}
|
|
3014
|
-
},
|
|
3015
|
-
day
|
|
3016
|
-
));
|
|
3017
|
-
})));
|
|
3018
|
-
};
|
|
3019
|
-
var DateRangeField = ({
|
|
3020
|
-
label,
|
|
3021
|
-
value,
|
|
3022
|
-
onChange,
|
|
3023
|
-
pickerType = "panel",
|
|
3024
|
-
variant = "outlined",
|
|
3025
|
-
size = "medium",
|
|
3026
|
-
color = "primary",
|
|
3027
|
-
error = false,
|
|
3028
|
-
helperText,
|
|
3029
|
-
fullWidth = false,
|
|
3030
|
-
disabled = false,
|
|
3031
|
-
required = false,
|
|
3032
|
-
className = "",
|
|
3033
|
-
style,
|
|
3034
|
-
sx
|
|
3035
|
-
}) => {
|
|
3036
|
-
const sxClass = useSx(sx);
|
|
3037
|
-
const today2 = todayFn();
|
|
3038
|
-
const committedStart = value?.start ? isoToDate2(value.start) : null;
|
|
3039
|
-
const committedEnd = value?.end ? isoToDate2(value.end) : null;
|
|
3040
|
-
const [open, setOpen] = useState6(false);
|
|
3041
|
-
const [draftStart, setDraftStart] = useState6(committedStart);
|
|
3042
|
-
const [draftEnd, setDraftEnd] = useState6(committedEnd);
|
|
3043
|
-
const [activePreset, setActivePreset] = useState6(
|
|
3044
|
-
() => detectPreset(committedStart, committedEnd)
|
|
3045
|
-
);
|
|
3046
|
-
const [startInputStr, setStartInputStr] = useState6(() => committedStart ? formatShort(committedStart) : "");
|
|
3047
|
-
const [endInputStr, setEndInputStr] = useState6(() => committedEnd ? formatShort(committedEnd) : "");
|
|
3048
|
-
const [inlineCal, setInlineCal] = useState6(null);
|
|
3049
|
-
const [hoverDate, setHoverDate] = useState6(null);
|
|
3050
|
-
const [selecting, setSelecting] = useState6("start");
|
|
3051
|
-
const [leftViewYear, setLeftViewYear] = useState6(() => today2.getFullYear());
|
|
3052
|
-
const [leftViewMonth, setLeftViewMonth] = useState6(() => today2.getMonth());
|
|
3053
|
-
const containerRef = useRef5(null);
|
|
3054
|
-
const inputId = useRef5(`rf-dr-${Math.random().toString(36).substr(2, 9)}`).current;
|
|
3055
|
-
useEffect6(() => {
|
|
3056
|
-
const s2 = value?.start ? isoToDate2(value.start) : null;
|
|
3057
|
-
const e = value?.end ? isoToDate2(value.end) : null;
|
|
3058
|
-
setDraftStart(s2);
|
|
3059
|
-
setDraftEnd(e);
|
|
3060
|
-
setStartInputStr(s2 ? formatShort(s2) : "");
|
|
3061
|
-
setEndInputStr(e ? formatShort(e) : "");
|
|
3062
|
-
setActivePreset(detectPreset(s2, e));
|
|
3063
|
-
}, [value?.start, value?.end]);
|
|
3064
|
-
useEffect6(() => {
|
|
3065
|
-
setActivePreset(detectPreset(draftStart, draftEnd));
|
|
3066
|
-
}, [draftStart?.getTime(), draftEnd?.getTime()]);
|
|
3067
|
-
useEffect6(() => {
|
|
3068
|
-
if (!open) return;
|
|
3069
|
-
const handler = (e) => {
|
|
3070
|
-
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
3071
|
-
setOpen(false);
|
|
3072
|
-
setInlineCal(null);
|
|
3073
|
-
setDraftStart(committedStart);
|
|
3074
|
-
setDraftEnd(committedEnd);
|
|
3075
|
-
setStartInputStr(committedStart ? formatShort(committedStart) : "");
|
|
3076
|
-
setEndInputStr(committedEnd ? formatShort(committedEnd) : "");
|
|
3077
|
-
setActivePreset(detectPreset(committedStart, committedEnd));
|
|
3078
|
-
setSelecting("start");
|
|
3079
|
-
}
|
|
3080
|
-
};
|
|
3081
|
-
document.addEventListener("mousedown", handler);
|
|
3082
|
-
return () => document.removeEventListener("mousedown", handler);
|
|
3083
|
-
}, [open, committedStart, committedEnd]);
|
|
3084
|
-
const displayStr = (() => {
|
|
3085
|
-
if (committedStart && committedEnd) {
|
|
3086
|
-
return `${formatShort(committedStart)} \u2013 ${formatShort(committedEnd)}`;
|
|
3087
|
-
}
|
|
3088
|
-
if (committedStart) return `${formatShort(committedStart)} \u2013`;
|
|
3089
|
-
return "";
|
|
3090
|
-
})();
|
|
3091
|
-
const handleApply = () => {
|
|
3092
|
-
if (draftStart && draftEnd) {
|
|
3093
|
-
const [s2, e] = draftStart <= draftEnd ? [draftStart, draftEnd] : [draftEnd, draftStart];
|
|
3094
|
-
onChange?.({ start: dateToISO(s2), end: dateToISO(e) });
|
|
3095
|
-
} else if (draftStart) {
|
|
3096
|
-
onChange?.({ start: dateToISO(draftStart), end: dateToISO(draftStart) });
|
|
3097
|
-
}
|
|
3098
|
-
setOpen(false);
|
|
3099
|
-
setInlineCal(null);
|
|
3100
|
-
};
|
|
3101
|
-
const handleClose = () => {
|
|
3102
|
-
setOpen(false);
|
|
3103
|
-
setInlineCal(null);
|
|
3104
|
-
setDraftStart(committedStart);
|
|
3105
|
-
setDraftEnd(committedEnd);
|
|
3106
|
-
setStartInputStr(committedStart ? formatShort(committedStart) : "");
|
|
3107
|
-
setEndInputStr(committedEnd ? formatShort(committedEnd) : "");
|
|
3108
|
-
setActivePreset(detectPreset(committedStart, committedEnd));
|
|
3109
|
-
setSelecting("start");
|
|
3110
|
-
};
|
|
3111
|
-
const handlePreset = (presetId) => {
|
|
3112
|
-
const range = getPresetRange(presetId, draftStart);
|
|
3113
|
-
const s2 = isoToDate2(range.start);
|
|
3114
|
-
const e = isoToDate2(range.end);
|
|
3115
|
-
setDraftStart(s2);
|
|
3116
|
-
setDraftEnd(e);
|
|
3117
|
-
setStartInputStr(s2 ? formatShort(s2) : "");
|
|
3118
|
-
setEndInputStr(e ? formatShort(e) : "");
|
|
3119
|
-
setInlineCal(null);
|
|
3120
|
-
};
|
|
3121
|
-
const handleCalDayClick = (d) => {
|
|
3122
|
-
if (selecting === "start") {
|
|
3123
|
-
setDraftStart(d);
|
|
3124
|
-
setDraftEnd(null);
|
|
3125
|
-
setSelecting("end");
|
|
3126
|
-
setActivePreset(null);
|
|
3127
|
-
} else {
|
|
3128
|
-
if (draftStart && d < draftStart) {
|
|
3129
|
-
setDraftEnd(draftStart);
|
|
3130
|
-
setDraftStart(d);
|
|
3131
|
-
} else {
|
|
3132
|
-
setDraftEnd(d);
|
|
3133
|
-
}
|
|
3134
|
-
setSelecting("start");
|
|
3135
|
-
setActivePreset(detectPreset(draftStart, d));
|
|
3136
|
-
}
|
|
3137
|
-
};
|
|
3138
|
-
const rightViewMonth = leftViewMonth === 11 ? 0 : leftViewMonth + 1;
|
|
3139
|
-
const rightViewYear = leftViewMonth === 11 ? leftViewYear + 1 : leftViewYear;
|
|
3140
|
-
const prevMonth = () => {
|
|
3141
|
-
if (leftViewMonth === 0) {
|
|
3142
|
-
setLeftViewMonth(11);
|
|
3143
|
-
setLeftViewYear((y) => y - 1);
|
|
3144
|
-
} else setLeftViewMonth((m) => m - 1);
|
|
3145
|
-
};
|
|
3146
|
-
const nextMonth = () => {
|
|
3147
|
-
if (leftViewMonth === 11) {
|
|
3148
|
-
setLeftViewMonth(0);
|
|
3149
|
-
setLeftViewYear((y) => y + 1);
|
|
3150
|
-
} else setLeftViewMonth((m) => m + 1);
|
|
3151
|
-
};
|
|
3152
|
-
const daysUntilToday = draftStart ? Math.max(0, daysBetween(draftStart, today2)) : 0;
|
|
3153
|
-
const daysFromToday = draftEnd ? Math.max(0, daysBetween(today2, draftEnd)) : 0;
|
|
3154
|
-
const handleDaysUntilChange = (e) => {
|
|
3155
|
-
const n = parseInt(e.target.value, 10);
|
|
3156
|
-
if (!isNaN(n) && n >= 0) {
|
|
3157
|
-
const d = addDays(today2, -n);
|
|
3158
|
-
setDraftStart(d);
|
|
3159
|
-
setStartInputStr(formatShort(d));
|
|
3160
|
-
}
|
|
3161
|
-
};
|
|
3162
|
-
const handleDaysFromChange = (e) => {
|
|
3163
|
-
const n = parseInt(e.target.value, 10);
|
|
3164
|
-
if (!isNaN(n) && n >= 0) {
|
|
3165
|
-
const d = addDays(today2, n);
|
|
3166
|
-
setDraftEnd(d);
|
|
3167
|
-
setEndInputStr(formatShort(d));
|
|
3168
|
-
}
|
|
3169
|
-
};
|
|
3170
|
-
const handleStartInputChange = (e) => {
|
|
3171
|
-
const raw = e.target.value;
|
|
3172
|
-
setStartInputStr(raw);
|
|
3173
|
-
const parsed = parseInputDate(raw);
|
|
3174
|
-
if (parsed) setDraftStart(parsed);
|
|
3175
|
-
else if (!raw) setDraftStart(null);
|
|
3176
|
-
};
|
|
3177
|
-
const handleStartInputBlur = () => {
|
|
3178
|
-
setStartInputStr(draftStart ? formatShort(draftStart) : "");
|
|
3179
|
-
};
|
|
3180
|
-
const handleEndInputChange = (e) => {
|
|
3181
|
-
const raw = e.target.value;
|
|
3182
|
-
setEndInputStr(raw);
|
|
3183
|
-
const parsed = parseInputDate(raw);
|
|
3184
|
-
if (parsed) setDraftEnd(parsed);
|
|
3185
|
-
else if (!raw) setDraftEnd(null);
|
|
3186
|
-
};
|
|
3187
|
-
const handleEndInputBlur = () => {
|
|
3188
|
-
setEndInputStr(draftEnd ? formatShort(draftEnd) : "");
|
|
3189
|
-
};
|
|
3190
|
-
const isFloating = Boolean(displayStr || open);
|
|
3191
|
-
const rootClasses = [
|
|
3192
|
-
"rf-text-field",
|
|
3193
|
-
`rf-text-field--${variant}`,
|
|
3194
|
-
`rf-text-field--${size}`,
|
|
3195
|
-
`rf-text-field--${color}`,
|
|
3196
|
-
error ? "rf-text-field--error" : "",
|
|
3197
|
-
fullWidth ? "rf-text-field--full-width" : "",
|
|
3198
|
-
disabled ? "rf-text-field--disabled" : "",
|
|
3199
|
-
isFloating ? "rf-text-field--floating" : "",
|
|
3200
|
-
Boolean(label) ? "rf-text-field--has-label" : "",
|
|
3201
|
-
"rf-text-field--adorned-end",
|
|
3202
|
-
"rf-date-field",
|
|
3203
|
-
"rf-date-range-field",
|
|
3204
|
-
fullWidth ? "rf-date-field--full-width" : "",
|
|
3205
|
-
sxClass,
|
|
3206
|
-
className
|
|
3207
|
-
].filter(Boolean).join(" ");
|
|
3208
|
-
const inputPlaceholder = variant === "outlined" ? " " : void 0;
|
|
3209
|
-
return /* @__PURE__ */ React71.createElement("div", { ref: containerRef, className: rootClasses, style }, /* @__PURE__ */ React71.createElement("div", { className: "rf-date-field__anchor" }, /* @__PURE__ */ React71.createElement(
|
|
3210
|
-
"div",
|
|
3211
|
-
{
|
|
3212
|
-
className: "rf-text-field__wrapper",
|
|
3213
|
-
onClick: () => {
|
|
3214
|
-
if (!disabled) setOpen((o) => !o);
|
|
3215
|
-
},
|
|
3216
|
-
style: { cursor: disabled ? "default" : "pointer" }
|
|
3217
|
-
},
|
|
3218
|
-
/* @__PURE__ */ React71.createElement(
|
|
3219
|
-
"input",
|
|
3220
|
-
{
|
|
3221
|
-
id: inputId,
|
|
3222
|
-
className: "rf-text-field__input",
|
|
3223
|
-
type: "text",
|
|
3224
|
-
value: displayStr,
|
|
3225
|
-
readOnly: true,
|
|
3226
|
-
placeholder: inputPlaceholder,
|
|
3227
|
-
disabled,
|
|
3228
|
-
onClick: (e) => e.stopPropagation(),
|
|
3229
|
-
onFocus: () => {
|
|
3230
|
-
if (!disabled) setOpen(true);
|
|
3231
|
-
}
|
|
3232
|
-
}
|
|
3233
|
-
),
|
|
3234
|
-
/* @__PURE__ */ React71.createElement("div", { className: "rf-text-field__adornment rf-text-field__adornment--end" }, /* @__PURE__ */ React71.createElement(
|
|
3235
|
-
"button",
|
|
3236
|
-
{
|
|
3237
|
-
type: "button",
|
|
3238
|
-
className: "rf-date-field__icon-btn",
|
|
3239
|
-
tabIndex: -1,
|
|
3240
|
-
disabled,
|
|
3241
|
-
onClick: (e) => {
|
|
3242
|
-
e.stopPropagation();
|
|
3243
|
-
if (!disabled) setOpen((o) => !o);
|
|
3244
|
-
},
|
|
3245
|
-
"aria-label": "Pick date range"
|
|
3246
|
-
},
|
|
3247
|
-
/* @__PURE__ */ React71.createElement(CalendarIcon2, null)
|
|
3248
|
-
)),
|
|
3249
|
-
label && /* @__PURE__ */ React71.createElement("label", { htmlFor: inputId, className: "rf-text-field__label" }, label, " ", required && /* @__PURE__ */ React71.createElement("span", { className: "rf-text-field__asterisk" }, "*")),
|
|
3250
|
-
variant === "outlined" && /* @__PURE__ */ React71.createElement("fieldset", { className: "rf-text-field__notch" }, label ? /* @__PURE__ */ React71.createElement("legend", { className: "rf-text-field__legend" }, /* @__PURE__ */ React71.createElement("span", null, label, required ? " *" : "")) : /* @__PURE__ */ React71.createElement("legend", { className: "rf-text-field__legend--empty" }))
|
|
3251
|
-
), open && !disabled && (pickerType === "panel" ? (
|
|
3252
|
-
/* ── Panel Mode ── */
|
|
3253
|
-
/* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker rf-dr-picker--panel", onMouseDown: (e) => e.preventDefault() }, /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__presets" }, PRESETS.map((p, i) => /* @__PURE__ */ React71.createElement(React71.Fragment, { key: p.id }, i > 0 && /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__preset-sep" }), /* @__PURE__ */ React71.createElement(
|
|
3254
|
-
"button",
|
|
3255
|
-
{
|
|
3256
|
-
type: "button",
|
|
3257
|
-
className: [
|
|
3258
|
-
"rf-dr-picker__preset-btn",
|
|
3259
|
-
activePreset === p.id ? "rf-dr-picker__preset-btn--active" : ""
|
|
3260
|
-
].filter(Boolean).join(" "),
|
|
3261
|
-
onClick: () => handlePreset(p.id)
|
|
3262
|
-
},
|
|
3263
|
-
p.label
|
|
3264
|
-
)))), /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__manual" }, /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__date-field-wrap" }, /* @__PURE__ */ React71.createElement(
|
|
3265
|
-
"div",
|
|
3266
|
-
{
|
|
3267
|
-
className: [
|
|
3268
|
-
"rf-dr-picker__date-field",
|
|
3269
|
-
inlineCal === "start" ? "rf-dr-picker__date-field--active" : ""
|
|
3270
|
-
].filter(Boolean).join(" ")
|
|
3271
|
-
},
|
|
3272
|
-
/* @__PURE__ */ React71.createElement("span", { className: "rf-dr-picker__date-floating-label" }, "Start Date"),
|
|
3273
|
-
/* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__date-display" }, /* @__PURE__ */ React71.createElement(
|
|
3274
|
-
"input",
|
|
3275
|
-
{
|
|
3276
|
-
type: "text",
|
|
3277
|
-
className: "rf-dr-picker__date-input",
|
|
3278
|
-
value: startInputStr,
|
|
3279
|
-
placeholder: "DD Mon YYYY",
|
|
3280
|
-
onChange: handleStartInputChange,
|
|
3281
|
-
onBlur: handleStartInputBlur,
|
|
3282
|
-
onMouseDown: (e) => e.stopPropagation()
|
|
3283
|
-
}
|
|
3284
|
-
), /* @__PURE__ */ React71.createElement(
|
|
3285
|
-
"button",
|
|
3286
|
-
{
|
|
3287
|
-
type: "button",
|
|
3288
|
-
className: "rf-dr-picker__cal-icon-btn",
|
|
3289
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3290
|
-
onClick: () => setInlineCal((v) => v === "start" ? null : "start"),
|
|
3291
|
-
"aria-label": "Pick start date"
|
|
3292
|
-
},
|
|
3293
|
-
/* @__PURE__ */ React71.createElement(CalendarIcon2, null)
|
|
3294
|
-
))
|
|
3295
|
-
), inlineCal === "start" && /* @__PURE__ */ React71.createElement(
|
|
3296
|
-
MiniCalendar,
|
|
3297
|
-
{
|
|
3298
|
-
selectedDate: draftStart,
|
|
3299
|
-
todayDate: today2,
|
|
3300
|
-
onSelect: (d) => {
|
|
3301
|
-
setDraftStart(d);
|
|
3302
|
-
setStartInputStr(formatShort(d));
|
|
3303
|
-
},
|
|
3304
|
-
onClose: () => setInlineCal(null)
|
|
3305
|
-
}
|
|
3306
|
-
)), /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__date-field-wrap" }, /* @__PURE__ */ React71.createElement(
|
|
3307
|
-
"div",
|
|
3308
|
-
{
|
|
3309
|
-
className: [
|
|
3310
|
-
"rf-dr-picker__date-field",
|
|
3311
|
-
inlineCal === "end" ? "rf-dr-picker__date-field--active" : ""
|
|
3312
|
-
].filter(Boolean).join(" ")
|
|
3313
|
-
},
|
|
3314
|
-
/* @__PURE__ */ React71.createElement("span", { className: "rf-dr-picker__date-floating-label" }, "End Date"),
|
|
3315
|
-
/* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__date-display" }, /* @__PURE__ */ React71.createElement(
|
|
3316
|
-
"input",
|
|
3317
|
-
{
|
|
3318
|
-
type: "text",
|
|
3319
|
-
className: "rf-dr-picker__date-input",
|
|
3320
|
-
value: endInputStr,
|
|
3321
|
-
placeholder: "DD Mon YYYY",
|
|
3322
|
-
onChange: handleEndInputChange,
|
|
3323
|
-
onBlur: handleEndInputBlur,
|
|
3324
|
-
onMouseDown: (e) => e.stopPropagation()
|
|
3325
|
-
}
|
|
3326
|
-
), /* @__PURE__ */ React71.createElement(
|
|
3327
|
-
"button",
|
|
3328
|
-
{
|
|
3329
|
-
type: "button",
|
|
3330
|
-
className: "rf-dr-picker__cal-icon-btn",
|
|
3331
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3332
|
-
onClick: () => setInlineCal((v) => v === "end" ? null : "end"),
|
|
3333
|
-
"aria-label": "Pick end date"
|
|
3334
|
-
},
|
|
3335
|
-
/* @__PURE__ */ React71.createElement(CalendarIcon2, null)
|
|
3336
|
-
))
|
|
3337
|
-
), inlineCal === "end" && /* @__PURE__ */ React71.createElement(
|
|
3338
|
-
MiniCalendar,
|
|
3339
|
-
{
|
|
3340
|
-
selectedDate: draftEnd,
|
|
3341
|
-
todayDate: today2,
|
|
3342
|
-
onSelect: (d) => {
|
|
3343
|
-
setDraftEnd(d);
|
|
3344
|
-
setEndInputStr(formatShort(d));
|
|
3345
|
-
},
|
|
3346
|
-
onClose: () => setInlineCal(null)
|
|
3347
|
-
}
|
|
3348
|
-
)), !inlineCal && /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__days-section" }, /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__days-row" }, /* @__PURE__ */ React71.createElement("span", { className: "rf-dr-picker__days-label" }, "Days until today"), /* @__PURE__ */ React71.createElement(
|
|
3349
|
-
"input",
|
|
3350
|
-
{
|
|
3351
|
-
type: "number",
|
|
3352
|
-
className: "rf-dr-picker__days-input",
|
|
3353
|
-
value: draftStart ? daysUntilToday : "",
|
|
3354
|
-
min: 0,
|
|
3355
|
-
onChange: handleDaysUntilChange,
|
|
3356
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3357
|
-
placeholder: "\u2014"
|
|
3358
|
-
}
|
|
3359
|
-
)), /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__days-row" }, /* @__PURE__ */ React71.createElement("span", { className: "rf-dr-picker__days-label" }, "Days from today"), /* @__PURE__ */ React71.createElement(
|
|
3360
|
-
"input",
|
|
3361
|
-
{
|
|
3362
|
-
type: "number",
|
|
3363
|
-
className: "rf-dr-picker__days-input",
|
|
3364
|
-
value: draftEnd ? daysFromToday : "",
|
|
3365
|
-
min: 0,
|
|
3366
|
-
onChange: handleDaysFromChange,
|
|
3367
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3368
|
-
placeholder: "\u2014"
|
|
3369
|
-
}
|
|
3370
|
-
))), /* @__PURE__ */ React71.createElement("div", { style: { flex: 1 } }), /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__footer" }, /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-dr-picker__close-btn", onClick: handleClose }, "CLOSE"), /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-dr-picker__apply-btn", onClick: handleApply }, "APPLY"))))
|
|
3371
|
-
) : (
|
|
3372
|
-
/* ── Calendar Mode ── */
|
|
3373
|
-
/* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker rf-dr-picker--calendar", onMouseDown: (e) => e.preventDefault() }, /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__calendars" }, /* @__PURE__ */ React71.createElement(
|
|
3374
|
-
RangeCalendarBody,
|
|
3375
|
-
{
|
|
3376
|
-
viewYear: leftViewYear,
|
|
3377
|
-
viewMonth: leftViewMonth,
|
|
3378
|
-
startDate: draftStart,
|
|
3379
|
-
endDate: draftEnd,
|
|
3380
|
-
hoverDate: selecting === "end" ? hoverDate : null,
|
|
3381
|
-
todayDate: today2,
|
|
3382
|
-
onDayClick: handleCalDayClick,
|
|
3383
|
-
onDayHover: setHoverDate,
|
|
3384
|
-
onPrev: prevMonth,
|
|
3385
|
-
onNext: nextMonth,
|
|
3386
|
-
showNext: false
|
|
3387
|
-
}
|
|
3388
|
-
), /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__cal-col-divider" }), /* @__PURE__ */ React71.createElement(
|
|
3389
|
-
RangeCalendarBody,
|
|
3390
|
-
{
|
|
3391
|
-
viewYear: rightViewYear,
|
|
3392
|
-
viewMonth: rightViewMonth,
|
|
3393
|
-
startDate: draftStart,
|
|
3394
|
-
endDate: draftEnd,
|
|
3395
|
-
hoverDate: selecting === "end" ? hoverDate : null,
|
|
3396
|
-
todayDate: today2,
|
|
3397
|
-
onDayClick: handleCalDayClick,
|
|
3398
|
-
onDayHover: setHoverDate,
|
|
3399
|
-
onPrev: prevMonth,
|
|
3400
|
-
onNext: nextMonth,
|
|
3401
|
-
showPrev: false
|
|
3402
|
-
}
|
|
3403
|
-
)), selecting === "end" && draftStart && /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__cal-hint" }, /* @__PURE__ */ React71.createElement("span", { className: "rf-dr-picker__cal-hint-dot" }), /* @__PURE__ */ React71.createElement("span", null, "Select end date \xB7 started from ", /* @__PURE__ */ React71.createElement("strong", null, formatShort(draftStart)))), /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__divider" }), /* @__PURE__ */ React71.createElement("div", { className: "rf-dr-picker__cal-footer" }, draftStart && draftEnd && /* @__PURE__ */ React71.createElement("span", { className: "rf-dr-picker__cal-range-label" }, formatShort(draftStart <= draftEnd ? draftStart : draftEnd), " \u2013 ", formatShort(draftStart <= draftEnd ? draftEnd : draftStart), /* @__PURE__ */ React71.createElement("span", { className: "rf-dr-picker__cal-range-days" }, " ", "(", Math.abs(daysBetween(draftStart, draftEnd)) + 1, " days)")), /* @__PURE__ */ React71.createElement("div", { style: { flex: 1 } }), /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-dr-picker__close-btn", onClick: handleClose }, "CLOSE"), /* @__PURE__ */ React71.createElement("button", { type: "button", className: "rf-dr-picker__apply-btn", onClick: handleApply }, "APPLY")))
|
|
3404
|
-
))), helperText && /* @__PURE__ */ React71.createElement("div", { className: "rf-text-field__helper-text" }, helperText));
|
|
3405
|
-
};
|
|
3406
|
-
DateRangeField.displayName = "DateRangeField";
|
|
3407
|
-
|
|
3408
|
-
// lib/TextFields/Autocomplete.tsx
|
|
3409
|
-
import React72, {
|
|
3410
|
-
useState as useState7,
|
|
3411
|
-
useRef as useRef6,
|
|
3412
|
-
useEffect as useEffect7,
|
|
3413
|
-
useCallback as useCallback2
|
|
3414
|
-
} from "react";
|
|
3415
|
-
import ReactDOM2 from "react-dom";
|
|
3416
|
-
var ChevronDownIcon = () => /* @__PURE__ */ React72.createElement("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ React72.createElement("polyline", { points: "6 9 12 15 18 9" }));
|
|
3417
|
-
var CloseSmIcon = ({ size = 16 }) => /* @__PURE__ */ React72.createElement("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round" }, /* @__PURE__ */ React72.createElement("line", { x1: "18", y1: "6", x2: "6", y2: "18" }), /* @__PURE__ */ React72.createElement("line", { x1: "6", y1: "6", x2: "18", y2: "18" }));
|
|
3418
|
-
var CheckIcon = () => /* @__PURE__ */ React72.createElement("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ React72.createElement("polyline", { points: "20 6 9 17 4 12" }));
|
|
3419
|
-
function defaultGetLabel(option) {
|
|
3420
|
-
if (option === null || option === void 0) return "";
|
|
3421
|
-
if (typeof option === "string") return option;
|
|
3422
|
-
if (typeof option === "object" && "label" in option)
|
|
3423
|
-
return String(option.label);
|
|
3424
|
-
return String(option);
|
|
3425
|
-
}
|
|
3426
|
-
function defaultFilter(options, inputValue, getLabel) {
|
|
3427
|
-
if (!inputValue) return options;
|
|
3428
|
-
const q = inputValue.toLowerCase();
|
|
3429
|
-
return options.filter((o) => getLabel(o).toLowerCase().includes(q));
|
|
3430
|
-
}
|
|
3431
|
-
function AutocompleteInner(props, _ref) {
|
|
3432
|
-
const {
|
|
3433
|
-
options,
|
|
3434
|
-
value,
|
|
3435
|
-
onChange,
|
|
3436
|
-
inputValue: controlledInput,
|
|
3437
|
-
onInputChange,
|
|
3438
|
-
getOptionLabel = defaultGetLabel,
|
|
3439
|
-
isOptionEqualToValue,
|
|
3440
|
-
groupBy,
|
|
3441
|
-
filterOptions,
|
|
3442
|
-
renderOption,
|
|
3443
|
-
getOptionDisabled,
|
|
3444
|
-
multiple = false,
|
|
3445
|
-
freeSolo = false,
|
|
3446
|
-
clearable = true,
|
|
3447
|
-
loading = false,
|
|
3448
|
-
loadingText = "Loading\u2026",
|
|
3449
|
-
noOptionsText = "No options",
|
|
3450
|
-
limitTags,
|
|
3451
|
-
label,
|
|
3452
|
-
placeholder,
|
|
3453
|
-
variant = "outlined",
|
|
3454
|
-
size = "medium",
|
|
3455
|
-
error = false,
|
|
3456
|
-
helperText,
|
|
3457
|
-
fullWidth = false,
|
|
3458
|
-
disabled = false,
|
|
3459
|
-
required = false,
|
|
3460
|
-
className = "",
|
|
3461
|
-
style,
|
|
3462
|
-
sx,
|
|
3463
|
-
onOpen,
|
|
3464
|
-
onClose
|
|
3465
|
-
} = props;
|
|
3466
|
-
const [open, setOpen] = useState7(false);
|
|
3467
|
-
const [inputStr, setInputStr] = useState7("");
|
|
3468
|
-
const [focusedIdx, setFocusedIdx] = useState7(-1);
|
|
3469
|
-
const [popupStyle, setPopupStyle] = useState7({});
|
|
3470
|
-
const containerRef = useRef6(null);
|
|
3471
|
-
const inputRef = useRef6(null);
|
|
3472
|
-
const listRef = useRef6(null);
|
|
3473
|
-
const inputId = useRef6(`rf-ac-${Math.random().toString(36).slice(2, 9)}`).current;
|
|
3474
|
-
const sxClass = useSx(sx);
|
|
3475
|
-
const calcPopupStyle = useCallback2(() => {
|
|
3476
|
-
if (!containerRef.current) return;
|
|
3477
|
-
const rect = containerRef.current.getBoundingClientRect();
|
|
3478
|
-
setPopupStyle({
|
|
3479
|
-
top: rect.bottom + 4,
|
|
3480
|
-
left: rect.left,
|
|
3481
|
-
width: rect.width
|
|
3482
|
-
});
|
|
3483
|
-
}, []);
|
|
3484
|
-
const activeInput = controlledInput !== void 0 ? controlledInput : inputStr;
|
|
3485
|
-
const selectedValues = multiple ? Array.isArray(value) ? value : [] : value != null ? [value] : [];
|
|
3486
|
-
const isEqual = useCallback2(
|
|
3487
|
-
(a, b) => isOptionEqualToValue ? isOptionEqualToValue(a, b) : a === b,
|
|
3488
|
-
[isOptionEqualToValue]
|
|
3489
|
-
);
|
|
3490
|
-
const isSelected = useCallback2(
|
|
3491
|
-
(opt) => selectedValues.some((v) => isEqual(opt, v)),
|
|
3492
|
-
[selectedValues, isEqual]
|
|
3493
|
-
);
|
|
3494
|
-
const filtered = filterOptions ? filterOptions(options, activeInput) : defaultFilter(options, activeInput, getOptionLabel);
|
|
3495
|
-
const flatEntries = [];
|
|
3496
|
-
if (groupBy) {
|
|
3497
|
-
const groups = {};
|
|
3498
|
-
const order = [];
|
|
3499
|
-
filtered.forEach((opt) => {
|
|
3500
|
-
const g = groupBy(opt);
|
|
3501
|
-
if (!groups[g]) {
|
|
3502
|
-
groups[g] = [];
|
|
3503
|
-
order.push(g);
|
|
3504
|
-
}
|
|
3505
|
-
groups[g].push(opt);
|
|
3506
|
-
});
|
|
3507
|
-
order.forEach((g) => {
|
|
3508
|
-
flatEntries.push({ kind: "group", label: g });
|
|
3509
|
-
groups[g].forEach((opt) => {
|
|
3510
|
-
flatEntries.push({ kind: "option", option: opt, flatIdx: flatEntries.filter((e) => e.kind === "option").length });
|
|
3511
|
-
});
|
|
3512
|
-
});
|
|
3513
|
-
} else {
|
|
3514
|
-
filtered.forEach((opt, i) => flatEntries.push({ kind: "option", option: opt, flatIdx: i }));
|
|
3515
|
-
}
|
|
3516
|
-
const selectableOptions = flatEntries.filter((e) => e.kind === "option");
|
|
3517
|
-
const openPopup = useCallback2(() => {
|
|
3518
|
-
if (disabled) return;
|
|
3519
|
-
calcPopupStyle();
|
|
3520
|
-
setOpen(true);
|
|
3521
|
-
setFocusedIdx(-1);
|
|
3522
|
-
onOpen?.();
|
|
3523
|
-
}, [disabled, calcPopupStyle, onOpen]);
|
|
3524
|
-
const closePopup = useCallback2(() => {
|
|
3525
|
-
setOpen(false);
|
|
3526
|
-
setFocusedIdx(-1);
|
|
3527
|
-
onClose?.();
|
|
3528
|
-
if (!freeSolo && !multiple && value == null) {
|
|
3529
|
-
setInputStr("");
|
|
3530
|
-
onInputChange?.("");
|
|
3433
|
+
return /* @__PURE__ */ React72.createElement("div", { key: `e-${idx}`, className: "rf-dr-calendar__cell rf-dr-calendar__cell--empty" });
|
|
3531
3434
|
}
|
|
3532
|
-
|
|
3435
|
+
const cellDate = new Date(viewYear, viewMonth, day);
|
|
3436
|
+
const isSel = selectedDate ? isSameDay2(cellDate, selectedDate) : false;
|
|
3437
|
+
const isToday = isSameDay2(cellDate, todayDate);
|
|
3438
|
+
return /* @__PURE__ */ React72.createElement("div", { key: day, className: "rf-dr-calendar__cell" }, /* @__PURE__ */ React72.createElement(
|
|
3439
|
+
"button",
|
|
3440
|
+
{
|
|
3441
|
+
type: "button",
|
|
3442
|
+
className: [
|
|
3443
|
+
"rf-dr-calendar__day",
|
|
3444
|
+
isSel ? "rf-dr-calendar__day--selected" : "",
|
|
3445
|
+
isToday && !isSel ? "rf-dr-calendar__day--today" : ""
|
|
3446
|
+
].filter(Boolean).join(" "),
|
|
3447
|
+
onClick: () => {
|
|
3448
|
+
onSelect(cellDate);
|
|
3449
|
+
onClose();
|
|
3450
|
+
}
|
|
3451
|
+
},
|
|
3452
|
+
day
|
|
3453
|
+
));
|
|
3454
|
+
})));
|
|
3455
|
+
};
|
|
3456
|
+
var DateRangeField = ({
|
|
3457
|
+
label,
|
|
3458
|
+
value,
|
|
3459
|
+
onChange,
|
|
3460
|
+
pickerType = "panel",
|
|
3461
|
+
variant = "outlined",
|
|
3462
|
+
size = "medium",
|
|
3463
|
+
color = "primary",
|
|
3464
|
+
error = false,
|
|
3465
|
+
helperText,
|
|
3466
|
+
fullWidth = false,
|
|
3467
|
+
disabled = false,
|
|
3468
|
+
required = false,
|
|
3469
|
+
className = "",
|
|
3470
|
+
style,
|
|
3471
|
+
sx
|
|
3472
|
+
}) => {
|
|
3473
|
+
const sxClass = useSx(sx);
|
|
3474
|
+
const today2 = todayFn();
|
|
3475
|
+
const committedStart = value?.start ? isoToDate2(value.start) : null;
|
|
3476
|
+
const committedEnd = value?.end ? isoToDate2(value.end) : null;
|
|
3477
|
+
const [open, setOpen] = useState7(false);
|
|
3478
|
+
const [draftStart, setDraftStart] = useState7(committedStart);
|
|
3479
|
+
const [draftEnd, setDraftEnd] = useState7(committedEnd);
|
|
3480
|
+
const [activePreset, setActivePreset] = useState7(
|
|
3481
|
+
() => detectPreset(committedStart, committedEnd)
|
|
3482
|
+
);
|
|
3483
|
+
const [startInputStr, setStartInputStr] = useState7(() => committedStart ? formatShort(committedStart) : "");
|
|
3484
|
+
const [endInputStr, setEndInputStr] = useState7(() => committedEnd ? formatShort(committedEnd) : "");
|
|
3485
|
+
const [inlineCal, setInlineCal] = useState7(null);
|
|
3486
|
+
const [hoverDate, setHoverDate] = useState7(null);
|
|
3487
|
+
const [selecting, setSelecting] = useState7("start");
|
|
3488
|
+
const [leftViewYear, setLeftViewYear] = useState7(() => today2.getFullYear());
|
|
3489
|
+
const [leftViewMonth, setLeftViewMonth] = useState7(() => today2.getMonth());
|
|
3490
|
+
const containerRef = useRef6(null);
|
|
3491
|
+
const inputId = useRef6(`rf-dr-${Math.random().toString(36).substr(2, 9)}`).current;
|
|
3492
|
+
useEffect7(() => {
|
|
3493
|
+
const s2 = value?.start ? isoToDate2(value.start) : null;
|
|
3494
|
+
const e = value?.end ? isoToDate2(value.end) : null;
|
|
3495
|
+
setDraftStart(s2);
|
|
3496
|
+
setDraftEnd(e);
|
|
3497
|
+
setStartInputStr(s2 ? formatShort(s2) : "");
|
|
3498
|
+
setEndInputStr(e ? formatShort(e) : "");
|
|
3499
|
+
setActivePreset(detectPreset(s2, e));
|
|
3500
|
+
}, [value?.start, value?.end]);
|
|
3501
|
+
useEffect7(() => {
|
|
3502
|
+
setActivePreset(detectPreset(draftStart, draftEnd));
|
|
3503
|
+
}, [draftStart?.getTime(), draftEnd?.getTime()]);
|
|
3533
3504
|
useEffect7(() => {
|
|
3534
3505
|
if (!open) return;
|
|
3535
|
-
const
|
|
3506
|
+
const handler = (e) => {
|
|
3536
3507
|
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
3537
|
-
|
|
3508
|
+
setOpen(false);
|
|
3509
|
+
setInlineCal(null);
|
|
3510
|
+
setDraftStart(committedStart);
|
|
3511
|
+
setDraftEnd(committedEnd);
|
|
3512
|
+
setStartInputStr(committedStart ? formatShort(committedStart) : "");
|
|
3513
|
+
setEndInputStr(committedEnd ? formatShort(committedEnd) : "");
|
|
3514
|
+
setActivePreset(detectPreset(committedStart, committedEnd));
|
|
3515
|
+
setSelecting("start");
|
|
3538
3516
|
}
|
|
3539
3517
|
};
|
|
3540
|
-
document.addEventListener("mousedown",
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
window.removeEventListener("resize", calcPopupStyle);
|
|
3547
|
-
};
|
|
3548
|
-
}, [open, closePopup, calcPopupStyle]);
|
|
3549
|
-
useEffect7(() => {
|
|
3550
|
-
if (controlledInput !== void 0) return;
|
|
3551
|
-
if (!multiple) {
|
|
3552
|
-
const v = value;
|
|
3553
|
-
setInputStr(v != null ? getOptionLabel(v) : "");
|
|
3518
|
+
document.addEventListener("mousedown", handler);
|
|
3519
|
+
return () => document.removeEventListener("mousedown", handler);
|
|
3520
|
+
}, [open, committedStart, committedEnd]);
|
|
3521
|
+
const displayStr = (() => {
|
|
3522
|
+
if (committedStart && committedEnd) {
|
|
3523
|
+
return `${formatShort(committedStart)} \u2013 ${formatShort(committedEnd)}`;
|
|
3554
3524
|
}
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
const
|
|
3561
|
-
onChange?.(
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3525
|
+
if (committedStart) return `${formatShort(committedStart)} \u2013`;
|
|
3526
|
+
return "";
|
|
3527
|
+
})();
|
|
3528
|
+
const handleApply = () => {
|
|
3529
|
+
if (draftStart && draftEnd) {
|
|
3530
|
+
const [s2, e] = draftStart <= draftEnd ? [draftStart, draftEnd] : [draftEnd, draftStart];
|
|
3531
|
+
onChange?.({ start: dateToISO(s2), end: dateToISO(e) });
|
|
3532
|
+
} else if (draftStart) {
|
|
3533
|
+
onChange?.({ start: dateToISO(draftStart), end: dateToISO(draftStart) });
|
|
3534
|
+
}
|
|
3535
|
+
setOpen(false);
|
|
3536
|
+
setInlineCal(null);
|
|
3537
|
+
};
|
|
3538
|
+
const handleClose = () => {
|
|
3539
|
+
setOpen(false);
|
|
3540
|
+
setInlineCal(null);
|
|
3541
|
+
setDraftStart(committedStart);
|
|
3542
|
+
setDraftEnd(committedEnd);
|
|
3543
|
+
setStartInputStr(committedStart ? formatShort(committedStart) : "");
|
|
3544
|
+
setEndInputStr(committedEnd ? formatShort(committedEnd) : "");
|
|
3545
|
+
setActivePreset(detectPreset(committedStart, committedEnd));
|
|
3546
|
+
setSelecting("start");
|
|
3547
|
+
};
|
|
3548
|
+
const handlePreset = (presetId) => {
|
|
3549
|
+
const range = getPresetRange(presetId, draftStart);
|
|
3550
|
+
const s2 = isoToDate2(range.start);
|
|
3551
|
+
const e = isoToDate2(range.end);
|
|
3552
|
+
setDraftStart(s2);
|
|
3553
|
+
setDraftEnd(e);
|
|
3554
|
+
setStartInputStr(s2 ? formatShort(s2) : "");
|
|
3555
|
+
setEndInputStr(e ? formatShort(e) : "");
|
|
3556
|
+
setInlineCal(null);
|
|
3557
|
+
};
|
|
3558
|
+
const handleCalDayClick = (d) => {
|
|
3559
|
+
if (selecting === "start") {
|
|
3560
|
+
setDraftStart(d);
|
|
3561
|
+
setDraftEnd(null);
|
|
3562
|
+
setSelecting("end");
|
|
3563
|
+
setActivePreset(null);
|
|
3565
3564
|
} else {
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3565
|
+
if (draftStart && d < draftStart) {
|
|
3566
|
+
setDraftEnd(draftStart);
|
|
3567
|
+
setDraftStart(d);
|
|
3568
|
+
} else {
|
|
3569
|
+
setDraftEnd(d);
|
|
3570
|
+
}
|
|
3571
|
+
setSelecting("start");
|
|
3572
|
+
setActivePreset(detectPreset(draftStart, d));
|
|
3570
3573
|
}
|
|
3571
|
-
setFocusedIdx(-1);
|
|
3572
3574
|
};
|
|
3573
|
-
const
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3575
|
+
const rightViewMonth = leftViewMonth === 11 ? 0 : leftViewMonth + 1;
|
|
3576
|
+
const rightViewYear = leftViewMonth === 11 ? leftViewYear + 1 : leftViewYear;
|
|
3577
|
+
const prevMonth = () => {
|
|
3578
|
+
if (leftViewMonth === 0) {
|
|
3579
|
+
setLeftViewMonth(11);
|
|
3580
|
+
setLeftViewYear((y) => y - 1);
|
|
3581
|
+
} else setLeftViewMonth((m) => m - 1);
|
|
3579
3582
|
};
|
|
3580
|
-
const
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3583
|
+
const nextMonth = () => {
|
|
3584
|
+
if (leftViewMonth === 11) {
|
|
3585
|
+
setLeftViewMonth(0);
|
|
3586
|
+
setLeftViewYear((y) => y + 1);
|
|
3587
|
+
} else setLeftViewMonth((m) => m + 1);
|
|
3584
3588
|
};
|
|
3585
|
-
const
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
if (!
|
|
3589
|
+
const daysUntilToday = draftStart ? Math.max(0, daysBetween(draftStart, today2)) : 0;
|
|
3590
|
+
const daysFromToday = draftEnd ? Math.max(0, daysBetween(today2, draftEnd)) : 0;
|
|
3591
|
+
const handleDaysUntilChange = (e) => {
|
|
3592
|
+
const n = parseInt(e.target.value, 10);
|
|
3593
|
+
if (!isNaN(n) && n >= 0) {
|
|
3594
|
+
const d = addDays(today2, -n);
|
|
3595
|
+
setDraftStart(d);
|
|
3596
|
+
setStartInputStr(formatShort(d));
|
|
3597
|
+
}
|
|
3590
3598
|
};
|
|
3591
|
-
const
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
}
|
|
3598
|
-
setFocusedIdx((i) => {
|
|
3599
|
-
const next = (i + 1) % selectableOptions.length;
|
|
3600
|
-
scrollOptionIntoView(next);
|
|
3601
|
-
return next;
|
|
3602
|
-
});
|
|
3603
|
-
} else if (e.key === "ArrowUp") {
|
|
3604
|
-
e.preventDefault();
|
|
3605
|
-
if (!open) {
|
|
3606
|
-
openPopup();
|
|
3607
|
-
return;
|
|
3608
|
-
}
|
|
3609
|
-
setFocusedIdx((i) => {
|
|
3610
|
-
const next = (i - 1 + selectableOptions.length) % selectableOptions.length;
|
|
3611
|
-
scrollOptionIntoView(next);
|
|
3612
|
-
return next;
|
|
3613
|
-
});
|
|
3614
|
-
} else if (e.key === "Enter") {
|
|
3615
|
-
e.preventDefault();
|
|
3616
|
-
if (!open) {
|
|
3617
|
-
openPopup();
|
|
3618
|
-
return;
|
|
3619
|
-
}
|
|
3620
|
-
if (focusedIdx >= 0 && focusedIdx < selectableOptions.length) {
|
|
3621
|
-
selectOption(selectableOptions[focusedIdx].option);
|
|
3622
|
-
} else if (freeSolo && activeInput) {
|
|
3623
|
-
onChange?.(activeInput);
|
|
3624
|
-
if (!multiple) closePopup();
|
|
3625
|
-
}
|
|
3626
|
-
} else if (e.key === "Escape") {
|
|
3627
|
-
closePopup();
|
|
3628
|
-
} else if (e.key === "Backspace" && multiple && !activeInput && selectedValues.length > 0) {
|
|
3629
|
-
removeTag(selectedValues[selectedValues.length - 1], { stopPropagation: () => {
|
|
3630
|
-
} });
|
|
3599
|
+
const handleDaysFromChange = (e) => {
|
|
3600
|
+
const n = parseInt(e.target.value, 10);
|
|
3601
|
+
if (!isNaN(n) && n >= 0) {
|
|
3602
|
+
const d = addDays(today2, n);
|
|
3603
|
+
setDraftEnd(d);
|
|
3604
|
+
setEndInputStr(formatShort(d));
|
|
3631
3605
|
}
|
|
3632
3606
|
};
|
|
3633
|
-
const
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3607
|
+
const handleStartInputChange = (e) => {
|
|
3608
|
+
const raw = e.target.value;
|
|
3609
|
+
setStartInputStr(raw);
|
|
3610
|
+
const parsed = parseInputDate(raw);
|
|
3611
|
+
if (parsed) setDraftStart(parsed);
|
|
3612
|
+
else if (!raw) setDraftStart(null);
|
|
3613
|
+
};
|
|
3614
|
+
const handleStartInputBlur = () => {
|
|
3615
|
+
setStartInputStr(draftStart ? formatShort(draftStart) : "");
|
|
3616
|
+
};
|
|
3617
|
+
const handleEndInputChange = (e) => {
|
|
3618
|
+
const raw = e.target.value;
|
|
3619
|
+
setEndInputStr(raw);
|
|
3620
|
+
const parsed = parseInputDate(raw);
|
|
3621
|
+
if (parsed) setDraftEnd(parsed);
|
|
3622
|
+
else if (!raw) setDraftEnd(null);
|
|
3623
|
+
};
|
|
3624
|
+
const handleEndInputBlur = () => {
|
|
3625
|
+
setEndInputStr(draftEnd ? formatShort(draftEnd) : "");
|
|
3638
3626
|
};
|
|
3639
|
-
const
|
|
3640
|
-
const visibleTags = multiple && limitTags != null ? selectedValues.slice(0, limitTags) : selectedValues;
|
|
3641
|
-
const hiddenCount = multiple && limitTags != null ? Math.max(0, selectedValues.length - limitTags) : 0;
|
|
3642
|
-
const isFloating = Boolean(
|
|
3643
|
-
open || activeInput || (multiple ? selectedValues.length > 0 : value != null)
|
|
3644
|
-
);
|
|
3627
|
+
const isFloating = Boolean(displayStr || open);
|
|
3645
3628
|
const rootClasses = [
|
|
3646
3629
|
"rf-text-field",
|
|
3647
3630
|
`rf-text-field--${variant}`,
|
|
3648
3631
|
`rf-text-field--${size}`,
|
|
3649
|
-
|
|
3632
|
+
`rf-text-field--${color}`,
|
|
3650
3633
|
error ? "rf-text-field--error" : "",
|
|
3651
3634
|
fullWidth ? "rf-text-field--full-width" : "",
|
|
3652
3635
|
disabled ? "rf-text-field--disabled" : "",
|
|
3653
3636
|
isFloating ? "rf-text-field--floating" : "",
|
|
3654
|
-
label ? "rf-text-field--has-label" : "",
|
|
3637
|
+
Boolean(label) ? "rf-text-field--has-label" : "",
|
|
3655
3638
|
"rf-text-field--adorned-end",
|
|
3656
|
-
"rf-
|
|
3639
|
+
"rf-date-field",
|
|
3640
|
+
"rf-date-range-field",
|
|
3641
|
+
fullWidth ? "rf-date-field--full-width" : "",
|
|
3657
3642
|
sxClass,
|
|
3658
3643
|
className
|
|
3659
3644
|
].filter(Boolean).join(" ");
|
|
3660
|
-
const inputPlaceholder =
|
|
3661
|
-
return /* @__PURE__ */ React72.createElement("div", { ref: containerRef, className: rootClasses, style }, /* @__PURE__ */ React72.createElement(
|
|
3645
|
+
const inputPlaceholder = variant === "outlined" ? " " : void 0;
|
|
3646
|
+
return /* @__PURE__ */ React72.createElement("div", { ref: containerRef, className: rootClasses, style }, /* @__PURE__ */ React72.createElement("div", { className: "rf-date-field__anchor" }, /* @__PURE__ */ React72.createElement(
|
|
3662
3647
|
"div",
|
|
3663
3648
|
{
|
|
3664
3649
|
className: "rf-text-field__wrapper",
|
|
3665
3650
|
onClick: () => {
|
|
3666
|
-
if (!disabled)
|
|
3667
|
-
inputRef.current?.focus();
|
|
3668
|
-
if (!open) openPopup();
|
|
3669
|
-
}
|
|
3670
|
-
}
|
|
3671
|
-
},
|
|
3672
|
-
multiple && visibleTags.map((opt, i) => /* @__PURE__ */ React72.createElement("span", { key: i, className: "rf-autocomplete__tag" }, /* @__PURE__ */ React72.createElement("span", { style: { overflow: "hidden", textOverflow: "ellipsis" } }, getOptionLabel(opt)), /* @__PURE__ */ React72.createElement(
|
|
3673
|
-
"button",
|
|
3674
|
-
{
|
|
3675
|
-
type: "button",
|
|
3676
|
-
className: "rf-autocomplete__tag-delete",
|
|
3677
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
3678
|
-
onClick: (e) => removeTag(opt, e),
|
|
3679
|
-
tabIndex: -1
|
|
3651
|
+
if (!disabled) setOpen((o) => !o);
|
|
3680
3652
|
},
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
hiddenCount > 0 && /* @__PURE__ */ React72.createElement("span", { className: "rf-autocomplete__tag-more" }, "+", hiddenCount, " more"),
|
|
3653
|
+
style: { cursor: disabled ? "default" : "pointer" }
|
|
3654
|
+
},
|
|
3684
3655
|
/* @__PURE__ */ React72.createElement(
|
|
3685
3656
|
"input",
|
|
3686
3657
|
{
|
|
3687
|
-
ref: inputRef,
|
|
3688
3658
|
id: inputId,
|
|
3689
3659
|
className: "rf-text-field__input",
|
|
3690
3660
|
type: "text",
|
|
3691
|
-
value:
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
if (!open) openPopup();
|
|
3695
|
-
},
|
|
3696
|
-
onKeyDown: handleKeyDown,
|
|
3697
|
-
placeholder: !multiple || selectedValues.length === 0 ? inputPlaceholder : void 0,
|
|
3661
|
+
value: displayStr,
|
|
3662
|
+
readOnly: true,
|
|
3663
|
+
placeholder: inputPlaceholder,
|
|
3698
3664
|
disabled,
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
"aria-autocomplete": "list"
|
|
3665
|
+
onClick: (e) => e.stopPropagation(),
|
|
3666
|
+
onFocus: () => {
|
|
3667
|
+
if (!disabled) setOpen(true);
|
|
3668
|
+
}
|
|
3704
3669
|
}
|
|
3705
3670
|
),
|
|
3706
|
-
|
|
3707
|
-
variant === "outlined" && /* @__PURE__ */ React72.createElement("fieldset", { className: "rf-text-field__notch" }, label ? /* @__PURE__ */ React72.createElement("legend", { className: "rf-text-field__legend" }, /* @__PURE__ */ React72.createElement("span", null, label, required ? " *" : "")) : /* @__PURE__ */ React72.createElement("legend", { className: "rf-text-field__legend--empty" })),
|
|
3708
|
-
/* @__PURE__ */ React72.createElement("div", { className: "rf-autocomplete__endgroup" }, hasClearable && /* @__PURE__ */ React72.createElement(
|
|
3671
|
+
/* @__PURE__ */ React72.createElement("div", { className: "rf-text-field__adornment rf-text-field__adornment--end" }, /* @__PURE__ */ React72.createElement(
|
|
3709
3672
|
"button",
|
|
3710
3673
|
{
|
|
3711
3674
|
type: "button",
|
|
3712
|
-
className: "rf-
|
|
3713
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
3714
|
-
onClick: clearAll,
|
|
3675
|
+
className: "rf-date-field__icon-btn",
|
|
3715
3676
|
tabIndex: -1,
|
|
3716
|
-
|
|
3677
|
+
disabled,
|
|
3678
|
+
onClick: (e) => {
|
|
3679
|
+
e.stopPropagation();
|
|
3680
|
+
if (!disabled) setOpen((o) => !o);
|
|
3681
|
+
},
|
|
3682
|
+
"aria-label": "Pick date range"
|
|
3717
3683
|
},
|
|
3718
|
-
/* @__PURE__ */ React72.createElement(
|
|
3719
|
-
),
|
|
3684
|
+
/* @__PURE__ */ React72.createElement(CalendarIcon2, null)
|
|
3685
|
+
)),
|
|
3686
|
+
label && /* @__PURE__ */ React72.createElement("label", { htmlFor: inputId, className: "rf-text-field__label" }, label, " ", required && /* @__PURE__ */ React72.createElement("span", { className: "rf-text-field__asterisk" }, "*")),
|
|
3687
|
+
variant === "outlined" && /* @__PURE__ */ React72.createElement("fieldset", { className: "rf-text-field__notch" }, label ? /* @__PURE__ */ React72.createElement("legend", { className: "rf-text-field__legend" }, /* @__PURE__ */ React72.createElement("span", null, label, required ? " *" : "")) : /* @__PURE__ */ React72.createElement("legend", { className: "rf-text-field__legend--empty" }))
|
|
3688
|
+
), open && !disabled && (pickerType === "panel" ? (
|
|
3689
|
+
/* ── Panel Mode ── */
|
|
3690
|
+
/* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker rf-dr-picker--panel", onMouseDown: (e) => e.preventDefault() }, /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__presets" }, PRESETS.map((p, i) => /* @__PURE__ */ React72.createElement(React72.Fragment, { key: p.id }, i > 0 && /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__preset-sep" }), /* @__PURE__ */ React72.createElement(
|
|
3720
3691
|
"button",
|
|
3721
3692
|
{
|
|
3722
3693
|
type: "button",
|
|
3723
|
-
className:
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
tabIndex: -1,
|
|
3729
|
-
"aria-label": open ? "Close" : "Open"
|
|
3694
|
+
className: [
|
|
3695
|
+
"rf-dr-picker__preset-btn",
|
|
3696
|
+
activePreset === p.id ? "rf-dr-picker__preset-btn--active" : ""
|
|
3697
|
+
].filter(Boolean).join(" "),
|
|
3698
|
+
onClick: () => handlePreset(p.id)
|
|
3730
3699
|
},
|
|
3731
|
-
|
|
3732
|
-
))
|
|
3733
|
-
|
|
3734
|
-
/* @__PURE__ */ React72.createElement("div", { className: "rf-autocomplete__popup", role: "presentation", style: popupStyle }, loading ? /* @__PURE__ */ React72.createElement("div", { className: "rf-autocomplete__loading" }, /* @__PURE__ */ React72.createElement("span", { className: "rf-ac-spinner" }), loadingText) : flatEntries.length === 0 ? /* @__PURE__ */ React72.createElement("div", { className: "rf-autocomplete__no-options" }, noOptionsText) : /* @__PURE__ */ React72.createElement("ul", { ref: listRef, className: "rf-autocomplete__listbox", role: "listbox" }, groupBy ? (
|
|
3735
|
-
// Grouped render
|
|
3736
|
-
(() => {
|
|
3737
|
-
const rendered = [];
|
|
3738
|
-
let groupItems = [];
|
|
3739
|
-
let currentGroup = "";
|
|
3740
|
-
flatEntries.forEach((entry, ei) => {
|
|
3741
|
-
if (entry.kind === "group") {
|
|
3742
|
-
if (groupItems.length > 0) {
|
|
3743
|
-
rendered.push(
|
|
3744
|
-
/* @__PURE__ */ React72.createElement("li", { key: `g-${currentGroup}`, role: "presentation" }, /* @__PURE__ */ React72.createElement("div", { className: "rf-autocomplete__group-header" }, currentGroup), /* @__PURE__ */ React72.createElement("ul", { className: "rf-autocomplete__group-items", role: "group" }, groupItems))
|
|
3745
|
-
);
|
|
3746
|
-
groupItems = [];
|
|
3747
|
-
}
|
|
3748
|
-
currentGroup = entry.label;
|
|
3749
|
-
} else {
|
|
3750
|
-
const { option, flatIdx } = entry;
|
|
3751
|
-
groupItems.push(renderOptionItem(option, flatIdx));
|
|
3752
|
-
}
|
|
3753
|
-
if (ei === flatEntries.length - 1 && groupItems.length > 0) {
|
|
3754
|
-
rendered.push(
|
|
3755
|
-
/* @__PURE__ */ React72.createElement("li", { key: `g-${currentGroup}`, role: "presentation" }, /* @__PURE__ */ React72.createElement("div", { className: "rf-autocomplete__group-header" }, currentGroup), /* @__PURE__ */ React72.createElement("ul", { className: "rf-autocomplete__group-items", role: "group" }, groupItems))
|
|
3756
|
-
);
|
|
3757
|
-
}
|
|
3758
|
-
});
|
|
3759
|
-
return rendered;
|
|
3760
|
-
})()
|
|
3761
|
-
) : selectableOptions.map(({ option, flatIdx }) => renderOptionItem(option, flatIdx)))),
|
|
3762
|
-
document.body
|
|
3763
|
-
));
|
|
3764
|
-
function renderOptionItem(option, flatIdx) {
|
|
3765
|
-
const selected = isSelected(option);
|
|
3766
|
-
const focused = focusedIdx === flatIdx;
|
|
3767
|
-
const optDisabled = getOptionDisabled?.(option) ?? false;
|
|
3768
|
-
const label2 = getOptionLabel(option);
|
|
3769
|
-
return /* @__PURE__ */ React72.createElement(
|
|
3770
|
-
"li",
|
|
3700
|
+
p.label
|
|
3701
|
+
)))), /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__manual" }, /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__date-field-wrap" }, /* @__PURE__ */ React72.createElement(
|
|
3702
|
+
"div",
|
|
3771
3703
|
{
|
|
3772
|
-
key: label2 + flatIdx,
|
|
3773
|
-
"data-idx": flatIdx,
|
|
3774
|
-
role: "option",
|
|
3775
|
-
"aria-selected": selected,
|
|
3776
|
-
"aria-disabled": optDisabled,
|
|
3777
3704
|
className: [
|
|
3778
|
-
"rf-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
optDisabled ? "rf-autocomplete__option--disabled" : ""
|
|
3782
|
-
].filter(Boolean).join(" "),
|
|
3783
|
-
onMouseEnter: () => setFocusedIdx(flatIdx),
|
|
3784
|
-
onMouseLeave: () => setFocusedIdx(-1),
|
|
3785
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
3786
|
-
onClick: () => selectOption(option)
|
|
3705
|
+
"rf-dr-picker__date-field",
|
|
3706
|
+
inlineCal === "start" ? "rf-dr-picker__date-field--active" : ""
|
|
3707
|
+
].filter(Boolean).join(" ")
|
|
3787
3708
|
},
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3709
|
+
/* @__PURE__ */ React72.createElement("span", { className: "rf-dr-picker__date-floating-label" }, "Start Date"),
|
|
3710
|
+
/* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__date-display" }, /* @__PURE__ */ React72.createElement(
|
|
3711
|
+
"input",
|
|
3712
|
+
{
|
|
3713
|
+
type: "text",
|
|
3714
|
+
className: "rf-dr-picker__date-input",
|
|
3715
|
+
value: startInputStr,
|
|
3716
|
+
placeholder: "DD Mon YYYY",
|
|
3717
|
+
onChange: handleStartInputChange,
|
|
3718
|
+
onBlur: handleStartInputBlur,
|
|
3719
|
+
onMouseDown: (e) => e.stopPropagation()
|
|
3720
|
+
}
|
|
3721
|
+
), /* @__PURE__ */ React72.createElement(
|
|
3722
|
+
"button",
|
|
3723
|
+
{
|
|
3724
|
+
type: "button",
|
|
3725
|
+
className: "rf-dr-picker__cal-icon-btn",
|
|
3726
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
3727
|
+
onClick: () => setInlineCal((v) => v === "start" ? null : "start"),
|
|
3728
|
+
"aria-label": "Pick start date"
|
|
3729
|
+
},
|
|
3730
|
+
/* @__PURE__ */ React72.createElement(CalendarIcon2, null)
|
|
3731
|
+
))
|
|
3732
|
+
), inlineCal === "start" && /* @__PURE__ */ React72.createElement(
|
|
3733
|
+
MiniCalendar,
|
|
3734
|
+
{
|
|
3735
|
+
selectedDate: draftStart,
|
|
3736
|
+
todayDate: today2,
|
|
3737
|
+
onSelect: (d) => {
|
|
3738
|
+
setDraftStart(d);
|
|
3739
|
+
setStartInputStr(formatShort(d));
|
|
3740
|
+
},
|
|
3741
|
+
onClose: () => setInlineCal(null)
|
|
3742
|
+
}
|
|
3743
|
+
)), /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__date-field-wrap" }, /* @__PURE__ */ React72.createElement(
|
|
3744
|
+
"div",
|
|
3745
|
+
{
|
|
3746
|
+
className: [
|
|
3747
|
+
"rf-dr-picker__date-field",
|
|
3748
|
+
inlineCal === "end" ? "rf-dr-picker__date-field--active" : ""
|
|
3749
|
+
].filter(Boolean).join(" ")
|
|
3750
|
+
},
|
|
3751
|
+
/* @__PURE__ */ React72.createElement("span", { className: "rf-dr-picker__date-floating-label" }, "End Date"),
|
|
3752
|
+
/* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__date-display" }, /* @__PURE__ */ React72.createElement(
|
|
3753
|
+
"input",
|
|
3754
|
+
{
|
|
3755
|
+
type: "text",
|
|
3756
|
+
className: "rf-dr-picker__date-input",
|
|
3757
|
+
value: endInputStr,
|
|
3758
|
+
placeholder: "DD Mon YYYY",
|
|
3759
|
+
onChange: handleEndInputChange,
|
|
3760
|
+
onBlur: handleEndInputBlur,
|
|
3761
|
+
onMouseDown: (e) => e.stopPropagation()
|
|
3762
|
+
}
|
|
3763
|
+
), /* @__PURE__ */ React72.createElement(
|
|
3764
|
+
"button",
|
|
3765
|
+
{
|
|
3766
|
+
type: "button",
|
|
3767
|
+
className: "rf-dr-picker__cal-icon-btn",
|
|
3768
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
3769
|
+
onClick: () => setInlineCal((v) => v === "end" ? null : "end"),
|
|
3770
|
+
"aria-label": "Pick end date"
|
|
3771
|
+
},
|
|
3772
|
+
/* @__PURE__ */ React72.createElement(CalendarIcon2, null)
|
|
3773
|
+
))
|
|
3774
|
+
), inlineCal === "end" && /* @__PURE__ */ React72.createElement(
|
|
3775
|
+
MiniCalendar,
|
|
3776
|
+
{
|
|
3777
|
+
selectedDate: draftEnd,
|
|
3778
|
+
todayDate: today2,
|
|
3779
|
+
onSelect: (d) => {
|
|
3780
|
+
setDraftEnd(d);
|
|
3781
|
+
setEndInputStr(formatShort(d));
|
|
3782
|
+
},
|
|
3783
|
+
onClose: () => setInlineCal(null)
|
|
3784
|
+
}
|
|
3785
|
+
)), !inlineCal && /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__days-section" }, /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__days-row" }, /* @__PURE__ */ React72.createElement("span", { className: "rf-dr-picker__days-label" }, "Days until today"), /* @__PURE__ */ React72.createElement(
|
|
3786
|
+
"input",
|
|
3787
|
+
{
|
|
3788
|
+
type: "number",
|
|
3789
|
+
className: "rf-dr-picker__days-input",
|
|
3790
|
+
value: draftStart ? daysUntilToday : "",
|
|
3791
|
+
min: 0,
|
|
3792
|
+
onChange: handleDaysUntilChange,
|
|
3793
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
3794
|
+
placeholder: "\u2014"
|
|
3795
|
+
}
|
|
3796
|
+
)), /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__days-row" }, /* @__PURE__ */ React72.createElement("span", { className: "rf-dr-picker__days-label" }, "Days from today"), /* @__PURE__ */ React72.createElement(
|
|
3797
|
+
"input",
|
|
3798
|
+
{
|
|
3799
|
+
type: "number",
|
|
3800
|
+
className: "rf-dr-picker__days-input",
|
|
3801
|
+
value: draftEnd ? daysFromToday : "",
|
|
3802
|
+
min: 0,
|
|
3803
|
+
onChange: handleDaysFromChange,
|
|
3804
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
3805
|
+
placeholder: "\u2014"
|
|
3806
|
+
}
|
|
3807
|
+
))), /* @__PURE__ */ React72.createElement("div", { style: { flex: 1 } }), /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__footer" }, /* @__PURE__ */ React72.createElement("button", { type: "button", className: "rf-dr-picker__close-btn", onClick: handleClose }, "CLOSE"), /* @__PURE__ */ React72.createElement("button", { type: "button", className: "rf-dr-picker__apply-btn", onClick: handleApply }, "APPLY"))))
|
|
3808
|
+
) : (
|
|
3809
|
+
/* ── Calendar Mode ── */
|
|
3810
|
+
/* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker rf-dr-picker--calendar", onMouseDown: (e) => e.preventDefault() }, /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__calendars" }, /* @__PURE__ */ React72.createElement(
|
|
3811
|
+
RangeCalendarBody,
|
|
3812
|
+
{
|
|
3813
|
+
viewYear: leftViewYear,
|
|
3814
|
+
viewMonth: leftViewMonth,
|
|
3815
|
+
startDate: draftStart,
|
|
3816
|
+
endDate: draftEnd,
|
|
3817
|
+
hoverDate: selecting === "end" ? hoverDate : null,
|
|
3818
|
+
todayDate: today2,
|
|
3819
|
+
onDayClick: handleCalDayClick,
|
|
3820
|
+
onDayHover: setHoverDate,
|
|
3821
|
+
onPrev: prevMonth,
|
|
3822
|
+
onNext: nextMonth,
|
|
3823
|
+
showNext: false
|
|
3824
|
+
}
|
|
3825
|
+
), /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__cal-col-divider" }), /* @__PURE__ */ React72.createElement(
|
|
3826
|
+
RangeCalendarBody,
|
|
3827
|
+
{
|
|
3828
|
+
viewYear: rightViewYear,
|
|
3829
|
+
viewMonth: rightViewMonth,
|
|
3830
|
+
startDate: draftStart,
|
|
3831
|
+
endDate: draftEnd,
|
|
3832
|
+
hoverDate: selecting === "end" ? hoverDate : null,
|
|
3833
|
+
todayDate: today2,
|
|
3834
|
+
onDayClick: handleCalDayClick,
|
|
3835
|
+
onDayHover: setHoverDate,
|
|
3836
|
+
onPrev: prevMonth,
|
|
3837
|
+
onNext: nextMonth,
|
|
3838
|
+
showPrev: false
|
|
3839
|
+
}
|
|
3840
|
+
)), selecting === "end" && draftStart && /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__cal-hint" }, /* @__PURE__ */ React72.createElement("span", { className: "rf-dr-picker__cal-hint-dot" }), /* @__PURE__ */ React72.createElement("span", null, "Select end date \xB7 started from ", /* @__PURE__ */ React72.createElement("strong", null, formatShort(draftStart)))), /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__divider" }), /* @__PURE__ */ React72.createElement("div", { className: "rf-dr-picker__cal-footer" }, draftStart && draftEnd && /* @__PURE__ */ React72.createElement("span", { className: "rf-dr-picker__cal-range-label" }, formatShort(draftStart <= draftEnd ? draftStart : draftEnd), " \u2013 ", formatShort(draftStart <= draftEnd ? draftEnd : draftStart), /* @__PURE__ */ React72.createElement("span", { className: "rf-dr-picker__cal-range-days" }, " ", "(", Math.abs(daysBetween(draftStart, draftEnd)) + 1, " days)")), /* @__PURE__ */ React72.createElement("div", { style: { flex: 1 } }), /* @__PURE__ */ React72.createElement("button", { type: "button", className: "rf-dr-picker__close-btn", onClick: handleClose }, "CLOSE"), /* @__PURE__ */ React72.createElement("button", { type: "button", className: "rf-dr-picker__apply-btn", onClick: handleApply }, "APPLY")))
|
|
3841
|
+
))), helperText && /* @__PURE__ */ React72.createElement("div", { className: "rf-text-field__helper-text" }, helperText));
|
|
3842
|
+
};
|
|
3843
|
+
DateRangeField.displayName = "DateRangeField";
|
|
3795
3844
|
|
|
3796
3845
|
// lib/Progress/RufousLogoLoader.tsx
|
|
3797
3846
|
import * as React73 from "react";
|