@servicetitan/anvil2 1.40.3 → 1.42.0
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/CHANGELOG.md +55 -0
- package/dist/{AnvilProvider-Lh8YtV03.js → AnvilProvider-BLYCqIbb.js} +2 -2
- package/dist/{AnvilProvider-Lh8YtV03.js.map → AnvilProvider-BLYCqIbb.js.map} +1 -1
- package/dist/AnvilProvider.js +1 -1
- package/dist/{Avatar-B20IdOEO-Di14brYV.js → Avatar-C7cbRTCt-DCvzmr2C.js} +14 -12
- package/dist/Avatar-C7cbRTCt-DCvzmr2C.js.map +1 -0
- package/dist/{Avatar-B20IdOEO.css → Avatar-C7cbRTCt.css} +34 -19
- package/dist/{Avatar-hNOToS9S.js → Avatar-DREZJN2K.js} +2 -2
- package/dist/Avatar-DREZJN2K.js.map +1 -0
- package/dist/Avatar.js +1 -1
- package/dist/{Breadcrumbs-D_jgwoN3-Dlw-weD8.js → Breadcrumbs-B5bqrZ5D-BqK-Qfh9.js} +3 -3
- package/dist/{Breadcrumbs-D_jgwoN3-Dlw-weD8.js.map → Breadcrumbs-B5bqrZ5D-BqK-Qfh9.js.map} +1 -1
- package/dist/{Breadcrumbs-C_gan90a.js → Breadcrumbs-De8uoLi8.js} +2 -2
- package/dist/{Breadcrumbs-C_gan90a.js.map → Breadcrumbs-De8uoLi8.js.map} +1 -1
- package/dist/Breadcrumbs.js +1 -1
- package/dist/{Calendar-2q8zRbMK.js → Calendar-Bgpz99F2.js} +2 -2
- package/dist/{Calendar-2q8zRbMK.js.map → Calendar-Bgpz99F2.js.map} +1 -1
- package/dist/{Calendar-KVYGk3wS-CEptqxjI.js → Calendar-DD5kmVd3-CBGTR11R.js} +7 -5
- package/dist/{Calendar-KVYGk3wS-CEptqxjI.js.map → Calendar-DD5kmVd3-CBGTR11R.js.map} +1 -1
- package/dist/Calendar.js +1 -1
- package/dist/{Checkbox-Qucv_PK8-Bovwdnlj.js → Checkbox-DyHm7Ntt-DYw5QL3l.js} +2 -2
- package/dist/{Checkbox-Qucv_PK8-Bovwdnlj.js.map → Checkbox-DyHm7Ntt-DYw5QL3l.js.map} +1 -1
- package/dist/{Checkbox-cfgZP7Z2.js → Checkbox-zg8LVvB6.js} +2 -2
- package/dist/{Checkbox-cfgZP7Z2.js.map → Checkbox-zg8LVvB6.js.map} +1 -1
- package/dist/Checkbox.js +1 -1
- package/dist/Chip-DXQiqF8k.js +34 -0
- package/dist/Chip-DXQiqF8k.js.map +1 -0
- package/dist/{Chip-_daV8CmM-CTke7zH4.js → Chip-MbBEXeAm-DmAcwPRJ.js} +57 -10
- package/dist/Chip-MbBEXeAm-DmAcwPRJ.js.map +1 -0
- package/dist/{Chip-_daV8CmM.css → Chip-MbBEXeAm.css} +68 -18
- package/dist/Chip.js +1 -1
- package/dist/{Combobox-3l2SK47T.js → Combobox-D2aSaDkz.js} +7 -7
- package/dist/{Combobox-3l2SK47T.js.map → Combobox-D2aSaDkz.js.map} +1 -1
- package/dist/Combobox.js +1 -1
- package/dist/{DateField-BQFAvS78.js → DateField-D28_sa7P.js} +8 -8
- package/dist/{DateField-BQFAvS78.js.map → DateField-D28_sa7P.js.map} +1 -1
- package/dist/DateField.js +1 -1
- package/dist/{DateFieldRange-CGA5ZTRa.js → DateFieldRange-CgVqJrVg.js} +2 -2
- package/dist/DateFieldRange-CgVqJrVg.js.map +1 -0
- package/dist/DateFieldRange.js +1 -1
- package/dist/{DateFieldSingle-eP5l_TrQ.js → DateFieldSingle-CLoWDlPO.js} +2 -2
- package/dist/DateFieldSingle-CLoWDlPO.js.map +1 -0
- package/dist/DateFieldSingle.js +1 -1
- package/dist/DateFieldYearless-CXlUH0c7.js +22 -0
- package/dist/DateFieldYearless-CXlUH0c7.js.map +1 -0
- package/dist/{DateFieldRange-BRjBcR4r-CfuSiOfZ.js → DateFieldYearless-M5KDI_hn-akXtkIZA.js} +881 -579
- package/dist/DateFieldYearless-M5KDI_hn-akXtkIZA.js.map +1 -0
- package/dist/DateFieldYearless.d.ts +2 -0
- package/dist/DateFieldYearless.js +2 -0
- package/dist/DateFieldYearless.js.map +1 -0
- package/dist/{DaysOfTheWeek-Dl31wkmU.js → DaysOfTheWeek-ImBPjEvl.js} +2 -2
- package/dist/{DaysOfTheWeek-Dl31wkmU.js.map → DaysOfTheWeek-ImBPjEvl.js.map} +1 -1
- package/dist/DaysOfTheWeek.js +1 -1
- package/dist/{Dialog-CJZEBa5r.js → Dialog-BR6f-XRH.js} +10 -6
- package/dist/Dialog-BR6f-XRH.js.map +1 -0
- package/dist/Dialog.js +1 -1
- package/dist/{Drawer-Cj3nJc4k.js → Drawer-0ayAWgAA.js} +2 -2
- package/dist/{Drawer-Cj3nJc4k.js.map → Drawer-0ayAWgAA.js.map} +1 -1
- package/dist/Drawer.js +1 -1
- package/dist/{EditCard-C0hD1VPA.js → EditCard-B_n1uFkv.js} +2 -2
- package/dist/{EditCard-C0hD1VPA.js.map → EditCard-B_n1uFkv.js.map} +1 -1
- package/dist/EditCard.js +1 -1
- package/dist/FieldLabel-DWl5qsRY.js +13 -0
- package/dist/FieldLabel-DWl5qsRY.js.map +1 -0
- package/dist/FieldLabel.d.ts +6 -0
- package/dist/FieldLabel.js +2 -0
- package/dist/FieldLabel.js.map +1 -0
- package/dist/{HammerProvider-CYP98rq3-Dd9GVIyP.js → HammerProvider-vt3DkcCZ-06BeBrPu.js} +2 -2
- package/dist/{HammerProvider-CYP98rq3-Dd9GVIyP.js.map → HammerProvider-vt3DkcCZ-06BeBrPu.js.map} +1 -1
- package/dist/{InputMask-Hn-xudp1-BKhtZ7Zk.js → InputMask-CE3pdXwL-B8XVrj36.js} +2 -2
- package/dist/{InputMask-Hn-xudp1-BKhtZ7Zk.js.map → InputMask-CE3pdXwL-B8XVrj36.js.map} +1 -1
- package/dist/{InputMask-BdLGTTAk.js → InputMask-wUro4G2j.js} +2 -2
- package/dist/{InputMask-BdLGTTAk.js.map → InputMask-wUro4G2j.js.map} +1 -1
- package/dist/InputMask.js +1 -1
- package/dist/{ListView-_YFTewqc.js → ListView-DdHpJHTc.js} +3 -3
- package/dist/{ListView-_YFTewqc.js.map → ListView-DdHpJHTc.js.map} +1 -1
- package/dist/ListView.js +1 -1
- package/dist/{Listbox-BvJLSAVO-Br5k6fmq.js → Listbox-B-WUuj-_-BWWeWtLW.js} +2 -2
- package/dist/{Listbox-BvJLSAVO-Br5k6fmq.js.map → Listbox-B-WUuj-_-BWWeWtLW.js.map} +1 -1
- package/dist/{Listbox-dVARiucB.js → Listbox-Di6OS1Fk.js} +2 -2
- package/dist/{Listbox-dVARiucB.js.map → Listbox-Di6OS1Fk.js.map} +1 -1
- package/dist/Listbox.js +1 -1
- package/dist/{Menu-1EwVMNIw.js → Menu-DHCOMJx2.js} +2 -2
- package/dist/{Menu-1EwVMNIw.js.map → Menu-DHCOMJx2.js.map} +1 -1
- package/dist/{Menu-CffX1bPZ-BeEOvryY.js → Menu-TtVJnSrA-yBYichuJ.js} +6 -9
- package/dist/Menu-TtVJnSrA-yBYichuJ.js.map +1 -0
- package/dist/Menu.js +1 -1
- package/dist/{Page-BikjTlTM.js → Page-KN0DLtcf.js} +8 -8
- package/dist/{Page-BikjTlTM.js.map → Page-KN0DLtcf.js.map} +1 -1
- package/dist/Page.js +1 -1
- package/dist/Pagination.js +2 -2
- package/dist/Pagination.js.map +1 -1
- package/dist/{Popover-rB4BVx-A.js → Popover-B1HaUjGI.js} +2 -2
- package/dist/{Popover-rB4BVx-A.js.map → Popover-B1HaUjGI.js.map} +1 -1
- package/dist/{Popover-jcmNuir0-DjlCqU1z.js → Popover-CU2cGVD8-FWJOuFRj.js} +78 -15
- package/dist/Popover-CU2cGVD8-FWJOuFRj.js.map +1 -0
- package/dist/Popover.js +1 -1
- package/dist/{ProgressBar-CzXzPpIX-Clg1J71o.js → ProgressBar-BRvB-bD4-DppwBrFg.js} +52 -18
- package/dist/ProgressBar-BRvB-bD4-DppwBrFg.js.map +1 -0
- package/dist/{ProgressBar-BL34rg_J.js → ProgressBar-lPKNTz6i.js} +2 -2
- package/dist/{ProgressBar-BL34rg_J.js.map → ProgressBar-lPKNTz6i.js.map} +1 -1
- package/dist/ProgressBar.js +1 -1
- package/dist/{Radio-BnOSIK1U-1MmGQFPi.js → Radio-DQ_VQFGZ-SdFBlDnE.js} +3 -3
- package/dist/{Radio-BnOSIK1U-1MmGQFPi.js.map → Radio-DQ_VQFGZ-SdFBlDnE.js.map} +1 -1
- package/dist/{Radio-BzZUxQa6.js → Radio-DnOuBPi_.js} +2 -2
- package/dist/{Radio-BzZUxQa6.js.map → Radio-DnOuBPi_.js.map} +1 -1
- package/dist/Radio.js +1 -1
- package/dist/{SelectCard-ynL5QcZD-BtBzMtyR.js → SelectCard-DUNwYa5y-BSi21Aba.js} +4 -4
- package/dist/{SelectCard-ynL5QcZD-BtBzMtyR.js.map → SelectCard-DUNwYa5y-BSi21Aba.js.map} +1 -1
- package/dist/SelectCard.js +1 -1
- package/dist/{SelectCardGroup-D6GuJJB2.js → SelectCardGroup-YGYiBv5M.js} +2 -2
- package/dist/{SelectCardGroup-D6GuJJB2.js.map → SelectCardGroup-YGYiBv5M.js.map} +1 -1
- package/dist/{SelectTrigger-Bo2VPAD0.js → SelectTrigger-Cg-rlFKY.js} +3 -3
- package/dist/{SelectTrigger-Bo2VPAD0.js.map → SelectTrigger-Cg-rlFKY.js.map} +1 -1
- package/dist/SelectTrigger.js +1 -1
- package/dist/{SelectTriggerBase-BGHwx0mN-B3HiW5tQ.js → SelectTriggerBase-C0fhFfuj-DfR6h1Lq.js} +4 -4
- package/dist/{SelectTriggerBase-BGHwx0mN-B3HiW5tQ.js.map → SelectTriggerBase-C0fhFfuj-DfR6h1Lq.js.map} +1 -1
- package/dist/{SideNav-DEoGpeqJ.js → SideNav-Bh_pVeEw.js} +11 -11
- package/dist/{SideNav-DEoGpeqJ.js.map → SideNav-Bh_pVeEw.js.map} +1 -1
- package/dist/SideNav.css +70 -52
- package/dist/SideNav.js +1 -1
- package/dist/{Text-B91g6xKn.js → Text-35Ve4Uq0.js} +2 -2
- package/dist/{Text-B91g6xKn.js.map → Text-35Ve4Uq0.js.map} +1 -1
- package/dist/{Text-DCvcLCvf-DlmnnjTR.js → Text-CED_yrId-DsRYZw2-.js} +10 -10
- package/dist/{Text-DCvcLCvf-DlmnnjTR.js.map → Text-CED_yrId-DsRYZw2-.js.map} +1 -1
- package/dist/{Text-DCvcLCvf.css → Text-CED_yrId.css} +35 -17
- package/dist/Text.js +1 -1
- package/dist/{TextField-BIeCvDD--C7yp05g5.js → TextField-CRTh0gL_-D2CjcYXX.js} +6 -3
- package/dist/TextField-CRTh0gL_-D2CjcYXX.js.map +1 -0
- package/dist/{TextField-COXABNrR.js → TextField-gYAqTpcX.js} +2 -2
- package/dist/{TextField-COXABNrR.js.map → TextField-gYAqTpcX.js.map} +1 -1
- package/dist/TextField.js +1 -1
- package/dist/{Textarea-D6K3Jc5_.js → Textarea-DohNOiIp.js} +24 -11
- package/dist/Textarea-DohNOiIp.js.map +1 -0
- package/dist/Textarea.js +1 -1
- package/dist/{ThemeProvider-BKave7Ha.js → ThemeProvider-DwJqkbiU.js} +2 -2
- package/dist/{ThemeProvider-BKave7Ha.js.map → ThemeProvider-DwJqkbiU.js.map} +1 -1
- package/dist/{ThemeProvider-CR67FJg0-DYVRlJRA.js → ThemeProvider-Q3ji6Rpx-DBXlAuQ8.js} +5 -5
- package/dist/{ThemeProvider-CR67FJg0-DYVRlJRA.js.map → ThemeProvider-Q3ji6Rpx-DBXlAuQ8.js.map} +1 -1
- package/dist/{ThemeProvider-CR67FJg0.css → ThemeProvider-Q3ji6Rpx.css} +106 -4
- package/dist/ThemeProvider.js +1 -1
- package/dist/Toast.js +1 -1
- package/dist/{Toolbar-CLsgDAKk.js → Toolbar-BznMJKGJ.js} +4 -4
- package/dist/{Toolbar-CLsgDAKk.js.map → Toolbar-BznMJKGJ.js.map} +1 -1
- package/dist/Toolbar.js +1 -1
- package/dist/{Tooltip-B_swJyoW.js → Tooltip-C2HQDvYj.js} +2 -2
- package/dist/{Tooltip-B_swJyoW.js.map → Tooltip-C2HQDvYj.js.map} +1 -1
- package/dist/Tooltip.js +1 -1
- package/dist/assets/icons/st/fixed.svg +1 -0
- package/dist/assets/icons/st/full_fluid.svg +1 -0
- package/dist/assets/icons/st/installed_equipment.svg +1 -0
- package/dist/assets/icons/st/unpin.svg +1 -0
- package/dist/assets/icons/st.ts +4 -0
- package/dist/components/Avatar/Avatar.d.ts +7 -2
- package/dist/components/Chip/Chip.d.ts +12 -10
- package/dist/components/DateField/DateField.d.ts +1 -0
- package/dist/components/DateFieldRange/DateFieldRange.d.ts +4 -1
- package/dist/components/DateFieldRange/index.d.ts +1 -2
- package/dist/components/DateFieldSingle/DateFieldSingle.d.ts +3 -1
- package/dist/components/DateFieldSingle/index.d.ts +1 -2
- package/dist/components/DateFieldYearless/DateFieldYearless.d.ts +62 -0
- package/dist/components/DateFieldYearless/index.d.ts +1 -0
- package/dist/components/Dialog/Dialog.d.ts +1 -1
- package/dist/components/Drawer/Drawer.d.ts +1 -1
- package/dist/components/FieldLabel/FieldLabel.d.ts +8 -0
- package/dist/components/FieldLabel/index.d.ts +2 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/index.js +34 -32
- package/dist/index.js.map +1 -1
- package/dist/{toast-CJSBieY0.js → toast-BhV_Ask2.js} +2 -2
- package/dist/{toast-CJSBieY0.js.map → toast-BhV_Ask2.js.map} +1 -1
- package/dist/token/core/raw.js +85 -0
- package/dist/token/core/semantic-variables.scss +102 -0
- package/dist/token/core/semantic.js +357 -0
- package/dist/token/core/semantic.scss +51 -0
- package/dist/token.js +408 -0
- package/dist/token.js.map +1 -1
- package/package.json +3 -3
- package/dist/Avatar-B20IdOEO-Di14brYV.js.map +0 -1
- package/dist/Avatar-hNOToS9S.js.map +0 -1
- package/dist/Chip-BlLavyIK.js +0 -24
- package/dist/Chip-BlLavyIK.js.map +0 -1
- package/dist/Chip-_daV8CmM-CTke7zH4.js.map +0 -1
- package/dist/DateFieldRange-BRjBcR4r-CfuSiOfZ.js.map +0 -1
- package/dist/DateFieldRange-CGA5ZTRa.js.map +0 -1
- package/dist/DateFieldSingle-eP5l_TrQ.js.map +0 -1
- package/dist/Dialog-CJZEBa5r.js.map +0 -1
- package/dist/Menu-CffX1bPZ-BeEOvryY.js.map +0 -1
- package/dist/Popover-jcmNuir0-DjlCqU1z.js.map +0 -1
- package/dist/ProgressBar-CzXzPpIX-Clg1J71o.js.map +0 -1
- package/dist/TextField-BIeCvDD--C7yp05g5.js.map +0 -1
- package/dist/Textarea-D6K3Jc5_.js.map +0 -1
- /package/dist/{Breadcrumbs-D_jgwoN3.css → Breadcrumbs-B5bqrZ5D.css} +0 -0
- /package/dist/{Calendar-KVYGk3wS.css → Calendar-DD5kmVd3.css} +0 -0
- /package/dist/{Menu-CffX1bPZ.css → Menu-TtVJnSrA.css} +0 -0
- /package/dist/{Popover-jcmNuir0.css → Popover-CU2cGVD8.css} +0 -0
- /package/dist/{ProgressBar-CzXzPpIX.css → ProgressBar-BRvB-bD4.css} +0 -0
- /package/dist/{Radio-BnOSIK1U.css → Radio-DQ_VQFGZ.css} +0 -0
- /package/dist/{SelectCard-ynL5QcZD.css → SelectCard-DUNwYa5y.css} +0 -0
- /package/dist/{SelectTriggerBase-BGHwx0mN.css → SelectTriggerBase-C0fhFfuj.css} +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { useState, useCallback, useRef, useLayoutEffect, useEffect, useMemo, forwardRef, useImperativeHandle } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import { T as TextField } from './TextField-BIeCvDD--C7yp05g5.js';
|
|
3
|
+
import { T as TextField } from './TextField-CRTh0gL_-D2CjcYXX.js';
|
|
5
4
|
import { u as useMergeRefs$1 } from './floating-ui.react-BFNinq1w.js';
|
|
5
|
+
import { D as DateTime, f as Calendar } from './Calendar-DD5kmVd3-CBGTR11R.js';
|
|
6
6
|
import { I as Icon } from './Icon-B6HmlQiR-BxQkO3X5.js';
|
|
7
7
|
import { u as usePopoverCloseDelayWorkaround, S as SvgEvent } from './usePopoverCloseDelayWorkaround-BhhG-xEB-hfJZaXHC.js';
|
|
8
|
-
import { d as Popover } from './Popover-
|
|
9
|
-
import { u as useMergeRefs } from './useMergeRefs-Bde85AWI-Bde85AWI.js';
|
|
8
|
+
import { d as Popover } from './Popover-CU2cGVD8-FWJOuFRj.js';
|
|
10
9
|
import { u as useOptionallyControlledState } from './useOptionallyControlledState-DAv5LXXh-DAv5LXXh.js';
|
|
11
|
-
import {
|
|
10
|
+
import { u as useMergeRefs } from './useMergeRefs-Bde85AWI-Bde85AWI.js';
|
|
11
|
+
import { s as supportsPopover, u as useKeyboardFocusables } from './ProgressBar-BRvB-bD4-DppwBrFg.js';
|
|
12
12
|
|
|
13
13
|
function getContentEditableSelection(element) {
|
|
14
14
|
const { anchorOffset = 0, focusOffset = 0 } = element.ownerDocument.getSelection() || {};
|
|
@@ -1887,7 +1887,7 @@ const MaskedDateInput = forwardRef(
|
|
|
1887
1887
|
useEffect(() => {
|
|
1888
1888
|
if (mode !== previousMode) {
|
|
1889
1889
|
setInputValue(
|
|
1890
|
-
(oldInputValue) => swapMode$
|
|
1890
|
+
(oldInputValue) => swapMode$2(oldInputValue, previousMode ?? mode, mode)
|
|
1891
1891
|
);
|
|
1892
1892
|
}
|
|
1893
1893
|
}, [mode, previousMode]);
|
|
@@ -1902,17 +1902,21 @@ const MaskedDateInput = forwardRef(
|
|
|
1902
1902
|
}
|
|
1903
1903
|
}, [lastValidDate, mode, placeholder]);
|
|
1904
1904
|
const currentParsedData = useMemo(() => {
|
|
1905
|
-
return parseInputValue(inputValue, mode, removePlaceholder);
|
|
1905
|
+
return parseInputValue$1(inputValue, mode, removePlaceholder);
|
|
1906
1906
|
}, [inputValue, mode, removePlaceholder]);
|
|
1907
1907
|
const handleChange = (event) => {
|
|
1908
1908
|
setInputValue(event.target.value);
|
|
1909
|
-
const { date, isInputValid, isInputEmpty } = parseInputValue(
|
|
1909
|
+
const { date, isInputValid, isInputEmpty } = parseInputValue$1(
|
|
1910
1910
|
event.target.value,
|
|
1911
1911
|
mode,
|
|
1912
1912
|
removePlaceholder
|
|
1913
1913
|
);
|
|
1914
|
+
const isValueDifferent = isInputValid !== currentParsedData.isInputValid || // The input has changed validity
|
|
1915
|
+
isInputEmpty !== currentParsedData.isInputEmpty || // The input has changed emptiness
|
|
1916
|
+
date === null !== (lastValidDate === null) || // The input has changed from empty to non-empty or vice versa
|
|
1917
|
+
date !== null && lastValidDate !== null && !date.equals(lastValidDate);
|
|
1918
|
+
if (!isValueDifferent) return;
|
|
1914
1919
|
onChange?.({
|
|
1915
|
-
event,
|
|
1916
1920
|
date: date ?? lastValidDate ?? null,
|
|
1917
1921
|
isInputValid,
|
|
1918
1922
|
isInputEmpty
|
|
@@ -1941,13 +1945,13 @@ const MaskedDateInput = forwardRef(
|
|
|
1941
1945
|
value: inputValue,
|
|
1942
1946
|
onChange: handleChange,
|
|
1943
1947
|
prefix: /* @__PURE__ */ jsx(Icon, { svg: SvgEvent }),
|
|
1944
|
-
hint: disableHint ? void 0 : `
|
|
1948
|
+
hint: disableHint ? void 0 : `Format: ${mode}`
|
|
1945
1949
|
}
|
|
1946
1950
|
);
|
|
1947
1951
|
}
|
|
1948
1952
|
);
|
|
1949
1953
|
MaskedDateInput.displayName = "MaskedDateInput";
|
|
1950
|
-
function parseInputValue(value, mode, removePlaceholder) {
|
|
1954
|
+
function parseInputValue$1(value, mode, removePlaceholder) {
|
|
1951
1955
|
const valueMinusPlaceholder = removePlaceholder(value);
|
|
1952
1956
|
const jsDate = maskitoParseDate(valueMinusPlaceholder, { mode });
|
|
1953
1957
|
const luxonDate = jsDate ? DateTime.fromJSDate(jsDate, { zone: "utc" }) : null;
|
|
@@ -1957,11 +1961,11 @@ function parseInputValue(value, mode, removePlaceholder) {
|
|
|
1957
1961
|
isInputEmpty: valueMinusPlaceholder === ""
|
|
1958
1962
|
};
|
|
1959
1963
|
}
|
|
1960
|
-
function swapMode$
|
|
1961
|
-
const { day, month, year } = divideSegments(inputString, previousMode);
|
|
1964
|
+
function swapMode$2(inputString, previousMode, mode) {
|
|
1965
|
+
const { day, month, year } = divideSegments$1(inputString, previousMode);
|
|
1962
1966
|
return orderSegmentsByMode(day, month, year, mode);
|
|
1963
1967
|
}
|
|
1964
|
-
function divideSegments(value, mode) {
|
|
1968
|
+
function divideSegments$1(value, mode) {
|
|
1965
1969
|
const [segment1, segment2, segment3] = value.split("/");
|
|
1966
1970
|
if (mode === "dd/mm/yyyy") {
|
|
1967
1971
|
return { day: segment1, month: segment2, year: segment3 };
|
|
@@ -1984,6 +1988,206 @@ function orderSegmentsByMode(day, month, year, mode) {
|
|
|
1984
1988
|
}
|
|
1985
1989
|
}
|
|
1986
1990
|
|
|
1991
|
+
function containsRelatedTarget(event) {
|
|
1992
|
+
if (event.currentTarget instanceof HTMLElement && event.relatedTarget instanceof HTMLElement) {
|
|
1993
|
+
return event.currentTarget.contains(event.relatedTarget);
|
|
1994
|
+
}
|
|
1995
|
+
return false;
|
|
1996
|
+
}
|
|
1997
|
+
function useFocusWithin({
|
|
1998
|
+
onBlur,
|
|
1999
|
+
onFocus
|
|
2000
|
+
} = {}) {
|
|
2001
|
+
const [focused, setFocused] = useState(false);
|
|
2002
|
+
const focusedRef = useRef(false);
|
|
2003
|
+
const elementRef = useRef(null);
|
|
2004
|
+
const _setFocused = useCallback((value) => {
|
|
2005
|
+
setFocused(value);
|
|
2006
|
+
focusedRef.current = value;
|
|
2007
|
+
}, []);
|
|
2008
|
+
const handleFocusIn = useCallback(
|
|
2009
|
+
(event) => {
|
|
2010
|
+
if (!focusedRef.current) {
|
|
2011
|
+
_setFocused(true);
|
|
2012
|
+
onFocus?.(event);
|
|
2013
|
+
}
|
|
2014
|
+
},
|
|
2015
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2016
|
+
[onFocus]
|
|
2017
|
+
);
|
|
2018
|
+
const handleFocusOut = useCallback(
|
|
2019
|
+
(event) => {
|
|
2020
|
+
if (focusedRef.current && !containsRelatedTarget(event)) {
|
|
2021
|
+
_setFocused(false);
|
|
2022
|
+
onBlur?.(event);
|
|
2023
|
+
}
|
|
2024
|
+
},
|
|
2025
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2026
|
+
[onBlur]
|
|
2027
|
+
);
|
|
2028
|
+
useEffect(() => {
|
|
2029
|
+
const element = elementRef.current;
|
|
2030
|
+
if (!element) {
|
|
2031
|
+
return;
|
|
2032
|
+
}
|
|
2033
|
+
element.addEventListener("focusin", handleFocusIn);
|
|
2034
|
+
element.addEventListener("focusout", handleFocusOut);
|
|
2035
|
+
return () => {
|
|
2036
|
+
element.removeEventListener("focusin", handleFocusIn);
|
|
2037
|
+
element.removeEventListener("focusout", handleFocusOut);
|
|
2038
|
+
};
|
|
2039
|
+
}, [handleFocusIn, handleFocusOut]);
|
|
2040
|
+
return { ref: elementRef, focused };
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
function convertStringToDate(v) {
|
|
2044
|
+
if (v === void 0 || v === null) {
|
|
2045
|
+
return v;
|
|
2046
|
+
}
|
|
2047
|
+
const date = DateTime.fromISO(v, { setZone: true, zone: "utc" }).startOf(
|
|
2048
|
+
"day"
|
|
2049
|
+
);
|
|
2050
|
+
if (date.isValid) {
|
|
2051
|
+
return date;
|
|
2052
|
+
}
|
|
2053
|
+
return null;
|
|
2054
|
+
}
|
|
2055
|
+
function validateDate({
|
|
2056
|
+
date,
|
|
2057
|
+
constraints
|
|
2058
|
+
}) {
|
|
2059
|
+
const { required, unavailable, minDate, maxDate } = constraints;
|
|
2060
|
+
if (!date) {
|
|
2061
|
+
return required ? false : true;
|
|
2062
|
+
}
|
|
2063
|
+
if (unavailable?.dates?.some((d) => d.equals(date))) {
|
|
2064
|
+
return false;
|
|
2065
|
+
}
|
|
2066
|
+
if (unavailable?.daysOfWeek?.includes(date.weekday)) {
|
|
2067
|
+
return false;
|
|
2068
|
+
}
|
|
2069
|
+
if (minDate && date < minDate) {
|
|
2070
|
+
return false;
|
|
2071
|
+
}
|
|
2072
|
+
if (maxDate && date > maxDate) {
|
|
2073
|
+
return false;
|
|
2074
|
+
}
|
|
2075
|
+
return true;
|
|
2076
|
+
}
|
|
2077
|
+
function validateYearlessDate({
|
|
2078
|
+
value,
|
|
2079
|
+
constraints
|
|
2080
|
+
}) {
|
|
2081
|
+
const { required, unavailable, minDate, maxDate } = constraints;
|
|
2082
|
+
if (!value || !value?.day && !value?.month) {
|
|
2083
|
+
return required ? false : true;
|
|
2084
|
+
}
|
|
2085
|
+
if (value.day === null || value.month === null) {
|
|
2086
|
+
return false;
|
|
2087
|
+
}
|
|
2088
|
+
if (unavailable?.dates?.some(
|
|
2089
|
+
(d) => d.day === value.day && d.month === value.month
|
|
2090
|
+
)) {
|
|
2091
|
+
return false;
|
|
2092
|
+
}
|
|
2093
|
+
const minDateMonth = minDate?.month ?? 1;
|
|
2094
|
+
const minDateDay = minDate?.day ?? 1;
|
|
2095
|
+
const maxDateMonth = maxDate?.month ?? 12;
|
|
2096
|
+
const maxDateDay = maxDate?.day ?? 31;
|
|
2097
|
+
if (value.month < minDateMonth || // Earlier month
|
|
2098
|
+
value.month === minDateMonth && value.day < minDateDay) {
|
|
2099
|
+
return false;
|
|
2100
|
+
}
|
|
2101
|
+
if (value.month > maxDateMonth || // Later month
|
|
2102
|
+
value.month === maxDateMonth && value.day > maxDateDay) {
|
|
2103
|
+
return false;
|
|
2104
|
+
}
|
|
2105
|
+
return true;
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
function useDateFieldSingleConversion({
|
|
2109
|
+
value,
|
|
2110
|
+
defaultValue,
|
|
2111
|
+
minDate,
|
|
2112
|
+
maxDate,
|
|
2113
|
+
unavailable,
|
|
2114
|
+
onChange
|
|
2115
|
+
}) {
|
|
2116
|
+
const normalizedValue = useMemo(() => convertStringToDate(value), [value]);
|
|
2117
|
+
const normalizedDefaultValue = useMemo(
|
|
2118
|
+
() => convertStringToDate(defaultValue),
|
|
2119
|
+
[defaultValue]
|
|
2120
|
+
);
|
|
2121
|
+
const normalizedMinDate = useMemo(
|
|
2122
|
+
() => convertStringToDate(minDate),
|
|
2123
|
+
[minDate]
|
|
2124
|
+
);
|
|
2125
|
+
const normalizedMaxDate = useMemo(
|
|
2126
|
+
() => convertStringToDate(maxDate),
|
|
2127
|
+
[maxDate]
|
|
2128
|
+
);
|
|
2129
|
+
const normalizedUnavailableDates = useMemo(
|
|
2130
|
+
() => unavailable?.dates?.map((d) => convertStringToDate(d)).filter((d) => d !== null && d !== void 0),
|
|
2131
|
+
[unavailable?.dates]
|
|
2132
|
+
);
|
|
2133
|
+
const handleChange = useCallback(
|
|
2134
|
+
(change) => {
|
|
2135
|
+
onChange?.({
|
|
2136
|
+
...change,
|
|
2137
|
+
date: change.date?.toISODate() ?? null
|
|
2138
|
+
});
|
|
2139
|
+
},
|
|
2140
|
+
[onChange]
|
|
2141
|
+
);
|
|
2142
|
+
return {
|
|
2143
|
+
value: normalizedValue,
|
|
2144
|
+
defaultValue: normalizedDefaultValue,
|
|
2145
|
+
minDate: normalizedMinDate,
|
|
2146
|
+
maxDate: normalizedMaxDate,
|
|
2147
|
+
unavailable: {
|
|
2148
|
+
dates: normalizedUnavailableDates,
|
|
2149
|
+
daysOfWeek: unavailable?.daysOfWeek
|
|
2150
|
+
},
|
|
2151
|
+
onChange: handleChange
|
|
2152
|
+
};
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
function DateFieldSingleCalendar({
|
|
2156
|
+
onKeyDown,
|
|
2157
|
+
value,
|
|
2158
|
+
onSelection,
|
|
2159
|
+
minDate,
|
|
2160
|
+
maxDate,
|
|
2161
|
+
unavailable,
|
|
2162
|
+
...rest
|
|
2163
|
+
}) {
|
|
2164
|
+
const handleCalendarSelection = (data) => {
|
|
2165
|
+
if (data.value) {
|
|
2166
|
+
const date = DateTime.fromISO(data.value, { zone: "utc" });
|
|
2167
|
+
onSelection(date);
|
|
2168
|
+
}
|
|
2169
|
+
};
|
|
2170
|
+
return /* @__PURE__ */ jsx(
|
|
2171
|
+
Calendar,
|
|
2172
|
+
{
|
|
2173
|
+
...rest,
|
|
2174
|
+
range: false,
|
|
2175
|
+
onKeyDown,
|
|
2176
|
+
defaultFocusedDate: value?.toISODate() || DateTime.now().toISODate(),
|
|
2177
|
+
value: value?.toISODate() || void 0,
|
|
2178
|
+
onSelection: handleCalendarSelection,
|
|
2179
|
+
defaultTimeZone: "UTC",
|
|
2180
|
+
minDate: minDate?.toISODate() ?? void 0,
|
|
2181
|
+
maxDate: maxDate?.toISODate() ?? void 0,
|
|
2182
|
+
unavailable: unavailable ? {
|
|
2183
|
+
dates: unavailable.dates?.map((d) => d.toISODate() ?? ""),
|
|
2184
|
+
daysOfWeek: unavailable.daysOfWeek
|
|
2185
|
+
} : void 0,
|
|
2186
|
+
_disableAutofocus: true
|
|
2187
|
+
}
|
|
2188
|
+
);
|
|
2189
|
+
}
|
|
2190
|
+
|
|
1987
2191
|
const useDateFieldOrchestration = ({
|
|
1988
2192
|
inputRef,
|
|
1989
2193
|
calendarDefaultOpen,
|
|
@@ -2070,330 +2274,172 @@ const useDateFieldOrchestration = ({
|
|
|
2070
2274
|
};
|
|
2071
2275
|
};
|
|
2072
2276
|
|
|
2073
|
-
function
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
"day"
|
|
2079
|
-
);
|
|
2080
|
-
if (date.isValid) {
|
|
2081
|
-
return date;
|
|
2082
|
-
}
|
|
2083
|
-
return null;
|
|
2084
|
-
}
|
|
2085
|
-
function validateDate({
|
|
2086
|
-
date,
|
|
2087
|
-
constraints
|
|
2277
|
+
function useDateFieldSingleState({
|
|
2278
|
+
valueProp,
|
|
2279
|
+
defaultValueProp,
|
|
2280
|
+
inputRef,
|
|
2281
|
+
onChange
|
|
2088
2282
|
}) {
|
|
2089
|
-
const
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
}
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2283
|
+
const [value, setValue] = useOptionallyControlledState({
|
|
2284
|
+
controlledValue: valueProp,
|
|
2285
|
+
defaultValue: defaultValueProp
|
|
2286
|
+
});
|
|
2287
|
+
const setSharedValue = (date) => {
|
|
2288
|
+
inputRef.current?.setDate(date);
|
|
2289
|
+
setValue(date);
|
|
2290
|
+
};
|
|
2291
|
+
const handleInputChange = (change) => {
|
|
2292
|
+
const date = change.isInputEmpty ? null : change.date?.startOf("day") ?? null;
|
|
2293
|
+
onChange?.({
|
|
2294
|
+
date,
|
|
2295
|
+
isInputValid: change.isInputValid,
|
|
2296
|
+
isInputEmpty: change.isInputEmpty
|
|
2297
|
+
});
|
|
2298
|
+
if (change.isInputValid) {
|
|
2299
|
+
setSharedValue(change.isInputEmpty ? null : change.date);
|
|
2300
|
+
}
|
|
2301
|
+
if (change.isInputEmpty) {
|
|
2302
|
+
setSharedValue(null);
|
|
2303
|
+
return;
|
|
2304
|
+
}
|
|
2305
|
+
if (change.date) {
|
|
2306
|
+
setSharedValue(change.date);
|
|
2307
|
+
}
|
|
2308
|
+
};
|
|
2309
|
+
const handleCalendarSelection = (date) => {
|
|
2310
|
+
setSharedValue(date);
|
|
2311
|
+
onChange?.({
|
|
2312
|
+
date,
|
|
2313
|
+
isInputValid: true,
|
|
2314
|
+
isInputEmpty: false
|
|
2315
|
+
});
|
|
2316
|
+
};
|
|
2317
|
+
return {
|
|
2318
|
+
value,
|
|
2319
|
+
setValue: setSharedValue,
|
|
2320
|
+
handleInputChange,
|
|
2321
|
+
handleCalendarSelection
|
|
2322
|
+
};
|
|
2106
2323
|
}
|
|
2107
2324
|
|
|
2108
|
-
const
|
|
2109
|
-
|
|
2325
|
+
const DateFieldSingle = ({
|
|
2326
|
+
onFocus,
|
|
2327
|
+
onBlur,
|
|
2328
|
+
disableCalendar,
|
|
2329
|
+
required,
|
|
2330
|
+
mode,
|
|
2331
|
+
...rest
|
|
2332
|
+
}) => {
|
|
2333
|
+
const inputRef = useRef(null);
|
|
2334
|
+
const {
|
|
2110
2335
|
value: valueProp,
|
|
2111
|
-
mode = "mm/dd/yyyy",
|
|
2112
2336
|
defaultValue: defaultValueProp,
|
|
2113
|
-
onChange,
|
|
2114
|
-
disableCalendar = false,
|
|
2115
|
-
unavailable,
|
|
2116
2337
|
minDate,
|
|
2117
2338
|
maxDate,
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
const combinedRef = useMergeRefs([popoverTriggerRef, inputRef, ref]);
|
|
2127
|
-
const {
|
|
2128
|
-
calendarOpen,
|
|
2129
|
-
setCalendarOpen,
|
|
2130
|
-
handleCalendarKeyDown,
|
|
2131
|
-
handleInputKeyDown
|
|
2132
|
-
} = useDateFieldOrchestration({
|
|
2133
|
-
inputRef,
|
|
2134
|
-
calendarDefaultOpen: false,
|
|
2135
|
-
popoverContentRef,
|
|
2136
|
-
disableCalendar
|
|
2137
|
-
});
|
|
2138
|
-
const [lastValidDate, setLastValidDate] = useOptionallyControlledState({
|
|
2139
|
-
controlledValue: valueProp,
|
|
2140
|
-
defaultValue: defaultValueProp
|
|
2141
|
-
});
|
|
2142
|
-
const popoverSupported = usePopoverSupport();
|
|
2143
|
-
const shouldShowCalendar = usePopoverCloseDelayWorkaround(calendarOpen);
|
|
2144
|
-
const currentValidity = useMemo(
|
|
2145
|
-
() => validateDate({
|
|
2146
|
-
date: lastValidDate,
|
|
2339
|
+
unavailable,
|
|
2340
|
+
onChange
|
|
2341
|
+
} = useDateFieldSingleConversion(rest);
|
|
2342
|
+
const handleChange = (change) => {
|
|
2343
|
+
onChange?.({
|
|
2344
|
+
...change,
|
|
2345
|
+
isDateValid: validateDate({
|
|
2346
|
+
date: change.date,
|
|
2147
2347
|
constraints: {
|
|
2148
2348
|
required,
|
|
2149
2349
|
unavailable,
|
|
2150
2350
|
minDate: minDate ?? void 0,
|
|
2151
2351
|
maxDate: maxDate ?? void 0
|
|
2152
2352
|
}
|
|
2153
|
-
})
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
setLastValidDate(date);
|
|
2187
|
-
inputRef.current?.setDate(date);
|
|
2188
|
-
onChange?.({
|
|
2189
|
-
date: date.toISODate(),
|
|
2190
|
-
isInputValid: true,
|
|
2191
|
-
isInputEmpty: false,
|
|
2192
|
-
isDateValid: validateDate({
|
|
2193
|
-
date,
|
|
2194
|
-
constraints: {
|
|
2195
|
-
required,
|
|
2196
|
-
unavailable,
|
|
2197
|
-
minDate: minDate ?? void 0,
|
|
2198
|
-
maxDate: maxDate ?? void 0
|
|
2199
|
-
}
|
|
2200
|
-
})
|
|
2201
|
-
});
|
|
2202
|
-
}
|
|
2203
|
-
};
|
|
2204
|
-
const justTheField = /* @__PURE__ */ jsx(
|
|
2205
|
-
MaskedDateInput,
|
|
2206
|
-
{
|
|
2207
|
-
mode,
|
|
2208
|
-
ref: combinedRef,
|
|
2209
|
-
...rest,
|
|
2210
|
-
onChange: handleInputChange,
|
|
2211
|
-
onKeyDown: handleInputKeyDown,
|
|
2212
|
-
onClick: () => setCalendarOpen(true),
|
|
2213
|
-
lastValidDate,
|
|
2353
|
+
})
|
|
2354
|
+
});
|
|
2355
|
+
};
|
|
2356
|
+
const { value, handleInputChange, handleCalendarSelection } = useDateFieldSingleState({
|
|
2357
|
+
valueProp,
|
|
2358
|
+
defaultValueProp,
|
|
2359
|
+
inputRef,
|
|
2360
|
+
onChange: handleChange
|
|
2361
|
+
});
|
|
2362
|
+
const { ref: wrapperRef } = useFocusWithin({
|
|
2363
|
+
onBlur,
|
|
2364
|
+
onFocus
|
|
2365
|
+
});
|
|
2366
|
+
const [popoverTriggerRef, setPopoverTriggerRef] = useState();
|
|
2367
|
+
const popoverContentRef = useRef(null);
|
|
2368
|
+
const combinedRef = useMergeRefs([popoverTriggerRef, inputRef]);
|
|
2369
|
+
const {
|
|
2370
|
+
calendarOpen,
|
|
2371
|
+
setCalendarOpen,
|
|
2372
|
+
handleCalendarKeyDown,
|
|
2373
|
+
handleInputKeyDown
|
|
2374
|
+
} = useDateFieldOrchestration({
|
|
2375
|
+
inputRef,
|
|
2376
|
+
calendarDefaultOpen: false,
|
|
2377
|
+
popoverContentRef,
|
|
2378
|
+
disableCalendar
|
|
2379
|
+
});
|
|
2380
|
+
const popoverSupported = usePopoverSupport();
|
|
2381
|
+
const shouldShowCalendar = usePopoverCloseDelayWorkaround(calendarOpen);
|
|
2382
|
+
const currentValidity = useMemo(
|
|
2383
|
+
() => validateDate({
|
|
2384
|
+
date: value,
|
|
2385
|
+
constraints: {
|
|
2214
2386
|
required,
|
|
2215
|
-
|
|
2216
|
-
|
|
2387
|
+
unavailable,
|
|
2388
|
+
minDate: minDate ?? void 0,
|
|
2389
|
+
maxDate: maxDate ?? void 0
|
|
2217
2390
|
}
|
|
2218
|
-
)
|
|
2219
|
-
|
|
2220
|
-
return justTheField;
|
|
2221
|
-
}
|
|
2222
|
-
if (!popoverSupported) {
|
|
2223
|
-
return justTheField;
|
|
2224
|
-
}
|
|
2225
|
-
return /* @__PURE__ */ jsxs(
|
|
2226
|
-
Popover,
|
|
2227
|
-
{
|
|
2228
|
-
open: calendarOpen,
|
|
2229
|
-
modal: true,
|
|
2230
|
-
placement: "bottom-start",
|
|
2231
|
-
disableFlipFallback: true,
|
|
2232
|
-
disableTriggerFocus: true,
|
|
2233
|
-
onClose: () => setCalendarOpen(false),
|
|
2234
|
-
disableAutoUpdate: true,
|
|
2235
|
-
onClickOutside: () => setCalendarOpen(false),
|
|
2236
|
-
children: [
|
|
2237
|
-
/* @__PURE__ */ jsx(Popover.Trigger, { children: ({ ref: iRef }) => {
|
|
2238
|
-
setPopoverTriggerRef(iRef);
|
|
2239
|
-
return justTheField;
|
|
2240
|
-
} }),
|
|
2241
|
-
/* @__PURE__ */ jsx(Popover.Content, { ref: popoverContentRef, "data-testid": "calendar-popover", children: shouldShowCalendar && /* @__PURE__ */ jsx(
|
|
2242
|
-
Calendar,
|
|
2243
|
-
{
|
|
2244
|
-
range: false,
|
|
2245
|
-
onKeyDown: handleCalendarKeyDown,
|
|
2246
|
-
defaultFocusedDate: lastValidDate?.toISODate() || DateTime.now().toISODate(),
|
|
2247
|
-
value: lastValidDate?.toISODate() || void 0,
|
|
2248
|
-
onSelection: handleCalendarSelection,
|
|
2249
|
-
defaultTimeZone: "UTC",
|
|
2250
|
-
minDate: minDate?.toISODate() ?? void 0,
|
|
2251
|
-
maxDate: maxDate?.toISODate() ?? void 0,
|
|
2252
|
-
unavailable: unavailable ? {
|
|
2253
|
-
dates: unavailable.dates?.map((d) => d.toISODate() ?? ""),
|
|
2254
|
-
daysOfWeek: unavailable.daysOfWeek
|
|
2255
|
-
} : void 0,
|
|
2256
|
-
_disableAutofocus: true
|
|
2257
|
-
}
|
|
2258
|
-
) })
|
|
2259
|
-
]
|
|
2260
|
-
}
|
|
2261
|
-
);
|
|
2262
|
-
}
|
|
2263
|
-
);
|
|
2264
|
-
NormalizedDateFieldSingle.displayName = "NormalizedDateFieldSingle";
|
|
2265
|
-
|
|
2266
|
-
function containsRelatedTarget(event) {
|
|
2267
|
-
if (event.currentTarget instanceof HTMLElement && event.relatedTarget instanceof HTMLElement) {
|
|
2268
|
-
return event.currentTarget.contains(event.relatedTarget);
|
|
2269
|
-
}
|
|
2270
|
-
return false;
|
|
2271
|
-
}
|
|
2272
|
-
function useFocusWithin({
|
|
2273
|
-
onBlur,
|
|
2274
|
-
onFocus
|
|
2275
|
-
} = {}) {
|
|
2276
|
-
const [focused, setFocused] = useState(false);
|
|
2277
|
-
const focusedRef = useRef(false);
|
|
2278
|
-
const elementRef = useRef(null);
|
|
2279
|
-
const _setFocused = useCallback((value) => {
|
|
2280
|
-
setFocused(value);
|
|
2281
|
-
focusedRef.current = value;
|
|
2282
|
-
}, []);
|
|
2283
|
-
const handleFocusIn = useCallback(
|
|
2284
|
-
(event) => {
|
|
2285
|
-
if (!focusedRef.current) {
|
|
2286
|
-
_setFocused(true);
|
|
2287
|
-
onFocus?.(event);
|
|
2288
|
-
}
|
|
2289
|
-
},
|
|
2290
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2291
|
-
[onFocus]
|
|
2391
|
+
}),
|
|
2392
|
+
[value, required, unavailable, minDate, maxDate]
|
|
2292
2393
|
);
|
|
2293
|
-
const
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
return;
|
|
2394
|
+
const justTheField = /* @__PURE__ */ jsx(
|
|
2395
|
+
MaskedDateInput,
|
|
2396
|
+
{
|
|
2397
|
+
mode,
|
|
2398
|
+
ref: combinedRef,
|
|
2399
|
+
...rest,
|
|
2400
|
+
onChange: handleInputChange,
|
|
2401
|
+
onKeyDown: handleInputKeyDown,
|
|
2402
|
+
onClick: () => setCalendarOpen(true),
|
|
2403
|
+
lastValidDate: value,
|
|
2404
|
+
required,
|
|
2405
|
+
autoComplete: "off",
|
|
2406
|
+
"data-date-valid": currentValidity
|
|
2307
2407
|
}
|
|
2308
|
-
element.addEventListener("focusin", handleFocusIn);
|
|
2309
|
-
element.addEventListener("focusout", handleFocusOut);
|
|
2310
|
-
return () => {
|
|
2311
|
-
element.removeEventListener("focusin", handleFocusIn);
|
|
2312
|
-
element.removeEventListener("focusout", handleFocusOut);
|
|
2313
|
-
};
|
|
2314
|
-
}, [handleFocusIn, handleFocusOut]);
|
|
2315
|
-
return { ref: elementRef, focused };
|
|
2316
|
-
}
|
|
2317
|
-
|
|
2318
|
-
const useConditionalChange = ({
|
|
2319
|
-
changeHandler,
|
|
2320
|
-
compareFn
|
|
2321
|
-
}) => {
|
|
2322
|
-
const lastChangeRef = useRef(null);
|
|
2323
|
-
const onChange = useCallback(
|
|
2324
|
-
(change) => {
|
|
2325
|
-
if (!!lastChangeRef.current && !compareFn(lastChangeRef.current, change)) {
|
|
2326
|
-
return;
|
|
2327
|
-
}
|
|
2328
|
-
changeHandler?.(change);
|
|
2329
|
-
lastChangeRef.current = change;
|
|
2330
|
-
},
|
|
2331
|
-
[changeHandler, compareFn]
|
|
2332
|
-
);
|
|
2333
|
-
return onChange;
|
|
2334
|
-
};
|
|
2335
|
-
|
|
2336
|
-
const DateFieldSingle = ({
|
|
2337
|
-
value,
|
|
2338
|
-
defaultValue,
|
|
2339
|
-
minDate,
|
|
2340
|
-
maxDate,
|
|
2341
|
-
unavailable,
|
|
2342
|
-
onChange,
|
|
2343
|
-
onFocus,
|
|
2344
|
-
onBlur,
|
|
2345
|
-
...rest
|
|
2346
|
-
}) => {
|
|
2347
|
-
const handleBlur = useCallback(
|
|
2348
|
-
(event) => {
|
|
2349
|
-
onBlur?.(event);
|
|
2350
|
-
},
|
|
2351
|
-
[onBlur]
|
|
2352
|
-
);
|
|
2353
|
-
const handleFocus = useCallback(
|
|
2354
|
-
(event) => {
|
|
2355
|
-
onFocus?.(event);
|
|
2356
|
-
},
|
|
2357
|
-
[onFocus]
|
|
2358
|
-
);
|
|
2359
|
-
const { ref: wrapperRef } = useFocusWithin({
|
|
2360
|
-
onBlur: handleBlur,
|
|
2361
|
-
onFocus: handleFocus
|
|
2362
|
-
});
|
|
2363
|
-
const normalizedValue = useMemo(() => convertStringToDate(value), [value]);
|
|
2364
|
-
const normalizedDefaultValue = useMemo(
|
|
2365
|
-
() => convertStringToDate(defaultValue),
|
|
2366
|
-
[defaultValue]
|
|
2367
|
-
);
|
|
2368
|
-
const normalizedMinDate = useMemo(
|
|
2369
|
-
() => convertStringToDate(minDate),
|
|
2370
|
-
[minDate]
|
|
2371
|
-
);
|
|
2372
|
-
const normalizedMaxDate = useMemo(
|
|
2373
|
-
() => convertStringToDate(maxDate),
|
|
2374
|
-
[maxDate]
|
|
2375
|
-
);
|
|
2376
|
-
const normalizedUnavailableDates = useMemo(
|
|
2377
|
-
() => unavailable?.dates?.map((d) => convertStringToDate(d)).filter((d) => d !== null && d !== void 0),
|
|
2378
|
-
[unavailable?.dates]
|
|
2379
2408
|
);
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2409
|
+
if (disableCalendar) {
|
|
2410
|
+
return justTheField;
|
|
2411
|
+
}
|
|
2412
|
+
if (!popoverSupported) {
|
|
2413
|
+
return justTheField;
|
|
2414
|
+
}
|
|
2415
|
+
return /* @__PURE__ */ jsx("div", { ref: wrapperRef, children: /* @__PURE__ */ jsxs(
|
|
2416
|
+
Popover,
|
|
2386
2417
|
{
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2418
|
+
open: calendarOpen,
|
|
2419
|
+
modal: true,
|
|
2420
|
+
placement: "bottom-start",
|
|
2421
|
+
disableFlipFallback: true,
|
|
2422
|
+
disableTriggerFocus: true,
|
|
2423
|
+
onClose: () => setCalendarOpen(false),
|
|
2424
|
+
disableAutoUpdate: true,
|
|
2425
|
+
onClickOutside: () => setCalendarOpen(false),
|
|
2426
|
+
children: [
|
|
2427
|
+
/* @__PURE__ */ jsx(Popover.Trigger, { children: ({ ref: iRef }) => {
|
|
2428
|
+
setPopoverTriggerRef(iRef);
|
|
2429
|
+
return justTheField;
|
|
2430
|
+
} }),
|
|
2431
|
+
/* @__PURE__ */ jsx(Popover.Content, { ref: popoverContentRef, "data-testid": "calendar-popover", children: shouldShowCalendar && /* @__PURE__ */ jsx(
|
|
2432
|
+
DateFieldSingleCalendar,
|
|
2433
|
+
{
|
|
2434
|
+
onKeyDown: handleCalendarKeyDown,
|
|
2435
|
+
value,
|
|
2436
|
+
onSelection: handleCalendarSelection,
|
|
2437
|
+
minDate,
|
|
2438
|
+
maxDate,
|
|
2439
|
+
unavailable
|
|
2440
|
+
}
|
|
2441
|
+
) })
|
|
2442
|
+
]
|
|
2397
2443
|
}
|
|
2398
2444
|
) });
|
|
2399
2445
|
};
|
|
@@ -2458,7 +2504,7 @@ const MaskedDateRangeInput = forwardRef(
|
|
|
2458
2504
|
useEffect(() => {
|
|
2459
2505
|
if (mode !== previousMode) {
|
|
2460
2506
|
setInputValue(
|
|
2461
|
-
(previousInputValue) => swapMode(previousInputValue, previousMode ?? mode, mode)
|
|
2507
|
+
(previousInputValue) => swapMode$1(previousInputValue, previousMode ?? mode, mode)
|
|
2462
2508
|
);
|
|
2463
2509
|
}
|
|
2464
2510
|
}, [mode, fullPlaceholder, previousMode]);
|
|
@@ -2483,6 +2529,9 @@ const MaskedDateRangeInput = forwardRef(
|
|
|
2483
2529
|
previousStartDate,
|
|
2484
2530
|
previousEndDate
|
|
2485
2531
|
]);
|
|
2532
|
+
const currentParsedData = useMemo(() => {
|
|
2533
|
+
return parseRangeInputValue(inputValue, mode, removePlaceholder);
|
|
2534
|
+
}, [inputValue, mode, removePlaceholder]);
|
|
2486
2535
|
const handleChange = (event) => {
|
|
2487
2536
|
setInputValue(event.target.value);
|
|
2488
2537
|
const {
|
|
@@ -2492,17 +2541,20 @@ const MaskedDateRangeInput = forwardRef(
|
|
|
2492
2541
|
isInputEmpty,
|
|
2493
2542
|
isHalfEmpty
|
|
2494
2543
|
} = parseRangeInputValue(event.target.value, mode, removePlaceholder);
|
|
2544
|
+
const isValueDifferent = isInputValid !== currentParsedData.isInputValid || // The input has changed validity
|
|
2545
|
+
isInputEmpty !== currentParsedData.isInputEmpty || // The input has changed emptiness
|
|
2546
|
+
parsedStartDate === null !== (startDate === null) || // The start date has changed from empty to non-empty or vice versa
|
|
2547
|
+
parsedEndDate === null !== (endDate === null) || // The end date has changed from empty to non-empty or vice versa
|
|
2548
|
+
parsedStartDate !== null && startDate !== null && !parsedStartDate.equals(startDate) || // The start date has changed
|
|
2549
|
+
parsedEndDate !== null && endDate !== null && !parsedEndDate.equals(endDate);
|
|
2550
|
+
if (!isValueDifferent) return;
|
|
2495
2551
|
onChange?.({
|
|
2496
|
-
event,
|
|
2497
2552
|
startDate: isInputEmpty ? null : parsedStartDate ?? startDate ?? null,
|
|
2498
2553
|
endDate: isInputEmpty || isHalfEmpty ? null : parsedEndDate ?? endDate ?? null,
|
|
2499
2554
|
isInputValid,
|
|
2500
2555
|
isInputEmpty
|
|
2501
2556
|
});
|
|
2502
2557
|
};
|
|
2503
|
-
const currentParsedData = useMemo(() => {
|
|
2504
|
-
return parseRangeInputValue(inputValue, mode, removePlaceholder);
|
|
2505
|
-
}, [inputValue, mode, removePlaceholder]);
|
|
2506
2558
|
useImperativeHandle(ref, () => {
|
|
2507
2559
|
const input = inputRef.current;
|
|
2508
2560
|
if (!input) return null;
|
|
@@ -2530,7 +2582,7 @@ const MaskedDateRangeInput = forwardRef(
|
|
|
2530
2582
|
value: inputValue,
|
|
2531
2583
|
onChange: handleChange,
|
|
2532
2584
|
prefix: /* @__PURE__ */ jsx(Icon, { svg: SvgEvent }),
|
|
2533
|
-
hint: disableHint ? void 0 : `
|
|
2585
|
+
hint: disableHint ? void 0 : `Format: ${mode}`
|
|
2534
2586
|
}
|
|
2535
2587
|
);
|
|
2536
2588
|
}
|
|
@@ -2553,7 +2605,7 @@ function parseRangeInputValue(value, mode, removePlaceholder) {
|
|
|
2553
2605
|
isHalfEmpty: endDate === void 0
|
|
2554
2606
|
};
|
|
2555
2607
|
}
|
|
2556
|
-
function swapMode(inputString, previousMode, mode) {
|
|
2608
|
+
function swapMode$1(inputString, previousMode, mode) {
|
|
2557
2609
|
const halves = inputString.split(RANGE_SEPARATOR);
|
|
2558
2610
|
const segments = halves.map((half) => half.split("/"));
|
|
2559
2611
|
let startDay, startMonth, startYear, endDay, endMonth, endYear;
|
|
@@ -2593,202 +2645,299 @@ function swapMode(inputString, previousMode, mode) {
|
|
|
2593
2645
|
return inputString;
|
|
2594
2646
|
}
|
|
2595
2647
|
|
|
2596
|
-
const
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
const previousEndDate = usePrevious(endDate);
|
|
2627
|
-
const popoverSupported = usePopoverSupport();
|
|
2628
|
-
const {
|
|
2629
|
-
calendarOpen,
|
|
2630
|
-
setCalendarOpen,
|
|
2631
|
-
handleCalendarKeyDown,
|
|
2632
|
-
handleInputKeyDown
|
|
2633
|
-
} = useDateFieldOrchestration({
|
|
2634
|
-
inputRef,
|
|
2635
|
-
calendarDefaultOpen: false,
|
|
2636
|
-
popoverContentRef,
|
|
2637
|
-
disableCalendar
|
|
2638
|
-
});
|
|
2639
|
-
const shouldShowCalendar = usePopoverCloseDelayWorkaround(calendarOpen);
|
|
2640
|
-
const isDateRangeValid = useMemo(() => {
|
|
2641
|
-
return validateDate({
|
|
2642
|
-
date: startDate ?? null,
|
|
2643
|
-
constraints: {
|
|
2644
|
-
required,
|
|
2645
|
-
unavailable,
|
|
2646
|
-
minDate: minDate ?? void 0,
|
|
2647
|
-
maxDate: maxDate ?? void 0
|
|
2648
|
-
}
|
|
2649
|
-
}) && validateDate({
|
|
2650
|
-
date: endDate ?? null,
|
|
2651
|
-
constraints: {
|
|
2652
|
-
required,
|
|
2653
|
-
unavailable,
|
|
2654
|
-
minDate: minDate ?? void 0,
|
|
2655
|
-
maxDate: maxDate ?? void 0
|
|
2656
|
-
}
|
|
2657
|
-
}) && (!startDate || !endDate || startDate <= endDate);
|
|
2658
|
-
}, [required, unavailable, minDate, maxDate, startDate, endDate]);
|
|
2659
|
-
const defaultFocusedDate = useMemo(() => {
|
|
2660
|
-
if (!startDate && !endDate) return DateTime.now().toISODate();
|
|
2661
|
-
if (!startDate) return endDate?.toISODate();
|
|
2662
|
-
if (!endDate) return startDate?.toISODate();
|
|
2663
|
-
if (endDate && !previousEndDate?.equals(endDate)) {
|
|
2664
|
-
return endDate.toISODate();
|
|
2665
|
-
} else if (startDate && !previousStartDate?.equals(startDate)) {
|
|
2666
|
-
return startDate.toISODate();
|
|
2667
|
-
}
|
|
2668
|
-
if (endDate) return endDate.toISODate();
|
|
2669
|
-
if (startDate) return startDate.toISODate();
|
|
2670
|
-
return DateTime.now().toISODate();
|
|
2671
|
-
}, [previousStartDate, previousEndDate, startDate, endDate]);
|
|
2672
|
-
const handleInputChange = (change) => {
|
|
2673
|
-
const sharedConstraints = {
|
|
2674
|
-
unavailable,
|
|
2675
|
-
minDate: minDate ?? void 0,
|
|
2676
|
-
maxDate: maxDate ?? void 0
|
|
2677
|
-
};
|
|
2678
|
-
const range = change.isInputEmpty ? null : {
|
|
2679
|
-
startDate: change.startDate?.startOf("day") ?? null,
|
|
2680
|
-
endDate: change.endDate?.startOf("day") ?? null
|
|
2681
|
-
};
|
|
2682
|
-
setStartDate(range?.startDate ?? null);
|
|
2683
|
-
setEndDate(range?.endDate ?? null);
|
|
2648
|
+
const useDateFieldRangeConversion = (props) => {
|
|
2649
|
+
const { value, defaultValue, minDate, maxDate, unavailable, onChange } = props;
|
|
2650
|
+
const normalizedValue = useMemo(() => {
|
|
2651
|
+
if (value === null || value === void 0) return value;
|
|
2652
|
+
return {
|
|
2653
|
+
startDate: convertStringToDate(value.startDate) ?? null,
|
|
2654
|
+
endDate: convertStringToDate(value.endDate) ?? null
|
|
2655
|
+
};
|
|
2656
|
+
}, [value]);
|
|
2657
|
+
const normalizedDefaultValue = useMemo(() => {
|
|
2658
|
+
if (defaultValue === null || defaultValue === void 0)
|
|
2659
|
+
return defaultValue;
|
|
2660
|
+
return {
|
|
2661
|
+
startDate: convertStringToDate(defaultValue.startDate) ?? null,
|
|
2662
|
+
endDate: convertStringToDate(defaultValue.endDate) ?? null
|
|
2663
|
+
};
|
|
2664
|
+
}, [defaultValue]);
|
|
2665
|
+
const normalizedMinDate = useMemo(
|
|
2666
|
+
() => convertStringToDate(minDate),
|
|
2667
|
+
[minDate]
|
|
2668
|
+
);
|
|
2669
|
+
const normalizedMaxDate = useMemo(
|
|
2670
|
+
() => convertStringToDate(maxDate),
|
|
2671
|
+
[maxDate]
|
|
2672
|
+
);
|
|
2673
|
+
const normalizedUnavailableDates = useMemo(() => {
|
|
2674
|
+
return unavailable?.dates?.map((date) => convertStringToDate(date)).filter((date) => date !== null && date !== void 0);
|
|
2675
|
+
}, [unavailable?.dates]);
|
|
2676
|
+
const handleChange = useCallback(
|
|
2677
|
+
(change) => {
|
|
2684
2678
|
onChange?.({
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
isInputEmpty: change.isInputEmpty,
|
|
2689
|
-
isDateRangeValid: validateDateRange({
|
|
2690
|
-
required,
|
|
2691
|
-
startDate: range?.startDate ?? null,
|
|
2692
|
-
endDate: range?.endDate ?? null,
|
|
2693
|
-
startDateConstraints: sharedConstraints,
|
|
2694
|
-
endDateConstraints: sharedConstraints
|
|
2695
|
-
})
|
|
2679
|
+
...change,
|
|
2680
|
+
startDate: change.startDate?.toISODate() ?? null,
|
|
2681
|
+
endDate: change.endDate?.toISODate() ?? null
|
|
2696
2682
|
});
|
|
2683
|
+
},
|
|
2684
|
+
[onChange]
|
|
2685
|
+
);
|
|
2686
|
+
return {
|
|
2687
|
+
value: normalizedValue,
|
|
2688
|
+
defaultValue: normalizedDefaultValue,
|
|
2689
|
+
minDate: normalizedMinDate,
|
|
2690
|
+
maxDate: normalizedMaxDate,
|
|
2691
|
+
unavailable: {
|
|
2692
|
+
dates: normalizedUnavailableDates,
|
|
2693
|
+
daysOfWeek: unavailable?.daysOfWeek
|
|
2694
|
+
},
|
|
2695
|
+
onChange: handleChange
|
|
2696
|
+
};
|
|
2697
|
+
};
|
|
2698
|
+
|
|
2699
|
+
function useDateFieldRangeState({
|
|
2700
|
+
valueProp,
|
|
2701
|
+
defaultValueProp,
|
|
2702
|
+
inputRef,
|
|
2703
|
+
onChange
|
|
2704
|
+
}) {
|
|
2705
|
+
const [startDate, setStartDate] = useOptionallyControlledState({
|
|
2706
|
+
controlledValue: valueProp !== void 0 ? valueProp?.startDate : void 0,
|
|
2707
|
+
defaultValue: defaultValueProp !== void 0 ? defaultValueProp?.startDate : void 0
|
|
2708
|
+
});
|
|
2709
|
+
const [endDate, setEndDate] = useOptionallyControlledState({
|
|
2710
|
+
controlledValue: valueProp !== void 0 ? valueProp?.endDate : void 0,
|
|
2711
|
+
defaultValue: defaultValueProp !== void 0 ? defaultValueProp?.endDate : void 0
|
|
2712
|
+
});
|
|
2713
|
+
const setSharedValue = (value) => {
|
|
2714
|
+
inputRef.current?.setDateRange(value.startDate, value.endDate);
|
|
2715
|
+
setStartDate(value.startDate);
|
|
2716
|
+
setEndDate(value.endDate);
|
|
2717
|
+
};
|
|
2718
|
+
const handleInputChange = (change) => {
|
|
2719
|
+
const range = change.isInputEmpty ? null : {
|
|
2720
|
+
startDate: change.startDate?.startOf("day") ?? null,
|
|
2721
|
+
endDate: change.endDate?.startOf("day") ?? null
|
|
2697
2722
|
};
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2723
|
+
setStartDate(range?.startDate ?? null);
|
|
2724
|
+
setEndDate(range?.endDate ?? null);
|
|
2725
|
+
onChange?.({
|
|
2726
|
+
startDate: range?.startDate ?? null,
|
|
2727
|
+
endDate: range?.endDate ?? null,
|
|
2728
|
+
isInputValid: change.isInputValid,
|
|
2729
|
+
isInputEmpty: change.isInputEmpty
|
|
2730
|
+
});
|
|
2731
|
+
};
|
|
2732
|
+
const handleCalendarSelection = ({
|
|
2733
|
+
startDate: startDate2,
|
|
2734
|
+
endDate: endDate2
|
|
2735
|
+
}) => {
|
|
2736
|
+
setSharedValue({ startDate: startDate2, endDate: endDate2 });
|
|
2737
|
+
onChange?.({
|
|
2738
|
+
startDate: startDate2,
|
|
2739
|
+
endDate: endDate2,
|
|
2740
|
+
isInputValid: true,
|
|
2741
|
+
isInputEmpty: false
|
|
2742
|
+
});
|
|
2743
|
+
};
|
|
2744
|
+
return {
|
|
2745
|
+
startDate,
|
|
2746
|
+
endDate,
|
|
2747
|
+
setStartDate,
|
|
2748
|
+
setEndDate,
|
|
2749
|
+
handleInputChange,
|
|
2750
|
+
handleCalendarSelection
|
|
2751
|
+
};
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
const DateFieldRangeCalendar = ({
|
|
2755
|
+
startDate,
|
|
2756
|
+
endDate,
|
|
2757
|
+
onKeyDown,
|
|
2758
|
+
onSelection,
|
|
2759
|
+
minDate,
|
|
2760
|
+
maxDate,
|
|
2761
|
+
unavailable
|
|
2762
|
+
}) => {
|
|
2763
|
+
const previousStartDate = usePrevious(startDate);
|
|
2764
|
+
const previousEndDate = usePrevious(endDate);
|
|
2765
|
+
const handleCalendarSelection = (data) => {
|
|
2766
|
+
if (!data.value) return;
|
|
2767
|
+
const calStartDate = data.value.start ? DateTime.fromISO(data.value.start, { zone: "utc" }) : null;
|
|
2768
|
+
const calEndDate = data.value.end ? DateTime.fromISO(data.value.end, { zone: "utc" }) : null;
|
|
2769
|
+
onSelection({
|
|
2770
|
+
startDate: calStartDate,
|
|
2771
|
+
endDate: calEndDate
|
|
2772
|
+
});
|
|
2773
|
+
};
|
|
2774
|
+
const defaultFocusedDate = useMemo(() => {
|
|
2775
|
+
if (!startDate && !endDate) return DateTime.now().toISODate();
|
|
2776
|
+
if (!startDate) return endDate?.toISODate();
|
|
2777
|
+
if (!endDate) return startDate?.toISODate();
|
|
2778
|
+
if (endDate && !previousEndDate?.equals(endDate)) {
|
|
2779
|
+
return endDate.toISODate();
|
|
2780
|
+
} else if (startDate && !previousStartDate?.equals(startDate)) {
|
|
2781
|
+
return startDate.toISODate();
|
|
2782
|
+
}
|
|
2783
|
+
if (endDate) return endDate.toISODate();
|
|
2784
|
+
if (startDate) return startDate.toISODate();
|
|
2785
|
+
return DateTime.now().toISODate();
|
|
2786
|
+
}, [previousStartDate, previousEndDate, startDate, endDate]);
|
|
2787
|
+
return /* @__PURE__ */ jsx(
|
|
2788
|
+
Calendar,
|
|
2789
|
+
{
|
|
2790
|
+
range: true,
|
|
2791
|
+
onKeyDown,
|
|
2792
|
+
defaultFocusedDate,
|
|
2793
|
+
value: {
|
|
2794
|
+
start: startDate?.toISODate() || void 0,
|
|
2795
|
+
end: endDate?.toISODate() || void 0
|
|
2796
|
+
},
|
|
2797
|
+
onSelection: handleCalendarSelection,
|
|
2798
|
+
defaultTimeZone: "UTC",
|
|
2799
|
+
minDate: minDate?.toISODate() ?? void 0,
|
|
2800
|
+
maxDate: maxDate?.toISODate() ?? void 0,
|
|
2801
|
+
unavailable: unavailable ? {
|
|
2802
|
+
dates: unavailable.dates?.map((d) => d.toISODate() ?? ""),
|
|
2803
|
+
daysOfWeek: unavailable.daysOfWeek
|
|
2804
|
+
} : void 0,
|
|
2805
|
+
_disableAutofocus: true
|
|
2806
|
+
},
|
|
2807
|
+
`${startDate?.toISODate()}-${endDate?.toISODate()}`
|
|
2808
|
+
);
|
|
2809
|
+
};
|
|
2810
|
+
|
|
2811
|
+
const DateFieldRange = ({
|
|
2812
|
+
onFocus,
|
|
2813
|
+
onBlur,
|
|
2814
|
+
disableCalendar,
|
|
2815
|
+
required,
|
|
2816
|
+
mode,
|
|
2817
|
+
...rest
|
|
2818
|
+
}) => {
|
|
2819
|
+
const { ref: wrapperRef } = useFocusWithin({
|
|
2820
|
+
onBlur,
|
|
2821
|
+
onFocus
|
|
2822
|
+
});
|
|
2823
|
+
const { value, defaultValue, minDate, maxDate, unavailable, onChange } = useDateFieldRangeConversion(rest);
|
|
2824
|
+
const inputRef = useRef(null);
|
|
2825
|
+
const [popoverTriggerRef, setPopoverTriggerRef] = useState();
|
|
2826
|
+
const popoverContentRef = useRef(null);
|
|
2827
|
+
const combinedRef = useMergeRefs([popoverTriggerRef, inputRef]);
|
|
2828
|
+
const popoverSupported = usePopoverSupport();
|
|
2829
|
+
const handleChange = (change) => {
|
|
2830
|
+
const sharedConstraints = {
|
|
2831
|
+
unavailable,
|
|
2832
|
+
minDate: minDate ?? void 0,
|
|
2833
|
+
maxDate: maxDate ?? void 0
|
|
2724
2834
|
};
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
onChange: handleInputChange,
|
|
2732
|
-
disableHint: rest.disableHint,
|
|
2733
|
-
onKeyDown: handleInputKeyDown,
|
|
2734
|
-
onClick: () => setCalendarOpen(true),
|
|
2835
|
+
onChange?.({
|
|
2836
|
+
startDate: change.startDate?.startOf("day") ?? null,
|
|
2837
|
+
endDate: change.endDate?.startOf("day") ?? null,
|
|
2838
|
+
isInputValid: change.isInputValid,
|
|
2839
|
+
isInputEmpty: change.isInputEmpty,
|
|
2840
|
+
isDateRangeValid: validateDateRange({
|
|
2735
2841
|
required,
|
|
2736
|
-
|
|
2737
|
-
"
|
|
2738
|
-
|
|
2739
|
-
|
|
2842
|
+
startDate: change.startDate?.startOf("day") ?? null,
|
|
2843
|
+
endDate: change.endDate?.startOf("day") ?? null,
|
|
2844
|
+
startDateConstraints: sharedConstraints,
|
|
2845
|
+
endDateConstraints: sharedConstraints
|
|
2846
|
+
})
|
|
2847
|
+
});
|
|
2848
|
+
};
|
|
2849
|
+
const { startDate, endDate, handleInputChange, handleCalendarSelection } = useDateFieldRangeState({
|
|
2850
|
+
valueProp: value,
|
|
2851
|
+
defaultValueProp: defaultValue,
|
|
2852
|
+
inputRef,
|
|
2853
|
+
onChange: handleChange
|
|
2854
|
+
});
|
|
2855
|
+
const {
|
|
2856
|
+
calendarOpen,
|
|
2857
|
+
setCalendarOpen,
|
|
2858
|
+
handleCalendarKeyDown,
|
|
2859
|
+
handleInputKeyDown
|
|
2860
|
+
} = useDateFieldOrchestration({
|
|
2861
|
+
inputRef,
|
|
2862
|
+
calendarDefaultOpen: false,
|
|
2863
|
+
popoverContentRef,
|
|
2864
|
+
disableCalendar
|
|
2865
|
+
});
|
|
2866
|
+
const shouldShowCalendar = usePopoverCloseDelayWorkaround(calendarOpen);
|
|
2867
|
+
const currentValidity = useMemo(() => {
|
|
2868
|
+
return validateDateRange({
|
|
2869
|
+
required,
|
|
2870
|
+
startDate,
|
|
2871
|
+
endDate,
|
|
2872
|
+
startDateConstraints: {
|
|
2873
|
+
unavailable,
|
|
2874
|
+
minDate: minDate ?? void 0,
|
|
2875
|
+
maxDate: maxDate ?? void 0
|
|
2876
|
+
},
|
|
2877
|
+
endDateConstraints: {
|
|
2878
|
+
unavailable,
|
|
2879
|
+
minDate: minDate ?? void 0,
|
|
2880
|
+
maxDate: maxDate ?? void 0
|
|
2740
2881
|
}
|
|
2741
|
-
);
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2882
|
+
});
|
|
2883
|
+
}, [required, startDate, endDate, minDate, maxDate, unavailable]);
|
|
2884
|
+
const { defaultValue: _, ...passthroughProps } = rest;
|
|
2885
|
+
const justTheField = /* @__PURE__ */ jsx(
|
|
2886
|
+
MaskedDateRangeInput,
|
|
2887
|
+
{
|
|
2888
|
+
mode,
|
|
2889
|
+
ref: combinedRef,
|
|
2890
|
+
...passthroughProps,
|
|
2891
|
+
startDate: startDate ?? null,
|
|
2892
|
+
endDate: endDate ?? null,
|
|
2893
|
+
onChange: handleInputChange,
|
|
2894
|
+
disableHint: rest.disableHint,
|
|
2895
|
+
onKeyDown: handleInputKeyDown,
|
|
2896
|
+
onClick: () => setCalendarOpen(true),
|
|
2897
|
+
required,
|
|
2898
|
+
autoComplete: "off",
|
|
2899
|
+
"data-date-range-valid": currentValidity
|
|
2747
2900
|
}
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
open: calendarOpen,
|
|
2752
|
-
modal: true,
|
|
2753
|
-
placement: "bottom-start",
|
|
2754
|
-
disableFlipFallback: true,
|
|
2755
|
-
disableTriggerFocus: true,
|
|
2756
|
-
onClose: () => setCalendarOpen(false),
|
|
2757
|
-
disableAutoUpdate: true,
|
|
2758
|
-
onOutsidePress: () => setCalendarOpen(false),
|
|
2759
|
-
children: [
|
|
2760
|
-
/* @__PURE__ */ jsx(Popover.Trigger, { children: ({ ref: iRef }) => {
|
|
2761
|
-
setPopoverTriggerRef(iRef);
|
|
2762
|
-
return justTheField;
|
|
2763
|
-
} }),
|
|
2764
|
-
/* @__PURE__ */ jsx(Popover.Content, { ref: popoverContentRef, "data-testid": "calendar-popover", children: shouldShowCalendar && /* @__PURE__ */ jsx(
|
|
2765
|
-
Calendar,
|
|
2766
|
-
{
|
|
2767
|
-
range: true,
|
|
2768
|
-
onKeyDown: handleCalendarKeyDown,
|
|
2769
|
-
defaultFocusedDate,
|
|
2770
|
-
value: {
|
|
2771
|
-
start: startDate?.toISODate() || void 0,
|
|
2772
|
-
end: endDate?.toISODate() || void 0
|
|
2773
|
-
},
|
|
2774
|
-
onSelection: handleCalendarSelection,
|
|
2775
|
-
defaultTimeZone: "UTC",
|
|
2776
|
-
minDate: minDate?.toISODate() ?? void 0,
|
|
2777
|
-
maxDate: maxDate?.toISODate() ?? void 0,
|
|
2778
|
-
unavailable: unavailable ? {
|
|
2779
|
-
dates: unavailable.dates?.map((d) => d.toISODate() ?? ""),
|
|
2780
|
-
daysOfWeek: unavailable.daysOfWeek
|
|
2781
|
-
} : void 0,
|
|
2782
|
-
_disableAutofocus: true
|
|
2783
|
-
},
|
|
2784
|
-
`${startDate?.toISODate()}-${endDate?.toISODate()}`
|
|
2785
|
-
) })
|
|
2786
|
-
]
|
|
2787
|
-
}
|
|
2788
|
-
);
|
|
2901
|
+
);
|
|
2902
|
+
if (disableCalendar) {
|
|
2903
|
+
return justTheField;
|
|
2789
2904
|
}
|
|
2790
|
-
)
|
|
2791
|
-
|
|
2905
|
+
if (!popoverSupported) {
|
|
2906
|
+
return justTheField;
|
|
2907
|
+
}
|
|
2908
|
+
return /* @__PURE__ */ jsx("div", { ref: wrapperRef, children: /* @__PURE__ */ jsxs(
|
|
2909
|
+
Popover,
|
|
2910
|
+
{
|
|
2911
|
+
open: calendarOpen,
|
|
2912
|
+
modal: true,
|
|
2913
|
+
placement: "bottom-start",
|
|
2914
|
+
disableFlipFallback: true,
|
|
2915
|
+
disableTriggerFocus: true,
|
|
2916
|
+
onClose: () => setCalendarOpen(false),
|
|
2917
|
+
disableAutoUpdate: true,
|
|
2918
|
+
onOutsidePress: () => setCalendarOpen(false),
|
|
2919
|
+
children: [
|
|
2920
|
+
/* @__PURE__ */ jsx(Popover.Trigger, { children: ({ ref: iRef }) => {
|
|
2921
|
+
setPopoverTriggerRef(iRef);
|
|
2922
|
+
return justTheField;
|
|
2923
|
+
} }),
|
|
2924
|
+
/* @__PURE__ */ jsx(Popover.Content, { ref: popoverContentRef, "data-testid": "calendar-popover", children: shouldShowCalendar && /* @__PURE__ */ jsx(
|
|
2925
|
+
DateFieldRangeCalendar,
|
|
2926
|
+
{
|
|
2927
|
+
startDate,
|
|
2928
|
+
endDate,
|
|
2929
|
+
onKeyDown: handleCalendarKeyDown,
|
|
2930
|
+
onSelection: handleCalendarSelection,
|
|
2931
|
+
minDate,
|
|
2932
|
+
maxDate,
|
|
2933
|
+
unavailable
|
|
2934
|
+
}
|
|
2935
|
+
) })
|
|
2936
|
+
]
|
|
2937
|
+
}
|
|
2938
|
+
) });
|
|
2939
|
+
};
|
|
2940
|
+
DateFieldRange.displayName = "DateFieldRange";
|
|
2792
2941
|
function validateDateRange({
|
|
2793
2942
|
required,
|
|
2794
2943
|
startDate,
|
|
@@ -2806,80 +2955,233 @@ function validateDateRange({
|
|
|
2806
2955
|
}) && (!startDate || !endDate || startDate <= endDate);
|
|
2807
2956
|
}
|
|
2808
2957
|
|
|
2809
|
-
const
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
maxDate,
|
|
2814
|
-
unavailable,
|
|
2815
|
-
onChange,
|
|
2816
|
-
onFocus,
|
|
2817
|
-
onBlur,
|
|
2818
|
-
...rest
|
|
2958
|
+
const yearlessDatePlaceholderMask = ({
|
|
2959
|
+
mode,
|
|
2960
|
+
separator = "/",
|
|
2961
|
+
placeholder
|
|
2819
2962
|
}) => {
|
|
2820
|
-
const
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2963
|
+
const dateOptions = maskitoDateOptionsGenerator({
|
|
2964
|
+
mode,
|
|
2965
|
+
separator
|
|
2966
|
+
});
|
|
2967
|
+
const { plugins, removePlaceholder, ...placeholderOptions } = maskitoWithPlaceholder(placeholder);
|
|
2968
|
+
const datePlaceholderMask = {
|
|
2969
|
+
...dateOptions,
|
|
2970
|
+
plugins: plugins.concat(dateOptions.plugins || []),
|
|
2971
|
+
preprocessors: [
|
|
2972
|
+
...placeholderOptions.preprocessors,
|
|
2973
|
+
...dateOptions.preprocessors,
|
|
2974
|
+
makeZeroShortcutPreprocessor(mode, separator)
|
|
2975
|
+
],
|
|
2976
|
+
postprocessors: [
|
|
2977
|
+
...dateOptions.postprocessors,
|
|
2978
|
+
...placeholderOptions.postprocessors
|
|
2979
|
+
]
|
|
2980
|
+
};
|
|
2981
|
+
return { options: datePlaceholderMask, removePlaceholder };
|
|
2982
|
+
};
|
|
2983
|
+
|
|
2984
|
+
const MaskedYearlessDateInput = forwardRef(({ onChange, mode = "mm/dd", value, disableHint = false, ...props }, ref) => {
|
|
2985
|
+
const placeholder = "__/__";
|
|
2986
|
+
const [inputValue, setInputValue] = useState(placeholder);
|
|
2987
|
+
const { options, removePlaceholder } = yearlessDatePlaceholderMask({
|
|
2988
|
+
mode,
|
|
2989
|
+
placeholder
|
|
2990
|
+
});
|
|
2991
|
+
const maskedInputRef = useMaskito({ options });
|
|
2992
|
+
const inputRef = useRef(null);
|
|
2993
|
+
const combinedRef = useMergeRefs$1([maskedInputRef, inputRef, ref]);
|
|
2994
|
+
const previousValue = usePrevious(value);
|
|
2995
|
+
const previousMode = usePrevious(mode);
|
|
2996
|
+
useEffect(() => {
|
|
2997
|
+
if (mode !== previousMode) {
|
|
2998
|
+
setInputValue(
|
|
2999
|
+
(oldInputValue) => swapMode(oldInputValue, previousMode ?? mode, mode)
|
|
3000
|
+
);
|
|
3001
|
+
}
|
|
3002
|
+
}, [mode, previousMode]);
|
|
3003
|
+
useEffect(() => {
|
|
3004
|
+
if (previousValue?.day !== value?.day || previousValue?.month !== value?.month) {
|
|
3005
|
+
if (value?.day && value?.month) {
|
|
3006
|
+
setInputValue(stringifyYearlessDate(value.day, value.month, mode));
|
|
3007
|
+
} else if (previousValue !== null && previousValue !== void 0 && (value === null || value?.day === null && value?.month === null)) {
|
|
3008
|
+
setInputValue(placeholder);
|
|
3009
|
+
} else {
|
|
3010
|
+
return;
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
}, [value, mode, previousValue]);
|
|
3014
|
+
const currentParsedData = useMemo(() => {
|
|
3015
|
+
return parseInputValue(inputValue, mode, removePlaceholder);
|
|
3016
|
+
}, [inputValue, mode, removePlaceholder]);
|
|
3017
|
+
const handleChange = (event) => {
|
|
3018
|
+
setInputValue(event.target.value);
|
|
3019
|
+
const {
|
|
3020
|
+
value: v,
|
|
3021
|
+
isInputValid,
|
|
3022
|
+
isInputEmpty
|
|
3023
|
+
} = parseInputValue(event.target.value, mode, removePlaceholder);
|
|
3024
|
+
onChange?.({
|
|
3025
|
+
event,
|
|
3026
|
+
value: v ?? currentParsedData.value ?? null,
|
|
3027
|
+
isInputValid,
|
|
3028
|
+
isInputEmpty
|
|
3029
|
+
});
|
|
3030
|
+
};
|
|
3031
|
+
useImperativeHandle(ref, () => {
|
|
3032
|
+
const input = inputRef.current;
|
|
3033
|
+
if (!input) return null;
|
|
3034
|
+
return Object.assign(input, {
|
|
3035
|
+
setValue: (value2) => {
|
|
3036
|
+
if (!value2) {
|
|
3037
|
+
setInputValue(placeholder);
|
|
3038
|
+
return;
|
|
3039
|
+
}
|
|
3040
|
+
setInputValue(
|
|
3041
|
+
stringifyYearlessDate(value2.day ?? 1, value2.month ?? 1, mode)
|
|
3042
|
+
);
|
|
3043
|
+
}
|
|
3044
|
+
});
|
|
3045
|
+
}, [mode, placeholder]);
|
|
3046
|
+
return /* @__PURE__ */ jsx(
|
|
3047
|
+
TextField,
|
|
3048
|
+
{
|
|
3049
|
+
ref: combinedRef,
|
|
3050
|
+
"data-month-value": value?.month,
|
|
3051
|
+
"data-day-value": value?.day,
|
|
3052
|
+
"data-input-valid": currentParsedData.isInputValid,
|
|
3053
|
+
"data-input-empty": currentParsedData.isInputEmpty,
|
|
3054
|
+
...props,
|
|
3055
|
+
showCounter: false,
|
|
3056
|
+
value: inputValue,
|
|
3057
|
+
onChange: handleChange,
|
|
3058
|
+
hint: disableHint ? void 0 : `Format: ${mode}`
|
|
3059
|
+
}
|
|
2825
3060
|
);
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
3061
|
+
});
|
|
3062
|
+
MaskedYearlessDateInput.displayName = "MaskedYearlessDateInput";
|
|
3063
|
+
function parseInputValue(value, mode, removePlaceholder) {
|
|
3064
|
+
const valueMinusPlaceholder = removePlaceholder(value);
|
|
3065
|
+
const [segment1, segment2] = valueMinusPlaceholder.split("/");
|
|
3066
|
+
const incompleteFirstSegment = segment1?.length !== 2;
|
|
3067
|
+
const incompleteSecondSegment = segment2?.length !== 2;
|
|
3068
|
+
if (mode === "dd/mm") {
|
|
3069
|
+
return {
|
|
3070
|
+
value: {
|
|
3071
|
+
day: incompleteFirstSegment ? null : parseInt(segment1),
|
|
3072
|
+
month: incompleteSecondSegment ? null : parseInt(segment2)
|
|
3073
|
+
},
|
|
3074
|
+
isInputValid: !incompleteFirstSegment && !incompleteSecondSegment,
|
|
3075
|
+
isInputEmpty: valueMinusPlaceholder === ""
|
|
3076
|
+
};
|
|
3077
|
+
}
|
|
3078
|
+
return {
|
|
3079
|
+
value: {
|
|
3080
|
+
day: incompleteSecondSegment ? null : parseInt(segment2),
|
|
3081
|
+
month: incompleteFirstSegment ? null : parseInt(segment1)
|
|
2829
3082
|
},
|
|
2830
|
-
|
|
3083
|
+
isInputValid: !incompleteFirstSegment && !incompleteSecondSegment,
|
|
3084
|
+
isInputEmpty: valueMinusPlaceholder === ""
|
|
3085
|
+
};
|
|
3086
|
+
}
|
|
3087
|
+
function swapMode(inputString, previousMode, mode) {
|
|
3088
|
+
const { day, month } = divideSegments(inputString, previousMode);
|
|
3089
|
+
return stringifyYearlessDate(day, month, mode);
|
|
3090
|
+
}
|
|
3091
|
+
function divideSegments(value, mode) {
|
|
3092
|
+
const [segment1, segment2] = value.split("/");
|
|
3093
|
+
if (mode === "dd/mm") {
|
|
3094
|
+
return { day: segment1, month: segment2 };
|
|
3095
|
+
}
|
|
3096
|
+
return { day: segment2, month: segment1 };
|
|
3097
|
+
}
|
|
3098
|
+
function stringifyYearlessDate(day, month, mode) {
|
|
3099
|
+
const dd = day.toString().padStart(2, "0");
|
|
3100
|
+
const mm = month.toString().padStart(2, "0");
|
|
3101
|
+
if (mode === "dd/mm") {
|
|
3102
|
+
return `${dd}/${mm}`;
|
|
3103
|
+
}
|
|
3104
|
+
return `${mm}/${dd}`;
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
const useConditionalChange = ({
|
|
3108
|
+
changeHandler,
|
|
3109
|
+
compareFn
|
|
3110
|
+
}) => {
|
|
3111
|
+
const lastChangeRef = useRef(null);
|
|
3112
|
+
const onChange = useCallback(
|
|
3113
|
+
(change) => {
|
|
3114
|
+
if (!!lastChangeRef.current && !compareFn(lastChangeRef.current, change)) {
|
|
3115
|
+
return;
|
|
3116
|
+
}
|
|
3117
|
+
changeHandler?.(change);
|
|
3118
|
+
lastChangeRef.current = change;
|
|
3119
|
+
},
|
|
3120
|
+
[changeHandler, compareFn]
|
|
2831
3121
|
);
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
3122
|
+
return onChange;
|
|
3123
|
+
};
|
|
3124
|
+
|
|
3125
|
+
const DateFieldYearless = ({
|
|
3126
|
+
value: valueProp,
|
|
3127
|
+
defaultValue: defaultValueProp,
|
|
3128
|
+
onChange,
|
|
3129
|
+
minDate,
|
|
3130
|
+
maxDate,
|
|
3131
|
+
unavailable,
|
|
3132
|
+
required,
|
|
3133
|
+
...restProps
|
|
3134
|
+
}) => {
|
|
3135
|
+
const [value, setValue] = useOptionallyControlledState({
|
|
3136
|
+
controlledValue: valueProp,
|
|
3137
|
+
defaultValue: defaultValueProp
|
|
2835
3138
|
});
|
|
2836
|
-
const
|
|
2837
|
-
() =>
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
} : void 0,
|
|
2848
|
-
[defaultValue]
|
|
2849
|
-
);
|
|
2850
|
-
const normalizedMinDate = useMemo(
|
|
2851
|
-
() => convertStringToDate(minDate),
|
|
2852
|
-
[minDate]
|
|
2853
|
-
);
|
|
2854
|
-
const normalizedMaxDate = useMemo(
|
|
2855
|
-
() => convertStringToDate(maxDate),
|
|
2856
|
-
[maxDate]
|
|
2857
|
-
);
|
|
2858
|
-
const normalizedUnavailableDates = useMemo(
|
|
2859
|
-
() => unavailable?.dates?.map((d) => convertStringToDate(d)).filter((d) => d !== null && d !== void 0),
|
|
2860
|
-
[unavailable?.dates]
|
|
3139
|
+
const currentValidity = useMemo(
|
|
3140
|
+
() => validateYearlessDate({
|
|
3141
|
+
value: value ?? null,
|
|
3142
|
+
constraints: {
|
|
3143
|
+
required,
|
|
3144
|
+
unavailable,
|
|
3145
|
+
minDate,
|
|
3146
|
+
maxDate
|
|
3147
|
+
}
|
|
3148
|
+
}),
|
|
3149
|
+
[value, required, unavailable, minDate, maxDate]
|
|
2861
3150
|
);
|
|
2862
|
-
const
|
|
3151
|
+
const conditionalChange = useConditionalChange({
|
|
2863
3152
|
changeHandler: onChange,
|
|
2864
|
-
compareFn: (a, b) => a.isInputValid !== b.isInputValid || a.isInputEmpty !== b.isInputEmpty || a.
|
|
3153
|
+
compareFn: (a, b) => a.isInputValid !== b.isInputValid || a.isInputEmpty !== b.isInputEmpty || a.isValid !== b.isValid || a.value?.day !== b.value?.day || a.value?.month !== b.value?.month
|
|
2865
3154
|
});
|
|
2866
|
-
|
|
2867
|
-
|
|
3155
|
+
const handleInputChange = (change) => {
|
|
3156
|
+
const { event, value: value2, ...restChange } = change;
|
|
3157
|
+
setValue(value2);
|
|
3158
|
+
return conditionalChange({
|
|
3159
|
+
...restChange,
|
|
3160
|
+
value: value2,
|
|
3161
|
+
isValid: validateYearlessDate({
|
|
3162
|
+
value: value2,
|
|
3163
|
+
constraints: {
|
|
3164
|
+
required,
|
|
3165
|
+
unavailable,
|
|
3166
|
+
minDate,
|
|
3167
|
+
maxDate
|
|
3168
|
+
}
|
|
3169
|
+
})
|
|
3170
|
+
});
|
|
3171
|
+
};
|
|
3172
|
+
return /* @__PURE__ */ jsx(
|
|
3173
|
+
MaskedYearlessDateInput,
|
|
2868
3174
|
{
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
dates: normalizedUnavailableDates,
|
|
2876
|
-
daysOfWeek: unavailable?.daysOfWeek
|
|
2877
|
-
} : void 0,
|
|
2878
|
-
onChange: handleChange
|
|
3175
|
+
required,
|
|
3176
|
+
...restProps,
|
|
3177
|
+
autoComplete: "off",
|
|
3178
|
+
onChange: handleInputChange,
|
|
3179
|
+
value,
|
|
3180
|
+
"data-valid": currentValidity
|
|
2879
3181
|
}
|
|
2880
|
-
)
|
|
3182
|
+
);
|
|
2881
3183
|
};
|
|
2882
|
-
|
|
3184
|
+
DateFieldYearless.displayName = "DateFieldYearless";
|
|
2883
3185
|
|
|
2884
|
-
export { DateFieldRange as D, DateFieldSingle as a };
|
|
2885
|
-
//# sourceMappingURL=
|
|
3186
|
+
export { DateFieldRange as D, DateFieldSingle as a, DateFieldYearless as b };
|
|
3187
|
+
//# sourceMappingURL=DateFieldYearless-M5KDI_hn-akXtkIZA.js.map
|