@superdispatch/dates 0.16.0-alpha.0 → 0.16.0-alpha.1

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.
@@ -16,10 +16,6 @@ var jsxRuntime = require('react/jsx-runtime');
16
16
  var iconsMaterial = require('@mui/icons-material');
17
17
  var js = require('@mdi/js');
18
18
  var hooks = require('@superdispatch/hooks');
19
- var core = require('@material-ui/core');
20
- var styles$1 = require('@material-ui/styles');
21
- var icons = require('@material-ui/icons');
22
- var lab = require('@material-ui/lab');
23
19
 
24
20
  function setDefaultTimeZone(offset) {
25
21
  if (offset === 'local') {
@@ -805,10 +801,6 @@ var CalendarQuickSelection = /*#__PURE__*/react.forwardRef((_ref2, ref) => {
805
801
  if (process.env.NODE_ENV !== "production") CalendarQuickSelection.displayName = "CalendarQuickSelection";
806
802
 
807
803
  var _excluded$1 = ["id", "api", "onClear", "onClick", "onClose", "onKeyDown", "disabled", "children", "enableClearable", "inputRef", "InputProps"];
808
- var {
809
- mergeRefs,
810
- useUID
811
- } = ui.v5;
812
804
  var BaseDatePicker = /*#__PURE__*/react.forwardRef((_ref, ref) => {
813
805
  var {
814
806
  id,
@@ -825,7 +817,7 @@ var BaseDatePicker = /*#__PURE__*/react.forwardRef((_ref, ref) => {
825
817
  } = _ref,
826
818
  textFieldProps = _objectWithoutProperties(_ref, _excluded$1);
827
819
 
828
- var uid = useUID(id);
820
+ var uid = ui.useUID(id);
829
821
  var labelID = "".concat(uid, "-label");
830
822
  var clearIconID = "".concat(uid, "-clear-icon");
831
823
  var inputRef = react.useRef(null);
@@ -867,9 +859,9 @@ var BaseDatePicker = /*#__PURE__*/react.forwardRef((_ref, ref) => {
867
859
  children: children
868
860
  }), /*#__PURE__*/jsxRuntime.jsx(material.TextField, _objectSpread(_objectSpread({}, textFieldProps), {}, {
869
861
  id: uid,
870
- ref: mergeRefs(ref, textFieldRef),
862
+ ref: ui.mergeRefs(ref, textFieldRef),
871
863
  disabled: disabled,
872
- inputRef: mergeRefs(inputRef, inputRefProp),
864
+ inputRef: ui.mergeRefs(inputRef, inputRefProp),
873
865
  onClick: event => {
874
866
  _onClick === null || _onClick === void 0 ? void 0 : _onClick(event);
875
867
 
@@ -1688,1750 +1680,42 @@ var TimeField = /*#__PURE__*/react.forwardRef((_ref2, ref) => {
1688
1680
  });
1689
1681
  if (process.env.NODE_ENV !== "production") TimeField.displayName = "TimeField";
1690
1682
 
1691
-
1692
-
1693
- var index = /*#__PURE__*/Object.freeze({
1694
- __proto__: null,
1695
- Calendar: Calendar,
1696
- CalendarQuickSelectionItem: CalendarQuickSelectionItem,
1697
- CalendarQuickSelection: CalendarQuickSelection,
1698
- setDefaultTimeZone: setDefaultTimeZone,
1699
- useDefaultTimeZone: useDefaultTimeZone,
1700
- defaultDateConfig: defaultDateConfig,
1701
- useDateConfig: useDateConfig,
1702
- DateConfigProvider: DateConfigProvider,
1703
- DateField: DateField,
1704
- DateRangeField: DateRangeField,
1705
- toPrimitiveDateInput: toPrimitiveDateInput,
1706
- parseDate: parseDate,
1707
- stringifyDate: stringifyDate,
1708
- formatDate: formatDate,
1709
- formatRelativeTime: formatRelativeTime,
1710
- toDatePayload: toDatePayload,
1711
- toPrimitiveDateRangeInput: toPrimitiveDateRangeInput,
1712
- parseDateRange: parseDateRange,
1713
- stringifyDateRange: stringifyDateRange,
1714
- formatDateRange: formatDateRange,
1715
- toDateRangePayload: toDateRangePayload,
1716
- isDate: isDate,
1717
- isDateLike: isDateLike,
1718
- isValidDate: isValidDate,
1719
- isDateRange: isDateRange,
1720
- isDateRangeLike: isDateRangeLike,
1721
- isValidDateRange: isValidDateRange,
1722
- toDate: toDate,
1723
- toDateRange: toDateRange,
1724
- DateUtils: DateUtils,
1725
- useDateUtils: useDateUtils,
1726
- useFormattedDate: useFormattedDate,
1727
- FormattedDate: FormattedDate,
1728
- useFormattedRelativeTime: useFormattedRelativeTime,
1729
- FormattedRelativeTime: FormattedRelativeTime,
1730
- TimeField: TimeField,
1731
- useDateTimeRange: useDateTimeRange,
1732
- useDateTime: useDateTime
1733
- });
1734
-
1735
- function setDefaultTimeZone$1(offset) {
1736
- if (offset === 'local') {
1737
- luxon.Settings.defaultZoneName = offset;
1738
- } else {
1739
- var zone = luxon.FixedOffsetZone.instance(offset);
1740
-
1741
- if (zone.isValid) {
1742
- luxon.Settings.defaultZoneName = zone.name;
1743
- }
1744
- }
1745
-
1746
- return luxon.Settings.defaultZoneName;
1747
- }
1748
- function useDefaultTimeZone$1(offset) {
1749
- return react.useMemo(() => setDefaultTimeZone$1(offset), [offset]);
1750
- }
1751
- var defaultDateConfig$1 = {
1752
- format: 'DateTimeISO'
1753
- };
1754
- var Context$1 = /*#__PURE__*/react.createContext(defaultDateConfig$1);
1755
- function useDateConfig$1() {
1756
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1757
- var config = react.useContext(Context$1);
1758
- var {
1759
- format = config.format
1760
- } = options;
1761
- return react.useMemo(() => ({
1762
- format
1763
- }), [format]);
1764
- }
1765
- function DateConfigProvider$1(_ref) {
1766
- var {
1767
- format,
1768
- children
1769
- } = _ref;
1770
- var prev = useDateConfig$1();
1771
- var ctx = react.useMemo(() => ({
1772
- format: format || prev.format
1773
- }), [format, prev.format]);
1774
- return /*#__PURE__*/jsxRuntime.jsx(Context$1.Provider, {
1775
- value: ctx,
1776
- children: children
1777
- });
1778
- }
1779
-
1780
- // Config
1781
- //
1782
-
1783
- var DATE_FORMATS$1 = {
1784
- DateISO: '',
1785
- DateTimeISO: '',
1786
- JodaISO: "yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"
1787
- };
1788
- var DATE_DISPLAY_VARIANTS$1 = {
1789
- Date: {
1790
- day: '2-digit',
1791
- month: 'short',
1792
- year: 'numeric'
1793
- },
1794
- ShortDate: {
1795
- day: '2-digit',
1796
- month: 'short'
1797
- },
1798
- Time: {
1799
- hour: 'numeric',
1800
- minute: 'numeric'
1801
- },
1802
- DateTime: {
1803
- day: '2-digit',
1804
- month: 'short',
1805
- year: 'numeric',
1806
- hour: 'numeric',
1807
- minute: 'numeric'
1808
- }
1809
- }; //
1810
- // Date Utils
1811
- //
1812
-
1813
- function toPrimitiveDateInput$1(input) {
1814
- if (typeof input == 'number' || typeof input == 'string') {
1815
- return input;
1816
- }
1817
-
1818
- if (input instanceof Date || input instanceof luxon.DateTime) {
1819
- return input.valueOf();
1820
- }
1821
-
1822
- return NaN;
1823
- }
1824
- function parseDate$1(input) {
1825
- var {
1826
- format
1827
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDateConfig$1;
1828
-
1829
- if (input instanceof luxon.DateTime) {
1830
- var {
1831
- defaultZone
1832
- } = luxon.Settings;
1833
-
1834
- if (!defaultZone.equals(input.zone)) {
1835
- return input.setZone(defaultZone);
1836
- }
1837
-
1838
- return input;
1839
- }
1840
-
1841
- if (input instanceof Date) {
1842
- return luxon.DateTime.fromJSDate(input);
1843
- }
1844
-
1845
- if (typeof input === 'number') {
1846
- return luxon.DateTime.fromMillis(input);
1847
- }
1848
-
1849
- if (typeof input == 'string') {
1850
- switch (format) {
1851
- case 'DateISO':
1852
- case 'DateTimeISO':
1853
- return luxon.DateTime.fromISO(input);
1854
-
1855
- default:
1856
- return luxon.DateTime.fromFormat(input, DATE_FORMATS$1[format]);
1857
- }
1858
- }
1859
-
1860
- return luxon.DateTime.invalid('invalid input');
1861
- }
1862
- function stringifyDate$1(input) {
1863
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDateConfig$1;
1864
- var date = parseDate$1(input, config);
1865
-
1866
- if (date.isValid) {
1867
- var {
1868
- format
1869
- } = config;
1870
-
1871
- switch (format) {
1872
- case 'DateISO':
1873
- return date.toISODate();
1874
-
1875
- case 'DateTimeISO':
1876
- return date.toISO();
1877
-
1878
- default:
1879
- return date.toFormat(DATE_FORMATS$1[format]);
1880
- }
1881
- }
1882
-
1883
- return null;
1884
- }
1885
- function formatDate$1(input, _ref) {
1886
- var {
1887
- variant,
1888
- fallback = 'Invalid Date'
1889
- } = _ref;
1890
- var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultDateConfig$1;
1891
- var date = parseDate$1(input, config);
1892
-
1893
- if (!date.isValid) {
1894
- return fallback;
1895
- }
1896
-
1897
- return date.toLocaleString(DATE_DISPLAY_VARIANTS$1[variant]);
1898
- }
1899
-
1900
- function formatUnit$1(unit) {
1901
- switch (unit) {
1902
- case 'months':
1903
- return 'mo';
1904
-
1905
- default:
1906
- return unit.charAt(0);
1907
- }
1908
- }
1909
-
1910
- function formatRelativeTime$1(input) {
1911
- var {
1912
- round = true,
1913
- unit: unitOption,
1914
- base: baseOption,
1915
- padding: paddingOption,
1916
- fallback = 'Invalid Date'
1917
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1918
- var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultDateConfig$1;
1919
- var base = baseOption == null ? luxon.DateTime.now() : parseDate$1(baseOption, config);
1920
- var date = parseDate$1(input, config);
1921
- var padding = paddingOption ? date < base ? -paddingOption : paddingOption : 0;
1922
-
1923
- function format(value, unit) {
1924
- var isPast = Object.is(value, -0) || value < 0;
1925
- var diff = Math.abs(!round ? value : Math.trunc(value));
1926
- var formattedUnit = formatUnit$1(unit);
1927
- return isPast ? "".concat(diff).concat(formattedUnit, " ago") : "in ".concat(diff).concat(formattedUnit);
1928
- }
1929
-
1930
- function differ(unit) {
1931
- return date.plus(padding).diff(base, unit).get(unit);
1932
- }
1933
-
1934
- if (date.isValid && base.isValid) {
1935
- var units = ['years', 'months', 'days', 'hours', 'minutes', 'seconds'];
1936
-
1937
- if (unitOption) {
1938
- return format(differ(unitOption), unitOption);
1939
- }
1940
-
1941
- for (var unit of units) {
1942
- var diff = differ(unit);
1943
-
1944
- if (Math.abs(diff) >= 1) {
1945
- return format(diff, unit);
1946
- }
1947
- }
1948
-
1949
- return format(0, 'seconds');
1950
- }
1951
-
1952
- return fallback;
1953
- }
1954
- function toDatePayload$1(input) {
1955
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDateConfig$1;
1956
- var dateValue = parseDate$1(input, config);
1957
- return {
1958
- config,
1959
- dateValue,
1960
- stringValue: stringifyDate$1(dateValue, config)
1961
- };
1962
- } //
1963
- // Date Range Utils
1964
- //
1965
-
1966
- function toPrimitiveDateRangeInput$1(input) {
1967
- if (!Array.isArray(input)) {
1968
- return [undefined, undefined];
1969
- }
1970
-
1971
- return [toPrimitiveDateInput$1(input[0]), toPrimitiveDateInput$1(input[1])];
1972
- }
1973
- function parseDateRange$1(input, config) {
1974
- var start = null;
1975
- var finish = null;
1976
-
1977
- if (Array.isArray(input)) {
1978
- [start = null, finish = null] = input.map(value => parseDate$1(value, config)).filter(date => date.isValid).sort((a, b) => a.valueOf() - b.valueOf());
1979
- }
1980
-
1981
- return [start, finish];
1982
- }
1983
- function stringifyDateRange$1(input, config) {
1984
- var [start, finish] = parseDateRange$1(input, config);
1985
- return [stringifyDate$1(start, config), stringifyDate$1(finish, config)];
1986
- }
1987
- function formatDateRange$1(input, _ref2) {
1988
- var {
1989
- fallback = 'Invalid Date Range'
1990
- } = _ref2;
1991
- var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultDateConfig$1;
1992
- var [start, finish] = parseDateRange$1(input, config);
1993
-
1994
- if (!start) {
1995
- return fallback;
1996
- }
1997
-
1998
- var startVariant = !(finish !== null && finish !== void 0 && finish.hasSame(start, 'year')) ? 'Date' : 'ShortDate';
1999
- var startText = formatDate$1(start, {
2000
- variant: startVariant
2001
- }, config);
2002
- var finishText = !finish ? '…' : formatDate$1(finish, {
2003
- variant: 'Date'
2004
- });
2005
- return "".concat(startText, " - ").concat(finishText);
2006
- }
2007
- function toDateRangePayload$1(input) {
2008
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDateConfig$1;
2009
- var dateValue = parseDateRange$1(input, config);
2010
- return {
2011
- config,
2012
- dateValue,
2013
- stringValue: stringifyDateRange$1(dateValue, config)
2014
- };
2015
- }
2016
-
2017
- function useDateTime$1(input, options) {
2018
- var config = useDateConfig$1(options);
2019
- var primitiveInput = toPrimitiveDateInput$1(input);
2020
- return react.useMemo(() => {
2021
- var date = parseDate$1(primitiveInput, config);
2022
-
2023
- if (process.env.NODE_ENV !== 'production') {
2024
- if (!date.isValid && typeof primitiveInput === 'string') {
2025
- // eslint-disable-next-line no-console
2026
- console.error("[useDateTime] Failed to parse \"".concat(primitiveInput, "\" string with \"").concat(config.format, "\" format."));
2027
- }
2028
- }
2029
-
2030
- return date;
2031
- }, [config, primitiveInput]);
2032
- }
2033
-
2034
- function CalendarCaption$1(_ref) {
2035
- var {
2036
- date,
2037
- localeUtils,
2038
- classNames,
2039
- onClick
2040
- } = _ref;
2041
- return /*#__PURE__*/jsxRuntime.jsx(core.Typography, {
2042
- variant: "h4",
2043
- onClick: onClick,
2044
- className: classNames.caption,
2045
- children: localeUtils.formatMonthTitle(date)
2046
- });
2047
- }
2048
- function CalendarNavbar$1(_ref2) {
2049
- var {
2050
- labels,
2051
- classNames,
2052
- onNextClick,
2053
- onPreviousClick,
2054
- showNextButton,
2055
- showPreviousButton
2056
- } = _ref2;
2057
- return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2058
- children: [/*#__PURE__*/jsxRuntime.jsx(core.IconButton, {
2059
- size: "small",
2060
- color: "primary",
2061
- disabled: !showPreviousButton,
2062
- onClick: () => {
2063
- onPreviousClick();
2064
- },
2065
- "aria-label": labels.previousMonth,
2066
- className: classNames.navButtonPrev,
2067
- children: /*#__PURE__*/jsxRuntime.jsx(icons.ChevronLeft, {
2068
- color: "action"
2069
- })
2070
- }), /*#__PURE__*/jsxRuntime.jsx(core.IconButton, {
2071
- size: "small",
2072
- color: "primary",
2073
- disabled: !showNextButton,
2074
- onClick: () => {
2075
- onNextClick();
2076
- },
2077
- "aria-label": labels.nextMonth,
2078
- className: classNames.navButtonNext,
2079
- children: /*#__PURE__*/jsxRuntime.jsx(icons.ChevronRight, {
2080
- color: "action"
2081
- })
2082
- })]
2083
- });
2084
- }
2085
- var SHORT_WEEKDAYS$1 = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
2086
- function CalendarWeekDay$1(_ref3) {
2087
- var {
2088
- weekday,
2089
- className,
2090
- localeUtils
2091
- } = _ref3;
2092
- return /*#__PURE__*/jsxRuntime.jsx(core.Typography, {
2093
- variant: "h5",
2094
- component: "abbr",
2095
- className: className,
2096
- title: localeUtils.formatWeekdayLong(weekday),
2097
- children: SHORT_WEEKDAYS$1[weekday]
2098
- });
2099
- }
2100
-
2101
- var _excluded$7 = ["footer", "classes", "direction", "quickSelection", "selectedDays", "disabledDays", "onDayClick", "onDayKeyDown", "onDayMouseEnter", "onDayMouseLeave", "onDayMouseDown", "onDayMouseUp", "onDayTouchEnd", "onDayTouchStart", "modifiers", "highlightedDays", "format", "initialTime", "initialMonth"];
2102
- var useStyles$2 = /*#__PURE__*/styles$1.makeStyles(theme => ({
2103
- container: {
2104
- display: 'inline-block'
2105
- },
2106
- wrapper: {
2107
- userSelect: 'none',
2108
- position: 'relative',
2109
- flexDirection: 'row',
2110
- paddingBottom: theme.spacing(2),
2111
- '&:focus': {
2112
- outline: 'none'
2113
- }
2114
- },
2115
- interactionDisabled: {},
2116
- navBar: {},
2117
- navButtonPrev: {
2118
- position: 'absolute',
2119
- top: theme.spacing(1.5),
2120
- left: theme.spacing(1.5)
2121
- },
2122
- navButtonNext: {
2123
- position: 'absolute',
2124
- top: theme.spacing(1.5),
2125
- right: theme.spacing(1.5)
2126
- },
2127
- navButtonInteractionDisabled: {},
2128
- months: {
2129
- display: 'flex',
2130
- flexWrap: 'wrap',
2131
- justifyContent: 'center'
2132
- },
2133
- month: {
2134
- userSelect: 'none',
2135
- margin: theme.spacing(2, 2, 0, 2)
2136
- },
2137
- caption: {
2138
- textAlign: 'center',
2139
- display: 'table-caption',
2140
- marginBottom: theme.spacing(1),
2141
- padding: theme.spacing(0, 1)
2142
- },
2143
- weekdays: {
2144
- display: 'table-header-group'
2145
- },
2146
- weekdaysRow: {
2147
- display: 'flex',
2148
- margin: theme.spacing(1, 0)
2149
- },
2150
- weekday: {
2151
- margin: '1px',
2152
- display: 'flex',
2153
- alignItems: 'center',
2154
- justifyContent: 'center',
2155
- textDecoration: 'none',
2156
- color: ui.Color.Dark300,
2157
- width: theme.spacing(5),
2158
- height: theme.spacing(5)
2159
- },
2160
- weekNumber: {},
2161
- body: {
2162
- display: 'flex',
2163
- flexDirection: 'column'
2164
- },
2165
- week: {
2166
- display: 'flex'
2167
- },
2168
- // Day modifiers.
2169
- today: {},
2170
- outside: {},
2171
- selected: {},
2172
- disabled: {},
2173
- firstDayOfMonth: {},
2174
- lastDayOfMonth: {},
2175
- blue: {},
2176
- green: {},
2177
- purple: {},
2178
- red: {},
2179
- teal: {},
2180
- yellow: {},
2181
- day: {
2182
- zIndex: 1,
2183
- margin: '1px',
2184
- width: theme.spacing(5),
2185
- height: theme.spacing(5),
2186
- borderRadius: theme.spacing(0.5),
2187
- position: 'relative',
2188
- display: 'flex',
2189
- alignItems: 'center',
2190
- justifyContent: 'center',
2191
- transition: theme.transitions.create(['color', 'background-color']),
2192
- '&:before': {
2193
- content: '""',
2194
- top: 0,
2195
- left: -1,
2196
- right: -1,
2197
- bottom: 0,
2198
- zIndex: -1,
2199
- position: 'absolute',
2200
- backgroundColor: ui.Color.Transparent,
2201
- transition: theme.transitions.create('background-color')
2202
- },
2203
- '&:first-child, &$firstDayOfMonth': {
2204
- '&:before': {
2205
- borderRadius: theme.spacing(0.5, 0, 0, 0.5)
2206
- }
2207
- },
2208
- '&:last-child, &$lastDayOfMonth': {
2209
- '&:before': {
2210
- borderRadius: theme.spacing(0, 0.5, 0.5, 0)
2211
- }
2212
- },
2213
- '&:after': {
2214
- content: '""',
2215
- borderRadius: theme.spacing(0.5),
2216
- top: 0,
2217
- left: 0,
2218
- right: 0,
2219
- bottom: 0,
2220
- zIndex: -1,
2221
- position: 'absolute',
2222
- backgroundColor: ui.Color.Transparent,
2223
- transition: theme.transitions.create('background-color')
2224
- },
2225
- '&:hover, &:focus': {
2226
- outline: 'none'
2227
- },
2228
- '&$disabled': {
2229
- color: ui.Color.Dark100,
2230
- '&$selected:not($outside):after': {
2231
- backgroundColor: ui.Color.Silver300
2232
- }
2233
- },
2234
- '&:not($outside):not($disabled)': {
2235
- cursor: 'pointer',
2236
- color: ui.Color.Dark500,
2237
- '&:not($selected):not(:active)': {
2238
- '&$today': {
2239
- color: ui.Color.Blue300
2240
- },
2241
- '&:hover, &:focus': {
2242
- backgroundColor: ui.Color.Silver100
2243
- },
2244
- '&$blue': {
2245
- color: ui.Color.Blue500,
2246
- '&': {
2247
- backgroundColor: ui.Color.Blue50
2248
- }
2249
- },
2250
- '&$green': {
2251
- color: ui.Color.Green500,
2252
- '&': {
2253
- backgroundColor: ui.Color.Green50
2254
- }
2255
- },
2256
- '&$purple': {
2257
- color: ui.Color.Purple500,
2258
- '&': {
2259
- backgroundColor: ui.Color.Purple50
2260
- }
2261
- },
2262
- '&$red': {
2263
- color: ui.Color.Red500,
2264
- '&': {
2265
- backgroundColor: ui.Color.Red50
2266
- }
2267
- },
2268
- '&$teal': {
2269
- color: ui.Color.Teal500,
2270
- '&': {
2271
- backgroundColor: ui.Color.Teal50
2272
- }
2273
- },
2274
- '&$yellow': {
2275
- color: ui.Color.Yellow500,
2276
- '&': {
2277
- backgroundColor: ui.Color.Yellow50
2278
- }
2279
- }
2280
- },
2281
- '&:active, &$selected': {
2282
- color: ui.Color.White,
2283
- '&:after': {
2284
- backgroundColor: ui.Color.Blue300
2285
- }
2286
- }
2287
- }
2288
- },
2289
- footer: {
2290
- padding: theme.spacing(2)
2291
- },
2292
- todayButton: {}
2293
- }), {
2294
- name: 'SD-Calendar'
2295
- }); //
2296
- // Utility Types
2297
- //
2298
- //
2299
- // Internal Utils
2300
- //
2301
-
2302
- function toDayPickerModifier$1(config, modifier) {
2303
- if (!modifier) {
2304
- return undefined;
2305
- }
2306
-
2307
- return localDate => {
2308
- var dateValue = luxon.DateTime.fromObject({
2309
- year: localDate.getFullYear(),
2310
- month: localDate.getMonth() + 1,
2311
- day: localDate.getDate(),
2312
- hour: localDate.getHours(),
2313
- minute: localDate.getMinutes(),
2314
- second: localDate.getSeconds(),
2315
- millisecond: localDate.getMilliseconds()
2316
- });
2317
- return modifier({
2318
- config,
2319
- dateValue,
2320
- stringValue: stringifyDate$1(dateValue, config)
2321
- });
2322
- };
2323
- }
2324
-
2325
- function toDayPickerHandler$1(config, classes, initialTime, handler) {
2326
- if (!handler) {
2327
- return undefined;
2328
- }
2329
-
2330
- return (localDate, modifiers) => {
2331
- var dateValue = luxon.DateTime.fromObject({
2332
- year: localDate.getFullYear(),
2333
- month: localDate.getMonth() + 1,
2334
- day: localDate.getDate(),
2335
- hour: initialTime.hour,
2336
- minute: initialTime.minute,
2337
- second: initialTime.second,
2338
- millisecond: initialTime.millisecond
2339
- });
2340
- handler({
2341
- disabled: !!modifiers[classes.disabled],
2342
- selected: !!modifiers[classes.selected],
2343
- config,
2344
- dateValue,
2345
- stringValue: stringifyDate$1(dateValue, config)
2346
- });
2347
- };
2348
- } //
2349
- // Calendar
2350
- //
2351
-
2352
-
2353
- var Calendar$1 = /*#__PURE__*/react.forwardRef((_ref, ref) => {
2354
- var {
2355
- footer,
2356
- classes,
2357
- direction,
2358
- quickSelection,
2359
- selectedDays,
2360
- disabledDays,
2361
- onDayClick,
2362
- onDayKeyDown,
2363
- onDayMouseEnter,
2364
- onDayMouseLeave,
2365
- onDayMouseDown,
2366
- onDayMouseUp,
2367
- onDayTouchEnd,
2368
- onDayTouchStart,
2369
- modifiers,
2370
- highlightedDays,
2371
- format: formatProp,
2372
- initialTime: initialTimeInputProp,
2373
- initialMonth: initialMonthInputProp
2374
- } = _ref,
2375
- dayPickerProps = _objectWithoutProperties(_ref, _excluded$7);
2376
-
2377
- var styles = useStyles$2({
2378
- classes
2379
- });
2380
- var config = useDateConfig$1({
2381
- format: formatProp
2382
- });
2383
- var initialTimeInput = useDateTime$1(initialTimeInputProp, config);
2384
- var initialMonthInput = useDateTime$1(initialMonthInputProp, config);
2385
- var [initialTime, initialMonth] = react.useMemo(() => {
2386
- var time = initialTimeInput;
2387
- var month = initialMonthInput;
2388
-
2389
- if (!month.isValid) {
2390
- month = luxon.DateTime.local().startOf('month');
2391
- }
2392
-
2393
- if (!time.isValid) {
2394
- time = month;
2395
- }
2396
-
2397
- return [time, new Date(month.year, month.month - 1, month.day, month.hour, month.minute, month.second, month.millisecond)];
2398
- }, [initialTimeInput, initialMonthInput]);
2399
- var wrapModifier = toDayPickerModifier$1.bind(null, config);
2400
- var wrapHandler = toDayPickerHandler$1.bind(null, config, styles, initialTime);
2401
- var dayPickerModifiers = {
2402
- [styles.firstDayOfMonth]: wrapModifier(_ref2 => {
2403
- var {
2404
- dateValue
2405
- } = _ref2;
2406
- return dateValue.day === 1;
2407
- }),
2408
- [styles.lastDayOfMonth]: wrapModifier(_ref3 => {
2409
- var {
2410
- dateValue
2411
- } = _ref3;
2412
- return dateValue.day === dateValue.daysInMonth;
2413
- })
2414
- };
2415
-
2416
- if (modifiers) {
2417
- for (var [key, modifier] of Object.entries(modifiers)) {
2418
- dayPickerModifiers[key] = wrapModifier(modifier);
2419
- }
2420
- }
2421
-
2422
- if (highlightedDays) {
2423
- for (var [_key, _modifier] of Object.entries(highlightedDays)) {
2424
- dayPickerModifiers[styles[_key]] = wrapModifier(_modifier);
2425
- }
2426
- }
2427
-
2428
- return /*#__PURE__*/jsxRuntime.jsxs(core.Grid, {
2429
- ref: ref,
2430
- container: true,
2431
- direction: direction,
2432
- children: [!!quickSelection && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2433
- children: [/*#__PURE__*/jsxRuntime.jsx(core.Grid, {
2434
- item: true,
2435
- xs: 12,
2436
- sm: "auto",
2437
- children: quickSelection
2438
- }), /*#__PURE__*/jsxRuntime.jsx(core.Hidden, {
2439
- xsDown: true,
2440
- children: /*#__PURE__*/jsxRuntime.jsx(core.Grid, {
2441
- item: true,
2442
- sm: "auto",
2443
- children: /*#__PURE__*/jsxRuntime.jsx(core.Divider, {
2444
- orientation: "vertical"
2445
- })
2446
- })
2447
- }), /*#__PURE__*/jsxRuntime.jsx(core.Hidden, {
2448
- smUp: true,
2449
- children: /*#__PURE__*/jsxRuntime.jsx(core.Grid, {
2450
- item: true,
2451
- xs: 12,
2452
- children: /*#__PURE__*/jsxRuntime.jsx(core.Divider, {
2453
- orientation: "horizontal"
2454
- })
2455
- })
2456
- })]
2457
- }), /*#__PURE__*/jsxRuntime.jsxs(core.Grid, {
2458
- item: true,
2459
- xs: 12,
2460
- sm: "auto",
2461
- children: [/*#__PURE__*/jsxRuntime.jsx(DayPicker, _objectSpread(_objectSpread({}, dayPickerProps), {}, {
2462
- classNames: styles,
2463
- navbarElement: CalendarNavbar$1,
2464
- captionElement: CalendarCaption$1,
2465
- weekdayElement: CalendarWeekDay$1,
2466
- initialMonth: initialMonth,
2467
- modifiers: dayPickerModifiers,
2468
- selectedDays: wrapModifier(selectedDays),
2469
- disabledDays: wrapModifier(disabledDays),
2470
- onDayClick: wrapHandler(onDayClick),
2471
- onDayKeyDown: wrapHandler(onDayKeyDown),
2472
- onDayMouseEnter: wrapHandler(onDayMouseEnter),
2473
- onDayMouseLeave: wrapHandler(onDayMouseLeave),
2474
- onDayMouseDown: wrapHandler(onDayMouseDown),
2475
- onDayMouseUp: wrapHandler(onDayMouseUp),
2476
- onDayTouchEnd: wrapHandler(onDayTouchEnd),
2477
- onDayTouchStart: wrapHandler(onDayTouchStart)
2478
- })), !!footer && /*#__PURE__*/jsxRuntime.jsx("div", {
2479
- className: styles.footer,
2480
- children: footer
2481
- })]
2482
- })]
2483
- });
2484
- });
2485
- if (process.env.NODE_ENV !== "production") Calendar$1.displayName = "Calendar";
2486
-
2487
- var CalendarQuickSelectionItem$1 = /*#__PURE__*/react.forwardRef((_ref, ref) => {
2488
- var {
2489
- onClick,
2490
- selected,
2491
- children
2492
- } = _ref;
2493
- return /*#__PURE__*/jsxRuntime.jsx(core.ListItem, {
2494
- ref: ref,
2495
- button: true,
2496
- selected: selected,
2497
- onClick: onClick,
2498
- children: children
2499
- });
2500
- });
2501
- if (process.env.NODE_ENV !== "production") CalendarQuickSelectionItem$1.displayName = "CalendarQuickSelectionItem";
2502
- var CalendarQuickSelection$1 = /*#__PURE__*/react.forwardRef((_ref2, ref) => {
2503
- var {
2504
- children
2505
- } = _ref2;
2506
- return /*#__PURE__*/jsxRuntime.jsxs(core.List, {
2507
- ref: ref,
2508
- children: [/*#__PURE__*/jsxRuntime.jsx(core.ListItem, {
2509
- children: /*#__PURE__*/jsxRuntime.jsx(core.Typography, {
2510
- variant: "h4",
2511
- children: "Quick Selection"
2512
- })
2513
- }), children]
2514
- });
2515
- });
2516
- if (process.env.NODE_ENV !== "production") CalendarQuickSelection$1.displayName = "CalendarQuickSelection";
2517
-
2518
- var _excluded$8 = ["id", "api", "onClear", "onClick", "onClose", "onKeyDown", "disabled", "children", "enableClearable", "inputRef", "InputProps"];
2519
- var BaseDatePicker$1 = /*#__PURE__*/react.forwardRef((_ref, ref) => {
2520
- var {
2521
- id,
2522
- api,
2523
- onClear,
2524
- onClick: _onClick,
2525
- onClose,
2526
- onKeyDown: _onKeyDown,
2527
- disabled,
2528
- children,
2529
- enableClearable,
2530
- inputRef: inputRefProp,
2531
- InputProps: inputProps
2532
- } = _ref,
2533
- textFieldProps = _objectWithoutProperties(_ref, _excluded$8);
2534
-
2535
- var uid = ui.useUID(id);
2536
- var labelID = "".concat(uid, "-label");
2537
- var clearIconID = "".concat(uid, "-clear-icon");
2538
- var inputRef = react.useRef(null);
2539
- var textFieldRef = react.useRef(null);
2540
- var [popoverAnchor, setPopoverAnchor] = react.useState(null);
2541
-
2542
- function handleOpen() {
2543
- if (!disabled && textFieldRef.current) {
2544
- setPopoverAnchor(textFieldRef.current);
2545
- }
2546
- }
2547
-
2548
- function handleClose() {
2549
- setPopoverAnchor(null);
2550
- }
2551
-
2552
- react.useImperativeHandle(api, () => ({
2553
- close: handleClose
2554
- })); // We want to trigger close event only when UI will be ready after updates.
2555
-
2556
- hooks.useValueObserver(popoverAnchor, () => {
2557
- if (!popoverAnchor) {
2558
- onClose === null || onClose === void 0 ? void 0 : onClose();
2559
- }
2560
- });
2561
- return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2562
- children: [/*#__PURE__*/jsxRuntime.jsx(core.Popover, {
2563
- open: !!popoverAnchor,
2564
- onClose: handleClose,
2565
- anchorEl: popoverAnchor,
2566
- anchorOrigin: {
2567
- vertical: 'bottom',
2568
- horizontal: 'left'
2569
- },
2570
- transformOrigin: {
2571
- vertical: 'top',
2572
- horizontal: 'left'
2573
- },
2574
- children: children
2575
- }), /*#__PURE__*/jsxRuntime.jsx(core.TextField, _objectSpread(_objectSpread({}, textFieldProps), {}, {
2576
- id: uid,
2577
- ref: ui.mergeRefs(ref, textFieldRef),
2578
- disabled: disabled,
2579
- inputRef: ui.mergeRefs(inputRef, inputRefProp),
2580
- onClick: event => {
2581
- _onClick === null || _onClick === void 0 ? void 0 : _onClick(event);
2582
-
2583
- if (!event.defaultPrevented) {
2584
- handleOpen();
2585
- }
2586
- },
2587
- onKeyDown: event => {
2588
- _onKeyDown === null || _onKeyDown === void 0 ? void 0 : _onKeyDown(event);
2589
-
2590
- if (!event.defaultPrevented && (event.key === ' ' || event.key === 'Enter')) {
2591
- handleOpen();
2592
- }
2593
- },
2594
- inputProps: {
2595
- readOnly: true
2596
- },
2597
- InputProps: _objectSpread(_objectSpread({}, inputProps), {}, {
2598
- endAdornment: /*#__PURE__*/jsxRuntime.jsx(core.InputAdornment, {
2599
- position: "end",
2600
- children: enableClearable ? /*#__PURE__*/jsxRuntime.jsx(core.IconButton, {
2601
- disabled: disabled,
2602
- "aria-labelledby": "".concat(clearIconID, " ").concat(labelID),
2603
- onClick: event => {
2604
- // Do not bubble up clicks.
2605
- event.stopPropagation();
2606
- onClear === null || onClear === void 0 ? void 0 : onClear();
2607
- },
2608
- children: /*#__PURE__*/jsxRuntime.jsx(icons.Clear, {
2609
- id: clearIconID,
2610
- "aria-label": "clear"
2611
- })
2612
- }) : /*#__PURE__*/jsxRuntime.jsx(core.IconButton, {
2613
- disabled: disabled,
2614
- children: /*#__PURE__*/jsxRuntime.jsx(core.SvgIcon, {
2615
- children: /*#__PURE__*/jsxRuntime.jsx("path", {
2616
- d: js.mdiCalendarMonth
2617
- })
2618
- })
2619
- })
2620
- })
2621
- })
2622
- }))]
2623
- });
2624
- });
2625
- if (process.env.NODE_ENV !== "production") BaseDatePicker$1.displayName = "BaseDatePicker";
2626
-
2627
- var _excluded$9 = ["variant", "fallback"],
2628
- _excluded2$4 = ["date", "fallback"];
2629
- function useFormattedDate$1(input, _ref) {
2630
- var {
2631
- variant,
2632
- fallback
2633
- } = _ref,
2634
- dateConfig = _objectWithoutProperties(_ref, _excluded$9);
2635
-
2636
- var config = useDateConfig$1(dateConfig);
2637
- var date = useDateTime$1(input, config);
2638
- return react.useMemo(() => formatDate$1(date, {
2639
- variant,
2640
- fallback
2641
- }, config), [date, config, variant, fallback]);
2642
- }
2643
- function FormattedDate$1(_ref2) {
2644
- var {
2645
- date,
2646
- fallback = 'Invalid Date'
2647
- } = _ref2,
2648
- options = _objectWithoutProperties(_ref2, _excluded2$4);
2649
-
2650
- var formatted = useFormattedDate$1(date, _objectSpread(_objectSpread({}, options), {}, {
2651
- fallback: ''
2652
- }));
2653
- return ui.renderChildren(formatted || fallback);
2654
- }
2655
-
2656
- var _excluded$a = ["onDayClick"],
2657
- _excluded2$5 = ["onBlur", "onFocus", "onChange", "renderFooter", "renderQuickSelection", "value", "format", "fallback", "variant", "enableClearable", "disableCloseOnSelect", "CalendarProps"];
2658
- var DateField$1 = /*#__PURE__*/react.forwardRef((_ref, ref) => {
2659
- var {
2660
- onBlur,
2661
- onFocus,
2662
- onChange,
2663
- renderFooter,
2664
- renderQuickSelection,
2665
- value: valueProp,
2666
- format: formatProp,
2667
- fallback = '',
2668
- variant = 'Date',
2669
- enableClearable,
2670
- disableCloseOnSelect,
2671
- CalendarProps: {
2672
- onDayClick: _onDayClick
2673
- } = {}
2674
- } = _ref,
2675
- calendarProps = _objectWithoutProperties(_ref.CalendarProps, _excluded$a),
2676
- textFieldProps = _objectWithoutProperties(_ref, _excluded2$5);
2677
-
2678
- var config = useDateConfig$1({
2679
- format: formatProp
2680
- });
2681
- var apiRef = react.useRef(null);
2682
- var date = useDateTime$1(valueProp, config);
2683
- var displayValue = useFormattedDate$1(date, _objectSpread({
2684
- variant,
2685
- fallback
2686
- }, config));
2687
- var dateString = react.useMemo(() => stringifyDate$1(date, config), [date, config]);
2688
-
2689
- function handleClose() {
2690
- var _apiRef$current;
2691
-
2692
- (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.close();
2693
- }
2694
-
2695
- function handleChange(nextInput) {
2696
- if (onChange) {
2697
- onChange(toDatePayload$1(nextInput, config));
2698
- }
2699
-
2700
- if (!disableCloseOnSelect) {
2701
- handleClose();
2702
- }
2703
- }
2704
-
2705
- var api = {
2706
- config,
2707
- dateValue: date,
2708
- stringValue: dateString,
2709
- close: handleClose,
2710
- change: handleChange
2711
- };
2712
- return /*#__PURE__*/jsxRuntime.jsx(BaseDatePicker$1, _objectSpread(_objectSpread({}, textFieldProps), {}, {
2713
- ref: ref,
2714
- api: apiRef,
2715
- onClose: onBlur,
2716
- value: displayValue || fallback,
2717
- enableClearable: enableClearable && date.isValid,
2718
- onClear: () => {
2719
- handleChange(undefined);
2720
- },
2721
- children: /*#__PURE__*/jsxRuntime.jsx(Calendar$1, _objectSpread(_objectSpread({}, calendarProps), {}, {
2722
- initialMonth: date,
2723
- footer: renderFooter === null || renderFooter === void 0 ? void 0 : renderFooter(api),
2724
- quickSelection: renderQuickSelection === null || renderQuickSelection === void 0 ? void 0 : renderQuickSelection(api),
2725
- selectedDays: _ref2 => {
2726
- var {
2727
- dateValue
2728
- } = _ref2;
2729
- return date.hasSame(dateValue, 'day');
2730
- },
2731
- onDayClick: event => {
2732
- _onDayClick === null || _onDayClick === void 0 ? void 0 : _onDayClick(event);
2733
-
2734
- if (!event.disabled) {
2735
- handleChange(event.dateValue);
2736
- }
2737
- }
2738
- }))
2739
- }));
2740
- });
2741
- if (process.env.NODE_ENV !== "production") DateField$1.displayName = "DateField";
2742
-
2743
- function useDateTimeRange$1(input, options) {
2744
- var config = useDateConfig$1(options);
2745
- var [startInput, finishInput] = toPrimitiveDateRangeInput$1(input);
2746
- var startDate = useDateTime$1(startInput, config);
2747
- var finishDate = useDateTime$1(finishInput, config);
2748
- return react.useMemo(() => parseDateRange$1([startDate, finishDate], config), [config, startDate, finishDate]);
2749
- }
2750
-
2751
- var _excluded$b = ["modifiers", "onDayClick", "onDayMouseEnter"],
2752
- _excluded2$6 = ["onBlur", "onFocus", "onChange", "renderFooter", "renderQuickSelection", "value", "format", "fallback", "enableClearable", "disableCloseOnSelect", "CalendarProps"],
2753
- _excluded3$1 = ["rangeStart", "rangeFinish"];
2754
- var useStyles$3 = /*#__PURE__*/styles$1.makeStyles(theme => ({
2755
- rangeStart: {},
2756
- rangeFinish: {},
2757
- outside: {},
2758
- disabled: {},
2759
- selected: {},
2760
- day: {
2761
- '&$selected:not($outside)': {
2762
- '&$rangeStart:before': {
2763
- left: theme.spacing(0.5)
2764
- },
2765
- '&$rangeFinish:before': {
2766
- right: theme.spacing(0.5)
2767
- },
2768
- '&:not($rangeStart):not($rangeFinish)': {
2769
- '&:after': {
2770
- backgroundColor: ui.Color.Transparent
2771
- },
2772
- '&$disabled': {
2773
- '&:before': {
2774
- backgroundColor: ui.Color.Silver100
2775
- }
2776
- },
2777
- '&:not($disabled)': {
2778
- color: ui.Color.Blue500,
2779
- '&:before': {
2780
- backgroundColor: ui.Color.Blue50
2781
- }
2782
- }
2783
- }
2784
- }
2785
- }
2786
- }), {
2787
- name: 'SD-DateRangeField'
2788
- });
2789
- var DateRangeField$1 = /*#__PURE__*/react.forwardRef((_ref, ref) => {
2790
- var {
2791
- onBlur,
2792
- onFocus,
2793
- onChange,
2794
- renderFooter,
2795
- renderQuickSelection,
2796
- value: valueProp,
2797
- format: formatProp,
2798
- fallback = '',
2799
- enableClearable,
2800
- disableCloseOnSelect,
2801
- CalendarProps: {
2802
- modifiers,
2803
- onDayClick: _onDayClick,
2804
- onDayMouseEnter: _onDayMouseEnter
2805
- } = {}
2806
- } = _ref,
2807
- calendarProps = _objectWithoutProperties(_ref.CalendarProps, _excluded$b),
2808
- textFieldProps = _objectWithoutProperties(_ref, _excluded2$6);
2809
-
2810
- var apiRef = react.useRef(null);
2811
-
2812
- var _useStyles = useStyles$3({}),
2813
- {
2814
- rangeStart,
2815
- rangeFinish
2816
- } = _useStyles,
2817
- styles = _objectWithoutProperties(_useStyles, _excluded3$1);
2818
-
2819
- var config = useDateConfig$1({
2820
- format: formatProp
2821
- });
2822
- var [startDate, finishDate] = useDateTimeRange$1(valueProp, config);
2823
- var [startDateString, finishDateString] = react.useMemo(() => stringifyDateRange$1([startDate, finishDate], config), [config, startDate, finishDate]);
2824
- var displayValue = react.useMemo(() => formatDateRange$1([startDate, finishDate], {
2825
- fallback
2826
- }, config), [config, fallback, startDate, finishDate]);
2827
- var [hoveredDate, setHoveredDate] = react.useState();
2828
- var [calendarStartDate, calendarFinishDate] = react.useMemo(() => {
2829
- var [nextCalendarStartDate, nextCalendarFinishDate] = parseDateRange$1([startDate, finishDate || hoveredDate], config);
2830
- return [nextCalendarStartDate === null || nextCalendarStartDate === void 0 ? void 0 : nextCalendarStartDate.startOf('day'), nextCalendarFinishDate === null || nextCalendarFinishDate === void 0 ? void 0 : nextCalendarFinishDate.endOf('day')];
2831
- }, [config, startDate, finishDate, hoveredDate]);
2832
-
2833
- function handleClose() {
2834
- var _apiRef$current;
2835
-
2836
- (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.close();
2837
- }
2838
-
2839
- function handleChange(nextValue) {
2840
- var _nextFinishDate;
2841
-
2842
- var [nextStartDate, nextFinishDate] = parseDateRange$1(nextValue, config);
2843
-
2844
- if (onChange) {
2845
- if (nextStartDate) {
2846
- if (startDate) {
2847
- nextStartDate = nextStartDate.set({
2848
- hour: startDate.hour,
2849
- minute: startDate.minute,
2850
- second: startDate.second,
2851
- millisecond: startDate.millisecond
2852
- });
2853
- } else {
2854
- nextStartDate = nextStartDate.startOf('day');
2855
- }
2856
- }
2857
-
2858
- if (nextFinishDate) {
2859
- nextFinishDate = nextFinishDate.endOf('day');
2860
- }
2861
-
2862
- onChange(toDateRangePayload$1([nextStartDate, nextFinishDate], config));
2863
- }
2864
-
2865
- if (!disableCloseOnSelect && (_nextFinishDate = nextFinishDate) !== null && _nextFinishDate !== void 0 && _nextFinishDate.isValid) {
2866
- handleClose();
2867
- }
2868
- }
2869
-
2870
- var api = {
2871
- config,
2872
- close: handleClose,
2873
- change: handleChange,
2874
- dateValue: [startDate, finishDate],
2875
- stringValue: [startDateString, finishDateString]
2876
- };
2877
- return /*#__PURE__*/jsxRuntime.jsx(BaseDatePicker$1, _objectSpread(_objectSpread({}, textFieldProps), {}, {
2878
- ref: ref,
2879
- api: apiRef,
2880
- value: displayValue || fallback,
2881
- enableClearable: enableClearable && !!startDate && !!finishDate,
2882
- onClear: () => {
2883
- handleChange([undefined, undefined]);
2884
- },
2885
- onClose: () => {
2886
- onBlur === null || onBlur === void 0 ? void 0 : onBlur();
2887
- setHoveredDate(undefined);
2888
- },
2889
- children: /*#__PURE__*/jsxRuntime.jsx(Calendar$1, _objectSpread(_objectSpread({
2890
- numberOfMonths: 2
2891
- }, calendarProps), {}, {
2892
- classes: styles,
2893
- initialMonth: startDateString,
2894
- modifiers: _objectSpread(_objectSpread({}, modifiers), {}, {
2895
- [rangeStart]: _ref2 => {
2896
- var {
2897
- dateValue
2898
- } = _ref2;
2899
- return !!(calendarStartDate !== null && calendarStartDate !== void 0 && calendarStartDate.hasSame(dateValue, 'day'));
2900
- },
2901
- [rangeFinish]: _ref3 => {
2902
- var {
2903
- dateValue
2904
- } = _ref3;
2905
- return !!(calendarFinishDate !== null && calendarFinishDate !== void 0 && calendarFinishDate.hasSame(dateValue, 'day'));
2906
- }
2907
- }),
2908
- selectedDays: _ref4 => {
2909
- var {
2910
- dateValue
2911
- } = _ref4;
2912
-
2913
- if (calendarStartDate) {
2914
- if (!calendarFinishDate) {
2915
- return calendarStartDate.hasSame(dateValue, 'day');
2916
- }
2917
-
2918
- return calendarStartDate <= dateValue && dateValue <= calendarFinishDate;
2919
- }
2920
-
2921
- return false;
2922
- },
2923
- footer: renderFooter === null || renderFooter === void 0 ? void 0 : renderFooter(api),
2924
- quickSelection: renderQuickSelection === null || renderQuickSelection === void 0 ? void 0 : renderQuickSelection(api),
2925
- onDayMouseEnter: event => {
2926
- _onDayMouseEnter === null || _onDayMouseEnter === void 0 ? void 0 : _onDayMouseEnter(event);
2927
- setHoveredDate(!event.disabled ? event.dateValue.valueOf() : undefined);
2928
- },
2929
- onDayClick: event => {
2930
- _onDayClick === null || _onDayClick === void 0 ? void 0 : _onDayClick(event);
2931
-
2932
- if (!event.disabled) {
2933
- if (startDate && !finishDate) {
2934
- handleChange([startDateString, event.stringValue]);
2935
- } else {
2936
- handleChange([event.stringValue, undefined]);
2937
- }
2938
- }
2939
- }
2940
- }))
2941
- }));
2942
- });
2943
- if (process.env.NODE_ENV !== "production") DateRangeField$1.displayName = "DateRangeField";
2944
-
2945
- /** @deprecated */
2946
-
2947
- /** @deprecated */
2948
-
2949
- function toDateTime$1(value) {
2950
- return typeof value === 'number' ? luxon.DateTime.fromMillis(value) : luxon.DateTime.fromJSDate(value);
2951
- }
2952
- /** @deprecated */
2953
-
2954
-
2955
- function isDate$1(value) {
2956
- return value != null && value instanceof Date;
2957
- }
2958
- /** @deprecated */
2959
-
2960
- function isDateLike$1(value) {
2961
- return isDate$1(value) || typeof value === 'number' && Number.isInteger(value);
2962
- }
2963
- /** @deprecated */
2964
-
2965
- function isValidDate$1(value) {
2966
- return isDate$1(value) && Number.isFinite(value.getTime());
2967
- }
2968
- /** @deprecated */
2969
-
2970
- function checkRange$1(range, validator) {
2971
- if (!Array.isArray(range) || range.length > 2) {
2972
- return false;
2973
- }
2974
-
2975
- var [start, finish] = range;
2976
- return (start == null || validator(start)) && (finish == null || validator(finish));
2977
- }
2978
- /** @deprecated */
2979
-
2980
-
2981
- function isDateRange$1(range) {
2982
- return checkRange$1(range, isDate$1);
2983
- }
2984
- /** @deprecated */
2985
-
2986
- function isDateRangeLike$1(range) {
2987
- return checkRange$1(range, isDateLike$1);
2988
- }
2989
- /** @deprecated */
2990
-
2991
- function isValidDateRange$1(range) {
2992
- return checkRange$1(range, isValidDate$1);
2993
- }
2994
- /** @deprecated */
2995
-
2996
- function toDate$1(value) {
2997
- return !isDateLike$1(value) ? new Date(NaN) : new Date(value);
2998
- }
2999
- /** @deprecated */
3000
-
3001
- function toDateRange$1(range) {
3002
- if (range == null || !isDateRangeLike$1(range)) {
3003
- return [];
3004
- }
3005
-
3006
- return range.filter(x => x != null).map(x => x == null ? undefined : toDate$1(x)).sort((a, b) => !isValidDate$1(a) ? -1 : !isValidDate$1(b) ? 1 : a.valueOf() - b.valueOf());
3007
- }
3008
- /** @deprecated */
3009
-
3010
- /** @deprecated */
3011
-
3012
- class DateUtils$1 {
3013
- /** @deprecated */
3014
- toObject(value) {
3015
- var {
3016
- year = NaN,
3017
- month = NaN,
3018
- day = NaN,
3019
- hour = NaN,
3020
- minute = NaN,
3021
- second = NaN,
3022
- millisecond = NaN
3023
- } = toDateTime$1(value).toObject({
3024
- includeConfig: false
3025
- });
3026
- return {
3027
- year,
3028
- month,
3029
- day,
3030
- hour,
3031
- minute,
3032
- second,
3033
- millisecond
3034
- };
3035
- }
3036
- /** @deprecated */
3037
-
3038
-
3039
- fromObject(_ref) {
3040
- var {
3041
- year = 0,
3042
- month = 1,
3043
- day = 1,
3044
- hour = 0,
3045
- minute = 0,
3046
- second = 0,
3047
- millisecond = 0
3048
- } = _ref;
3049
-
3050
- if (Number.isNaN(year) || Number.isNaN(month) || Number.isNaN(day) || Number.isNaN(hour) || Number.isNaN(minute) || Number.isNaN(second) || Number.isNaN(millisecond)) {
3051
- return new Date(NaN);
3052
- }
3053
-
3054
- return luxon.DateTime.fromObject({
3055
- year,
3056
- month,
3057
- day,
3058
- hour,
3059
- minute,
3060
- second,
3061
- millisecond
3062
- }).toJSDate();
3063
- }
3064
- /** @deprecated */
3065
-
3066
-
3067
- update(value, values) {
3068
- return toDateTime$1(value).set(values).toJSDate();
3069
- }
3070
- /** @deprecated */
3071
-
3072
-
3073
- mergeDateAndTime(date, time) {
3074
- var {
3075
- hour,
3076
- minute,
3077
- second,
3078
- millisecond
3079
- } = this.toObject(time);
3080
-
3081
- if (Number.isNaN(hour) || Number.isNaN(minute) || Number.isNaN(second) || Number.isNaN(millisecond)) {
3082
- return new Date(NaN);
3083
- }
3084
-
3085
- return this.update(date, {
3086
- hour,
3087
- minute,
3088
- second,
3089
- millisecond
3090
- });
3091
- }
3092
- /** @deprecated */
3093
-
3094
-
3095
- startOf(value, unit) {
3096
- return toDateTime$1(value).startOf(unit).toJSDate();
3097
- }
3098
- /** @deprecated */
3099
-
3100
-
3101
- endOf(value, unit) {
3102
- return toDateTime$1(value).endOf(unit).toJSDate();
3103
- }
3104
- /** @deprecated */
3105
-
3106
-
3107
- plus(value, values) {
3108
- return toDateTime$1(value).plus(values).toJSDate();
3109
- }
3110
- /** @deprecated */
3111
-
3112
-
3113
- minus(value, values) {
3114
- return toDateTime$1(value).minus(values).toJSDate();
3115
- }
3116
- /** @deprecated */
3117
-
3118
-
3119
- isSameDate(value, compare) {
3120
- var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'millisecond';
3121
-
3122
- if (value == null && compare == null) {
3123
- return true;
3124
- }
3125
-
3126
- if (value == null || compare == null) {
3127
- return false;
3128
- }
3129
-
3130
- var dateTimeValue = toDateTime$1(value);
3131
- var dateTimeCompare = toDateTime$1(compare);
3132
- return dateTimeValue.isValid && dateTimeCompare.isValid && dateTimeValue.startOf(unit).equals(dateTimeCompare.startOf(unit));
3133
- }
3134
- /** @deprecated */
3135
-
3136
-
3137
- isSameDateRange(value, compare, unit) {
3138
- var range1 = toDateRange$1(value);
3139
- var range2 = toDateRange$1(compare);
3140
- return !range1.some((date, idx) => !this.isSameDate(date, range2[idx], unit));
3141
- }
3142
- /** @deprecated */
3143
-
3144
-
3145
- diff(value, compare, unit) {
3146
- var valueDateTime = toDateTime$1(value);
3147
- var compareDateTime = toDateTime$1(compare);
3148
- return valueDateTime.diff(compareDateTime, unit).as(unit);
3149
- }
3150
- /** @deprecated */
3151
-
3152
-
3153
- toLocaleString(value, options) {
3154
- return toDateTime$1(value).toLocaleString(options);
3155
- }
3156
- /** @deprecated */
3157
-
3158
-
3159
- format(value, variant) {
3160
- return this.toLocaleString(value, variant === 'date' ? {
3161
- day: '2-digit',
3162
- month: 'short',
3163
- year: 'numeric'
3164
- } : variant === 'shortDate' ? {
3165
- day: '2-digit',
3166
- month: 'short'
3167
- } : variant === 'time' ? {
3168
- hour: 'numeric',
3169
- minute: 'numeric'
3170
- } : {
3171
- day: '2-digit',
3172
- month: 'short',
3173
- year: 'numeric',
3174
- hour: 'numeric',
3175
- minute: 'numeric'
3176
- });
3177
- }
3178
- /** @deprecated */
3179
-
3180
-
3181
- formatRange(value) {
3182
- var emptyText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
3183
- var range = toDateRange$1(value);
3184
-
3185
- if (!isValidDateRange$1(range)) {
3186
- return 'Invalid Date Range';
3187
- }
3188
-
3189
- var [start, finish] = range;
3190
-
3191
- if (!start) {
3192
- return emptyText;
3193
- }
3194
-
3195
- var startText = this.format(start, !this.isSameDate(start, finish, 'year') ? 'date' : 'shortDate');
3196
- var finishText = !finish ? '…' : this.format(finish, 'date');
3197
- return "".concat(startText, " - ").concat(finishText);
3198
- }
3199
- /** @deprecated */
3200
-
3201
-
3202
- formatRelativeTime(value) {
3203
- var {
3204
- style = 'long',
3205
- compare = Date.now()
3206
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3207
- var valueDateTime = toDateTime$1(value);
3208
- var compareDateTime = toDateTime$1(compare);
3209
- return valueDateTime.toRelative({
3210
- style,
3211
- base: compareDateTime
3212
- });
3213
- }
3214
-
3215
- }
3216
- function useDateUtils$1() {
3217
- return react.useMemo(() => new DateUtils$1(), []);
3218
- }
3219
-
3220
- var _excluded$c = ["unit", "round", "padding", "fallback", "base"],
3221
- _excluded2$7 = ["date", "fallback"];
3222
- function useFormattedRelativeTime$1(input) {
3223
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
3224
- {
3225
- unit,
3226
- round,
3227
- padding,
3228
- fallback,
3229
- base: baseOption
3230
- } = _ref,
3231
- dateConfig = _objectWithoutProperties(_ref, _excluded$c);
3232
-
3233
- var config = useDateConfig$1(dateConfig);
3234
- var date = useDateTime$1(input, config);
3235
- var baseOptionDate = useDateTime$1(baseOption, config);
3236
- var base = baseOption == null ? undefined : baseOptionDate;
3237
- return react.useMemo(() => formatRelativeTime$1(date, {
3238
- base,
3239
- unit,
3240
- round,
3241
- padding,
3242
- fallback
3243
- }, config), [base, date, unit, round, config, padding, fallback]);
3244
- }
3245
- function FormattedRelativeTime$1(_ref2) {
3246
- var {
3247
- date,
3248
- fallback = 'Invalid Date'
3249
- } = _ref2,
3250
- options = _objectWithoutProperties(_ref2, _excluded2$7);
3251
-
3252
- var formatted = useFormattedRelativeTime$1(date, _objectSpread(_objectSpread({}, options), {}, {
3253
- fallback: ''
3254
- }));
3255
- return ui.renderChildren(formatted || fallback);
3256
- }
3257
-
3258
- var _excluded$d = ["disabled", "onChange", "value", "format"];
3259
- var TIME_MATCH_FORMATS$1 = ['h:mm a', 'h:mma', 'H:mm', 'h:mm', 'hmm', 'Hmm', 'h', 'H'];
3260
-
3261
- function toTimeFieldOption$1(date, config) {
3262
- return {
3263
- value: date.valueOf(),
3264
- label: formatDate$1(date, {
3265
- variant: 'Time'
3266
- }, config),
3267
- pattern: new RegExp("^(".concat(TIME_MATCH_FORMATS$1.map(format => date.toFormat(format)).join('|'), ")"), 'i')
3268
- };
3269
- }
3270
-
3271
- function normalizeInputValue$1(inputValue) {
3272
- return inputValue.replace(/[\s]/g, '').toLowerCase();
3273
- }
3274
-
3275
- function makeOptions$1(config) {
3276
- var options = [];
3277
- var now = luxon.DateTime.local().startOf('day');
3278
-
3279
- for (var i = 0; i < 96; i++) {
3280
- options.push(toTimeFieldOption$1(now.set({
3281
- minute: i * 15
3282
- }), config));
3283
- }
3284
-
3285
- var cache = new Map();
3286
- return [options, (_, _ref) => {
3287
- var {
3288
- inputValue
3289
- } = _ref;
3290
- var query = normalizeInputValue$1(inputValue);
3291
-
3292
- if (!query) {
3293
- return options;
3294
- }
3295
-
3296
- var filtered = cache.get(query);
3297
-
3298
- if (!filtered) {
3299
- filtered = options.filter(option => option.pattern.test(query));
3300
- cache.set(query, filtered);
3301
- }
3302
-
3303
- return filtered;
3304
- }];
3305
- }
3306
-
3307
- var TimeField$1 = /*#__PURE__*/react.forwardRef((_ref2, ref) => {
3308
- var {
3309
- disabled,
3310
- onChange,
3311
- value: valueProp,
3312
- format: formatProp
3313
- } = _ref2,
3314
- props = _objectWithoutProperties(_ref2, _excluded$d);
3315
-
3316
- var config = useDateConfig$1({
3317
- format: formatProp
3318
- });
3319
- var date = useDateTime$1(valueProp, config);
3320
- var selectedOption = react.useMemo(() => !date.isValid ? undefined : toTimeFieldOption$1(date, config), [date, config]);
3321
- var [options, filterOptions] = react.useMemo(() => makeOptions$1(config), [config]);
3322
- var [inputValue, setInputValue] = react.useState('');
3323
-
3324
- function handleChange(nextValue) {
3325
- if (onChange) {
3326
- onChange(toDatePayload$1(nextValue, config));
3327
- }
3328
- }
3329
-
3330
- function handleType(text) {
3331
- text = normalizeInputValue$1(text);
3332
-
3333
- for (var timeFormat of TIME_MATCH_FORMATS$1) {
3334
- var nextDate = luxon.DateTime.fromFormat(text, timeFormat);
3335
-
3336
- if (nextDate.isValid) {
3337
- if (onChange) {
3338
- if (date.isValid) {
3339
- nextDate = nextDate.set({
3340
- year: date.year,
3341
- month: date.month,
3342
- day: date.day
3343
- });
3344
- }
3345
-
3346
- onChange(toDatePayload$1(nextDate, config));
3347
- }
3348
-
3349
- return;
3350
- }
3351
- }
3352
-
3353
- setInputValue((selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) || '');
3354
- }
3355
-
3356
- react.useEffect(() => {
3357
- if (!date.isValid) {
3358
- setInputValue('');
3359
- } else {
3360
- setInputValue(formatDate$1(date, {
3361
- variant: 'Time'
3362
- }, config));
3363
- }
3364
- }, [date, config]);
3365
- return /*#__PURE__*/jsxRuntime.jsx(lab.Autocomplete, {
3366
- ref: ref,
3367
- disabled: disabled,
3368
- freeSolo: true,
3369
- autoComplete: true,
3370
- value: selectedOption,
3371
- inputValue: inputValue,
3372
- options: options,
3373
- includeInputInList: true,
3374
- filterOptions: filterOptions,
3375
- getOptionLabel: option => typeof option === 'string' ? option : option.label,
3376
- onBlur: event => {
3377
- handleType(event.target.value);
3378
- },
3379
- onChange: (_, nextValue) => {
3380
- if (typeof nextValue === 'string') {
3381
- handleType(nextValue);
3382
- } else {
3383
- handleChange(nextValue === null || nextValue === void 0 ? void 0 : nextValue.value);
3384
- }
3385
- },
3386
- onInputChange: (_, nextInputValue) => {
3387
- setInputValue(nextInputValue);
3388
- },
3389
- renderInput: params => /*#__PURE__*/jsxRuntime.jsx(core.TextField, _objectSpread(_objectSpread(_objectSpread({
3390
- variant: "outlined"
3391
- }, props), params), {}, {
3392
- InputProps: params.InputProps
3393
- }))
3394
- });
3395
- });
3396
- if (process.env.NODE_ENV !== "production") TimeField$1.displayName = "TimeField";
3397
-
3398
- exports.Calendar = Calendar$1;
3399
- exports.CalendarQuickSelection = CalendarQuickSelection$1;
3400
- exports.CalendarQuickSelectionItem = CalendarQuickSelectionItem$1;
3401
- exports.DateConfigProvider = DateConfigProvider$1;
3402
- exports.DateField = DateField$1;
3403
- exports.DateRangeField = DateRangeField$1;
3404
- exports.DateUtils = DateUtils$1;
3405
- exports.FormattedDate = FormattedDate$1;
3406
- exports.FormattedRelativeTime = FormattedRelativeTime$1;
3407
- exports.TimeField = TimeField$1;
3408
- exports.defaultDateConfig = defaultDateConfig$1;
3409
- exports.formatDate = formatDate$1;
3410
- exports.formatDateRange = formatDateRange$1;
3411
- exports.formatRelativeTime = formatRelativeTime$1;
3412
- exports.isDate = isDate$1;
3413
- exports.isDateLike = isDateLike$1;
3414
- exports.isDateRange = isDateRange$1;
3415
- exports.isDateRangeLike = isDateRangeLike$1;
3416
- exports.isValidDate = isValidDate$1;
3417
- exports.isValidDateRange = isValidDateRange$1;
3418
- exports.parseDate = parseDate$1;
3419
- exports.parseDateRange = parseDateRange$1;
3420
- exports.setDefaultTimeZone = setDefaultTimeZone$1;
3421
- exports.stringifyDate = stringifyDate$1;
3422
- exports.stringifyDateRange = stringifyDateRange$1;
3423
- exports.toDate = toDate$1;
3424
- exports.toDatePayload = toDatePayload$1;
3425
- exports.toDateRange = toDateRange$1;
3426
- exports.toDateRangePayload = toDateRangePayload$1;
3427
- exports.toPrimitiveDateInput = toPrimitiveDateInput$1;
3428
- exports.toPrimitiveDateRangeInput = toPrimitiveDateRangeInput$1;
3429
- exports.useDateConfig = useDateConfig$1;
3430
- exports.useDateTime = useDateTime$1;
3431
- exports.useDateTimeRange = useDateTimeRange$1;
3432
- exports.useDateUtils = useDateUtils$1;
3433
- exports.useDefaultTimeZone = useDefaultTimeZone$1;
3434
- exports.useFormattedDate = useFormattedDate$1;
3435
- exports.useFormattedRelativeTime = useFormattedRelativeTime$1;
3436
- exports.v5 = index;
1683
+ exports.Calendar = Calendar;
1684
+ exports.CalendarQuickSelection = CalendarQuickSelection;
1685
+ exports.CalendarQuickSelectionItem = CalendarQuickSelectionItem;
1686
+ exports.DateConfigProvider = DateConfigProvider;
1687
+ exports.DateField = DateField;
1688
+ exports.DateRangeField = DateRangeField;
1689
+ exports.DateUtils = DateUtils;
1690
+ exports.FormattedDate = FormattedDate;
1691
+ exports.FormattedRelativeTime = FormattedRelativeTime;
1692
+ exports.TimeField = TimeField;
1693
+ exports.defaultDateConfig = defaultDateConfig;
1694
+ exports.formatDate = formatDate;
1695
+ exports.formatDateRange = formatDateRange;
1696
+ exports.formatRelativeTime = formatRelativeTime;
1697
+ exports.isDate = isDate;
1698
+ exports.isDateLike = isDateLike;
1699
+ exports.isDateRange = isDateRange;
1700
+ exports.isDateRangeLike = isDateRangeLike;
1701
+ exports.isValidDate = isValidDate;
1702
+ exports.isValidDateRange = isValidDateRange;
1703
+ exports.parseDate = parseDate;
1704
+ exports.parseDateRange = parseDateRange;
1705
+ exports.setDefaultTimeZone = setDefaultTimeZone;
1706
+ exports.stringifyDate = stringifyDate;
1707
+ exports.stringifyDateRange = stringifyDateRange;
1708
+ exports.toDate = toDate;
1709
+ exports.toDatePayload = toDatePayload;
1710
+ exports.toDateRange = toDateRange;
1711
+ exports.toDateRangePayload = toDateRangePayload;
1712
+ exports.toPrimitiveDateInput = toPrimitiveDateInput;
1713
+ exports.toPrimitiveDateRangeInput = toPrimitiveDateRangeInput;
1714
+ exports.useDateConfig = useDateConfig;
1715
+ exports.useDateTime = useDateTime;
1716
+ exports.useDateTimeRange = useDateTimeRange;
1717
+ exports.useDateUtils = useDateUtils;
1718
+ exports.useDefaultTimeZone = useDefaultTimeZone;
1719
+ exports.useFormattedDate = useFormattedDate;
1720
+ exports.useFormattedRelativeTime = useFormattedRelativeTime;
3437
1721
  //# sourceMappingURL=index.js.map