@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.cjs
CHANGED
|
@@ -1908,83 +1908,492 @@ var TextField = (0, import_react17.forwardRef)(({
|
|
|
1908
1908
|
TextField.displayName = "TextField";
|
|
1909
1909
|
|
|
1910
1910
|
// lib/TextFields/AddressLookup.tsx
|
|
1911
|
-
var
|
|
1911
|
+
var import_react19 = __toESM(require("react"), 1);
|
|
1912
1912
|
var import_axios = __toESM(require("axios"), 1);
|
|
1913
1913
|
var import_country_state_city = require("country-state-city");
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
const
|
|
1914
|
+
|
|
1915
|
+
// lib/TextFields/Autocomplete.tsx
|
|
1916
|
+
var import_react18 = __toESM(require("react"), 1);
|
|
1917
|
+
var import_react_dom2 = __toESM(require("react-dom"), 1);
|
|
1918
|
+
var ChevronDownIcon = () => /* @__PURE__ */ import_react18.default.createElement("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ import_react18.default.createElement("polyline", { points: "6 9 12 15 18 9" }));
|
|
1919
|
+
var CloseSmIcon = ({ size = 16 }) => /* @__PURE__ */ import_react18.default.createElement("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round" }, /* @__PURE__ */ import_react18.default.createElement("line", { x1: "18", y1: "6", x2: "6", y2: "18" }), /* @__PURE__ */ import_react18.default.createElement("line", { x1: "6", y1: "6", x2: "18", y2: "18" }));
|
|
1920
|
+
var CheckIcon = () => /* @__PURE__ */ import_react18.default.createElement("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ import_react18.default.createElement("polyline", { points: "20 6 9 17 4 12" }));
|
|
1921
|
+
function defaultGetLabel(option) {
|
|
1922
|
+
if (option === null || option === void 0) return "";
|
|
1923
|
+
if (typeof option === "string") return option;
|
|
1924
|
+
if (typeof option === "object" && "label" in option)
|
|
1925
|
+
return String(option.label);
|
|
1926
|
+
return String(option);
|
|
1927
|
+
}
|
|
1928
|
+
function defaultFilter(options, inputValue, getLabel) {
|
|
1929
|
+
if (!inputValue) return options;
|
|
1930
|
+
const q = inputValue.toLowerCase();
|
|
1931
|
+
return options.filter((o) => getLabel(o).toLowerCase().includes(q));
|
|
1932
|
+
}
|
|
1933
|
+
function AutocompleteInner(props, _ref) {
|
|
1934
|
+
const {
|
|
1935
|
+
options,
|
|
1936
|
+
value,
|
|
1937
|
+
onChange,
|
|
1938
|
+
inputValue: controlledInput,
|
|
1939
|
+
onInputChange,
|
|
1940
|
+
getOptionLabel = defaultGetLabel,
|
|
1941
|
+
isOptionEqualToValue,
|
|
1942
|
+
groupBy,
|
|
1943
|
+
filterOptions,
|
|
1944
|
+
renderOption,
|
|
1945
|
+
getOptionDisabled,
|
|
1946
|
+
multiple = false,
|
|
1947
|
+
freeSolo = false,
|
|
1948
|
+
clearable = true,
|
|
1949
|
+
loading = false,
|
|
1950
|
+
loadingText = "Loading\u2026",
|
|
1951
|
+
noOptionsText = "No options",
|
|
1952
|
+
limitTags,
|
|
1953
|
+
label,
|
|
1954
|
+
placeholder,
|
|
1955
|
+
variant = "outlined",
|
|
1956
|
+
size = "medium",
|
|
1957
|
+
error = false,
|
|
1958
|
+
helperText,
|
|
1959
|
+
fullWidth = false,
|
|
1960
|
+
disabled = false,
|
|
1961
|
+
required = false,
|
|
1962
|
+
className = "",
|
|
1963
|
+
style,
|
|
1964
|
+
sx,
|
|
1965
|
+
onOpen,
|
|
1966
|
+
onClose
|
|
1967
|
+
} = props;
|
|
1968
|
+
const [open, setOpen] = (0, import_react18.useState)(false);
|
|
1969
|
+
const [inputStr, setInputStr] = (0, import_react18.useState)("");
|
|
1970
|
+
const [focusedIdx, setFocusedIdx] = (0, import_react18.useState)(-1);
|
|
1971
|
+
const [popupStyle, setPopupStyle] = (0, import_react18.useState)({});
|
|
1931
1972
|
const containerRef = (0, import_react18.useRef)(null);
|
|
1932
|
-
const
|
|
1933
|
-
const
|
|
1934
|
-
const
|
|
1935
|
-
const
|
|
1973
|
+
const popupRef = (0, import_react18.useRef)(null);
|
|
1974
|
+
const inputRef = (0, import_react18.useRef)(null);
|
|
1975
|
+
const listRef = (0, import_react18.useRef)(null);
|
|
1976
|
+
const inputId = (0, import_react18.useRef)(`rf-ac-${Math.random().toString(36).slice(2, 9)}`).current;
|
|
1977
|
+
const sxClass = useSx(sx);
|
|
1978
|
+
const calcPopupStyle = (0, import_react18.useCallback)(() => {
|
|
1979
|
+
if (!containerRef.current) return;
|
|
1980
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
1981
|
+
const POPUP_MAX_HEIGHT = 280;
|
|
1982
|
+
const GAP2 = 4;
|
|
1983
|
+
const viewportH = window.innerHeight;
|
|
1984
|
+
const viewportW = window.innerWidth;
|
|
1985
|
+
const spaceBelow = viewportH - rect.bottom - GAP2;
|
|
1986
|
+
const spaceAbove = rect.top - GAP2;
|
|
1987
|
+
const openUpward = spaceBelow < POPUP_MAX_HEIGHT && spaceAbove > spaceBelow;
|
|
1988
|
+
const minLeft = 8;
|
|
1989
|
+
const maxLeft = viewportW - rect.width - 8;
|
|
1990
|
+
const left = Math.min(Math.max(rect.left, minLeft), maxLeft);
|
|
1991
|
+
if (openUpward) {
|
|
1992
|
+
setPopupStyle({
|
|
1993
|
+
bottom: viewportH - rect.top + GAP2,
|
|
1994
|
+
top: "auto",
|
|
1995
|
+
left,
|
|
1996
|
+
width: rect.width
|
|
1997
|
+
});
|
|
1998
|
+
} else {
|
|
1999
|
+
setPopupStyle({
|
|
2000
|
+
top: rect.bottom + GAP2,
|
|
2001
|
+
bottom: "auto",
|
|
2002
|
+
left,
|
|
2003
|
+
width: rect.width
|
|
2004
|
+
});
|
|
2005
|
+
}
|
|
2006
|
+
}, []);
|
|
2007
|
+
const activeInput = controlledInput !== void 0 ? controlledInput : inputStr;
|
|
2008
|
+
const selectedValues = multiple ? Array.isArray(value) ? value : [] : value != null ? [value] : [];
|
|
2009
|
+
const isEqual = (0, import_react18.useCallback)(
|
|
2010
|
+
(a, b) => isOptionEqualToValue ? isOptionEqualToValue(a, b) : a === b,
|
|
2011
|
+
[isOptionEqualToValue]
|
|
2012
|
+
);
|
|
2013
|
+
const isSelected = (0, import_react18.useCallback)(
|
|
2014
|
+
(opt) => selectedValues.some((v) => isEqual(opt, v)),
|
|
2015
|
+
[selectedValues, isEqual]
|
|
2016
|
+
);
|
|
2017
|
+
const filtered = filterOptions ? filterOptions(options, activeInput) : defaultFilter(options, activeInput, getOptionLabel);
|
|
2018
|
+
const flatEntries = [];
|
|
2019
|
+
if (groupBy) {
|
|
2020
|
+
const groups = {};
|
|
2021
|
+
const order = [];
|
|
2022
|
+
filtered.forEach((opt) => {
|
|
2023
|
+
const g = groupBy(opt);
|
|
2024
|
+
if (!groups[g]) {
|
|
2025
|
+
groups[g] = [];
|
|
2026
|
+
order.push(g);
|
|
2027
|
+
}
|
|
2028
|
+
groups[g].push(opt);
|
|
2029
|
+
});
|
|
2030
|
+
order.forEach((g) => {
|
|
2031
|
+
flatEntries.push({ kind: "group", label: g });
|
|
2032
|
+
groups[g].forEach((opt) => {
|
|
2033
|
+
flatEntries.push({ kind: "option", option: opt, flatIdx: flatEntries.filter((e) => e.kind === "option").length });
|
|
2034
|
+
});
|
|
2035
|
+
});
|
|
2036
|
+
} else {
|
|
2037
|
+
filtered.forEach((opt, i) => flatEntries.push({ kind: "option", option: opt, flatIdx: i }));
|
|
2038
|
+
}
|
|
2039
|
+
const selectableOptions = flatEntries.filter((e) => e.kind === "option");
|
|
2040
|
+
const openPopup = (0, import_react18.useCallback)(() => {
|
|
2041
|
+
if (disabled) return;
|
|
2042
|
+
calcPopupStyle();
|
|
2043
|
+
setOpen(true);
|
|
2044
|
+
setFocusedIdx(-1);
|
|
2045
|
+
onOpen?.();
|
|
2046
|
+
}, [disabled, calcPopupStyle, onOpen]);
|
|
2047
|
+
const closePopup = (0, import_react18.useCallback)((justSelected = false) => {
|
|
2048
|
+
setOpen(false);
|
|
2049
|
+
setFocusedIdx(-1);
|
|
2050
|
+
onClose?.();
|
|
2051
|
+
if (!justSelected && !freeSolo && !multiple && value == null) {
|
|
2052
|
+
setInputStr("");
|
|
2053
|
+
onInputChange?.("");
|
|
2054
|
+
}
|
|
2055
|
+
}, [freeSolo, multiple, value, onInputChange, onClose]);
|
|
1936
2056
|
(0, import_react18.useEffect)(() => {
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
2057
|
+
if (!open) return;
|
|
2058
|
+
const handleOutside = (e) => {
|
|
2059
|
+
const target = e.target;
|
|
2060
|
+
const insideContainer = containerRef.current?.contains(target);
|
|
2061
|
+
const insidePopup = popupRef.current?.contains(target);
|
|
2062
|
+
if (!insideContainer && !insidePopup) {
|
|
2063
|
+
closePopup();
|
|
1940
2064
|
}
|
|
1941
2065
|
};
|
|
1942
|
-
document.addEventListener("mousedown",
|
|
1943
|
-
|
|
1944
|
-
|
|
2066
|
+
document.addEventListener("mousedown", handleOutside);
|
|
2067
|
+
window.addEventListener("scroll", calcPopupStyle, true);
|
|
2068
|
+
window.addEventListener("resize", calcPopupStyle);
|
|
2069
|
+
return () => {
|
|
2070
|
+
document.removeEventListener("mousedown", handleOutside);
|
|
2071
|
+
window.removeEventListener("scroll", calcPopupStyle, true);
|
|
2072
|
+
window.removeEventListener("resize", calcPopupStyle);
|
|
2073
|
+
};
|
|
2074
|
+
}, [open, closePopup, calcPopupStyle]);
|
|
1945
2075
|
(0, import_react18.useEffect)(() => {
|
|
1946
|
-
if (
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
2076
|
+
if (controlledInput !== void 0) return;
|
|
2077
|
+
if (!multiple) {
|
|
2078
|
+
const v = value;
|
|
2079
|
+
setInputStr(v != null ? getOptionLabel(v) : "");
|
|
2080
|
+
}
|
|
2081
|
+
}, [value, multiple, getOptionLabel, controlledInput]);
|
|
2082
|
+
const selectOption = (opt) => {
|
|
2083
|
+
if (getOptionDisabled?.(opt)) return;
|
|
2084
|
+
if (multiple) {
|
|
2085
|
+
const already = isSelected(opt);
|
|
2086
|
+
const next = already ? selectedValues.filter((v) => !isEqual(v, opt)) : [...selectedValues, opt];
|
|
2087
|
+
onChange?.(next);
|
|
2088
|
+
setInputStr("");
|
|
2089
|
+
onInputChange?.("");
|
|
2090
|
+
inputRef.current?.focus();
|
|
1954
2091
|
} else {
|
|
1955
|
-
|
|
2092
|
+
onChange?.(opt);
|
|
2093
|
+
setInputStr(getOptionLabel(opt));
|
|
2094
|
+
onInputChange?.(getOptionLabel(opt));
|
|
2095
|
+
closePopup(true);
|
|
1956
2096
|
}
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
2097
|
+
setFocusedIdx(-1);
|
|
2098
|
+
};
|
|
2099
|
+
const clearAll = (e) => {
|
|
2100
|
+
e.stopPropagation();
|
|
2101
|
+
onChange?.(multiple ? [] : null);
|
|
2102
|
+
setInputStr("");
|
|
2103
|
+
onInputChange?.("");
|
|
2104
|
+
inputRef.current?.focus();
|
|
2105
|
+
};
|
|
2106
|
+
const removeTag = (opt, e) => {
|
|
2107
|
+
e.stopPropagation();
|
|
2108
|
+
const next = selectedValues.filter((v) => !isEqual(v, opt));
|
|
2109
|
+
onChange?.(next);
|
|
2110
|
+
};
|
|
2111
|
+
const handleInputChange = (e) => {
|
|
2112
|
+
const v = e.target.value;
|
|
2113
|
+
setInputStr(v);
|
|
2114
|
+
onInputChange?.(v);
|
|
2115
|
+
if (!open) openPopup();
|
|
2116
|
+
};
|
|
2117
|
+
const handleKeyDown = (e) => {
|
|
2118
|
+
if (e.key === "ArrowDown") {
|
|
2119
|
+
e.preventDefault();
|
|
2120
|
+
if (!open) {
|
|
2121
|
+
openPopup();
|
|
2122
|
+
return;
|
|
1971
2123
|
}
|
|
1972
|
-
|
|
1973
|
-
|
|
2124
|
+
setFocusedIdx((i) => {
|
|
2125
|
+
const next = (i + 1) % selectableOptions.length;
|
|
2126
|
+
scrollOptionIntoView(next);
|
|
2127
|
+
return next;
|
|
2128
|
+
});
|
|
2129
|
+
} else if (e.key === "ArrowUp") {
|
|
2130
|
+
e.preventDefault();
|
|
2131
|
+
if (!open) {
|
|
2132
|
+
openPopup();
|
|
2133
|
+
return;
|
|
2134
|
+
}
|
|
2135
|
+
setFocusedIdx((i) => {
|
|
2136
|
+
const next = (i - 1 + selectableOptions.length) % selectableOptions.length;
|
|
2137
|
+
scrollOptionIntoView(next);
|
|
2138
|
+
return next;
|
|
2139
|
+
});
|
|
2140
|
+
} else if (e.key === "Enter") {
|
|
2141
|
+
e.preventDefault();
|
|
2142
|
+
if (!open) {
|
|
2143
|
+
openPopup();
|
|
2144
|
+
return;
|
|
2145
|
+
}
|
|
2146
|
+
if (focusedIdx >= 0 && focusedIdx < selectableOptions.length) {
|
|
2147
|
+
selectOption(selectableOptions[focusedIdx].option);
|
|
2148
|
+
} else if (freeSolo && activeInput) {
|
|
2149
|
+
onChange?.(activeInput);
|
|
2150
|
+
if (!multiple) closePopup();
|
|
2151
|
+
}
|
|
2152
|
+
} else if (e.key === "Escape") {
|
|
2153
|
+
closePopup();
|
|
2154
|
+
} else if (e.key === "Backspace" && multiple && !activeInput && selectedValues.length > 0) {
|
|
2155
|
+
removeTag(selectedValues[selectedValues.length - 1], { stopPropagation: () => {
|
|
2156
|
+
} });
|
|
1974
2157
|
}
|
|
1975
|
-
}
|
|
1976
|
-
const
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
2158
|
+
};
|
|
2159
|
+
const scrollOptionIntoView = (idx) => {
|
|
2160
|
+
requestAnimationFrame(() => {
|
|
2161
|
+
const el = listRef.current?.querySelector(`[data-idx="${idx}"]`);
|
|
2162
|
+
el?.scrollIntoView({ block: "nearest" });
|
|
1980
2163
|
});
|
|
1981
2164
|
};
|
|
1982
|
-
const
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
2165
|
+
const hasClearable = clearable && !disabled && (multiple ? selectedValues.length > 0 : value != null);
|
|
2166
|
+
const visibleTags = multiple && limitTags != null ? selectedValues.slice(0, limitTags) : selectedValues;
|
|
2167
|
+
const hiddenCount = multiple && limitTags != null ? Math.max(0, selectedValues.length - limitTags) : 0;
|
|
2168
|
+
const isFloating = Boolean(
|
|
2169
|
+
open || activeInput || (multiple ? selectedValues.length > 0 : value != null)
|
|
2170
|
+
);
|
|
2171
|
+
const rootClasses = [
|
|
2172
|
+
"rf-text-field",
|
|
2173
|
+
`rf-text-field--${variant}`,
|
|
2174
|
+
`rf-text-field--${size}`,
|
|
2175
|
+
"rf-text-field--primary",
|
|
2176
|
+
error ? "rf-text-field--error" : "",
|
|
2177
|
+
fullWidth ? "rf-text-field--full-width" : "",
|
|
2178
|
+
disabled ? "rf-text-field--disabled" : "",
|
|
2179
|
+
isFloating ? "rf-text-field--floating" : "",
|
|
2180
|
+
label ? "rf-text-field--has-label" : "",
|
|
2181
|
+
"rf-text-field--adorned-end",
|
|
2182
|
+
"rf-autocomplete",
|
|
2183
|
+
sxClass,
|
|
2184
|
+
className
|
|
2185
|
+
].filter(Boolean).join(" ");
|
|
2186
|
+
const inputPlaceholder = placeholder || (variant === "outlined" ? " " : void 0);
|
|
2187
|
+
return /* @__PURE__ */ import_react18.default.createElement("div", { ref: containerRef, className: rootClasses, style }, /* @__PURE__ */ import_react18.default.createElement(
|
|
2188
|
+
"div",
|
|
2189
|
+
{
|
|
2190
|
+
className: "rf-text-field__wrapper",
|
|
2191
|
+
onClick: () => {
|
|
2192
|
+
if (!disabled) {
|
|
2193
|
+
inputRef.current?.focus();
|
|
2194
|
+
if (!open) openPopup();
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
},
|
|
2198
|
+
multiple && visibleTags.map((opt, i) => /* @__PURE__ */ import_react18.default.createElement("span", { key: i, className: "rf-autocomplete__tag" }, /* @__PURE__ */ import_react18.default.createElement("span", { style: { overflow: "hidden", textOverflow: "ellipsis" } }, getOptionLabel(opt)), /* @__PURE__ */ import_react18.default.createElement(
|
|
2199
|
+
"button",
|
|
2200
|
+
{
|
|
2201
|
+
type: "button",
|
|
2202
|
+
className: "rf-autocomplete__tag-delete",
|
|
2203
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2204
|
+
onClick: (e) => removeTag(opt, e),
|
|
2205
|
+
tabIndex: -1
|
|
2206
|
+
},
|
|
2207
|
+
/* @__PURE__ */ import_react18.default.createElement(CloseSmIcon, { size: 12 })
|
|
2208
|
+
))),
|
|
2209
|
+
hiddenCount > 0 && /* @__PURE__ */ import_react18.default.createElement("span", { className: "rf-autocomplete__tag-more" }, "+", hiddenCount, " more"),
|
|
2210
|
+
/* @__PURE__ */ import_react18.default.createElement(
|
|
2211
|
+
"input",
|
|
2212
|
+
{
|
|
2213
|
+
ref: inputRef,
|
|
2214
|
+
id: inputId,
|
|
2215
|
+
className: "rf-text-field__input",
|
|
2216
|
+
type: "text",
|
|
2217
|
+
value: activeInput,
|
|
2218
|
+
onChange: handleInputChange,
|
|
2219
|
+
onFocus: () => {
|
|
2220
|
+
if (!open) openPopup();
|
|
2221
|
+
},
|
|
2222
|
+
onKeyDown: handleKeyDown,
|
|
2223
|
+
placeholder: !multiple || selectedValues.length === 0 ? inputPlaceholder : void 0,
|
|
2224
|
+
disabled,
|
|
2225
|
+
autoComplete: "off",
|
|
2226
|
+
role: "combobox",
|
|
2227
|
+
"aria-expanded": open,
|
|
2228
|
+
"aria-haspopup": "listbox",
|
|
2229
|
+
"aria-autocomplete": "list"
|
|
2230
|
+
}
|
|
2231
|
+
),
|
|
2232
|
+
label && /* @__PURE__ */ import_react18.default.createElement("label", { htmlFor: inputId, className: "rf-text-field__label" }, label, required && /* @__PURE__ */ import_react18.default.createElement("span", { className: "rf-text-field__asterisk" }, " *")),
|
|
2233
|
+
variant === "outlined" && /* @__PURE__ */ import_react18.default.createElement("fieldset", { className: "rf-text-field__notch" }, label ? /* @__PURE__ */ import_react18.default.createElement("legend", { className: "rf-text-field__legend" }, /* @__PURE__ */ import_react18.default.createElement("span", null, label, required ? " *" : "")) : /* @__PURE__ */ import_react18.default.createElement("legend", { className: "rf-text-field__legend--empty" })),
|
|
2234
|
+
/* @__PURE__ */ import_react18.default.createElement("div", { className: "rf-autocomplete__endgroup" }, hasClearable && /* @__PURE__ */ import_react18.default.createElement(
|
|
2235
|
+
"button",
|
|
2236
|
+
{
|
|
2237
|
+
type: "button",
|
|
2238
|
+
className: "rf-autocomplete__icon-btn",
|
|
2239
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2240
|
+
onClick: clearAll,
|
|
2241
|
+
tabIndex: -1,
|
|
2242
|
+
"aria-label": "Clear"
|
|
2243
|
+
},
|
|
2244
|
+
/* @__PURE__ */ import_react18.default.createElement(CloseSmIcon, { size: 16 })
|
|
2245
|
+
), !freeSolo && /* @__PURE__ */ import_react18.default.createElement(
|
|
2246
|
+
"button",
|
|
2247
|
+
{
|
|
2248
|
+
type: "button",
|
|
2249
|
+
className: `rf-autocomplete__icon-btn rf-autocomplete__icon-btn--popup ${open ? "rf-autocomplete__icon-btn--open" : ""}`,
|
|
2250
|
+
onMouseDown: (e) => {
|
|
2251
|
+
e.preventDefault();
|
|
2252
|
+
open ? closePopup() : openPopup();
|
|
2253
|
+
},
|
|
2254
|
+
tabIndex: -1,
|
|
2255
|
+
"aria-label": open ? "Close" : "Open"
|
|
2256
|
+
},
|
|
2257
|
+
/* @__PURE__ */ import_react18.default.createElement(ChevronDownIcon, null)
|
|
2258
|
+
))
|
|
2259
|
+
), helperText && /* @__PURE__ */ import_react18.default.createElement("div", { className: `rf-text-field__helper-text${error ? " rf-text-field__helper-text--error" : ""}` }, helperText), open && !disabled && import_react_dom2.default.createPortal(
|
|
2260
|
+
/* @__PURE__ */ import_react18.default.createElement("div", { ref: popupRef, className: "rf-autocomplete__popup", role: "presentation", style: popupStyle }, loading ? /* @__PURE__ */ import_react18.default.createElement("div", { className: "rf-autocomplete__loading" }, /* @__PURE__ */ import_react18.default.createElement("span", { className: "rf-ac-spinner" }), loadingText) : flatEntries.length === 0 ? /* @__PURE__ */ import_react18.default.createElement("div", { className: "rf-autocomplete__no-options" }, noOptionsText) : /* @__PURE__ */ import_react18.default.createElement("ul", { ref: listRef, className: "rf-autocomplete__listbox", role: "listbox" }, groupBy ? (
|
|
2261
|
+
// Grouped render
|
|
2262
|
+
(() => {
|
|
2263
|
+
const rendered = [];
|
|
2264
|
+
let groupItems = [];
|
|
2265
|
+
let currentGroup = "";
|
|
2266
|
+
flatEntries.forEach((entry, ei) => {
|
|
2267
|
+
if (entry.kind === "group") {
|
|
2268
|
+
if (groupItems.length > 0) {
|
|
2269
|
+
rendered.push(
|
|
2270
|
+
/* @__PURE__ */ import_react18.default.createElement("li", { key: `g-${currentGroup}`, role: "presentation" }, /* @__PURE__ */ import_react18.default.createElement("div", { className: "rf-autocomplete__group-header" }, currentGroup), /* @__PURE__ */ import_react18.default.createElement("ul", { className: "rf-autocomplete__group-items", role: "group" }, groupItems))
|
|
2271
|
+
);
|
|
2272
|
+
groupItems = [];
|
|
2273
|
+
}
|
|
2274
|
+
currentGroup = entry.label;
|
|
2275
|
+
} else {
|
|
2276
|
+
const { option, flatIdx } = entry;
|
|
2277
|
+
groupItems.push(renderOptionItem(option, flatIdx));
|
|
2278
|
+
}
|
|
2279
|
+
if (ei === flatEntries.length - 1 && groupItems.length > 0) {
|
|
2280
|
+
rendered.push(
|
|
2281
|
+
/* @__PURE__ */ import_react18.default.createElement("li", { key: `g-${currentGroup}`, role: "presentation" }, /* @__PURE__ */ import_react18.default.createElement("div", { className: "rf-autocomplete__group-header" }, currentGroup), /* @__PURE__ */ import_react18.default.createElement("ul", { className: "rf-autocomplete__group-items", role: "group" }, groupItems))
|
|
2282
|
+
);
|
|
2283
|
+
}
|
|
2284
|
+
});
|
|
2285
|
+
return rendered;
|
|
2286
|
+
})()
|
|
2287
|
+
) : selectableOptions.map(({ option, flatIdx }) => renderOptionItem(option, flatIdx)))),
|
|
2288
|
+
document.body
|
|
2289
|
+
));
|
|
2290
|
+
function renderOptionItem(option, flatIdx) {
|
|
2291
|
+
const selected = isSelected(option);
|
|
2292
|
+
const focused = focusedIdx === flatIdx;
|
|
2293
|
+
const optDisabled = getOptionDisabled?.(option) ?? false;
|
|
2294
|
+
const label2 = getOptionLabel(option);
|
|
2295
|
+
return /* @__PURE__ */ import_react18.default.createElement(
|
|
2296
|
+
"li",
|
|
2297
|
+
{
|
|
2298
|
+
key: label2 + flatIdx,
|
|
2299
|
+
"data-idx": flatIdx,
|
|
2300
|
+
role: "option",
|
|
2301
|
+
"aria-selected": selected,
|
|
2302
|
+
"aria-disabled": optDisabled,
|
|
2303
|
+
className: [
|
|
2304
|
+
"rf-autocomplete__option",
|
|
2305
|
+
selected ? "rf-autocomplete__option--selected" : "",
|
|
2306
|
+
focused ? "rf-autocomplete__option--focused" : "",
|
|
2307
|
+
optDisabled ? "rf-autocomplete__option--disabled" : ""
|
|
2308
|
+
].filter(Boolean).join(" "),
|
|
2309
|
+
onMouseEnter: () => setFocusedIdx(flatIdx),
|
|
2310
|
+
onMouseLeave: () => setFocusedIdx(-1),
|
|
2311
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2312
|
+
onClick: () => selectOption(option)
|
|
2313
|
+
},
|
|
2314
|
+
renderOption ? renderOption(option, { selected, focused, index: flatIdx }) : /* @__PURE__ */ import_react18.default.createElement("span", { style: { flex: 1, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, label2),
|
|
2315
|
+
!renderOption && /* @__PURE__ */ import_react18.default.createElement("span", { className: "rf-autocomplete__option-check" }, /* @__PURE__ */ import_react18.default.createElement(CheckIcon, null))
|
|
2316
|
+
);
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
var Autocomplete = import_react18.default.forwardRef(AutocompleteInner);
|
|
2320
|
+
Autocomplete.displayName = "Autocomplete";
|
|
2321
|
+
|
|
2322
|
+
// lib/TextFields/AddressLookup.tsx
|
|
2323
|
+
var AddressLookup = ({
|
|
2324
|
+
value = {},
|
|
2325
|
+
onChange = () => {
|
|
2326
|
+
},
|
|
2327
|
+
label = "Address",
|
|
2328
|
+
error = {},
|
|
2329
|
+
size = "medium",
|
|
2330
|
+
sx = {},
|
|
2331
|
+
layout = "stack",
|
|
2332
|
+
required = false,
|
|
2333
|
+
token = ""
|
|
2334
|
+
}) => {
|
|
2335
|
+
const { theme } = useRufousTheme();
|
|
2336
|
+
const [suggestions, setSuggestions] = (0, import_react19.useState)([]);
|
|
2337
|
+
const [loading, setLoading] = (0, import_react19.useState)(false);
|
|
2338
|
+
const [showSuggestions, setShowSuggestions] = (0, import_react19.useState)(false);
|
|
2339
|
+
const debounceTimeout = (0, import_react19.useRef)(null);
|
|
2340
|
+
const containerRef = (0, import_react19.useRef)(null);
|
|
2341
|
+
const apiKey = token || "";
|
|
2342
|
+
const countries = import_country_state_city.Country.getAllCountries();
|
|
2343
|
+
const [states, setStates] = (0, import_react19.useState)([]);
|
|
2344
|
+
const [cities, setCities] = (0, import_react19.useState)([]);
|
|
2345
|
+
(0, import_react19.useEffect)(() => {
|
|
2346
|
+
const handleClickOutside = (event) => {
|
|
2347
|
+
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
2348
|
+
setShowSuggestions(false);
|
|
2349
|
+
}
|
|
2350
|
+
};
|
|
2351
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
2352
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
2353
|
+
}, []);
|
|
2354
|
+
(0, import_react19.useEffect)(() => {
|
|
2355
|
+
if (value.country) {
|
|
2356
|
+
const country = countries.find((c) => c.name === value.country);
|
|
2357
|
+
if (country) {
|
|
2358
|
+
const stateList = import_country_state_city.State.getStatesOfCountry(country.isoCode);
|
|
2359
|
+
setStates(stateList);
|
|
2360
|
+
} else {
|
|
2361
|
+
setStates([]);
|
|
2362
|
+
}
|
|
2363
|
+
} else {
|
|
2364
|
+
setStates([]);
|
|
2365
|
+
}
|
|
2366
|
+
}, [value.country]);
|
|
2367
|
+
(0, import_react19.useEffect)(() => {
|
|
2368
|
+
if (value.state && value.country) {
|
|
2369
|
+
const country = countries.find((c) => c.name === value.country);
|
|
2370
|
+
if (country) {
|
|
2371
|
+
const state = import_country_state_city.State.getStatesOfCountry(country.isoCode).find((s2) => s2.name === value.state);
|
|
2372
|
+
if (state) {
|
|
2373
|
+
const cityList = import_country_state_city.City.getCitiesOfState(country.isoCode, state.isoCode);
|
|
2374
|
+
setCities(cityList);
|
|
2375
|
+
} else {
|
|
2376
|
+
setCities([]);
|
|
2377
|
+
}
|
|
2378
|
+
} else {
|
|
2379
|
+
setCities([]);
|
|
2380
|
+
}
|
|
2381
|
+
} else {
|
|
2382
|
+
setCities([]);
|
|
2383
|
+
}
|
|
2384
|
+
}, [value.state, value.country]);
|
|
2385
|
+
const handleChange = (field, newVal) => {
|
|
2386
|
+
onChange({
|
|
2387
|
+
...value,
|
|
2388
|
+
[field]: newVal
|
|
2389
|
+
});
|
|
2390
|
+
};
|
|
2391
|
+
const fetchPlaceDetails = async (placeId, mainText = "") => {
|
|
2392
|
+
if (!apiKey) {
|
|
2393
|
+
console.warn("Google Places API Key (token) is missing.");
|
|
2394
|
+
return;
|
|
2395
|
+
}
|
|
2396
|
+
setLoading(true);
|
|
1988
2397
|
try {
|
|
1989
2398
|
const res = await import_axios.default.get(
|
|
1990
2399
|
`https://places.googleapis.com/v1/places/${placeId}`,
|
|
@@ -2060,7 +2469,7 @@ var AddressLookup = ({
|
|
|
2060
2469
|
city: ""
|
|
2061
2470
|
});
|
|
2062
2471
|
};
|
|
2063
|
-
return /* @__PURE__ */
|
|
2472
|
+
return /* @__PURE__ */ import_react19.default.createElement("div", { className: "address-lookup-container", style: sx, ref: containerRef }, /* @__PURE__ */ import_react19.default.createElement("div", { className: `address-lookup-grid address-lookup-grid-${layout}` }, /* @__PURE__ */ import_react19.default.createElement("div", { className: "address-lookup-grid-item col-l1" }, /* @__PURE__ */ import_react19.default.createElement(
|
|
2064
2473
|
TextField,
|
|
2065
2474
|
{
|
|
2066
2475
|
label,
|
|
@@ -2092,7 +2501,7 @@ var AddressLookup = ({
|
|
|
2092
2501
|
},
|
|
2093
2502
|
onFocus: () => suggestions.length > 0 && setShowSuggestions(true)
|
|
2094
2503
|
}
|
|
2095
|
-
), loading && /* @__PURE__ */
|
|
2504
|
+
), loading && /* @__PURE__ */ import_react19.default.createElement("div", { className: "loading-indicator" }, /* @__PURE__ */ import_react19.default.createElement(circularProgress_default, { size: 20 })), showSuggestions && suggestions.length > 0 && /* @__PURE__ */ import_react19.default.createElement("div", { className: "autocomplete-dropdown" }, suggestions.map((option, idx) => /* @__PURE__ */ import_react19.default.createElement(
|
|
2096
2505
|
"div",
|
|
2097
2506
|
{
|
|
2098
2507
|
key: idx,
|
|
@@ -2103,9 +2512,9 @@ var AddressLookup = ({
|
|
|
2103
2512
|
fetchPlaceDetails(option.placePrediction.placeId, mainText);
|
|
2104
2513
|
}
|
|
2105
2514
|
},
|
|
2106
|
-
/* @__PURE__ */
|
|
2107
|
-
/* @__PURE__ */
|
|
2108
|
-
))), error.addressLine1 && /* @__PURE__ */
|
|
2515
|
+
/* @__PURE__ */ import_react19.default.createElement("div", { className: "autocomplete-main-text" }, option?.placePrediction?.structuredFormat?.mainText?.text),
|
|
2516
|
+
/* @__PURE__ */ import_react19.default.createElement("div", { className: "autocomplete-secondary-text" }, option?.placePrediction?.structuredFormat?.secondaryText?.text)
|
|
2517
|
+
))), error.addressLine1 && /* @__PURE__ */ import_react19.default.createElement("div", { className: "field-error-text" }, error.addressLine1)), layout === "compact" && /* @__PURE__ */ import_react19.default.createElement("div", { className: "address-lookup-grid-item col-l2" }, /* @__PURE__ */ import_react19.default.createElement(
|
|
2109
2518
|
TextField,
|
|
2110
2519
|
{
|
|
2111
2520
|
label: "Address Line 2",
|
|
@@ -2114,7 +2523,7 @@ var AddressLookup = ({
|
|
|
2114
2523
|
value: value.addressLine2 || "",
|
|
2115
2524
|
onChange: (e) => handleChange("addressLine2", e.target.value)
|
|
2116
2525
|
}
|
|
2117
|
-
)), layout !== "compact" && /* @__PURE__ */
|
|
2526
|
+
)), layout !== "compact" && /* @__PURE__ */ import_react19.default.createElement("div", { className: "address-lookup-grid-item col-l2" }, /* @__PURE__ */ import_react19.default.createElement(
|
|
2118
2527
|
TextField,
|
|
2119
2528
|
{
|
|
2120
2529
|
label: "Address Line 2",
|
|
@@ -2123,40 +2532,40 @@ var AddressLookup = ({
|
|
|
2123
2532
|
value: value.addressLine2 || "",
|
|
2124
2533
|
onChange: (e) => handleChange("addressLine2", e.target.value)
|
|
2125
2534
|
}
|
|
2126
|
-
)), /* @__PURE__ */
|
|
2127
|
-
|
|
2535
|
+
)), /* @__PURE__ */ import_react19.default.createElement("div", { className: "address-lookup-grid-item col-country" }, /* @__PURE__ */ import_react19.default.createElement(
|
|
2536
|
+
Autocomplete,
|
|
2128
2537
|
{
|
|
2538
|
+
options: countries.map((c) => c.name),
|
|
2539
|
+
value: value.country || null,
|
|
2540
|
+
onChange: (v) => handleCountryChange(v || ""),
|
|
2129
2541
|
label: "Country",
|
|
2130
|
-
name: "country",
|
|
2131
2542
|
fullWidth: true,
|
|
2132
|
-
value: value.country || "",
|
|
2133
2543
|
required,
|
|
2134
|
-
|
|
2135
|
-
list: "countries-list"
|
|
2544
|
+
error: !!error.country
|
|
2136
2545
|
}
|
|
2137
|
-
),
|
|
2138
|
-
|
|
2546
|
+
), error.country && /* @__PURE__ */ import_react19.default.createElement("div", { className: "field-error-text" }, error.country)), /* @__PURE__ */ import_react19.default.createElement("div", { className: "address-lookup-grid-item col-state" }, /* @__PURE__ */ import_react19.default.createElement(
|
|
2547
|
+
Autocomplete,
|
|
2139
2548
|
{
|
|
2549
|
+
options: states.map((s2) => s2.name),
|
|
2550
|
+
value: value.state || null,
|
|
2551
|
+
onChange: (v) => handleStateChange(v || ""),
|
|
2140
2552
|
label: "State",
|
|
2141
|
-
name: "state",
|
|
2142
2553
|
fullWidth: true,
|
|
2143
|
-
value: value.state || "",
|
|
2144
2554
|
required,
|
|
2145
|
-
|
|
2146
|
-
list: "states-list"
|
|
2555
|
+
error: !!error.state
|
|
2147
2556
|
}
|
|
2148
|
-
),
|
|
2149
|
-
|
|
2557
|
+
), error.state && /* @__PURE__ */ import_react19.default.createElement("div", { className: "field-error-text" }, error.state)), /* @__PURE__ */ import_react19.default.createElement("div", { className: "address-lookup-grid-item col-city" }, /* @__PURE__ */ import_react19.default.createElement(
|
|
2558
|
+
Autocomplete,
|
|
2150
2559
|
{
|
|
2560
|
+
options: cities.map((c) => c.name),
|
|
2561
|
+
value: value.city || null,
|
|
2562
|
+
onChange: (v) => handleChange("city", v || ""),
|
|
2151
2563
|
label: "City",
|
|
2152
|
-
name: "city",
|
|
2153
2564
|
fullWidth: true,
|
|
2154
|
-
value: value.city || "",
|
|
2155
2565
|
required,
|
|
2156
|
-
|
|
2157
|
-
list: "cities-list"
|
|
2566
|
+
error: !!error.city
|
|
2158
2567
|
}
|
|
2159
|
-
),
|
|
2568
|
+
), error.city && /* @__PURE__ */ import_react19.default.createElement("div", { className: "field-error-text" }, error.city)), /* @__PURE__ */ import_react19.default.createElement("div", { className: "address-lookup-grid-item col-pin" }, /* @__PURE__ */ import_react19.default.createElement(
|
|
2160
2569
|
TextField,
|
|
2161
2570
|
{
|
|
2162
2571
|
label: "Pincode",
|
|
@@ -2166,13 +2575,13 @@ var AddressLookup = ({
|
|
|
2166
2575
|
required,
|
|
2167
2576
|
onChange: (e) => handleChange("pincode", e.target.value)
|
|
2168
2577
|
}
|
|
2169
|
-
), error.pincode && /* @__PURE__ */
|
|
2578
|
+
), error.pincode && /* @__PURE__ */ import_react19.default.createElement("div", { className: "field-error-text" }, error.pincode))));
|
|
2170
2579
|
};
|
|
2171
2580
|
var AddressLookup_default = AddressLookup;
|
|
2172
2581
|
|
|
2173
2582
|
// lib/TextFields/DateField.tsx
|
|
2174
|
-
var
|
|
2175
|
-
var
|
|
2583
|
+
var import_react20 = __toESM(require("react"), 1);
|
|
2584
|
+
var import_react_dom3 = require("react-dom");
|
|
2176
2585
|
var WEEKDAYS = ["SU", "MO", "TU", "WE", "TH", "FR", "SA"];
|
|
2177
2586
|
var MONTHS = [
|
|
2178
2587
|
"January",
|
|
@@ -2239,6 +2648,13 @@ var parseMonthName = (name) => {
|
|
|
2239
2648
|
idx = MONTHS_SHORT.findIndex((m) => m.toLowerCase() === lower);
|
|
2240
2649
|
return idx;
|
|
2241
2650
|
};
|
|
2651
|
+
var strictDate = (yyyy, mm0, dd) => {
|
|
2652
|
+
if (dd < 1 || dd > 31 || mm0 < 0 || mm0 > 11) return null;
|
|
2653
|
+
const d = new Date(yyyy, mm0, dd);
|
|
2654
|
+
if (isNaN(d.getTime())) return null;
|
|
2655
|
+
if (d.getMonth() !== mm0 || d.getDate() !== dd) return null;
|
|
2656
|
+
return d;
|
|
2657
|
+
};
|
|
2242
2658
|
var parseDisplay = (str, fmt = "MM/DD/YYYY") => {
|
|
2243
2659
|
if (fmt === "DD MMM YYYY" || fmt === "DD MMMM YYYY") {
|
|
2244
2660
|
const parts2 = str.split(" ");
|
|
@@ -2246,9 +2662,8 @@ var parseDisplay = (str, fmt = "MM/DD/YYYY") => {
|
|
|
2246
2662
|
const dd2 = parseInt(parts2[0], 10);
|
|
2247
2663
|
const mm2 = parseMonthName(parts2[1]);
|
|
2248
2664
|
const yyyy2 = parseInt(parts2[2], 10);
|
|
2249
|
-
if (isNaN(dd2) ||
|
|
2250
|
-
|
|
2251
|
-
return isNaN(d2.getTime()) ? null : d2;
|
|
2665
|
+
if (isNaN(dd2) || isNaN(yyyy2) || yyyy2 < 1e3) return null;
|
|
2666
|
+
return strictDate(yyyy2, mm2, dd2);
|
|
2252
2667
|
}
|
|
2253
2668
|
if (fmt === "MMM DD, YYYY" || fmt === "MMMM DD, YYYY") {
|
|
2254
2669
|
const cleaned = str.replace(",", "");
|
|
@@ -2257,9 +2672,8 @@ var parseDisplay = (str, fmt = "MM/DD/YYYY") => {
|
|
|
2257
2672
|
const mm2 = parseMonthName(parts2[0]);
|
|
2258
2673
|
const dd2 = parseInt(parts2[1], 10);
|
|
2259
2674
|
const yyyy2 = parseInt(parts2[2], 10);
|
|
2260
|
-
if (
|
|
2261
|
-
|
|
2262
|
-
return isNaN(d2.getTime()) ? null : d2;
|
|
2675
|
+
if (isNaN(dd2) || isNaN(yyyy2) || yyyy2 < 1e3) return null;
|
|
2676
|
+
return strictDate(yyyy2, mm2, dd2);
|
|
2263
2677
|
}
|
|
2264
2678
|
const sep = str.includes("/") ? "/" : "-";
|
|
2265
2679
|
const parts = str.split(sep);
|
|
@@ -2281,10 +2695,8 @@ var parseDisplay = (str, fmt = "MM/DD/YYYY") => {
|
|
|
2281
2695
|
[mm, dd, yyyy] = nums;
|
|
2282
2696
|
break;
|
|
2283
2697
|
}
|
|
2284
|
-
if (!
|
|
2285
|
-
|
|
2286
|
-
if (isNaN(d.getTime())) return null;
|
|
2287
|
-
return d;
|
|
2698
|
+
if (!yyyy || yyyy < 1e3) return null;
|
|
2699
|
+
return strictDate(yyyy, mm - 1, dd);
|
|
2288
2700
|
};
|
|
2289
2701
|
var isoToDate = (iso) => {
|
|
2290
2702
|
if (!iso) return null;
|
|
@@ -2308,6 +2720,17 @@ var buildISO = (date, type, hour, minute, ampm) => {
|
|
|
2308
2720
|
if (ampm === "PM") h24 += 12;
|
|
2309
2721
|
return `${y}-${mo}-${d}T${String(h24).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
|
|
2310
2722
|
};
|
|
2723
|
+
var getDateWordCount = (fmt) => {
|
|
2724
|
+
switch (fmt) {
|
|
2725
|
+
case "DD MMM YYYY":
|
|
2726
|
+
case "MMM DD, YYYY":
|
|
2727
|
+
case "DD MMMM YYYY":
|
|
2728
|
+
case "MMMM DD, YYYY":
|
|
2729
|
+
return 3;
|
|
2730
|
+
default:
|
|
2731
|
+
return 1;
|
|
2732
|
+
}
|
|
2733
|
+
};
|
|
2311
2734
|
var parseTimeFromISO = (iso) => {
|
|
2312
2735
|
const timePart = iso.split("T")[1] || "";
|
|
2313
2736
|
const [hStr, mStr] = timePart.split(":");
|
|
@@ -2318,25 +2741,25 @@ var parseTimeFromISO = (iso) => {
|
|
|
2318
2741
|
if (h === 0) h = 12;
|
|
2319
2742
|
return { h, m, ampm };
|
|
2320
2743
|
};
|
|
2321
|
-
var CalendarIcon = () => /* @__PURE__ */
|
|
2322
|
-
var ChevUp = () => /* @__PURE__ */
|
|
2323
|
-
var ChevDown = () => /* @__PURE__ */
|
|
2744
|
+
var CalendarIcon = () => /* @__PURE__ */ import_react20.default.createElement("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ import_react20.default.createElement("rect", { x: "3", y: "4", width: "18", height: "18", rx: "2", ry: "2" }), /* @__PURE__ */ import_react20.default.createElement("line", { x1: "16", y1: "2", x2: "16", y2: "6" }), /* @__PURE__ */ import_react20.default.createElement("line", { x1: "8", y1: "2", x2: "8", y2: "6" }), /* @__PURE__ */ import_react20.default.createElement("line", { x1: "3", y1: "10", x2: "21", y2: "10" }));
|
|
2745
|
+
var ChevUp = () => /* @__PURE__ */ import_react20.default.createElement("svg", { width: "10", height: "7", viewBox: "0 0 10 7", fill: "currentColor" }, /* @__PURE__ */ import_react20.default.createElement("path", { d: "M5 0L10 7H0L5 0Z" }));
|
|
2746
|
+
var ChevDown = () => /* @__PURE__ */ import_react20.default.createElement("svg", { width: "10", height: "7", viewBox: "0 0 10 7", fill: "currentColor" }, /* @__PURE__ */ import_react20.default.createElement("path", { d: "M5 7L0 0H10L5 7Z" }));
|
|
2324
2747
|
var ITEM_H = 36;
|
|
2325
2748
|
var ScrollColumn = ({ items, selected, onSelect, infinite = true }) => {
|
|
2326
|
-
const listRef = (0,
|
|
2327
|
-
const isInternalScroll = (0,
|
|
2328
|
-
const scrollTimeout = (0,
|
|
2749
|
+
const listRef = (0, import_react20.useRef)(null);
|
|
2750
|
+
const isInternalScroll = (0, import_react20.useRef)(false);
|
|
2751
|
+
const scrollTimeout = (0, import_react20.useRef)(null);
|
|
2329
2752
|
const MULTIPLIER = infinite ? 100 : 1;
|
|
2330
2753
|
const virtualItems = infinite ? Array(MULTIPLIER).fill(items).flat() : items;
|
|
2331
2754
|
const centerOffset = infinite ? Math.floor(MULTIPLIER / 2) * items.length : 0;
|
|
2332
2755
|
const VISUAL_OFFSET = 54;
|
|
2333
|
-
(0,
|
|
2756
|
+
(0, import_react20.useEffect)(() => {
|
|
2334
2757
|
if (listRef.current) {
|
|
2335
2758
|
const targetIndex = centerOffset + selected;
|
|
2336
2759
|
listRef.current.scrollTop = targetIndex * ITEM_H - (infinite ? VISUAL_OFFSET : 0);
|
|
2337
2760
|
}
|
|
2338
2761
|
}, [centerOffset, infinite, selected]);
|
|
2339
|
-
(0,
|
|
2762
|
+
(0, import_react20.useEffect)(() => {
|
|
2340
2763
|
if (listRef.current && !isInternalScroll.current) {
|
|
2341
2764
|
const targetIndex = centerOffset + selected;
|
|
2342
2765
|
listRef.current.scrollTo({
|
|
@@ -2368,15 +2791,15 @@ var ScrollColumn = ({ items, selected, onSelect, infinite = true }) => {
|
|
|
2368
2791
|
}
|
|
2369
2792
|
}, 100);
|
|
2370
2793
|
};
|
|
2371
|
-
return /* @__PURE__ */
|
|
2794
|
+
return /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-timescroll__col-wrapper" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
2372
2795
|
"div",
|
|
2373
2796
|
{
|
|
2374
2797
|
className: "rf-timescroll__col",
|
|
2375
2798
|
ref: listRef,
|
|
2376
2799
|
onScroll: handleScroll
|
|
2377
2800
|
},
|
|
2378
|
-
!infinite && /* @__PURE__ */
|
|
2379
|
-
virtualItems.map((label, idx) => /* @__PURE__ */
|
|
2801
|
+
!infinite && /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-timescroll__spacer" }),
|
|
2802
|
+
virtualItems.map((label, idx) => /* @__PURE__ */ import_react20.default.createElement(
|
|
2380
2803
|
"div",
|
|
2381
2804
|
{
|
|
2382
2805
|
key: `${label}-${idx}`,
|
|
@@ -2384,8 +2807,8 @@ var ScrollColumn = ({ items, selected, onSelect, infinite = true }) => {
|
|
|
2384
2807
|
},
|
|
2385
2808
|
label
|
|
2386
2809
|
)),
|
|
2387
|
-
!infinite && /* @__PURE__ */
|
|
2388
|
-
), /* @__PURE__ */
|
|
2810
|
+
!infinite && /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-timescroll__spacer" })
|
|
2811
|
+
), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-timescroll__mask rf-timescroll__mask--top" }), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-timescroll__mask rf-timescroll__mask--bottom" }));
|
|
2389
2812
|
};
|
|
2390
2813
|
var SpinnerPanel = ({
|
|
2391
2814
|
hour,
|
|
@@ -2396,7 +2819,7 @@ var SpinnerPanel = ({
|
|
|
2396
2819
|
onHourInput,
|
|
2397
2820
|
onMinuteInput,
|
|
2398
2821
|
onAmpmToggle
|
|
2399
|
-
}) => /* @__PURE__ */
|
|
2822
|
+
}) => /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__time-row" }, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__time-input-wrap" }, /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-date-picker__time-spin-btn", onMouseDown: (e) => e.preventDefault(), onClick: () => onHourChange(1) }, /* @__PURE__ */ import_react20.default.createElement(ChevUp, null)), /* @__PURE__ */ import_react20.default.createElement(
|
|
2400
2823
|
"input",
|
|
2401
2824
|
{
|
|
2402
2825
|
type: "number",
|
|
@@ -2407,7 +2830,7 @@ var SpinnerPanel = ({
|
|
|
2407
2830
|
onChange: onHourInput,
|
|
2408
2831
|
onMouseDown: (e) => e.stopPropagation()
|
|
2409
2832
|
}
|
|
2410
|
-
), /* @__PURE__ */
|
|
2833
|
+
), /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-date-picker__time-spin-btn", onMouseDown: (e) => e.preventDefault(), onClick: () => onHourChange(-1) }, /* @__PURE__ */ import_react20.default.createElement(ChevDown, null))), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__time-colon" }, ":"), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__time-input-wrap" }, /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-date-picker__time-spin-btn", onMouseDown: (e) => e.preventDefault(), onClick: () => onMinuteChange(1) }, /* @__PURE__ */ import_react20.default.createElement(ChevUp, null)), /* @__PURE__ */ import_react20.default.createElement(
|
|
2411
2834
|
"input",
|
|
2412
2835
|
{
|
|
2413
2836
|
type: "number",
|
|
@@ -2418,7 +2841,7 @@ var SpinnerPanel = ({
|
|
|
2418
2841
|
onChange: onMinuteInput,
|
|
2419
2842
|
onMouseDown: (e) => e.stopPropagation()
|
|
2420
2843
|
}
|
|
2421
|
-
), /* @__PURE__ */
|
|
2844
|
+
), /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-date-picker__time-spin-btn", onMouseDown: (e) => e.preventDefault(), onClick: () => onMinuteChange(-1) }, /* @__PURE__ */ import_react20.default.createElement(ChevDown, null))), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__ampm" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
2422
2845
|
"button",
|
|
2423
2846
|
{
|
|
2424
2847
|
type: "button",
|
|
@@ -2427,7 +2850,7 @@ var SpinnerPanel = ({
|
|
|
2427
2850
|
onClick: () => onAmpmToggle("AM")
|
|
2428
2851
|
},
|
|
2429
2852
|
"AM"
|
|
2430
|
-
), /* @__PURE__ */
|
|
2853
|
+
), /* @__PURE__ */ import_react20.default.createElement(
|
|
2431
2854
|
"button",
|
|
2432
2855
|
{
|
|
2433
2856
|
type: "button",
|
|
@@ -2449,7 +2872,7 @@ var CalendarBody = ({
|
|
|
2449
2872
|
onMonthSelect,
|
|
2450
2873
|
onYearSelect
|
|
2451
2874
|
}) => {
|
|
2452
|
-
const [pickerView, setPickerView] = (0,
|
|
2875
|
+
const [pickerView, setPickerView] = (0, import_react20.useState)("calendar");
|
|
2453
2876
|
const handleMonthClick = () => {
|
|
2454
2877
|
setPickerView(pickerView === "month" ? "calendar" : "month");
|
|
2455
2878
|
};
|
|
@@ -2467,21 +2890,21 @@ var CalendarBody = ({
|
|
|
2467
2890
|
const currentYear = todayDate.getFullYear();
|
|
2468
2891
|
const yearStart = viewYear - 6;
|
|
2469
2892
|
const years = Array.from({ length: 16 }, (_, i) => yearStart + i);
|
|
2470
|
-
return /* @__PURE__ */
|
|
2893
|
+
return /* @__PURE__ */ import_react20.default.createElement(import_react20.default.Fragment, null, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__header" }, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__header-labels" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
2471
2894
|
"span",
|
|
2472
2895
|
{
|
|
2473
2896
|
className: `rf-date-picker__month-label ${pickerView === "month" ? "rf-date-picker__month-label--active" : ""}`,
|
|
2474
2897
|
onClick: handleMonthClick
|
|
2475
2898
|
},
|
|
2476
2899
|
MONTHS[viewMonth]
|
|
2477
|
-
), /* @__PURE__ */
|
|
2900
|
+
), /* @__PURE__ */ import_react20.default.createElement(
|
|
2478
2901
|
"span",
|
|
2479
2902
|
{
|
|
2480
2903
|
className: `rf-date-picker__year-label ${pickerView === "year" ? "rf-date-picker__year-label--active" : ""}`,
|
|
2481
2904
|
onClick: handleYearClick
|
|
2482
2905
|
},
|
|
2483
2906
|
viewYear
|
|
2484
|
-
)), /* @__PURE__ */
|
|
2907
|
+
)), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__nav" }, pickerView === "year" ? /* @__PURE__ */ import_react20.default.createElement(import_react20.default.Fragment, null, /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-date-picker__nav-btn", onClick: () => onYearSelect(viewYear - 16), "aria-label": "Previous years" }, "\u2039"), /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-date-picker__nav-btn", onClick: () => onYearSelect(viewYear + 16), "aria-label": "Next years" }, "\u203A")) : /* @__PURE__ */ import_react20.default.createElement(import_react20.default.Fragment, null, /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-date-picker__nav-btn", onClick: onPrev, "aria-label": "Previous month" }, "\u2039"), /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-date-picker__nav-btn", onClick: onNext, "aria-label": "Next month" }, "\u203A")))), pickerView === "month" && /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__month-grid" }, MONTHS_SHORT.map((m, idx) => /* @__PURE__ */ import_react20.default.createElement(
|
|
2485
2908
|
"button",
|
|
2486
2909
|
{
|
|
2487
2910
|
key: m,
|
|
@@ -2494,7 +2917,7 @@ var CalendarBody = ({
|
|
|
2494
2917
|
onClick: () => handleMonthPick(idx)
|
|
2495
2918
|
},
|
|
2496
2919
|
m
|
|
2497
|
-
))), pickerView === "year" && /* @__PURE__ */
|
|
2920
|
+
))), pickerView === "year" && /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__year-grid" }, years.map((y) => /* @__PURE__ */ import_react20.default.createElement(
|
|
2498
2921
|
"button",
|
|
2499
2922
|
{
|
|
2500
2923
|
key: y,
|
|
@@ -2507,12 +2930,12 @@ var CalendarBody = ({
|
|
|
2507
2930
|
onClick: () => handleYearPick(y)
|
|
2508
2931
|
},
|
|
2509
2932
|
y
|
|
2510
|
-
))), pickerView === "calendar" && /* @__PURE__ */
|
|
2511
|
-
if (day === null) return /* @__PURE__ */
|
|
2933
|
+
))), pickerView === "calendar" && /* @__PURE__ */ import_react20.default.createElement(import_react20.default.Fragment, null, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__weekdays" }, WEEKDAYS.map((w) => /* @__PURE__ */ import_react20.default.createElement("div", { key: w, className: "rf-date-picker__weekday" }, w))), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__grid" }, dayCells.map((day, idx) => {
|
|
2934
|
+
if (day === null) return /* @__PURE__ */ import_react20.default.createElement("div", { key: `e-${idx}`, className: "rf-date-picker__day rf-date-picker__day--empty" });
|
|
2512
2935
|
const cellDate = new Date(viewYear, viewMonth, day);
|
|
2513
2936
|
const isSelected = selectedDate ? isSameDay(cellDate, selectedDate) : false;
|
|
2514
2937
|
const isToday = isSameDay(cellDate, todayDate);
|
|
2515
|
-
return /* @__PURE__ */
|
|
2938
|
+
return /* @__PURE__ */ import_react20.default.createElement(
|
|
2516
2939
|
"button",
|
|
2517
2940
|
{
|
|
2518
2941
|
key: day,
|
|
@@ -2548,29 +2971,29 @@ var DateField = ({
|
|
|
2548
2971
|
sx
|
|
2549
2972
|
}) => {
|
|
2550
2973
|
const sxClass = useSx(sx);
|
|
2551
|
-
const [open, setOpen] = (0,
|
|
2552
|
-
const [selectedDate, setSelectedDate] = (0,
|
|
2553
|
-
const [hour, setHour] = (0,
|
|
2974
|
+
const [open, setOpen] = (0, import_react20.useState)(false);
|
|
2975
|
+
const [selectedDate, setSelectedDate] = (0, import_react20.useState)(() => value ? isoToDate(value) : null);
|
|
2976
|
+
const [hour, setHour] = (0, import_react20.useState)(() => {
|
|
2554
2977
|
if (value && isDatetimeType(type)) return parseTimeFromISO(value).h;
|
|
2555
2978
|
return 12;
|
|
2556
2979
|
});
|
|
2557
|
-
const [minute, setMinute] = (0,
|
|
2980
|
+
const [minute, setMinute] = (0, import_react20.useState)(() => {
|
|
2558
2981
|
if (value && isDatetimeType(type)) return parseTimeFromISO(value).m;
|
|
2559
2982
|
return 0;
|
|
2560
2983
|
});
|
|
2561
|
-
const [ampm, setAmpm] = (0,
|
|
2984
|
+
const [ampm, setAmpm] = (0, import_react20.useState)(() => {
|
|
2562
2985
|
if (value && isDatetimeType(type)) return parseTimeFromISO(value).ampm;
|
|
2563
2986
|
return "AM";
|
|
2564
2987
|
});
|
|
2565
|
-
const [viewYear, setViewYear] = (0,
|
|
2988
|
+
const [viewYear, setViewYear] = (0, import_react20.useState)(() => {
|
|
2566
2989
|
const base = value ? isoToDate(value) : null;
|
|
2567
2990
|
return base ? base.getFullYear() : today().getFullYear();
|
|
2568
2991
|
});
|
|
2569
|
-
const [viewMonth, setViewMonth] = (0,
|
|
2992
|
+
const [viewMonth, setViewMonth] = (0, import_react20.useState)(() => {
|
|
2570
2993
|
const base = value ? isoToDate(value) : null;
|
|
2571
2994
|
return base ? base.getMonth() : today().getMonth();
|
|
2572
2995
|
});
|
|
2573
|
-
const [inputStr, setInputStr] = (0,
|
|
2996
|
+
const [inputStr, setInputStr] = (0, import_react20.useState)(() => {
|
|
2574
2997
|
if (!value) return "";
|
|
2575
2998
|
const d = isoToDate(value);
|
|
2576
2999
|
if (!d) return "";
|
|
@@ -2584,12 +3007,17 @@ var DateField = ({
|
|
|
2584
3007
|
const HOURS = Array.from({ length: 12 }, (_, i) => String(i + 1).padStart(2, "0"));
|
|
2585
3008
|
const MINUTES = Array.from({ length: 60 }, (_, i) => String(i).padStart(2, "0"));
|
|
2586
3009
|
const AMPMS = ["AM", "PM"];
|
|
2587
|
-
const containerRef = (0,
|
|
2588
|
-
const pickerRef = (0,
|
|
2589
|
-
const [dropUp, setDropUp] = (0,
|
|
2590
|
-
const inputId = (0,
|
|
2591
|
-
(0,
|
|
3010
|
+
const containerRef = (0, import_react20.useRef)(null);
|
|
3011
|
+
const pickerRef = (0, import_react20.useRef)(null);
|
|
3012
|
+
const [dropUp, setDropUp] = (0, import_react20.useState)(false);
|
|
3013
|
+
const inputId = (0, import_react20.useRef)(`rf-df-${Math.random().toString(36).substring(2, 11)}`).current;
|
|
3014
|
+
const isInternalChange = (0, import_react20.useRef)(false);
|
|
3015
|
+
(0, import_react20.useEffect)(() => {
|
|
2592
3016
|
if (value === void 0) return;
|
|
3017
|
+
if (isInternalChange.current) {
|
|
3018
|
+
isInternalChange.current = false;
|
|
3019
|
+
return;
|
|
3020
|
+
}
|
|
2593
3021
|
if (!value) {
|
|
2594
3022
|
setSelectedDate(null);
|
|
2595
3023
|
setInputStr("");
|
|
@@ -2611,7 +3039,7 @@ var DateField = ({
|
|
|
2611
3039
|
setInputStr(str);
|
|
2612
3040
|
}
|
|
2613
3041
|
}, [value, type]);
|
|
2614
|
-
(0,
|
|
3042
|
+
(0, import_react20.useEffect)(() => {
|
|
2615
3043
|
if (!open) return;
|
|
2616
3044
|
const handler = (e) => {
|
|
2617
3045
|
const target = e.target;
|
|
@@ -2622,14 +3050,14 @@ var DateField = ({
|
|
|
2622
3050
|
document.addEventListener("mousedown", handler);
|
|
2623
3051
|
return () => document.removeEventListener("mousedown", handler);
|
|
2624
3052
|
}, [open]);
|
|
2625
|
-
(0,
|
|
3053
|
+
(0, import_react20.useEffect)(() => {
|
|
2626
3054
|
if (!open || !containerRef.current) return;
|
|
2627
3055
|
const rect = containerRef.current.getBoundingClientRect();
|
|
2628
3056
|
const spaceBelow = window.innerHeight - rect.bottom;
|
|
2629
3057
|
const pickerHeight = 400;
|
|
2630
3058
|
setDropUp(spaceBelow < pickerHeight && rect.top > pickerHeight);
|
|
2631
3059
|
}, [open]);
|
|
2632
|
-
const commitDate = (0,
|
|
3060
|
+
const commitDate = (0, import_react20.useCallback)((d, h, m, ap) => {
|
|
2633
3061
|
setSelectedDate(d);
|
|
2634
3062
|
if (!d) {
|
|
2635
3063
|
setInputStr("");
|
|
@@ -2661,17 +3089,19 @@ var DateField = ({
|
|
|
2661
3089
|
const handleInputChange = (e) => {
|
|
2662
3090
|
const raw = e.target.value;
|
|
2663
3091
|
setInputStr(raw);
|
|
2664
|
-
const
|
|
2665
|
-
const
|
|
3092
|
+
const dateWordCount = getDateWordCount(dateFormat);
|
|
3093
|
+
const words = raw.split(" ");
|
|
3094
|
+
const datePart = words.slice(0, dateWordCount).join(" ");
|
|
3095
|
+
const timeParts = words.slice(dateWordCount);
|
|
2666
3096
|
const parsed = parseDisplay(datePart, dateFormat);
|
|
2667
3097
|
if (parsed) {
|
|
2668
3098
|
setSelectedDate(parsed);
|
|
2669
3099
|
setViewYear(parsed.getFullYear());
|
|
2670
3100
|
setViewMonth(parsed.getMonth());
|
|
2671
3101
|
let h = hour, m = minute, ap = ampm;
|
|
2672
|
-
if (isDatetimeType(type) &&
|
|
2673
|
-
const timePart =
|
|
2674
|
-
const periodPart =
|
|
3102
|
+
if (isDatetimeType(type) && timeParts.length >= 2) {
|
|
3103
|
+
const timePart = timeParts[0];
|
|
3104
|
+
const periodPart = timeParts[1]?.toUpperCase();
|
|
2675
3105
|
if (timePart?.includes(":")) {
|
|
2676
3106
|
const [hStr, mStr] = timePart.split(":");
|
|
2677
3107
|
const parsedH = parseInt(hStr, 10);
|
|
@@ -2690,9 +3120,11 @@ var DateField = ({
|
|
|
2690
3120
|
setAmpm(ap);
|
|
2691
3121
|
}
|
|
2692
3122
|
}
|
|
3123
|
+
isInternalChange.current = true;
|
|
2693
3124
|
onChange?.(buildISO(parsed, type, h, m, ap));
|
|
2694
3125
|
} else if (!raw) {
|
|
2695
3126
|
setSelectedDate(null);
|
|
3127
|
+
isInternalChange.current = true;
|
|
2696
3128
|
onChange?.("");
|
|
2697
3129
|
}
|
|
2698
3130
|
};
|
|
@@ -2776,7 +3208,7 @@ var DateField = ({
|
|
|
2776
3208
|
const inputPlaceholder = placeholder || (variant === "outlined" ? " " : void 0);
|
|
2777
3209
|
const todayDate = today();
|
|
2778
3210
|
const isSideVariant = type === "datetime-side" || type === "datetime-scroll";
|
|
2779
|
-
return /* @__PURE__ */
|
|
3211
|
+
return /* @__PURE__ */ import_react20.default.createElement("div", { ref: containerRef, className: rootClasses, style }, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-field__anchor" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
2780
3212
|
"div",
|
|
2781
3213
|
{
|
|
2782
3214
|
className: "rf-text-field__wrapper",
|
|
@@ -2785,7 +3217,7 @@ var DateField = ({
|
|
|
2785
3217
|
},
|
|
2786
3218
|
style: { cursor: disabled ? "default" : "pointer" }
|
|
2787
3219
|
},
|
|
2788
|
-
/* @__PURE__ */
|
|
3220
|
+
/* @__PURE__ */ import_react20.default.createElement(
|
|
2789
3221
|
"input",
|
|
2790
3222
|
{
|
|
2791
3223
|
id: inputId,
|
|
@@ -2801,7 +3233,7 @@ var DateField = ({
|
|
|
2801
3233
|
}
|
|
2802
3234
|
}
|
|
2803
3235
|
),
|
|
2804
|
-
/* @__PURE__ */
|
|
3236
|
+
/* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-text-field__adornment rf-text-field__adornment--end" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
2805
3237
|
"button",
|
|
2806
3238
|
{
|
|
2807
3239
|
type: "button",
|
|
@@ -2814,12 +3246,12 @@ var DateField = ({
|
|
|
2814
3246
|
},
|
|
2815
3247
|
"aria-label": "Pick date"
|
|
2816
3248
|
},
|
|
2817
|
-
/* @__PURE__ */
|
|
3249
|
+
/* @__PURE__ */ import_react20.default.createElement(CalendarIcon, null)
|
|
2818
3250
|
)),
|
|
2819
|
-
label && /* @__PURE__ */
|
|
2820
|
-
variant === "outlined" && /* @__PURE__ */
|
|
2821
|
-
), open && !disabled && (0,
|
|
2822
|
-
/* @__PURE__ */
|
|
3251
|
+
label && /* @__PURE__ */ import_react20.default.createElement("label", { htmlFor: inputId, className: "rf-text-field__label" }, label, " ", required && /* @__PURE__ */ import_react20.default.createElement("span", { className: "rf-text-field__asterisk" }, "*")),
|
|
3252
|
+
variant === "outlined" && /* @__PURE__ */ import_react20.default.createElement("fieldset", { className: "rf-text-field__notch" }, label && /* @__PURE__ */ import_react20.default.createElement("legend", { className: "rf-text-field__legend" }, /* @__PURE__ */ import_react20.default.createElement("span", null, label, required ? " *" : "")))
|
|
3253
|
+
), open && !disabled && (0, import_react_dom3.createPortal)(
|
|
3254
|
+
/* @__PURE__ */ import_react20.default.createElement(
|
|
2823
3255
|
"div",
|
|
2824
3256
|
{
|
|
2825
3257
|
ref: pickerRef,
|
|
@@ -2844,7 +3276,7 @@ var DateField = ({
|
|
|
2844
3276
|
})(),
|
|
2845
3277
|
onMouseDown: (e) => e.preventDefault()
|
|
2846
3278
|
},
|
|
2847
|
-
/* @__PURE__ */
|
|
3279
|
+
/* @__PURE__ */ import_react20.default.createElement("div", { className: isSideVariant ? "rf-date-picker__cal-col" : void 0 }, /* @__PURE__ */ import_react20.default.createElement(
|
|
2848
3280
|
CalendarBody,
|
|
2849
3281
|
{
|
|
2850
3282
|
viewMonth,
|
|
@@ -2858,7 +3290,7 @@ var DateField = ({
|
|
|
2858
3290
|
onMonthSelect: setViewMonth,
|
|
2859
3291
|
onYearSelect: setViewYear
|
|
2860
3292
|
}
|
|
2861
|
-
), type === "datetime" && /* @__PURE__ */
|
|
3293
|
+
), type === "datetime" && /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__time-section" }, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__time-label" }, "Time"), /* @__PURE__ */ import_react20.default.createElement(
|
|
2862
3294
|
SpinnerPanel,
|
|
2863
3295
|
{
|
|
2864
3296
|
hour,
|
|
@@ -2870,8 +3302,8 @@ var DateField = ({
|
|
|
2870
3302
|
onMinuteInput: handleMinuteInput,
|
|
2871
3303
|
onAmpmToggle: handleAmpmToggle
|
|
2872
3304
|
}
|
|
2873
|
-
)), /* @__PURE__ */
|
|
2874
|
-
type === "datetime-side" && /* @__PURE__ */
|
|
3305
|
+
)), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__divider" }), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__footer" }, /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-date-picker__footer-btn", onClick: handleToday }, "Today"), /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-date-picker__footer-btn rf-date-picker__footer-btn--clear", onClick: handleClear }, "Clear"))),
|
|
3306
|
+
type === "datetime-side" && /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__side-panel" }, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__side-label" }, "Time"), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__side-spinner" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
2875
3307
|
SpinnerPanel,
|
|
2876
3308
|
{
|
|
2877
3309
|
hour,
|
|
@@ -2883,22 +3315,22 @@ var DateField = ({
|
|
|
2883
3315
|
onMinuteInput: handleMinuteInput,
|
|
2884
3316
|
onAmpmToggle: handleAmpmToggle
|
|
2885
3317
|
}
|
|
2886
|
-
)), /* @__PURE__ */
|
|
2887
|
-
type === "datetime-scroll" && /* @__PURE__ */
|
|
3318
|
+
)), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__side-time-display" }, String(hour).padStart(2, "0"), ":", String(minute).padStart(2, "0"), " ", ampm)),
|
|
3319
|
+
type === "datetime-scroll" && /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__side-panel" }, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__side-label" }, "Time"), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-timescroll" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
2888
3320
|
ScrollColumn,
|
|
2889
3321
|
{
|
|
2890
3322
|
items: HOURS,
|
|
2891
3323
|
selected: hour - 1,
|
|
2892
3324
|
onSelect: handleScrollHour
|
|
2893
3325
|
}
|
|
2894
|
-
), /* @__PURE__ */
|
|
3326
|
+
), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-timescroll__colon" }, ":"), /* @__PURE__ */ import_react20.default.createElement(
|
|
2895
3327
|
ScrollColumn,
|
|
2896
3328
|
{
|
|
2897
3329
|
items: MINUTES,
|
|
2898
3330
|
selected: minute,
|
|
2899
3331
|
onSelect: handleScrollMinute
|
|
2900
3332
|
}
|
|
2901
|
-
), /* @__PURE__ */
|
|
3333
|
+
), /* @__PURE__ */ import_react20.default.createElement(
|
|
2902
3334
|
ScrollColumn,
|
|
2903
3335
|
{
|
|
2904
3336
|
items: AMPMS,
|
|
@@ -2906,15 +3338,15 @@ var DateField = ({
|
|
|
2906
3338
|
onSelect: handleScrollAmpm,
|
|
2907
3339
|
infinite: false
|
|
2908
3340
|
}
|
|
2909
|
-
)), /* @__PURE__ */
|
|
3341
|
+
)), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-picker__side-time-display" }, String(hour).padStart(2, "0"), ":", String(minute).padStart(2, "0"), " ", ampm))
|
|
2910
3342
|
),
|
|
2911
3343
|
document.body
|
|
2912
|
-
)), helperText && /* @__PURE__ */
|
|
3344
|
+
)), helperText && /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-text-field__helper-text" }, helperText));
|
|
2913
3345
|
};
|
|
2914
3346
|
DateField.displayName = "DateField";
|
|
2915
3347
|
|
|
2916
3348
|
// lib/TextFields/DateRangeField.tsx
|
|
2917
|
-
var
|
|
3349
|
+
var import_react21 = __toESM(require("react"), 1);
|
|
2918
3350
|
var WEEKDAYS2 = ["SU", "MO", "TU", "WE", "TH", "FR", "SA"];
|
|
2919
3351
|
var MONTHS2 = [
|
|
2920
3352
|
"January",
|
|
@@ -3039,7 +3471,7 @@ var detectPreset = (start, end) => {
|
|
|
3039
3471
|
if (isSameDay2(start, new Date(2e3, 0, 1)) && isSameDay2(end, today2)) return "all";
|
|
3040
3472
|
return null;
|
|
3041
3473
|
};
|
|
3042
|
-
var CalendarIcon2 = () => /* @__PURE__ */
|
|
3474
|
+
var CalendarIcon2 = () => /* @__PURE__ */ import_react21.default.createElement("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ import_react21.default.createElement("rect", { x: "3", y: "4", width: "18", height: "18", rx: "2", ry: "2" }), /* @__PURE__ */ import_react21.default.createElement("line", { x1: "16", y1: "2", x2: "16", y2: "6" }), /* @__PURE__ */ import_react21.default.createElement("line", { x1: "8", y1: "2", x2: "8", y2: "6" }), /* @__PURE__ */ import_react21.default.createElement("line", { x1: "3", y1: "10", x2: "21", y2: "10" }));
|
|
3043
3475
|
var RangeCalendarBody = ({
|
|
3044
3476
|
viewYear,
|
|
3045
3477
|
viewMonth,
|
|
@@ -3064,7 +3496,7 @@ var RangeCalendarBody = ({
|
|
|
3064
3496
|
const hasRange = startDate != null && effectiveEnd != null && !isSameDay2(startDate, effectiveEnd);
|
|
3065
3497
|
const lo = startDate && effectiveEnd ? startDate <= effectiveEnd ? startDate : effectiveEnd : null;
|
|
3066
3498
|
const hi = startDate && effectiveEnd ? startDate <= effectiveEnd ? effectiveEnd : startDate : null;
|
|
3067
|
-
return /* @__PURE__ */
|
|
3499
|
+
return /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-calendar" }, /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-calendar__header" }, /* @__PURE__ */ import_react21.default.createElement(
|
|
3068
3500
|
"button",
|
|
3069
3501
|
{
|
|
3070
3502
|
type: "button",
|
|
@@ -3074,7 +3506,7 @@ var RangeCalendarBody = ({
|
|
|
3074
3506
|
"aria-label": "Previous month"
|
|
3075
3507
|
},
|
|
3076
3508
|
"\u2039"
|
|
3077
|
-
), /* @__PURE__ */
|
|
3509
|
+
), /* @__PURE__ */ import_react21.default.createElement("span", { className: "rf-dr-calendar__month-label" }, MONTHS2[viewMonth], " ", viewYear), /* @__PURE__ */ import_react21.default.createElement(
|
|
3078
3510
|
"button",
|
|
3079
3511
|
{
|
|
3080
3512
|
type: "button",
|
|
@@ -3084,9 +3516,9 @@ var RangeCalendarBody = ({
|
|
|
3084
3516
|
"aria-label": "Next month"
|
|
3085
3517
|
},
|
|
3086
3518
|
"\u203A"
|
|
3087
|
-
)), /* @__PURE__ */
|
|
3519
|
+
)), /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-calendar__weekdays" }, WEEKDAYS2.map((w) => /* @__PURE__ */ import_react21.default.createElement("div", { key: w, className: "rf-dr-calendar__weekday" }, w))), /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-calendar__grid" }, dayCells.map((day, idx) => {
|
|
3088
3520
|
if (day === null) {
|
|
3089
|
-
return /* @__PURE__ */
|
|
3521
|
+
return /* @__PURE__ */ import_react21.default.createElement("div", { key: `e-${idx}`, className: "rf-dr-calendar__cell rf-dr-calendar__cell--empty" });
|
|
3090
3522
|
}
|
|
3091
3523
|
const cellDate = new Date(viewYear, viewMonth, day);
|
|
3092
3524
|
const isStart = startDate ? isSameDay2(cellDate, startDate) : false;
|
|
@@ -3106,7 +3538,7 @@ var RangeCalendarBody = ({
|
|
|
3106
3538
|
isStart || isEnd ? "rf-dr-calendar__day--selected" : "",
|
|
3107
3539
|
isToday && !isStart && !isEnd ? "rf-dr-calendar__day--today" : ""
|
|
3108
3540
|
].filter(Boolean).join(" ");
|
|
3109
|
-
return /* @__PURE__ */
|
|
3541
|
+
return /* @__PURE__ */ import_react21.default.createElement(
|
|
3110
3542
|
"div",
|
|
3111
3543
|
{
|
|
3112
3544
|
key: day,
|
|
@@ -3114,7 +3546,7 @@ var RangeCalendarBody = ({
|
|
|
3114
3546
|
onMouseEnter: () => onDayHover(cellDate),
|
|
3115
3547
|
onMouseLeave: () => onDayHover(null)
|
|
3116
3548
|
},
|
|
3117
|
-
/* @__PURE__ */
|
|
3549
|
+
/* @__PURE__ */ import_react21.default.createElement(
|
|
3118
3550
|
"button",
|
|
3119
3551
|
{
|
|
3120
3552
|
type: "button",
|
|
@@ -3128,8 +3560,8 @@ var RangeCalendarBody = ({
|
|
|
3128
3560
|
};
|
|
3129
3561
|
var MiniCalendar = ({ selectedDate, todayDate, onSelect, onClose }) => {
|
|
3130
3562
|
const init = selectedDate ?? todayDate;
|
|
3131
|
-
const [viewYear, setViewYear] = (0,
|
|
3132
|
-
const [viewMonth, setViewMonth] = (0,
|
|
3563
|
+
const [viewYear, setViewYear] = (0, import_react21.useState)(init.getFullYear());
|
|
3564
|
+
const [viewMonth, setViewMonth] = (0, import_react21.useState)(init.getMonth());
|
|
3133
3565
|
const firstDay = new Date(viewYear, viewMonth, 1).getDay();
|
|
3134
3566
|
const daysInMonth = new Date(viewYear, viewMonth + 1, 0).getDate();
|
|
3135
3567
|
const dayCells = [
|
|
@@ -3148,802 +3580,419 @@ var MiniCalendar = ({ selectedDate, todayDate, onSelect, onClose }) => {
|
|
|
3148
3580
|
setViewYear((y) => y + 1);
|
|
3149
3581
|
} else setViewMonth((m) => m + 1);
|
|
3150
3582
|
};
|
|
3151
|
-
return /* @__PURE__ */
|
|
3583
|
+
return /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-mini-cal" }, /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-mini-cal__header" }, /* @__PURE__ */ import_react21.default.createElement("button", { type: "button", className: "rf-dr-calendar__nav-btn", onClick: prevMonth }, "\u2039"), /* @__PURE__ */ import_react21.default.createElement("span", { className: "rf-dr-calendar__month-label", style: { fontSize: "0.88rem" } }, MONTHS2[viewMonth], " ", viewYear), /* @__PURE__ */ import_react21.default.createElement("button", { type: "button", className: "rf-dr-calendar__nav-btn", onClick: nextMonth }, "\u203A")), /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-calendar__weekdays" }, WEEKDAYS2.map((w) => /* @__PURE__ */ import_react21.default.createElement("div", { key: w, className: "rf-dr-calendar__weekday" }, w))), /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-calendar__grid" }, dayCells.map((day, idx) => {
|
|
3152
3584
|
if (day === null) {
|
|
3153
|
-
return /* @__PURE__ */
|
|
3154
|
-
}
|
|
3155
|
-
const cellDate = new Date(viewYear, viewMonth, day);
|
|
3156
|
-
const isSel = selectedDate ? isSameDay2(cellDate, selectedDate) : false;
|
|
3157
|
-
const isToday = isSameDay2(cellDate, todayDate);
|
|
3158
|
-
return /* @__PURE__ */ import_react20.default.createElement("div", { key: day, className: "rf-dr-calendar__cell" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
3159
|
-
"button",
|
|
3160
|
-
{
|
|
3161
|
-
type: "button",
|
|
3162
|
-
className: [
|
|
3163
|
-
"rf-dr-calendar__day",
|
|
3164
|
-
isSel ? "rf-dr-calendar__day--selected" : "",
|
|
3165
|
-
isToday && !isSel ? "rf-dr-calendar__day--today" : ""
|
|
3166
|
-
].filter(Boolean).join(" "),
|
|
3167
|
-
onClick: () => {
|
|
3168
|
-
onSelect(cellDate);
|
|
3169
|
-
onClose();
|
|
3170
|
-
}
|
|
3171
|
-
},
|
|
3172
|
-
day
|
|
3173
|
-
));
|
|
3174
|
-
})));
|
|
3175
|
-
};
|
|
3176
|
-
var DateRangeField = ({
|
|
3177
|
-
label,
|
|
3178
|
-
value,
|
|
3179
|
-
onChange,
|
|
3180
|
-
pickerType = "panel",
|
|
3181
|
-
variant = "outlined",
|
|
3182
|
-
size = "medium",
|
|
3183
|
-
color = "primary",
|
|
3184
|
-
error = false,
|
|
3185
|
-
helperText,
|
|
3186
|
-
fullWidth = false,
|
|
3187
|
-
disabled = false,
|
|
3188
|
-
required = false,
|
|
3189
|
-
className = "",
|
|
3190
|
-
style,
|
|
3191
|
-
sx
|
|
3192
|
-
}) => {
|
|
3193
|
-
const sxClass = useSx(sx);
|
|
3194
|
-
const today2 = todayFn();
|
|
3195
|
-
const committedStart = value?.start ? isoToDate2(value.start) : null;
|
|
3196
|
-
const committedEnd = value?.end ? isoToDate2(value.end) : null;
|
|
3197
|
-
const [open, setOpen] = (0, import_react20.useState)(false);
|
|
3198
|
-
const [draftStart, setDraftStart] = (0, import_react20.useState)(committedStart);
|
|
3199
|
-
const [draftEnd, setDraftEnd] = (0, import_react20.useState)(committedEnd);
|
|
3200
|
-
const [activePreset, setActivePreset] = (0, import_react20.useState)(
|
|
3201
|
-
() => detectPreset(committedStart, committedEnd)
|
|
3202
|
-
);
|
|
3203
|
-
const [startInputStr, setStartInputStr] = (0, import_react20.useState)(() => committedStart ? formatShort(committedStart) : "");
|
|
3204
|
-
const [endInputStr, setEndInputStr] = (0, import_react20.useState)(() => committedEnd ? formatShort(committedEnd) : "");
|
|
3205
|
-
const [inlineCal, setInlineCal] = (0, import_react20.useState)(null);
|
|
3206
|
-
const [hoverDate, setHoverDate] = (0, import_react20.useState)(null);
|
|
3207
|
-
const [selecting, setSelecting] = (0, import_react20.useState)("start");
|
|
3208
|
-
const [leftViewYear, setLeftViewYear] = (0, import_react20.useState)(() => today2.getFullYear());
|
|
3209
|
-
const [leftViewMonth, setLeftViewMonth] = (0, import_react20.useState)(() => today2.getMonth());
|
|
3210
|
-
const containerRef = (0, import_react20.useRef)(null);
|
|
3211
|
-
const inputId = (0, import_react20.useRef)(`rf-dr-${Math.random().toString(36).substr(2, 9)}`).current;
|
|
3212
|
-
(0, import_react20.useEffect)(() => {
|
|
3213
|
-
const s2 = value?.start ? isoToDate2(value.start) : null;
|
|
3214
|
-
const e = value?.end ? isoToDate2(value.end) : null;
|
|
3215
|
-
setDraftStart(s2);
|
|
3216
|
-
setDraftEnd(e);
|
|
3217
|
-
setStartInputStr(s2 ? formatShort(s2) : "");
|
|
3218
|
-
setEndInputStr(e ? formatShort(e) : "");
|
|
3219
|
-
setActivePreset(detectPreset(s2, e));
|
|
3220
|
-
}, [value?.start, value?.end]);
|
|
3221
|
-
(0, import_react20.useEffect)(() => {
|
|
3222
|
-
setActivePreset(detectPreset(draftStart, draftEnd));
|
|
3223
|
-
}, [draftStart?.getTime(), draftEnd?.getTime()]);
|
|
3224
|
-
(0, import_react20.useEffect)(() => {
|
|
3225
|
-
if (!open) return;
|
|
3226
|
-
const handler = (e) => {
|
|
3227
|
-
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
3228
|
-
setOpen(false);
|
|
3229
|
-
setInlineCal(null);
|
|
3230
|
-
setDraftStart(committedStart);
|
|
3231
|
-
setDraftEnd(committedEnd);
|
|
3232
|
-
setStartInputStr(committedStart ? formatShort(committedStart) : "");
|
|
3233
|
-
setEndInputStr(committedEnd ? formatShort(committedEnd) : "");
|
|
3234
|
-
setActivePreset(detectPreset(committedStart, committedEnd));
|
|
3235
|
-
setSelecting("start");
|
|
3236
|
-
}
|
|
3237
|
-
};
|
|
3238
|
-
document.addEventListener("mousedown", handler);
|
|
3239
|
-
return () => document.removeEventListener("mousedown", handler);
|
|
3240
|
-
}, [open, committedStart, committedEnd]);
|
|
3241
|
-
const displayStr = (() => {
|
|
3242
|
-
if (committedStart && committedEnd) {
|
|
3243
|
-
return `${formatShort(committedStart)} \u2013 ${formatShort(committedEnd)}`;
|
|
3244
|
-
}
|
|
3245
|
-
if (committedStart) return `${formatShort(committedStart)} \u2013`;
|
|
3246
|
-
return "";
|
|
3247
|
-
})();
|
|
3248
|
-
const handleApply = () => {
|
|
3249
|
-
if (draftStart && draftEnd) {
|
|
3250
|
-
const [s2, e] = draftStart <= draftEnd ? [draftStart, draftEnd] : [draftEnd, draftStart];
|
|
3251
|
-
onChange?.({ start: dateToISO(s2), end: dateToISO(e) });
|
|
3252
|
-
} else if (draftStart) {
|
|
3253
|
-
onChange?.({ start: dateToISO(draftStart), end: dateToISO(draftStart) });
|
|
3254
|
-
}
|
|
3255
|
-
setOpen(false);
|
|
3256
|
-
setInlineCal(null);
|
|
3257
|
-
};
|
|
3258
|
-
const handleClose = () => {
|
|
3259
|
-
setOpen(false);
|
|
3260
|
-
setInlineCal(null);
|
|
3261
|
-
setDraftStart(committedStart);
|
|
3262
|
-
setDraftEnd(committedEnd);
|
|
3263
|
-
setStartInputStr(committedStart ? formatShort(committedStart) : "");
|
|
3264
|
-
setEndInputStr(committedEnd ? formatShort(committedEnd) : "");
|
|
3265
|
-
setActivePreset(detectPreset(committedStart, committedEnd));
|
|
3266
|
-
setSelecting("start");
|
|
3267
|
-
};
|
|
3268
|
-
const handlePreset = (presetId) => {
|
|
3269
|
-
const range = getPresetRange(presetId, draftStart);
|
|
3270
|
-
const s2 = isoToDate2(range.start);
|
|
3271
|
-
const e = isoToDate2(range.end);
|
|
3272
|
-
setDraftStart(s2);
|
|
3273
|
-
setDraftEnd(e);
|
|
3274
|
-
setStartInputStr(s2 ? formatShort(s2) : "");
|
|
3275
|
-
setEndInputStr(e ? formatShort(e) : "");
|
|
3276
|
-
setInlineCal(null);
|
|
3277
|
-
};
|
|
3278
|
-
const handleCalDayClick = (d) => {
|
|
3279
|
-
if (selecting === "start") {
|
|
3280
|
-
setDraftStart(d);
|
|
3281
|
-
setDraftEnd(null);
|
|
3282
|
-
setSelecting("end");
|
|
3283
|
-
setActivePreset(null);
|
|
3284
|
-
} else {
|
|
3285
|
-
if (draftStart && d < draftStart) {
|
|
3286
|
-
setDraftEnd(draftStart);
|
|
3287
|
-
setDraftStart(d);
|
|
3288
|
-
} else {
|
|
3289
|
-
setDraftEnd(d);
|
|
3290
|
-
}
|
|
3291
|
-
setSelecting("start");
|
|
3292
|
-
setActivePreset(detectPreset(draftStart, d));
|
|
3293
|
-
}
|
|
3294
|
-
};
|
|
3295
|
-
const rightViewMonth = leftViewMonth === 11 ? 0 : leftViewMonth + 1;
|
|
3296
|
-
const rightViewYear = leftViewMonth === 11 ? leftViewYear + 1 : leftViewYear;
|
|
3297
|
-
const prevMonth = () => {
|
|
3298
|
-
if (leftViewMonth === 0) {
|
|
3299
|
-
setLeftViewMonth(11);
|
|
3300
|
-
setLeftViewYear((y) => y - 1);
|
|
3301
|
-
} else setLeftViewMonth((m) => m - 1);
|
|
3302
|
-
};
|
|
3303
|
-
const nextMonth = () => {
|
|
3304
|
-
if (leftViewMonth === 11) {
|
|
3305
|
-
setLeftViewMonth(0);
|
|
3306
|
-
setLeftViewYear((y) => y + 1);
|
|
3307
|
-
} else setLeftViewMonth((m) => m + 1);
|
|
3308
|
-
};
|
|
3309
|
-
const daysUntilToday = draftStart ? Math.max(0, daysBetween(draftStart, today2)) : 0;
|
|
3310
|
-
const daysFromToday = draftEnd ? Math.max(0, daysBetween(today2, draftEnd)) : 0;
|
|
3311
|
-
const handleDaysUntilChange = (e) => {
|
|
3312
|
-
const n = parseInt(e.target.value, 10);
|
|
3313
|
-
if (!isNaN(n) && n >= 0) {
|
|
3314
|
-
const d = addDays(today2, -n);
|
|
3315
|
-
setDraftStart(d);
|
|
3316
|
-
setStartInputStr(formatShort(d));
|
|
3317
|
-
}
|
|
3318
|
-
};
|
|
3319
|
-
const handleDaysFromChange = (e) => {
|
|
3320
|
-
const n = parseInt(e.target.value, 10);
|
|
3321
|
-
if (!isNaN(n) && n >= 0) {
|
|
3322
|
-
const d = addDays(today2, n);
|
|
3323
|
-
setDraftEnd(d);
|
|
3324
|
-
setEndInputStr(formatShort(d));
|
|
3325
|
-
}
|
|
3326
|
-
};
|
|
3327
|
-
const handleStartInputChange = (e) => {
|
|
3328
|
-
const raw = e.target.value;
|
|
3329
|
-
setStartInputStr(raw);
|
|
3330
|
-
const parsed = parseInputDate(raw);
|
|
3331
|
-
if (parsed) setDraftStart(parsed);
|
|
3332
|
-
else if (!raw) setDraftStart(null);
|
|
3333
|
-
};
|
|
3334
|
-
const handleStartInputBlur = () => {
|
|
3335
|
-
setStartInputStr(draftStart ? formatShort(draftStart) : "");
|
|
3336
|
-
};
|
|
3337
|
-
const handleEndInputChange = (e) => {
|
|
3338
|
-
const raw = e.target.value;
|
|
3339
|
-
setEndInputStr(raw);
|
|
3340
|
-
const parsed = parseInputDate(raw);
|
|
3341
|
-
if (parsed) setDraftEnd(parsed);
|
|
3342
|
-
else if (!raw) setDraftEnd(null);
|
|
3343
|
-
};
|
|
3344
|
-
const handleEndInputBlur = () => {
|
|
3345
|
-
setEndInputStr(draftEnd ? formatShort(draftEnd) : "");
|
|
3346
|
-
};
|
|
3347
|
-
const isFloating = Boolean(displayStr || open);
|
|
3348
|
-
const rootClasses = [
|
|
3349
|
-
"rf-text-field",
|
|
3350
|
-
`rf-text-field--${variant}`,
|
|
3351
|
-
`rf-text-field--${size}`,
|
|
3352
|
-
`rf-text-field--${color}`,
|
|
3353
|
-
error ? "rf-text-field--error" : "",
|
|
3354
|
-
fullWidth ? "rf-text-field--full-width" : "",
|
|
3355
|
-
disabled ? "rf-text-field--disabled" : "",
|
|
3356
|
-
isFloating ? "rf-text-field--floating" : "",
|
|
3357
|
-
Boolean(label) ? "rf-text-field--has-label" : "",
|
|
3358
|
-
"rf-text-field--adorned-end",
|
|
3359
|
-
"rf-date-field",
|
|
3360
|
-
"rf-date-range-field",
|
|
3361
|
-
fullWidth ? "rf-date-field--full-width" : "",
|
|
3362
|
-
sxClass,
|
|
3363
|
-
className
|
|
3364
|
-
].filter(Boolean).join(" ");
|
|
3365
|
-
const inputPlaceholder = variant === "outlined" ? " " : void 0;
|
|
3366
|
-
return /* @__PURE__ */ import_react20.default.createElement("div", { ref: containerRef, className: rootClasses, style }, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-date-field__anchor" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
3367
|
-
"div",
|
|
3368
|
-
{
|
|
3369
|
-
className: "rf-text-field__wrapper",
|
|
3370
|
-
onClick: () => {
|
|
3371
|
-
if (!disabled) setOpen((o) => !o);
|
|
3372
|
-
},
|
|
3373
|
-
style: { cursor: disabled ? "default" : "pointer" }
|
|
3374
|
-
},
|
|
3375
|
-
/* @__PURE__ */ import_react20.default.createElement(
|
|
3376
|
-
"input",
|
|
3377
|
-
{
|
|
3378
|
-
id: inputId,
|
|
3379
|
-
className: "rf-text-field__input",
|
|
3380
|
-
type: "text",
|
|
3381
|
-
value: displayStr,
|
|
3382
|
-
readOnly: true,
|
|
3383
|
-
placeholder: inputPlaceholder,
|
|
3384
|
-
disabled,
|
|
3385
|
-
onClick: (e) => e.stopPropagation(),
|
|
3386
|
-
onFocus: () => {
|
|
3387
|
-
if (!disabled) setOpen(true);
|
|
3388
|
-
}
|
|
3389
|
-
}
|
|
3390
|
-
),
|
|
3391
|
-
/* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-text-field__adornment rf-text-field__adornment--end" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
3392
|
-
"button",
|
|
3393
|
-
{
|
|
3394
|
-
type: "button",
|
|
3395
|
-
className: "rf-date-field__icon-btn",
|
|
3396
|
-
tabIndex: -1,
|
|
3397
|
-
disabled,
|
|
3398
|
-
onClick: (e) => {
|
|
3399
|
-
e.stopPropagation();
|
|
3400
|
-
if (!disabled) setOpen((o) => !o);
|
|
3401
|
-
},
|
|
3402
|
-
"aria-label": "Pick date range"
|
|
3403
|
-
},
|
|
3404
|
-
/* @__PURE__ */ import_react20.default.createElement(CalendarIcon2, null)
|
|
3405
|
-
)),
|
|
3406
|
-
label && /* @__PURE__ */ import_react20.default.createElement("label", { htmlFor: inputId, className: "rf-text-field__label" }, label, " ", required && /* @__PURE__ */ import_react20.default.createElement("span", { className: "rf-text-field__asterisk" }, "*")),
|
|
3407
|
-
variant === "outlined" && /* @__PURE__ */ import_react20.default.createElement("fieldset", { className: "rf-text-field__notch" }, label ? /* @__PURE__ */ import_react20.default.createElement("legend", { className: "rf-text-field__legend" }, /* @__PURE__ */ import_react20.default.createElement("span", null, label, required ? " *" : "")) : /* @__PURE__ */ import_react20.default.createElement("legend", { className: "rf-text-field__legend--empty" }))
|
|
3408
|
-
), open && !disabled && (pickerType === "panel" ? (
|
|
3409
|
-
/* ── Panel Mode ── */
|
|
3410
|
-
/* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker rf-dr-picker--panel", onMouseDown: (e) => e.preventDefault() }, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__presets" }, PRESETS.map((p, i) => /* @__PURE__ */ import_react20.default.createElement(import_react20.default.Fragment, { key: p.id }, i > 0 && /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__preset-sep" }), /* @__PURE__ */ import_react20.default.createElement(
|
|
3411
|
-
"button",
|
|
3412
|
-
{
|
|
3413
|
-
type: "button",
|
|
3414
|
-
className: [
|
|
3415
|
-
"rf-dr-picker__preset-btn",
|
|
3416
|
-
activePreset === p.id ? "rf-dr-picker__preset-btn--active" : ""
|
|
3417
|
-
].filter(Boolean).join(" "),
|
|
3418
|
-
onClick: () => handlePreset(p.id)
|
|
3419
|
-
},
|
|
3420
|
-
p.label
|
|
3421
|
-
)))), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__manual" }, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__date-field-wrap" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
3422
|
-
"div",
|
|
3423
|
-
{
|
|
3424
|
-
className: [
|
|
3425
|
-
"rf-dr-picker__date-field",
|
|
3426
|
-
inlineCal === "start" ? "rf-dr-picker__date-field--active" : ""
|
|
3427
|
-
].filter(Boolean).join(" ")
|
|
3428
|
-
},
|
|
3429
|
-
/* @__PURE__ */ import_react20.default.createElement("span", { className: "rf-dr-picker__date-floating-label" }, "Start Date"),
|
|
3430
|
-
/* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__date-display" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
3431
|
-
"input",
|
|
3432
|
-
{
|
|
3433
|
-
type: "text",
|
|
3434
|
-
className: "rf-dr-picker__date-input",
|
|
3435
|
-
value: startInputStr,
|
|
3436
|
-
placeholder: "DD Mon YYYY",
|
|
3437
|
-
onChange: handleStartInputChange,
|
|
3438
|
-
onBlur: handleStartInputBlur,
|
|
3439
|
-
onMouseDown: (e) => e.stopPropagation()
|
|
3440
|
-
}
|
|
3441
|
-
), /* @__PURE__ */ import_react20.default.createElement(
|
|
3442
|
-
"button",
|
|
3443
|
-
{
|
|
3444
|
-
type: "button",
|
|
3445
|
-
className: "rf-dr-picker__cal-icon-btn",
|
|
3446
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3447
|
-
onClick: () => setInlineCal((v) => v === "start" ? null : "start"),
|
|
3448
|
-
"aria-label": "Pick start date"
|
|
3449
|
-
},
|
|
3450
|
-
/* @__PURE__ */ import_react20.default.createElement(CalendarIcon2, null)
|
|
3451
|
-
))
|
|
3452
|
-
), inlineCal === "start" && /* @__PURE__ */ import_react20.default.createElement(
|
|
3453
|
-
MiniCalendar,
|
|
3454
|
-
{
|
|
3455
|
-
selectedDate: draftStart,
|
|
3456
|
-
todayDate: today2,
|
|
3457
|
-
onSelect: (d) => {
|
|
3458
|
-
setDraftStart(d);
|
|
3459
|
-
setStartInputStr(formatShort(d));
|
|
3460
|
-
},
|
|
3461
|
-
onClose: () => setInlineCal(null)
|
|
3462
|
-
}
|
|
3463
|
-
)), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__date-field-wrap" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
3464
|
-
"div",
|
|
3465
|
-
{
|
|
3466
|
-
className: [
|
|
3467
|
-
"rf-dr-picker__date-field",
|
|
3468
|
-
inlineCal === "end" ? "rf-dr-picker__date-field--active" : ""
|
|
3469
|
-
].filter(Boolean).join(" ")
|
|
3470
|
-
},
|
|
3471
|
-
/* @__PURE__ */ import_react20.default.createElement("span", { className: "rf-dr-picker__date-floating-label" }, "End Date"),
|
|
3472
|
-
/* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__date-display" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
3473
|
-
"input",
|
|
3474
|
-
{
|
|
3475
|
-
type: "text",
|
|
3476
|
-
className: "rf-dr-picker__date-input",
|
|
3477
|
-
value: endInputStr,
|
|
3478
|
-
placeholder: "DD Mon YYYY",
|
|
3479
|
-
onChange: handleEndInputChange,
|
|
3480
|
-
onBlur: handleEndInputBlur,
|
|
3481
|
-
onMouseDown: (e) => e.stopPropagation()
|
|
3482
|
-
}
|
|
3483
|
-
), /* @__PURE__ */ import_react20.default.createElement(
|
|
3484
|
-
"button",
|
|
3485
|
-
{
|
|
3486
|
-
type: "button",
|
|
3487
|
-
className: "rf-dr-picker__cal-icon-btn",
|
|
3488
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3489
|
-
onClick: () => setInlineCal((v) => v === "end" ? null : "end"),
|
|
3490
|
-
"aria-label": "Pick end date"
|
|
3491
|
-
},
|
|
3492
|
-
/* @__PURE__ */ import_react20.default.createElement(CalendarIcon2, null)
|
|
3493
|
-
))
|
|
3494
|
-
), inlineCal === "end" && /* @__PURE__ */ import_react20.default.createElement(
|
|
3495
|
-
MiniCalendar,
|
|
3496
|
-
{
|
|
3497
|
-
selectedDate: draftEnd,
|
|
3498
|
-
todayDate: today2,
|
|
3499
|
-
onSelect: (d) => {
|
|
3500
|
-
setDraftEnd(d);
|
|
3501
|
-
setEndInputStr(formatShort(d));
|
|
3502
|
-
},
|
|
3503
|
-
onClose: () => setInlineCal(null)
|
|
3504
|
-
}
|
|
3505
|
-
)), !inlineCal && /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__days-section" }, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__days-row" }, /* @__PURE__ */ import_react20.default.createElement("span", { className: "rf-dr-picker__days-label" }, "Days until today"), /* @__PURE__ */ import_react20.default.createElement(
|
|
3506
|
-
"input",
|
|
3507
|
-
{
|
|
3508
|
-
type: "number",
|
|
3509
|
-
className: "rf-dr-picker__days-input",
|
|
3510
|
-
value: draftStart ? daysUntilToday : "",
|
|
3511
|
-
min: 0,
|
|
3512
|
-
onChange: handleDaysUntilChange,
|
|
3513
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3514
|
-
placeholder: "\u2014"
|
|
3515
|
-
}
|
|
3516
|
-
)), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__days-row" }, /* @__PURE__ */ import_react20.default.createElement("span", { className: "rf-dr-picker__days-label" }, "Days from today"), /* @__PURE__ */ import_react20.default.createElement(
|
|
3517
|
-
"input",
|
|
3518
|
-
{
|
|
3519
|
-
type: "number",
|
|
3520
|
-
className: "rf-dr-picker__days-input",
|
|
3521
|
-
value: draftEnd ? daysFromToday : "",
|
|
3522
|
-
min: 0,
|
|
3523
|
-
onChange: handleDaysFromChange,
|
|
3524
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3525
|
-
placeholder: "\u2014"
|
|
3526
|
-
}
|
|
3527
|
-
))), /* @__PURE__ */ import_react20.default.createElement("div", { style: { flex: 1 } }), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__footer" }, /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-dr-picker__close-btn", onClick: handleClose }, "CLOSE"), /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-dr-picker__apply-btn", onClick: handleApply }, "APPLY"))))
|
|
3528
|
-
) : (
|
|
3529
|
-
/* ── Calendar Mode ── */
|
|
3530
|
-
/* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker rf-dr-picker--calendar", onMouseDown: (e) => e.preventDefault() }, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__calendars" }, /* @__PURE__ */ import_react20.default.createElement(
|
|
3531
|
-
RangeCalendarBody,
|
|
3532
|
-
{
|
|
3533
|
-
viewYear: leftViewYear,
|
|
3534
|
-
viewMonth: leftViewMonth,
|
|
3535
|
-
startDate: draftStart,
|
|
3536
|
-
endDate: draftEnd,
|
|
3537
|
-
hoverDate: selecting === "end" ? hoverDate : null,
|
|
3538
|
-
todayDate: today2,
|
|
3539
|
-
onDayClick: handleCalDayClick,
|
|
3540
|
-
onDayHover: setHoverDate,
|
|
3541
|
-
onPrev: prevMonth,
|
|
3542
|
-
onNext: nextMonth,
|
|
3543
|
-
showNext: false
|
|
3544
|
-
}
|
|
3545
|
-
), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__cal-col-divider" }), /* @__PURE__ */ import_react20.default.createElement(
|
|
3546
|
-
RangeCalendarBody,
|
|
3547
|
-
{
|
|
3548
|
-
viewYear: rightViewYear,
|
|
3549
|
-
viewMonth: rightViewMonth,
|
|
3550
|
-
startDate: draftStart,
|
|
3551
|
-
endDate: draftEnd,
|
|
3552
|
-
hoverDate: selecting === "end" ? hoverDate : null,
|
|
3553
|
-
todayDate: today2,
|
|
3554
|
-
onDayClick: handleCalDayClick,
|
|
3555
|
-
onDayHover: setHoverDate,
|
|
3556
|
-
onPrev: prevMonth,
|
|
3557
|
-
onNext: nextMonth,
|
|
3558
|
-
showPrev: false
|
|
3559
|
-
}
|
|
3560
|
-
)), selecting === "end" && draftStart && /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__cal-hint" }, /* @__PURE__ */ import_react20.default.createElement("span", { className: "rf-dr-picker__cal-hint-dot" }), /* @__PURE__ */ import_react20.default.createElement("span", null, "Select end date \xB7 started from ", /* @__PURE__ */ import_react20.default.createElement("strong", null, formatShort(draftStart)))), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__divider" }), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-dr-picker__cal-footer" }, draftStart && draftEnd && /* @__PURE__ */ import_react20.default.createElement("span", { className: "rf-dr-picker__cal-range-label" }, formatShort(draftStart <= draftEnd ? draftStart : draftEnd), " \u2013 ", formatShort(draftStart <= draftEnd ? draftEnd : draftStart), /* @__PURE__ */ import_react20.default.createElement("span", { className: "rf-dr-picker__cal-range-days" }, " ", "(", Math.abs(daysBetween(draftStart, draftEnd)) + 1, " days)")), /* @__PURE__ */ import_react20.default.createElement("div", { style: { flex: 1 } }), /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-dr-picker__close-btn", onClick: handleClose }, "CLOSE"), /* @__PURE__ */ import_react20.default.createElement("button", { type: "button", className: "rf-dr-picker__apply-btn", onClick: handleApply }, "APPLY")))
|
|
3561
|
-
))), helperText && /* @__PURE__ */ import_react20.default.createElement("div", { className: "rf-text-field__helper-text" }, helperText));
|
|
3562
|
-
};
|
|
3563
|
-
DateRangeField.displayName = "DateRangeField";
|
|
3564
|
-
|
|
3565
|
-
// lib/TextFields/Autocomplete.tsx
|
|
3566
|
-
var import_react21 = __toESM(require("react"), 1);
|
|
3567
|
-
var import_react_dom3 = __toESM(require("react-dom"), 1);
|
|
3568
|
-
var ChevronDownIcon = () => /* @__PURE__ */ import_react21.default.createElement("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ import_react21.default.createElement("polyline", { points: "6 9 12 15 18 9" }));
|
|
3569
|
-
var CloseSmIcon = ({ size = 16 }) => /* @__PURE__ */ import_react21.default.createElement("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round" }, /* @__PURE__ */ import_react21.default.createElement("line", { x1: "18", y1: "6", x2: "6", y2: "18" }), /* @__PURE__ */ import_react21.default.createElement("line", { x1: "6", y1: "6", x2: "18", y2: "18" }));
|
|
3570
|
-
var CheckIcon = () => /* @__PURE__ */ import_react21.default.createElement("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ import_react21.default.createElement("polyline", { points: "20 6 9 17 4 12" }));
|
|
3571
|
-
function defaultGetLabel(option) {
|
|
3572
|
-
if (option === null || option === void 0) return "";
|
|
3573
|
-
if (typeof option === "string") return option;
|
|
3574
|
-
if (typeof option === "object" && "label" in option)
|
|
3575
|
-
return String(option.label);
|
|
3576
|
-
return String(option);
|
|
3577
|
-
}
|
|
3578
|
-
function defaultFilter(options, inputValue, getLabel) {
|
|
3579
|
-
if (!inputValue) return options;
|
|
3580
|
-
const q = inputValue.toLowerCase();
|
|
3581
|
-
return options.filter((o) => getLabel(o).toLowerCase().includes(q));
|
|
3582
|
-
}
|
|
3583
|
-
function AutocompleteInner(props, _ref) {
|
|
3584
|
-
const {
|
|
3585
|
-
options,
|
|
3586
|
-
value,
|
|
3587
|
-
onChange,
|
|
3588
|
-
inputValue: controlledInput,
|
|
3589
|
-
onInputChange,
|
|
3590
|
-
getOptionLabel = defaultGetLabel,
|
|
3591
|
-
isOptionEqualToValue,
|
|
3592
|
-
groupBy,
|
|
3593
|
-
filterOptions,
|
|
3594
|
-
renderOption,
|
|
3595
|
-
getOptionDisabled,
|
|
3596
|
-
multiple = false,
|
|
3597
|
-
freeSolo = false,
|
|
3598
|
-
clearable = true,
|
|
3599
|
-
loading = false,
|
|
3600
|
-
loadingText = "Loading\u2026",
|
|
3601
|
-
noOptionsText = "No options",
|
|
3602
|
-
limitTags,
|
|
3603
|
-
label,
|
|
3604
|
-
placeholder,
|
|
3605
|
-
variant = "outlined",
|
|
3606
|
-
size = "medium",
|
|
3607
|
-
error = false,
|
|
3608
|
-
helperText,
|
|
3609
|
-
fullWidth = false,
|
|
3610
|
-
disabled = false,
|
|
3611
|
-
required = false,
|
|
3612
|
-
className = "",
|
|
3613
|
-
style,
|
|
3614
|
-
sx,
|
|
3615
|
-
onOpen,
|
|
3616
|
-
onClose
|
|
3617
|
-
} = props;
|
|
3618
|
-
const [open, setOpen] = (0, import_react21.useState)(false);
|
|
3619
|
-
const [inputStr, setInputStr] = (0, import_react21.useState)("");
|
|
3620
|
-
const [focusedIdx, setFocusedIdx] = (0, import_react21.useState)(-1);
|
|
3621
|
-
const [popupStyle, setPopupStyle] = (0, import_react21.useState)({});
|
|
3622
|
-
const containerRef = (0, import_react21.useRef)(null);
|
|
3623
|
-
const inputRef = (0, import_react21.useRef)(null);
|
|
3624
|
-
const listRef = (0, import_react21.useRef)(null);
|
|
3625
|
-
const inputId = (0, import_react21.useRef)(`rf-ac-${Math.random().toString(36).slice(2, 9)}`).current;
|
|
3626
|
-
const sxClass = useSx(sx);
|
|
3627
|
-
const calcPopupStyle = (0, import_react21.useCallback)(() => {
|
|
3628
|
-
if (!containerRef.current) return;
|
|
3629
|
-
const rect = containerRef.current.getBoundingClientRect();
|
|
3630
|
-
setPopupStyle({
|
|
3631
|
-
top: rect.bottom + 4,
|
|
3632
|
-
left: rect.left,
|
|
3633
|
-
width: rect.width
|
|
3634
|
-
});
|
|
3635
|
-
}, []);
|
|
3636
|
-
const activeInput = controlledInput !== void 0 ? controlledInput : inputStr;
|
|
3637
|
-
const selectedValues = multiple ? Array.isArray(value) ? value : [] : value != null ? [value] : [];
|
|
3638
|
-
const isEqual = (0, import_react21.useCallback)(
|
|
3639
|
-
(a, b) => isOptionEqualToValue ? isOptionEqualToValue(a, b) : a === b,
|
|
3640
|
-
[isOptionEqualToValue]
|
|
3641
|
-
);
|
|
3642
|
-
const isSelected = (0, import_react21.useCallback)(
|
|
3643
|
-
(opt) => selectedValues.some((v) => isEqual(opt, v)),
|
|
3644
|
-
[selectedValues, isEqual]
|
|
3645
|
-
);
|
|
3646
|
-
const filtered = filterOptions ? filterOptions(options, activeInput) : defaultFilter(options, activeInput, getOptionLabel);
|
|
3647
|
-
const flatEntries = [];
|
|
3648
|
-
if (groupBy) {
|
|
3649
|
-
const groups = {};
|
|
3650
|
-
const order = [];
|
|
3651
|
-
filtered.forEach((opt) => {
|
|
3652
|
-
const g = groupBy(opt);
|
|
3653
|
-
if (!groups[g]) {
|
|
3654
|
-
groups[g] = [];
|
|
3655
|
-
order.push(g);
|
|
3656
|
-
}
|
|
3657
|
-
groups[g].push(opt);
|
|
3658
|
-
});
|
|
3659
|
-
order.forEach((g) => {
|
|
3660
|
-
flatEntries.push({ kind: "group", label: g });
|
|
3661
|
-
groups[g].forEach((opt) => {
|
|
3662
|
-
flatEntries.push({ kind: "option", option: opt, flatIdx: flatEntries.filter((e) => e.kind === "option").length });
|
|
3663
|
-
});
|
|
3664
|
-
});
|
|
3665
|
-
} else {
|
|
3666
|
-
filtered.forEach((opt, i) => flatEntries.push({ kind: "option", option: opt, flatIdx: i }));
|
|
3667
|
-
}
|
|
3668
|
-
const selectableOptions = flatEntries.filter((e) => e.kind === "option");
|
|
3669
|
-
const openPopup = (0, import_react21.useCallback)(() => {
|
|
3670
|
-
if (disabled) return;
|
|
3671
|
-
calcPopupStyle();
|
|
3672
|
-
setOpen(true);
|
|
3673
|
-
setFocusedIdx(-1);
|
|
3674
|
-
onOpen?.();
|
|
3675
|
-
}, [disabled, calcPopupStyle, onOpen]);
|
|
3676
|
-
const closePopup = (0, import_react21.useCallback)(() => {
|
|
3677
|
-
setOpen(false);
|
|
3678
|
-
setFocusedIdx(-1);
|
|
3679
|
-
onClose?.();
|
|
3680
|
-
if (!freeSolo && !multiple && value == null) {
|
|
3681
|
-
setInputStr("");
|
|
3682
|
-
onInputChange?.("");
|
|
3585
|
+
return /* @__PURE__ */ import_react21.default.createElement("div", { key: `e-${idx}`, className: "rf-dr-calendar__cell rf-dr-calendar__cell--empty" });
|
|
3683
3586
|
}
|
|
3684
|
-
|
|
3587
|
+
const cellDate = new Date(viewYear, viewMonth, day);
|
|
3588
|
+
const isSel = selectedDate ? isSameDay2(cellDate, selectedDate) : false;
|
|
3589
|
+
const isToday = isSameDay2(cellDate, todayDate);
|
|
3590
|
+
return /* @__PURE__ */ import_react21.default.createElement("div", { key: day, className: "rf-dr-calendar__cell" }, /* @__PURE__ */ import_react21.default.createElement(
|
|
3591
|
+
"button",
|
|
3592
|
+
{
|
|
3593
|
+
type: "button",
|
|
3594
|
+
className: [
|
|
3595
|
+
"rf-dr-calendar__day",
|
|
3596
|
+
isSel ? "rf-dr-calendar__day--selected" : "",
|
|
3597
|
+
isToday && !isSel ? "rf-dr-calendar__day--today" : ""
|
|
3598
|
+
].filter(Boolean).join(" "),
|
|
3599
|
+
onClick: () => {
|
|
3600
|
+
onSelect(cellDate);
|
|
3601
|
+
onClose();
|
|
3602
|
+
}
|
|
3603
|
+
},
|
|
3604
|
+
day
|
|
3605
|
+
));
|
|
3606
|
+
})));
|
|
3607
|
+
};
|
|
3608
|
+
var DateRangeField = ({
|
|
3609
|
+
label,
|
|
3610
|
+
value,
|
|
3611
|
+
onChange,
|
|
3612
|
+
pickerType = "panel",
|
|
3613
|
+
variant = "outlined",
|
|
3614
|
+
size = "medium",
|
|
3615
|
+
color = "primary",
|
|
3616
|
+
error = false,
|
|
3617
|
+
helperText,
|
|
3618
|
+
fullWidth = false,
|
|
3619
|
+
disabled = false,
|
|
3620
|
+
required = false,
|
|
3621
|
+
className = "",
|
|
3622
|
+
style,
|
|
3623
|
+
sx
|
|
3624
|
+
}) => {
|
|
3625
|
+
const sxClass = useSx(sx);
|
|
3626
|
+
const today2 = todayFn();
|
|
3627
|
+
const committedStart = value?.start ? isoToDate2(value.start) : null;
|
|
3628
|
+
const committedEnd = value?.end ? isoToDate2(value.end) : null;
|
|
3629
|
+
const [open, setOpen] = (0, import_react21.useState)(false);
|
|
3630
|
+
const [draftStart, setDraftStart] = (0, import_react21.useState)(committedStart);
|
|
3631
|
+
const [draftEnd, setDraftEnd] = (0, import_react21.useState)(committedEnd);
|
|
3632
|
+
const [activePreset, setActivePreset] = (0, import_react21.useState)(
|
|
3633
|
+
() => detectPreset(committedStart, committedEnd)
|
|
3634
|
+
);
|
|
3635
|
+
const [startInputStr, setStartInputStr] = (0, import_react21.useState)(() => committedStart ? formatShort(committedStart) : "");
|
|
3636
|
+
const [endInputStr, setEndInputStr] = (0, import_react21.useState)(() => committedEnd ? formatShort(committedEnd) : "");
|
|
3637
|
+
const [inlineCal, setInlineCal] = (0, import_react21.useState)(null);
|
|
3638
|
+
const [hoverDate, setHoverDate] = (0, import_react21.useState)(null);
|
|
3639
|
+
const [selecting, setSelecting] = (0, import_react21.useState)("start");
|
|
3640
|
+
const [leftViewYear, setLeftViewYear] = (0, import_react21.useState)(() => today2.getFullYear());
|
|
3641
|
+
const [leftViewMonth, setLeftViewMonth] = (0, import_react21.useState)(() => today2.getMonth());
|
|
3642
|
+
const containerRef = (0, import_react21.useRef)(null);
|
|
3643
|
+
const inputId = (0, import_react21.useRef)(`rf-dr-${Math.random().toString(36).substr(2, 9)}`).current;
|
|
3644
|
+
(0, import_react21.useEffect)(() => {
|
|
3645
|
+
const s2 = value?.start ? isoToDate2(value.start) : null;
|
|
3646
|
+
const e = value?.end ? isoToDate2(value.end) : null;
|
|
3647
|
+
setDraftStart(s2);
|
|
3648
|
+
setDraftEnd(e);
|
|
3649
|
+
setStartInputStr(s2 ? formatShort(s2) : "");
|
|
3650
|
+
setEndInputStr(e ? formatShort(e) : "");
|
|
3651
|
+
setActivePreset(detectPreset(s2, e));
|
|
3652
|
+
}, [value?.start, value?.end]);
|
|
3653
|
+
(0, import_react21.useEffect)(() => {
|
|
3654
|
+
setActivePreset(detectPreset(draftStart, draftEnd));
|
|
3655
|
+
}, [draftStart?.getTime(), draftEnd?.getTime()]);
|
|
3685
3656
|
(0, import_react21.useEffect)(() => {
|
|
3686
3657
|
if (!open) return;
|
|
3687
|
-
const
|
|
3658
|
+
const handler = (e) => {
|
|
3688
3659
|
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
3689
|
-
|
|
3660
|
+
setOpen(false);
|
|
3661
|
+
setInlineCal(null);
|
|
3662
|
+
setDraftStart(committedStart);
|
|
3663
|
+
setDraftEnd(committedEnd);
|
|
3664
|
+
setStartInputStr(committedStart ? formatShort(committedStart) : "");
|
|
3665
|
+
setEndInputStr(committedEnd ? formatShort(committedEnd) : "");
|
|
3666
|
+
setActivePreset(detectPreset(committedStart, committedEnd));
|
|
3667
|
+
setSelecting("start");
|
|
3690
3668
|
}
|
|
3691
3669
|
};
|
|
3692
|
-
document.addEventListener("mousedown",
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
window.removeEventListener("resize", calcPopupStyle);
|
|
3699
|
-
};
|
|
3700
|
-
}, [open, closePopup, calcPopupStyle]);
|
|
3701
|
-
(0, import_react21.useEffect)(() => {
|
|
3702
|
-
if (controlledInput !== void 0) return;
|
|
3703
|
-
if (!multiple) {
|
|
3704
|
-
const v = value;
|
|
3705
|
-
setInputStr(v != null ? getOptionLabel(v) : "");
|
|
3670
|
+
document.addEventListener("mousedown", handler);
|
|
3671
|
+
return () => document.removeEventListener("mousedown", handler);
|
|
3672
|
+
}, [open, committedStart, committedEnd]);
|
|
3673
|
+
const displayStr = (() => {
|
|
3674
|
+
if (committedStart && committedEnd) {
|
|
3675
|
+
return `${formatShort(committedStart)} \u2013 ${formatShort(committedEnd)}`;
|
|
3706
3676
|
}
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
const
|
|
3713
|
-
onChange?.(
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3677
|
+
if (committedStart) return `${formatShort(committedStart)} \u2013`;
|
|
3678
|
+
return "";
|
|
3679
|
+
})();
|
|
3680
|
+
const handleApply = () => {
|
|
3681
|
+
if (draftStart && draftEnd) {
|
|
3682
|
+
const [s2, e] = draftStart <= draftEnd ? [draftStart, draftEnd] : [draftEnd, draftStart];
|
|
3683
|
+
onChange?.({ start: dateToISO(s2), end: dateToISO(e) });
|
|
3684
|
+
} else if (draftStart) {
|
|
3685
|
+
onChange?.({ start: dateToISO(draftStart), end: dateToISO(draftStart) });
|
|
3686
|
+
}
|
|
3687
|
+
setOpen(false);
|
|
3688
|
+
setInlineCal(null);
|
|
3689
|
+
};
|
|
3690
|
+
const handleClose = () => {
|
|
3691
|
+
setOpen(false);
|
|
3692
|
+
setInlineCal(null);
|
|
3693
|
+
setDraftStart(committedStart);
|
|
3694
|
+
setDraftEnd(committedEnd);
|
|
3695
|
+
setStartInputStr(committedStart ? formatShort(committedStart) : "");
|
|
3696
|
+
setEndInputStr(committedEnd ? formatShort(committedEnd) : "");
|
|
3697
|
+
setActivePreset(detectPreset(committedStart, committedEnd));
|
|
3698
|
+
setSelecting("start");
|
|
3699
|
+
};
|
|
3700
|
+
const handlePreset = (presetId) => {
|
|
3701
|
+
const range = getPresetRange(presetId, draftStart);
|
|
3702
|
+
const s2 = isoToDate2(range.start);
|
|
3703
|
+
const e = isoToDate2(range.end);
|
|
3704
|
+
setDraftStart(s2);
|
|
3705
|
+
setDraftEnd(e);
|
|
3706
|
+
setStartInputStr(s2 ? formatShort(s2) : "");
|
|
3707
|
+
setEndInputStr(e ? formatShort(e) : "");
|
|
3708
|
+
setInlineCal(null);
|
|
3709
|
+
};
|
|
3710
|
+
const handleCalDayClick = (d) => {
|
|
3711
|
+
if (selecting === "start") {
|
|
3712
|
+
setDraftStart(d);
|
|
3713
|
+
setDraftEnd(null);
|
|
3714
|
+
setSelecting("end");
|
|
3715
|
+
setActivePreset(null);
|
|
3717
3716
|
} else {
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3717
|
+
if (draftStart && d < draftStart) {
|
|
3718
|
+
setDraftEnd(draftStart);
|
|
3719
|
+
setDraftStart(d);
|
|
3720
|
+
} else {
|
|
3721
|
+
setDraftEnd(d);
|
|
3722
|
+
}
|
|
3723
|
+
setSelecting("start");
|
|
3724
|
+
setActivePreset(detectPreset(draftStart, d));
|
|
3722
3725
|
}
|
|
3723
|
-
setFocusedIdx(-1);
|
|
3724
3726
|
};
|
|
3725
|
-
const
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3727
|
+
const rightViewMonth = leftViewMonth === 11 ? 0 : leftViewMonth + 1;
|
|
3728
|
+
const rightViewYear = leftViewMonth === 11 ? leftViewYear + 1 : leftViewYear;
|
|
3729
|
+
const prevMonth = () => {
|
|
3730
|
+
if (leftViewMonth === 0) {
|
|
3731
|
+
setLeftViewMonth(11);
|
|
3732
|
+
setLeftViewYear((y) => y - 1);
|
|
3733
|
+
} else setLeftViewMonth((m) => m - 1);
|
|
3731
3734
|
};
|
|
3732
|
-
const
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3735
|
+
const nextMonth = () => {
|
|
3736
|
+
if (leftViewMonth === 11) {
|
|
3737
|
+
setLeftViewMonth(0);
|
|
3738
|
+
setLeftViewYear((y) => y + 1);
|
|
3739
|
+
} else setLeftViewMonth((m) => m + 1);
|
|
3736
3740
|
};
|
|
3737
|
-
const
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
if (!
|
|
3741
|
+
const daysUntilToday = draftStart ? Math.max(0, daysBetween(draftStart, today2)) : 0;
|
|
3742
|
+
const daysFromToday = draftEnd ? Math.max(0, daysBetween(today2, draftEnd)) : 0;
|
|
3743
|
+
const handleDaysUntilChange = (e) => {
|
|
3744
|
+
const n = parseInt(e.target.value, 10);
|
|
3745
|
+
if (!isNaN(n) && n >= 0) {
|
|
3746
|
+
const d = addDays(today2, -n);
|
|
3747
|
+
setDraftStart(d);
|
|
3748
|
+
setStartInputStr(formatShort(d));
|
|
3749
|
+
}
|
|
3742
3750
|
};
|
|
3743
|
-
const
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
}
|
|
3750
|
-
setFocusedIdx((i) => {
|
|
3751
|
-
const next = (i + 1) % selectableOptions.length;
|
|
3752
|
-
scrollOptionIntoView(next);
|
|
3753
|
-
return next;
|
|
3754
|
-
});
|
|
3755
|
-
} else if (e.key === "ArrowUp") {
|
|
3756
|
-
e.preventDefault();
|
|
3757
|
-
if (!open) {
|
|
3758
|
-
openPopup();
|
|
3759
|
-
return;
|
|
3760
|
-
}
|
|
3761
|
-
setFocusedIdx((i) => {
|
|
3762
|
-
const next = (i - 1 + selectableOptions.length) % selectableOptions.length;
|
|
3763
|
-
scrollOptionIntoView(next);
|
|
3764
|
-
return next;
|
|
3765
|
-
});
|
|
3766
|
-
} else if (e.key === "Enter") {
|
|
3767
|
-
e.preventDefault();
|
|
3768
|
-
if (!open) {
|
|
3769
|
-
openPopup();
|
|
3770
|
-
return;
|
|
3771
|
-
}
|
|
3772
|
-
if (focusedIdx >= 0 && focusedIdx < selectableOptions.length) {
|
|
3773
|
-
selectOption(selectableOptions[focusedIdx].option);
|
|
3774
|
-
} else if (freeSolo && activeInput) {
|
|
3775
|
-
onChange?.(activeInput);
|
|
3776
|
-
if (!multiple) closePopup();
|
|
3777
|
-
}
|
|
3778
|
-
} else if (e.key === "Escape") {
|
|
3779
|
-
closePopup();
|
|
3780
|
-
} else if (e.key === "Backspace" && multiple && !activeInput && selectedValues.length > 0) {
|
|
3781
|
-
removeTag(selectedValues[selectedValues.length - 1], { stopPropagation: () => {
|
|
3782
|
-
} });
|
|
3751
|
+
const handleDaysFromChange = (e) => {
|
|
3752
|
+
const n = parseInt(e.target.value, 10);
|
|
3753
|
+
if (!isNaN(n) && n >= 0) {
|
|
3754
|
+
const d = addDays(today2, n);
|
|
3755
|
+
setDraftEnd(d);
|
|
3756
|
+
setEndInputStr(formatShort(d));
|
|
3783
3757
|
}
|
|
3784
3758
|
};
|
|
3785
|
-
const
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3759
|
+
const handleStartInputChange = (e) => {
|
|
3760
|
+
const raw = e.target.value;
|
|
3761
|
+
setStartInputStr(raw);
|
|
3762
|
+
const parsed = parseInputDate(raw);
|
|
3763
|
+
if (parsed) setDraftStart(parsed);
|
|
3764
|
+
else if (!raw) setDraftStart(null);
|
|
3765
|
+
};
|
|
3766
|
+
const handleStartInputBlur = () => {
|
|
3767
|
+
setStartInputStr(draftStart ? formatShort(draftStart) : "");
|
|
3768
|
+
};
|
|
3769
|
+
const handleEndInputChange = (e) => {
|
|
3770
|
+
const raw = e.target.value;
|
|
3771
|
+
setEndInputStr(raw);
|
|
3772
|
+
const parsed = parseInputDate(raw);
|
|
3773
|
+
if (parsed) setDraftEnd(parsed);
|
|
3774
|
+
else if (!raw) setDraftEnd(null);
|
|
3775
|
+
};
|
|
3776
|
+
const handleEndInputBlur = () => {
|
|
3777
|
+
setEndInputStr(draftEnd ? formatShort(draftEnd) : "");
|
|
3790
3778
|
};
|
|
3791
|
-
const
|
|
3792
|
-
const visibleTags = multiple && limitTags != null ? selectedValues.slice(0, limitTags) : selectedValues;
|
|
3793
|
-
const hiddenCount = multiple && limitTags != null ? Math.max(0, selectedValues.length - limitTags) : 0;
|
|
3794
|
-
const isFloating = Boolean(
|
|
3795
|
-
open || activeInput || (multiple ? selectedValues.length > 0 : value != null)
|
|
3796
|
-
);
|
|
3779
|
+
const isFloating = Boolean(displayStr || open);
|
|
3797
3780
|
const rootClasses = [
|
|
3798
3781
|
"rf-text-field",
|
|
3799
3782
|
`rf-text-field--${variant}`,
|
|
3800
3783
|
`rf-text-field--${size}`,
|
|
3801
|
-
|
|
3784
|
+
`rf-text-field--${color}`,
|
|
3802
3785
|
error ? "rf-text-field--error" : "",
|
|
3803
3786
|
fullWidth ? "rf-text-field--full-width" : "",
|
|
3804
3787
|
disabled ? "rf-text-field--disabled" : "",
|
|
3805
3788
|
isFloating ? "rf-text-field--floating" : "",
|
|
3806
|
-
label ? "rf-text-field--has-label" : "",
|
|
3789
|
+
Boolean(label) ? "rf-text-field--has-label" : "",
|
|
3807
3790
|
"rf-text-field--adorned-end",
|
|
3808
|
-
"rf-
|
|
3791
|
+
"rf-date-field",
|
|
3792
|
+
"rf-date-range-field",
|
|
3793
|
+
fullWidth ? "rf-date-field--full-width" : "",
|
|
3809
3794
|
sxClass,
|
|
3810
3795
|
className
|
|
3811
3796
|
].filter(Boolean).join(" ");
|
|
3812
|
-
const inputPlaceholder =
|
|
3813
|
-
return /* @__PURE__ */ import_react21.default.createElement("div", { ref: containerRef, className: rootClasses, style }, /* @__PURE__ */ import_react21.default.createElement(
|
|
3797
|
+
const inputPlaceholder = variant === "outlined" ? " " : void 0;
|
|
3798
|
+
return /* @__PURE__ */ import_react21.default.createElement("div", { ref: containerRef, className: rootClasses, style }, /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-date-field__anchor" }, /* @__PURE__ */ import_react21.default.createElement(
|
|
3814
3799
|
"div",
|
|
3815
3800
|
{
|
|
3816
3801
|
className: "rf-text-field__wrapper",
|
|
3817
3802
|
onClick: () => {
|
|
3818
|
-
if (!disabled)
|
|
3819
|
-
inputRef.current?.focus();
|
|
3820
|
-
if (!open) openPopup();
|
|
3821
|
-
}
|
|
3822
|
-
}
|
|
3823
|
-
},
|
|
3824
|
-
multiple && visibleTags.map((opt, i) => /* @__PURE__ */ import_react21.default.createElement("span", { key: i, className: "rf-autocomplete__tag" }, /* @__PURE__ */ import_react21.default.createElement("span", { style: { overflow: "hidden", textOverflow: "ellipsis" } }, getOptionLabel(opt)), /* @__PURE__ */ import_react21.default.createElement(
|
|
3825
|
-
"button",
|
|
3826
|
-
{
|
|
3827
|
-
type: "button",
|
|
3828
|
-
className: "rf-autocomplete__tag-delete",
|
|
3829
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
3830
|
-
onClick: (e) => removeTag(opt, e),
|
|
3831
|
-
tabIndex: -1
|
|
3803
|
+
if (!disabled) setOpen((o) => !o);
|
|
3832
3804
|
},
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
hiddenCount > 0 && /* @__PURE__ */ import_react21.default.createElement("span", { className: "rf-autocomplete__tag-more" }, "+", hiddenCount, " more"),
|
|
3805
|
+
style: { cursor: disabled ? "default" : "pointer" }
|
|
3806
|
+
},
|
|
3836
3807
|
/* @__PURE__ */ import_react21.default.createElement(
|
|
3837
3808
|
"input",
|
|
3838
3809
|
{
|
|
3839
|
-
ref: inputRef,
|
|
3840
3810
|
id: inputId,
|
|
3841
3811
|
className: "rf-text-field__input",
|
|
3842
3812
|
type: "text",
|
|
3843
|
-
value:
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
if (!open) openPopup();
|
|
3847
|
-
},
|
|
3848
|
-
onKeyDown: handleKeyDown,
|
|
3849
|
-
placeholder: !multiple || selectedValues.length === 0 ? inputPlaceholder : void 0,
|
|
3813
|
+
value: displayStr,
|
|
3814
|
+
readOnly: true,
|
|
3815
|
+
placeholder: inputPlaceholder,
|
|
3850
3816
|
disabled,
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
"aria-autocomplete": "list"
|
|
3817
|
+
onClick: (e) => e.stopPropagation(),
|
|
3818
|
+
onFocus: () => {
|
|
3819
|
+
if (!disabled) setOpen(true);
|
|
3820
|
+
}
|
|
3856
3821
|
}
|
|
3857
3822
|
),
|
|
3858
|
-
|
|
3859
|
-
variant === "outlined" && /* @__PURE__ */ import_react21.default.createElement("fieldset", { className: "rf-text-field__notch" }, label ? /* @__PURE__ */ import_react21.default.createElement("legend", { className: "rf-text-field__legend" }, /* @__PURE__ */ import_react21.default.createElement("span", null, label, required ? " *" : "")) : /* @__PURE__ */ import_react21.default.createElement("legend", { className: "rf-text-field__legend--empty" })),
|
|
3860
|
-
/* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-autocomplete__endgroup" }, hasClearable && /* @__PURE__ */ import_react21.default.createElement(
|
|
3823
|
+
/* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-text-field__adornment rf-text-field__adornment--end" }, /* @__PURE__ */ import_react21.default.createElement(
|
|
3861
3824
|
"button",
|
|
3862
3825
|
{
|
|
3863
3826
|
type: "button",
|
|
3864
|
-
className: "rf-
|
|
3865
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
3866
|
-
onClick: clearAll,
|
|
3827
|
+
className: "rf-date-field__icon-btn",
|
|
3867
3828
|
tabIndex: -1,
|
|
3868
|
-
|
|
3829
|
+
disabled,
|
|
3830
|
+
onClick: (e) => {
|
|
3831
|
+
e.stopPropagation();
|
|
3832
|
+
if (!disabled) setOpen((o) => !o);
|
|
3833
|
+
},
|
|
3834
|
+
"aria-label": "Pick date range"
|
|
3869
3835
|
},
|
|
3870
|
-
/* @__PURE__ */ import_react21.default.createElement(
|
|
3871
|
-
),
|
|
3836
|
+
/* @__PURE__ */ import_react21.default.createElement(CalendarIcon2, null)
|
|
3837
|
+
)),
|
|
3838
|
+
label && /* @__PURE__ */ import_react21.default.createElement("label", { htmlFor: inputId, className: "rf-text-field__label" }, label, " ", required && /* @__PURE__ */ import_react21.default.createElement("span", { className: "rf-text-field__asterisk" }, "*")),
|
|
3839
|
+
variant === "outlined" && /* @__PURE__ */ import_react21.default.createElement("fieldset", { className: "rf-text-field__notch" }, label ? /* @__PURE__ */ import_react21.default.createElement("legend", { className: "rf-text-field__legend" }, /* @__PURE__ */ import_react21.default.createElement("span", null, label, required ? " *" : "")) : /* @__PURE__ */ import_react21.default.createElement("legend", { className: "rf-text-field__legend--empty" }))
|
|
3840
|
+
), open && !disabled && (pickerType === "panel" ? (
|
|
3841
|
+
/* ── Panel Mode ── */
|
|
3842
|
+
/* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker rf-dr-picker--panel", onMouseDown: (e) => e.preventDefault() }, /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__presets" }, PRESETS.map((p, i) => /* @__PURE__ */ import_react21.default.createElement(import_react21.default.Fragment, { key: p.id }, i > 0 && /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__preset-sep" }), /* @__PURE__ */ import_react21.default.createElement(
|
|
3872
3843
|
"button",
|
|
3873
3844
|
{
|
|
3874
3845
|
type: "button",
|
|
3875
|
-
className:
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
tabIndex: -1,
|
|
3881
|
-
"aria-label": open ? "Close" : "Open"
|
|
3846
|
+
className: [
|
|
3847
|
+
"rf-dr-picker__preset-btn",
|
|
3848
|
+
activePreset === p.id ? "rf-dr-picker__preset-btn--active" : ""
|
|
3849
|
+
].filter(Boolean).join(" "),
|
|
3850
|
+
onClick: () => handlePreset(p.id)
|
|
3882
3851
|
},
|
|
3883
|
-
|
|
3884
|
-
))
|
|
3885
|
-
|
|
3886
|
-
/* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-autocomplete__popup", role: "presentation", style: popupStyle }, loading ? /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-autocomplete__loading" }, /* @__PURE__ */ import_react21.default.createElement("span", { className: "rf-ac-spinner" }), loadingText) : flatEntries.length === 0 ? /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-autocomplete__no-options" }, noOptionsText) : /* @__PURE__ */ import_react21.default.createElement("ul", { ref: listRef, className: "rf-autocomplete__listbox", role: "listbox" }, groupBy ? (
|
|
3887
|
-
// Grouped render
|
|
3888
|
-
(() => {
|
|
3889
|
-
const rendered = [];
|
|
3890
|
-
let groupItems = [];
|
|
3891
|
-
let currentGroup = "";
|
|
3892
|
-
flatEntries.forEach((entry, ei) => {
|
|
3893
|
-
if (entry.kind === "group") {
|
|
3894
|
-
if (groupItems.length > 0) {
|
|
3895
|
-
rendered.push(
|
|
3896
|
-
/* @__PURE__ */ import_react21.default.createElement("li", { key: `g-${currentGroup}`, role: "presentation" }, /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-autocomplete__group-header" }, currentGroup), /* @__PURE__ */ import_react21.default.createElement("ul", { className: "rf-autocomplete__group-items", role: "group" }, groupItems))
|
|
3897
|
-
);
|
|
3898
|
-
groupItems = [];
|
|
3899
|
-
}
|
|
3900
|
-
currentGroup = entry.label;
|
|
3901
|
-
} else {
|
|
3902
|
-
const { option, flatIdx } = entry;
|
|
3903
|
-
groupItems.push(renderOptionItem(option, flatIdx));
|
|
3904
|
-
}
|
|
3905
|
-
if (ei === flatEntries.length - 1 && groupItems.length > 0) {
|
|
3906
|
-
rendered.push(
|
|
3907
|
-
/* @__PURE__ */ import_react21.default.createElement("li", { key: `g-${currentGroup}`, role: "presentation" }, /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-autocomplete__group-header" }, currentGroup), /* @__PURE__ */ import_react21.default.createElement("ul", { className: "rf-autocomplete__group-items", role: "group" }, groupItems))
|
|
3908
|
-
);
|
|
3909
|
-
}
|
|
3910
|
-
});
|
|
3911
|
-
return rendered;
|
|
3912
|
-
})()
|
|
3913
|
-
) : selectableOptions.map(({ option, flatIdx }) => renderOptionItem(option, flatIdx)))),
|
|
3914
|
-
document.body
|
|
3915
|
-
));
|
|
3916
|
-
function renderOptionItem(option, flatIdx) {
|
|
3917
|
-
const selected = isSelected(option);
|
|
3918
|
-
const focused = focusedIdx === flatIdx;
|
|
3919
|
-
const optDisabled = getOptionDisabled?.(option) ?? false;
|
|
3920
|
-
const label2 = getOptionLabel(option);
|
|
3921
|
-
return /* @__PURE__ */ import_react21.default.createElement(
|
|
3922
|
-
"li",
|
|
3852
|
+
p.label
|
|
3853
|
+
)))), /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__manual" }, /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__date-field-wrap" }, /* @__PURE__ */ import_react21.default.createElement(
|
|
3854
|
+
"div",
|
|
3923
3855
|
{
|
|
3924
|
-
key: label2 + flatIdx,
|
|
3925
|
-
"data-idx": flatIdx,
|
|
3926
|
-
role: "option",
|
|
3927
|
-
"aria-selected": selected,
|
|
3928
|
-
"aria-disabled": optDisabled,
|
|
3929
3856
|
className: [
|
|
3930
|
-
"rf-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
optDisabled ? "rf-autocomplete__option--disabled" : ""
|
|
3934
|
-
].filter(Boolean).join(" "),
|
|
3935
|
-
onMouseEnter: () => setFocusedIdx(flatIdx),
|
|
3936
|
-
onMouseLeave: () => setFocusedIdx(-1),
|
|
3937
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
3938
|
-
onClick: () => selectOption(option)
|
|
3857
|
+
"rf-dr-picker__date-field",
|
|
3858
|
+
inlineCal === "start" ? "rf-dr-picker__date-field--active" : ""
|
|
3859
|
+
].filter(Boolean).join(" ")
|
|
3939
3860
|
},
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3861
|
+
/* @__PURE__ */ import_react21.default.createElement("span", { className: "rf-dr-picker__date-floating-label" }, "Start Date"),
|
|
3862
|
+
/* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__date-display" }, /* @__PURE__ */ import_react21.default.createElement(
|
|
3863
|
+
"input",
|
|
3864
|
+
{
|
|
3865
|
+
type: "text",
|
|
3866
|
+
className: "rf-dr-picker__date-input",
|
|
3867
|
+
value: startInputStr,
|
|
3868
|
+
placeholder: "DD Mon YYYY",
|
|
3869
|
+
onChange: handleStartInputChange,
|
|
3870
|
+
onBlur: handleStartInputBlur,
|
|
3871
|
+
onMouseDown: (e) => e.stopPropagation()
|
|
3872
|
+
}
|
|
3873
|
+
), /* @__PURE__ */ import_react21.default.createElement(
|
|
3874
|
+
"button",
|
|
3875
|
+
{
|
|
3876
|
+
type: "button",
|
|
3877
|
+
className: "rf-dr-picker__cal-icon-btn",
|
|
3878
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
3879
|
+
onClick: () => setInlineCal((v) => v === "start" ? null : "start"),
|
|
3880
|
+
"aria-label": "Pick start date"
|
|
3881
|
+
},
|
|
3882
|
+
/* @__PURE__ */ import_react21.default.createElement(CalendarIcon2, null)
|
|
3883
|
+
))
|
|
3884
|
+
), inlineCal === "start" && /* @__PURE__ */ import_react21.default.createElement(
|
|
3885
|
+
MiniCalendar,
|
|
3886
|
+
{
|
|
3887
|
+
selectedDate: draftStart,
|
|
3888
|
+
todayDate: today2,
|
|
3889
|
+
onSelect: (d) => {
|
|
3890
|
+
setDraftStart(d);
|
|
3891
|
+
setStartInputStr(formatShort(d));
|
|
3892
|
+
},
|
|
3893
|
+
onClose: () => setInlineCal(null)
|
|
3894
|
+
}
|
|
3895
|
+
)), /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__date-field-wrap" }, /* @__PURE__ */ import_react21.default.createElement(
|
|
3896
|
+
"div",
|
|
3897
|
+
{
|
|
3898
|
+
className: [
|
|
3899
|
+
"rf-dr-picker__date-field",
|
|
3900
|
+
inlineCal === "end" ? "rf-dr-picker__date-field--active" : ""
|
|
3901
|
+
].filter(Boolean).join(" ")
|
|
3902
|
+
},
|
|
3903
|
+
/* @__PURE__ */ import_react21.default.createElement("span", { className: "rf-dr-picker__date-floating-label" }, "End Date"),
|
|
3904
|
+
/* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__date-display" }, /* @__PURE__ */ import_react21.default.createElement(
|
|
3905
|
+
"input",
|
|
3906
|
+
{
|
|
3907
|
+
type: "text",
|
|
3908
|
+
className: "rf-dr-picker__date-input",
|
|
3909
|
+
value: endInputStr,
|
|
3910
|
+
placeholder: "DD Mon YYYY",
|
|
3911
|
+
onChange: handleEndInputChange,
|
|
3912
|
+
onBlur: handleEndInputBlur,
|
|
3913
|
+
onMouseDown: (e) => e.stopPropagation()
|
|
3914
|
+
}
|
|
3915
|
+
), /* @__PURE__ */ import_react21.default.createElement(
|
|
3916
|
+
"button",
|
|
3917
|
+
{
|
|
3918
|
+
type: "button",
|
|
3919
|
+
className: "rf-dr-picker__cal-icon-btn",
|
|
3920
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
3921
|
+
onClick: () => setInlineCal((v) => v === "end" ? null : "end"),
|
|
3922
|
+
"aria-label": "Pick end date"
|
|
3923
|
+
},
|
|
3924
|
+
/* @__PURE__ */ import_react21.default.createElement(CalendarIcon2, null)
|
|
3925
|
+
))
|
|
3926
|
+
), inlineCal === "end" && /* @__PURE__ */ import_react21.default.createElement(
|
|
3927
|
+
MiniCalendar,
|
|
3928
|
+
{
|
|
3929
|
+
selectedDate: draftEnd,
|
|
3930
|
+
todayDate: today2,
|
|
3931
|
+
onSelect: (d) => {
|
|
3932
|
+
setDraftEnd(d);
|
|
3933
|
+
setEndInputStr(formatShort(d));
|
|
3934
|
+
},
|
|
3935
|
+
onClose: () => setInlineCal(null)
|
|
3936
|
+
}
|
|
3937
|
+
)), !inlineCal && /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__days-section" }, /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__days-row" }, /* @__PURE__ */ import_react21.default.createElement("span", { className: "rf-dr-picker__days-label" }, "Days until today"), /* @__PURE__ */ import_react21.default.createElement(
|
|
3938
|
+
"input",
|
|
3939
|
+
{
|
|
3940
|
+
type: "number",
|
|
3941
|
+
className: "rf-dr-picker__days-input",
|
|
3942
|
+
value: draftStart ? daysUntilToday : "",
|
|
3943
|
+
min: 0,
|
|
3944
|
+
onChange: handleDaysUntilChange,
|
|
3945
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
3946
|
+
placeholder: "\u2014"
|
|
3947
|
+
}
|
|
3948
|
+
)), /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__days-row" }, /* @__PURE__ */ import_react21.default.createElement("span", { className: "rf-dr-picker__days-label" }, "Days from today"), /* @__PURE__ */ import_react21.default.createElement(
|
|
3949
|
+
"input",
|
|
3950
|
+
{
|
|
3951
|
+
type: "number",
|
|
3952
|
+
className: "rf-dr-picker__days-input",
|
|
3953
|
+
value: draftEnd ? daysFromToday : "",
|
|
3954
|
+
min: 0,
|
|
3955
|
+
onChange: handleDaysFromChange,
|
|
3956
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
3957
|
+
placeholder: "\u2014"
|
|
3958
|
+
}
|
|
3959
|
+
))), /* @__PURE__ */ import_react21.default.createElement("div", { style: { flex: 1 } }), /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__footer" }, /* @__PURE__ */ import_react21.default.createElement("button", { type: "button", className: "rf-dr-picker__close-btn", onClick: handleClose }, "CLOSE"), /* @__PURE__ */ import_react21.default.createElement("button", { type: "button", className: "rf-dr-picker__apply-btn", onClick: handleApply }, "APPLY"))))
|
|
3960
|
+
) : (
|
|
3961
|
+
/* ── Calendar Mode ── */
|
|
3962
|
+
/* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker rf-dr-picker--calendar", onMouseDown: (e) => e.preventDefault() }, /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__calendars" }, /* @__PURE__ */ import_react21.default.createElement(
|
|
3963
|
+
RangeCalendarBody,
|
|
3964
|
+
{
|
|
3965
|
+
viewYear: leftViewYear,
|
|
3966
|
+
viewMonth: leftViewMonth,
|
|
3967
|
+
startDate: draftStart,
|
|
3968
|
+
endDate: draftEnd,
|
|
3969
|
+
hoverDate: selecting === "end" ? hoverDate : null,
|
|
3970
|
+
todayDate: today2,
|
|
3971
|
+
onDayClick: handleCalDayClick,
|
|
3972
|
+
onDayHover: setHoverDate,
|
|
3973
|
+
onPrev: prevMonth,
|
|
3974
|
+
onNext: nextMonth,
|
|
3975
|
+
showNext: false
|
|
3976
|
+
}
|
|
3977
|
+
), /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__cal-col-divider" }), /* @__PURE__ */ import_react21.default.createElement(
|
|
3978
|
+
RangeCalendarBody,
|
|
3979
|
+
{
|
|
3980
|
+
viewYear: rightViewYear,
|
|
3981
|
+
viewMonth: rightViewMonth,
|
|
3982
|
+
startDate: draftStart,
|
|
3983
|
+
endDate: draftEnd,
|
|
3984
|
+
hoverDate: selecting === "end" ? hoverDate : null,
|
|
3985
|
+
todayDate: today2,
|
|
3986
|
+
onDayClick: handleCalDayClick,
|
|
3987
|
+
onDayHover: setHoverDate,
|
|
3988
|
+
onPrev: prevMonth,
|
|
3989
|
+
onNext: nextMonth,
|
|
3990
|
+
showPrev: false
|
|
3991
|
+
}
|
|
3992
|
+
)), selecting === "end" && draftStart && /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__cal-hint" }, /* @__PURE__ */ import_react21.default.createElement("span", { className: "rf-dr-picker__cal-hint-dot" }), /* @__PURE__ */ import_react21.default.createElement("span", null, "Select end date \xB7 started from ", /* @__PURE__ */ import_react21.default.createElement("strong", null, formatShort(draftStart)))), /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__divider" }), /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-dr-picker__cal-footer" }, draftStart && draftEnd && /* @__PURE__ */ import_react21.default.createElement("span", { className: "rf-dr-picker__cal-range-label" }, formatShort(draftStart <= draftEnd ? draftStart : draftEnd), " \u2013 ", formatShort(draftStart <= draftEnd ? draftEnd : draftStart), /* @__PURE__ */ import_react21.default.createElement("span", { className: "rf-dr-picker__cal-range-days" }, " ", "(", Math.abs(daysBetween(draftStart, draftEnd)) + 1, " days)")), /* @__PURE__ */ import_react21.default.createElement("div", { style: { flex: 1 } }), /* @__PURE__ */ import_react21.default.createElement("button", { type: "button", className: "rf-dr-picker__close-btn", onClick: handleClose }, "CLOSE"), /* @__PURE__ */ import_react21.default.createElement("button", { type: "button", className: "rf-dr-picker__apply-btn", onClick: handleApply }, "APPLY")))
|
|
3993
|
+
))), helperText && /* @__PURE__ */ import_react21.default.createElement("div", { className: "rf-text-field__helper-text" }, helperText));
|
|
3994
|
+
};
|
|
3995
|
+
DateRangeField.displayName = "DateRangeField";
|
|
3947
3996
|
|
|
3948
3997
|
// lib/Progress/RufousLogoLoader.tsx
|
|
3949
3998
|
var React73 = __toESM(require("react"), 1);
|