react-native-molecules 0.5.0-beta.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/components/Accordion/Accordion.tsx +89 -0
- package/components/Accordion/AccordionItem.tsx +94 -0
- package/components/Accordion/AccordionItemContent.tsx +17 -0
- package/components/Accordion/AccordionItemHeader.tsx +122 -0
- package/components/Accordion/index.tsx +36 -0
- package/components/Accordion/utils.ts +62 -0
- package/components/ActivityIndicator/ActivityIndicator.ios.tsx +1 -0
- package/components/ActivityIndicator/ActivityIndicator.tsx +200 -0
- package/components/ActivityIndicator/AnimatedSpinner.tsx +121 -0
- package/components/ActivityIndicator/index.tsx +17 -0
- package/components/Appbar/AppbarActions.tsx +13 -0
- package/components/Appbar/AppbarBase.tsx +60 -0
- package/components/Appbar/AppbarCenterAligned.tsx +13 -0
- package/components/Appbar/AppbarLarge.tsx +13 -0
- package/components/Appbar/AppbarLeft.tsx +26 -0
- package/components/Appbar/AppbarMedium.tsx +13 -0
- package/components/Appbar/AppbarRight.tsx +40 -0
- package/components/Appbar/AppbarSmall.tsx +13 -0
- package/components/Appbar/AppbarTitle.tsx +49 -0
- package/components/Appbar/index.tsx +46 -0
- package/components/Appbar/types.ts +19 -0
- package/components/Appbar/utils.ts +127 -0
- package/components/Avatar/Avatar.tsx +189 -0
- package/components/Avatar/index.tsx +11 -0
- package/components/Avatar/utils.ts +35 -0
- package/components/Backdrop/Backdrop.tsx +18 -0
- package/components/Backdrop/index.tsx +11 -0
- package/components/Backdrop/types.ts +3 -0
- package/components/Backdrop/utils.ts +21 -0
- package/components/Badge/Badge.tsx +29 -0
- package/components/Badge/index.tsx +11 -0
- package/components/Badge/utils.ts +38 -0
- package/components/Button/Button.tsx +349 -0
- package/components/Button/index.tsx +11 -0
- package/components/Button/types.ts +5 -0
- package/components/Button/utils.ts +416 -0
- package/components/Card/Card.tsx +160 -0
- package/components/Card/CardActions.tsx +18 -0
- package/components/Card/CardContent.tsx +29 -0
- package/components/Card/CardHeader.tsx +31 -0
- package/components/Card/CardHeadline.tsx +15 -0
- package/components/Card/CardMedia.tsx +36 -0
- package/components/Card/CardSubhead.tsx +15 -0
- package/components/Card/CardText.tsx +13 -0
- package/components/Card/CardTypography.tsx +113 -0
- package/components/Card/index.tsx +38 -0
- package/components/Card/types.ts +1 -0
- package/components/Card/utils.ts +23 -0
- package/components/Checkbox/Checkbox.tsx +123 -0
- package/components/Checkbox/CheckboxBase.ios.tsx +86 -0
- package/components/Checkbox/CheckboxBase.tsx +216 -0
- package/components/Checkbox/index.tsx +11 -0
- package/components/Checkbox/types.ts +72 -0
- package/components/Checkbox/utils.ts +210 -0
- package/components/Chip/Chip.tsx +416 -0
- package/components/Chip/index.tsx +51 -0
- package/components/Chip/utils.ts +100 -0
- package/components/DatePickerDocked/DatePickerDocked.tsx +30 -0
- package/components/DatePickerDocked/DatePickerDockedHeader.tsx +129 -0
- package/components/DatePickerDocked/index.tsx +21 -0
- package/components/DatePickerDocked/types.ts +11 -0
- package/components/DatePickerDocked/utils.ts +155 -0
- package/components/DatePickerInline/AutoSizer.tsx +46 -0
- package/components/DatePickerInline/DatePickerContext.tsx +21 -0
- package/components/DatePickerInline/DatePickerInline.tsx +82 -0
- package/components/DatePickerInline/DatePickerInlineBase.tsx +181 -0
- package/components/DatePickerInline/DatePickerInlineHeader.tsx +108 -0
- package/components/DatePickerInline/Day.tsx +88 -0
- package/components/DatePickerInline/DayName.tsx +17 -0
- package/components/DatePickerInline/DayNames.tsx +32 -0
- package/components/DatePickerInline/DayRange.tsx +48 -0
- package/components/DatePickerInline/HeaderItem.tsx +111 -0
- package/components/DatePickerInline/Month.tsx +233 -0
- package/components/DatePickerInline/MonthPicker.tsx +174 -0
- package/components/DatePickerInline/Swiper.native.tsx +172 -0
- package/components/DatePickerInline/Swiper.tsx +172 -0
- package/components/DatePickerInline/SwiperUtils.ts +40 -0
- package/components/DatePickerInline/Week.tsx +67 -0
- package/components/DatePickerInline/YearPicker.tsx +139 -0
- package/components/DatePickerInline/dateUtils.tsx +334 -0
- package/components/DatePickerInline/index.tsx +41 -0
- package/components/DatePickerInline/types.ts +104 -0
- package/components/DatePickerInline/utils.ts +367 -0
- package/components/DatePickerInput/DatePickerInput.tsx +139 -0
- package/components/DatePickerInput/DatePickerInputModal.tsx +48 -0
- package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +77 -0
- package/components/DatePickerInput/DateRangeInput.tsx +88 -0
- package/components/DatePickerInput/index.tsx +14 -0
- package/components/DatePickerInput/inputUtils.ts +138 -0
- package/components/DatePickerInput/types.ts +28 -0
- package/components/DatePickerInput/utils.ts +16 -0
- package/components/DatePickerModal/AnimatedCrossView.tsx +94 -0
- package/components/DatePickerModal/CalendarEdit.tsx +139 -0
- package/components/DatePickerModal/DatePickerModal.tsx +85 -0
- package/components/DatePickerModal/DatePickerModalContent.tsx +155 -0
- package/components/DatePickerModal/DatePickerModalContentHeader.tsx +213 -0
- package/components/DatePickerModal/DatePickerModalHeader.tsx +74 -0
- package/components/DatePickerModal/DatePickerModalHeaderBackground.tsx +13 -0
- package/components/DatePickerModal/index.tsx +20 -0
- package/components/DatePickerModal/types.ts +92 -0
- package/components/DatePickerModal/utils.ts +121 -0
- package/components/DateTimePicker/DateTimePicker.tsx +172 -0
- package/components/DateTimePicker/index.tsx +14 -0
- package/components/DateTimePicker/utils.ts +13 -0
- package/components/Dialog/Dialog.tsx +66 -0
- package/components/Dialog/DialogActions.tsx +89 -0
- package/components/Dialog/DialogContent.tsx +37 -0
- package/components/Dialog/DialogIcon.tsx +69 -0
- package/components/Dialog/DialogTitle.tsx +68 -0
- package/components/Dialog/index.tsx +37 -0
- package/components/Dialog/utils.ts +80 -0
- package/components/Drawer/Collapsible/DrawerCollapsible.tsx +22 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItem.tsx +38 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItemContent.tsx +16 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItemHeader.tsx +48 -0
- package/components/Drawer/Collapsible/index.tsx +23 -0
- package/components/Drawer/Collapsible/utils.ts +49 -0
- package/components/Drawer/Drawer.tsx +43 -0
- package/components/Drawer/DrawerContent.tsx +35 -0
- package/components/Drawer/DrawerFooter.tsx +27 -0
- package/components/Drawer/DrawerHeader.tsx +27 -0
- package/components/Drawer/DrawerItem.tsx +206 -0
- package/components/Drawer/DrawerItemGroup.tsx +82 -0
- package/components/Drawer/index.tsx +47 -0
- package/components/Drawer/types.ts +3 -0
- package/components/Drawer/utils.ts +8 -0
- package/components/ElementGroup/ElementGroup.tsx +139 -0
- package/components/ElementGroup/index.tsx +11 -0
- package/components/ElementGroup/utils.ts +25 -0
- package/components/FAB/FAB.tsx +176 -0
- package/components/FAB/index.tsx +12 -0
- package/components/FAB/types.ts +1 -0
- package/components/FAB/utils.ts +221 -0
- package/components/FilePicker/FilePicker.tsx +133 -0
- package/components/FilePicker/index.tsx +11 -0
- package/components/FilePicker/utils.ts +13 -0
- package/components/HelperText/HelperText.tsx +139 -0
- package/components/HelperText/index.tsx +11 -0
- package/components/HelperText/utils.ts +29 -0
- package/components/HorizontalDivider/HorizontalDivider.tsx +101 -0
- package/components/HorizontalDivider/index.tsx +13 -0
- package/components/Icon/CrossFadeIcon.tsx +116 -0
- package/components/Icon/Icon.tsx +41 -0
- package/components/Icon/iconFactory.tsx +23 -0
- package/components/Icon/index.tsx +11 -0
- package/components/Icon/types.ts +35 -0
- package/components/IconButton/IconButton.tsx +218 -0
- package/components/IconButton/index.tsx +11 -0
- package/components/IconButton/types.ts +1 -0
- package/components/IconButton/utils.ts +325 -0
- package/components/If/index.tsx +13 -0
- package/components/InputAddon/InputAddon.tsx +27 -0
- package/components/InputAddon/index.tsx +11 -0
- package/components/InputAddon/utils.ts +33 -0
- package/components/Link/Link.tsx +48 -0
- package/components/Link/index.tsx +11 -0
- package/components/Link/utils.ts +37 -0
- package/components/ListItem/ListItem.tsx +136 -0
- package/components/ListItem/ListItemDescription.tsx +25 -0
- package/components/ListItem/ListItemTitle.tsx +25 -0
- package/components/ListItem/index.tsx +18 -0
- package/components/ListItem/utils.ts +113 -0
- package/components/Menu/Menu.tsx +69 -0
- package/components/Menu/MenuDivider.tsx +13 -0
- package/components/Menu/MenuItem.tsx +128 -0
- package/components/Menu/index.tsx +19 -0
- package/components/Menu/utils.ts +92 -0
- package/components/Modal/Modal.tsx +261 -0
- package/components/Modal/index.tsx +11 -0
- package/components/Modal/utils.ts +45 -0
- package/components/NavigationRail/NavigationRail.tsx +32 -0
- package/components/NavigationRail/NavigationRailContent.tsx +25 -0
- package/components/NavigationRail/NavigationRailFooter.tsx +18 -0
- package/components/NavigationRail/NavigationRailHeader.tsx +18 -0
- package/components/NavigationRail/NavigationRailItem.tsx +226 -0
- package/components/NavigationRail/index.tsx +35 -0
- package/components/NavigationRail/utils.ts +170 -0
- package/components/NavigationStack/NavigationStack.tsx +85 -0
- package/components/NavigationStack/NavigationStackItem.tsx +60 -0
- package/components/NavigationStack/index.tsx +20 -0
- package/components/NavigationStack/utils.tsx +16 -0
- package/components/Popover/Popover.native.tsx +185 -0
- package/components/Popover/Popover.tsx +198 -0
- package/components/Popover/common.ts +459 -0
- package/components/Popover/index.ts +2 -0
- package/components/Portal/Portal.tsx +13 -0
- package/components/Portal/index.tsx +12 -0
- package/components/RadioButton/RadioButton.tsx +138 -0
- package/components/RadioButton/RadioButtonAndroid.tsx +188 -0
- package/components/RadioButton/RadioButtonGroup.tsx +98 -0
- package/components/RadioButton/RadioButtonIOS.tsx +106 -0
- package/components/RadioButton/RadioButtonItem.tsx +232 -0
- package/components/RadioButton/index.ts +27 -0
- package/components/RadioButton/utils.ts +164 -0
- package/components/Rating/Rating.tsx +149 -0
- package/components/Rating/RatingItem.tsx +125 -0
- package/components/Rating/index.tsx +13 -0
- package/components/Rating/utils.ts +38 -0
- package/components/Select/Select.tsx +1038 -0
- package/components/Select/index.ts +14 -0
- package/components/Select/types.ts +115 -0
- package/components/StateLayer/StateLayer.tsx +12 -0
- package/components/StateLayer/index.tsx +11 -0
- package/components/StateLayer/utils.ts +17 -0
- package/components/Surface/BackgroundContextWrapper.tsx +27 -0
- package/components/Surface/Surface.android.tsx +62 -0
- package/components/Surface/Surface.ios.tsx +123 -0
- package/components/Surface/Surface.tsx +48 -0
- package/components/Surface/index.tsx +12 -0
- package/components/Surface/utils.ts +106 -0
- package/components/Switch/Switch.ios.tsx +67 -0
- package/components/Switch/Switch.tsx +278 -0
- package/components/Switch/index.tsx +11 -0
- package/components/Switch/utils.ts +283 -0
- package/components/Tabs/TabItem.tsx +150 -0
- package/components/Tabs/TabLabel.tsx +84 -0
- package/components/Tabs/Tabs.tsx +398 -0
- package/components/Tabs/index.tsx +21 -0
- package/components/Tabs/utils.ts +126 -0
- package/components/Text/Text.tsx +23 -0
- package/components/Text/index.tsx +2 -0
- package/components/Text/textFactory.tsx +33 -0
- package/components/TextInput/InputLabel.tsx +181 -0
- package/components/TextInput/TextInput.tsx +693 -0
- package/components/TextInput/index.tsx +16 -0
- package/components/TextInput/types.ts +96 -0
- package/components/TextInput/utils.ts +544 -0
- package/components/TextInputWithMask/TextInputMask.tsx +57 -0
- package/components/TextInputWithMask/index.tsx +11 -0
- package/components/TextInputWithMask/utils.ts +56 -0
- package/components/TimePicker/AmPmSwitcher.tsx +99 -0
- package/components/TimePicker/AnalogClock.tsx +165 -0
- package/components/TimePicker/AnalogClockHours.tsx +163 -0
- package/components/TimePicker/AnalogClockMinutes.tsx +68 -0
- package/components/TimePicker/AnimatedClockSwitcher.tsx +72 -0
- package/components/TimePicker/DisplayModeContext.tsx +6 -0
- package/components/TimePicker/TimeInput.tsx +112 -0
- package/components/TimePicker/TimeInputs.tsx +148 -0
- package/components/TimePicker/TimePicker.tsx +130 -0
- package/components/TimePicker/index.tsx +19 -0
- package/components/TimePicker/timeUtils.ts +159 -0
- package/components/TimePicker/utils.ts +285 -0
- package/components/TimePickerField/TimePickerField.tsx +152 -0
- package/components/TimePickerField/index.tsx +14 -0
- package/components/TimePickerField/sanitizeTime.ts +85 -0
- package/components/TimePickerField/utils.ts +95 -0
- package/components/TimePickerModal/TimePickerModal.tsx +115 -0
- package/components/TimePickerModal/index.tsx +14 -0
- package/components/TimePickerModal/utils.ts +48 -0
- package/components/Tooltip/Tooltip.tsx +137 -0
- package/components/Tooltip/TooltipContent.tsx +12 -0
- package/components/Tooltip/TooltipTrigger.tsx +94 -0
- package/components/Tooltip/index.tsx +20 -0
- package/components/Tooltip/utils.ts +21 -0
- package/components/TouchableRipple/TouchableRipple.native.tsx +105 -0
- package/components/TouchableRipple/TouchableRipple.tsx +286 -0
- package/components/TouchableRipple/index.tsx +14 -0
- package/components/TouchableRipple/utils.ts +15 -0
- package/components/VerticalDivider/VerticalDivider.tsx +99 -0
- package/components/VerticalDivider/index.tsx +13 -0
- package/context-bridge/index.tsx +87 -0
- package/core/componentsRegistry.ts +164 -0
- package/core/index.tsx +2 -0
- package/fast-context/index.tsx +190 -0
- package/hocs/index.tsx +5 -0
- package/hocs/typedMemo.tsx +5 -0
- package/hocs/withKeyboardAccessibility.tsx +231 -0
- package/hocs/withPortal.tsx +16 -0
- package/hooks/createPsuedoHook.tsx +50 -0
- package/hooks/index.tsx +29 -0
- package/hooks/useActionState.native.tsx +22 -0
- package/hooks/useActionState.tsx +34 -0
- package/hooks/useActive.tsx +5 -0
- package/hooks/useBreakpoints.tsx +7 -0
- package/hooks/useColorMode.tsx +17 -0
- package/hooks/useContrastColor.ts +15 -0
- package/hooks/useControlledValue.tsx +68 -0
- package/hooks/useFilePicker.tsx +48 -0
- package/hooks/useFocus.tsx +5 -0
- package/hooks/useHandleNumberFormat.tsx +106 -0
- package/hooks/useHover.tsx +5 -0
- package/hooks/useKeyboardDismissable.ts +66 -0
- package/hooks/useLatest.tsx +9 -0
- package/hooks/useMediaQuery.tsx +64 -0
- package/hooks/useMergedRefs.ts +14 -0
- package/hooks/usePrevious.ts +13 -0
- package/hooks/useQueryFilter.tsx +35 -0
- package/hooks/useSearchable.tsx +74 -0
- package/hooks/useSubcomponents.tsx +59 -0
- package/hooks/useTheme.ts +3 -0
- package/hooks/useToggle.tsx +24 -0
- package/package.json +114 -0
- package/shortcuts-manager/EventsManager.tsx +121 -0
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.native.tsx +9 -0
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +58 -0
- package/shortcuts-manager/ShortcutsManager/index.tsx +2 -0
- package/shortcuts-manager/ShortcutsManager/utils.tsx +30 -0
- package/shortcuts-manager/index.tsx +6 -0
- package/shortcuts-manager/types.ts +24 -0
- package/shortcuts-manager/useIsKeyPressed/index.tsx +1 -0
- package/shortcuts-manager/useIsKeyPressed/useIsKeyPress.tsx +9 -0
- package/shortcuts-manager/useSetScopes/index.tsx +1 -0
- package/shortcuts-manager/useSetScopes/useSetScopes.native.tsx +9 -0
- package/shortcuts-manager/useSetScopes/useSetScopes.tsx +25 -0
- package/shortcuts-manager/useShortcut/index.tsx +2 -0
- package/shortcuts-manager/useShortcut/types.ts +3 -0
- package/shortcuts-manager/useShortcut/useShortcut.native.tsx +9 -0
- package/shortcuts-manager/useShortcut/useShortcut.tsx +61 -0
- package/shortcuts-manager/utils.ts +105 -0
- package/styles/index.ts +4 -0
- package/styles/overlay.ts +69 -0
- package/styles/shadow.ts +21 -0
- package/styles/themes/DarkTheme.tsx +98 -0
- package/styles/themes/LightTheme.tsx +212 -0
- package/styles/themes/tokens.ts +248 -0
- package/styles/utils.ts +11 -0
- package/types/index.ts +129 -0
- package/types/theme.ts +159 -0
- package/utils/DocumentPicker/documentPicker.native.ts +10 -0
- package/utils/DocumentPicker/documentPicker.ts +76 -0
- package/utils/DocumentPicker/index.ts +2 -0
- package/utils/DocumentPicker/types.ts +28 -0
- package/utils/addEventListener.tsx +51 -0
- package/utils/backgroundContext.ts +9 -0
- package/utils/color.ts +22 -0
- package/utils/compare/index.ts +54 -0
- package/utils/composeEventHandlers.ts +9 -0
- package/utils/createNumberMask/createNumberMask.ts +98 -0
- package/utils/createNumberMask/index.ts +5 -0
- package/utils/createSyntheticEvent.ts +31 -0
- package/utils/date-fns.ts +7 -0
- package/utils/dateTimePicker.ts +5 -0
- package/utils/escapeRegex.ts +9 -0
- package/utils/extractTextStyles.ts +52 -0
- package/utils/formatNumberWithMask/formatNumberWithMask.ts +26 -0
- package/utils/formatNumberWithMask/formatWithMask.ts +119 -0
- package/utils/formatNumberWithMask/index.ts +6 -0
- package/utils/getCursorStyle/getCursorStyle.native.ts +1 -0
- package/utils/getCursorStyle/getCursorStyle.ts +1 -0
- package/utils/getCursorStyle/index.ts +1 -0
- package/utils/getOS/getOS.native.ts +7 -0
- package/utils/getOS/getOS.ts +24 -0
- package/utils/getOS/index.ts +1 -0
- package/utils/getyearRange.ts +5 -0
- package/utils/index.ts +20 -0
- package/utils/lodash.ts +50 -0
- package/utils/mergeRefs.ts +13 -0
- package/utils/normalizeBorderRadiuses.ts +24 -0
- package/utils/normalizeSpacings.ts +110 -0
- package/utils/normalizeToNumberString/index.ts +4 -0
- package/utils/normalizeToNumberString/normalizeToNumberString.ts +48 -0
- package/utils/repository.ts +103 -0
- package/utils/resolveColorMode.ts +9 -0
- package/utils/resolveStateVariant.ts +26 -0
- package/utils/tokenStylesParser.ts +7 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useLatest } from '../../hooks';
|
|
4
|
+
import type { CalendarDate, CalendarDates, ValidRangeType } from './types';
|
|
5
|
+
|
|
6
|
+
export type DisableWeekDaysType = number[];
|
|
7
|
+
|
|
8
|
+
export function showWeekDay(dayIndex: number, disableWeekDays?: DisableWeekDaysType): boolean {
|
|
9
|
+
return !(disableWeekDays && disableWeekDays.some(di => di === dayIndex));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function dateToUnix(d: Date): number {
|
|
13
|
+
return Math.round(d.getTime() / 1000);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function addMonths(date: Date, count: number) {
|
|
17
|
+
const n = date.getDate();
|
|
18
|
+
const n2 = new Date(date.getTime());
|
|
19
|
+
n2.setDate(1);
|
|
20
|
+
n2.setMonth(n2.getMonth() + count);
|
|
21
|
+
n2.setDate(Math.min(n, getDaysInMonth({ year: n2.getFullYear(), month: n2.getMonth() })));
|
|
22
|
+
|
|
23
|
+
return n2;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// https://stackoverflow.com/a/1185068/2508481
|
|
27
|
+
// pass in any date as parameter anyDateInMonth based on dayjs
|
|
28
|
+
export function getDaysInMonth({ year, month }: { year: number; month: number }): number {
|
|
29
|
+
return [31, isLeapYear({ year }) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getFirstDayOfMonth({ year, month }: { year: number; month: number }): number {
|
|
33
|
+
return new Date(year, month, 1).getDay();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function useRangeChecker(validRange: ValidRangeType | undefined) {
|
|
37
|
+
const validStart = validRange?.startDate;
|
|
38
|
+
const validEnd = validRange?.endDate;
|
|
39
|
+
const startUnix =
|
|
40
|
+
validStart instanceof Date ? dateToUnix(getStartOfDay(validStart)) : undefined;
|
|
41
|
+
|
|
42
|
+
const endUnix = validEnd instanceof Date ? dateToUnix(getEndOfDay(validEnd)) : undefined;
|
|
43
|
+
|
|
44
|
+
const validDisabledDatesRef = useLatest(validRange?.disabledDates);
|
|
45
|
+
|
|
46
|
+
const isWithinValidRange = useCallback(
|
|
47
|
+
(day: Date) => {
|
|
48
|
+
return isDateWithinOptionalRange(day, {
|
|
49
|
+
startUnix: startUnix,
|
|
50
|
+
endUnix: endUnix,
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
[startUnix, endUnix],
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const isDisabled = useCallback(
|
|
57
|
+
(day: Date) => {
|
|
58
|
+
return validDisabledDatesRef.current
|
|
59
|
+
? validDisabledDatesRef.current.some(disabledDate =>
|
|
60
|
+
areDatesOnSameDay(disabledDate, day),
|
|
61
|
+
)
|
|
62
|
+
: false;
|
|
63
|
+
},
|
|
64
|
+
[validDisabledDatesRef],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return { isDisabled, isWithinValidRange, validStart, validEnd };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function areDatesOnSameDay(a: Date, b?: Date | null | undefined) {
|
|
71
|
+
if (!b) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
a.getFullYear() === b.getFullYear() &&
|
|
77
|
+
a.getMonth() === b.getMonth() &&
|
|
78
|
+
a.getDate() === b.getDate()
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function isDateBetween(
|
|
83
|
+
date: Date,
|
|
84
|
+
{
|
|
85
|
+
startDate,
|
|
86
|
+
endDate,
|
|
87
|
+
}: {
|
|
88
|
+
startDate?: Date | null | undefined;
|
|
89
|
+
endDate?: Date | null | undefined;
|
|
90
|
+
},
|
|
91
|
+
): boolean {
|
|
92
|
+
if (!startDate || !endDate) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return date <= endDate && date >= startDate;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Check if a date is within an optional range.
|
|
100
|
+
*
|
|
101
|
+
* If the range doesn't exist, it defaults to `true`.
|
|
102
|
+
*/
|
|
103
|
+
export function isDateWithinOptionalRange(
|
|
104
|
+
date: Date,
|
|
105
|
+
{ startUnix, endUnix }: { startUnix: number | undefined; endUnix: number | undefined },
|
|
106
|
+
) {
|
|
107
|
+
const dateUnix = dateToUnix(date);
|
|
108
|
+
// if startUnix is provided and date is before start
|
|
109
|
+
if (startUnix && dateUnix < startUnix) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// if endUnix is provided and date is after end
|
|
114
|
+
if (endUnix && dateUnix > endUnix) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function isLeapYear({ year }: { year: number }) {
|
|
122
|
+
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export const daySize = 40;
|
|
126
|
+
export const estimatedMonthHeight = 360;
|
|
127
|
+
// TODO This number startAtIndex is not adding any significance to the date picker, So we probably will change the logic.
|
|
128
|
+
export const startAtIndex = 1200;
|
|
129
|
+
export const totalMonths = startAtIndex * 2;
|
|
130
|
+
export const beginOffset = estimatedMonthHeight * startAtIndex;
|
|
131
|
+
export const gridCounts = new Array<number | undefined>(totalMonths);
|
|
132
|
+
|
|
133
|
+
export function getGridCount(index: number) {
|
|
134
|
+
const cHeight = gridCounts[index];
|
|
135
|
+
if (cHeight) {
|
|
136
|
+
return cHeight + 1;
|
|
137
|
+
}
|
|
138
|
+
const monthDate = addMonths(new Date(), getRealIndex(index));
|
|
139
|
+
const h = getGridCountForDate(monthDate);
|
|
140
|
+
gridCounts[index] = h;
|
|
141
|
+
return h;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function getGridCountForDate(date: Date) {
|
|
145
|
+
const year = date.getFullYear();
|
|
146
|
+
const month = date.getMonth();
|
|
147
|
+
const daysInMonth = getDaysInMonth({ year, month });
|
|
148
|
+
const dayOfWeek = getFirstDayOfMonth({ year, month });
|
|
149
|
+
return Math.ceil((daysInMonth + dayOfWeek) / 7);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function getRealIndex(index: number) {
|
|
153
|
+
return index - startAtIndex;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function getInitialIndex(date: Date | undefined) {
|
|
157
|
+
if (!date) {
|
|
158
|
+
return startAtIndex;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const today = new Date();
|
|
162
|
+
const months = differenceInMonths(today, date);
|
|
163
|
+
|
|
164
|
+
return startAtIndex + months;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function getStartOfDay(d: Date): Date {
|
|
168
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function getEndOfDay(d: Date): Date {
|
|
172
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59, 59);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function differenceInMonths(firstDate: Date, secondDate: Date) {
|
|
176
|
+
let diffMonths = (secondDate.getFullYear() - firstDate.getFullYear()) * 12;
|
|
177
|
+
diffMonths -= firstDate.getMonth();
|
|
178
|
+
diffMonths += secondDate.getMonth();
|
|
179
|
+
return diffMonths;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
type GenerateCalendarGridArgs = {
|
|
183
|
+
year: number;
|
|
184
|
+
month: number;
|
|
185
|
+
monthGrid: (index: number) => { days: any[]; weekGrid: number }[];
|
|
186
|
+
index: number;
|
|
187
|
+
isDisabled: (day: Date) => boolean;
|
|
188
|
+
startDate: CalendarDate;
|
|
189
|
+
endDate: CalendarDate;
|
|
190
|
+
mode: 'single' | 'range' | 'multiple';
|
|
191
|
+
dates: CalendarDates;
|
|
192
|
+
date: CalendarDate;
|
|
193
|
+
isWithinValidRange: (day: Date) => boolean;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export const generateCalendarGrid = ({
|
|
197
|
+
year,
|
|
198
|
+
month,
|
|
199
|
+
monthGrid,
|
|
200
|
+
index,
|
|
201
|
+
isDisabled,
|
|
202
|
+
startDate,
|
|
203
|
+
endDate,
|
|
204
|
+
mode,
|
|
205
|
+
dates,
|
|
206
|
+
date,
|
|
207
|
+
isWithinValidRange,
|
|
208
|
+
}: GenerateCalendarGridArgs) => {
|
|
209
|
+
const today = new Date();
|
|
210
|
+
|
|
211
|
+
const daysInMonth = getDaysInMonth({ year, month });
|
|
212
|
+
const dayOfWeek = getFirstDayOfMonth({ year, month });
|
|
213
|
+
const emptyDays = dayOfWeek;
|
|
214
|
+
|
|
215
|
+
return monthGrid(index).map(({ days, weekGrid }) => {
|
|
216
|
+
return {
|
|
217
|
+
weekIndex: weekGrid,
|
|
218
|
+
generatedDays: days.map((_, dayIndex) => {
|
|
219
|
+
const isFirstWeek = weekGrid === 0;
|
|
220
|
+
const realDayIndex = emptyDays - dayIndex;
|
|
221
|
+
const beforeWeekDay = isFirstWeek && realDayIndex > 0;
|
|
222
|
+
const dayOfMonth = weekGrid * 7 + dayIndex - emptyDays + 1;
|
|
223
|
+
const afterWeekDay = dayOfMonth > daysInMonth;
|
|
224
|
+
|
|
225
|
+
const day = new Date(year, month, dayOfMonth);
|
|
226
|
+
const isToday = areDatesOnSameDay(day, today);
|
|
227
|
+
|
|
228
|
+
let inRange = false;
|
|
229
|
+
let disabled = isDisabled(day);
|
|
230
|
+
let selected = false;
|
|
231
|
+
|
|
232
|
+
let leftCrop = dayOfMonth === 1;
|
|
233
|
+
let rightCrop = dayOfMonth === daysInMonth;
|
|
234
|
+
|
|
235
|
+
const isFirstDayOfMonth = dayOfMonth === 1;
|
|
236
|
+
const isLastDayOfMonth = dayOfMonth === daysInMonth;
|
|
237
|
+
|
|
238
|
+
if (mode === 'range') {
|
|
239
|
+
const selectedStartDay = areDatesOnSameDay(day, startDate);
|
|
240
|
+
const selectedEndDay = areDatesOnSameDay(day, endDate);
|
|
241
|
+
selected = selectedStartDay || selectedEndDay;
|
|
242
|
+
inRange = isDateBetween(day, {
|
|
243
|
+
startDate,
|
|
244
|
+
endDate,
|
|
245
|
+
});
|
|
246
|
+
if (selectedStartDay) {
|
|
247
|
+
leftCrop = true;
|
|
248
|
+
}
|
|
249
|
+
if (selectedEndDay) {
|
|
250
|
+
rightCrop = true;
|
|
251
|
+
}
|
|
252
|
+
if (dayIndex === 0 && !selectedStartDay) {
|
|
253
|
+
leftCrop = false;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (dayIndex === 6 && !selectedEndDay) {
|
|
257
|
+
rightCrop = false;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (
|
|
261
|
+
(isFirstDayOfMonth && selectedEndDay) ||
|
|
262
|
+
(isLastDayOfMonth && selectedStartDay)
|
|
263
|
+
) {
|
|
264
|
+
inRange = false;
|
|
265
|
+
}
|
|
266
|
+
} else if (mode === 'multiple') {
|
|
267
|
+
const safeDates = dates || [];
|
|
268
|
+
selected = safeDates.some(d => areDatesOnSameDay(day, d));
|
|
269
|
+
|
|
270
|
+
const yesterday = new Date(year, month, dayOfMonth - 1);
|
|
271
|
+
const tomorrow = new Date(year, month, dayOfMonth + 1);
|
|
272
|
+
|
|
273
|
+
const yesterdaySelected = safeDates.some(d => areDatesOnSameDay(d, yesterday));
|
|
274
|
+
const tomorrowSelected = safeDates.some(d => areDatesOnSameDay(d, tomorrow));
|
|
275
|
+
|
|
276
|
+
if (selected) {
|
|
277
|
+
if (tomorrowSelected && yesterdaySelected) {
|
|
278
|
+
inRange = true;
|
|
279
|
+
}
|
|
280
|
+
if (tomorrowSelected && !yesterdaySelected) {
|
|
281
|
+
inRange = true;
|
|
282
|
+
leftCrop = true;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (yesterdaySelected && !tomorrowSelected) {
|
|
286
|
+
inRange = true;
|
|
287
|
+
rightCrop = true;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (isFirstDayOfMonth && !tomorrowSelected) {
|
|
291
|
+
inRange = false;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (isLastDayOfMonth && !yesterdaySelected) {
|
|
295
|
+
inRange = false;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (inRange && !leftCrop && !rightCrop) {
|
|
299
|
+
selected = false;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
} else if (mode === 'single') {
|
|
303
|
+
selected = areDatesOnSameDay(day, date);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const isWithinOptionalValidRange = isWithinValidRange(day);
|
|
307
|
+
|
|
308
|
+
if (inRange && !disabled) {
|
|
309
|
+
disabled = false;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (!isWithinOptionalValidRange) {
|
|
313
|
+
disabled = true;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return {
|
|
317
|
+
beforeWeekDay,
|
|
318
|
+
afterWeekDay,
|
|
319
|
+
year,
|
|
320
|
+
month,
|
|
321
|
+
dayOfMonth,
|
|
322
|
+
dayIndex,
|
|
323
|
+
mode,
|
|
324
|
+
selected,
|
|
325
|
+
inRange,
|
|
326
|
+
leftCrop,
|
|
327
|
+
rightCrop,
|
|
328
|
+
isToday,
|
|
329
|
+
disabled,
|
|
330
|
+
};
|
|
331
|
+
}),
|
|
332
|
+
};
|
|
333
|
+
});
|
|
334
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
|
|
2
|
+
import DatePickerInlineDefault from './DatePickerInline';
|
|
3
|
+
|
|
4
|
+
registerMoleculesComponents({
|
|
5
|
+
DatePickerInline: DatePickerInlineDefault,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const DatePickerInline = getRegisteredComponentWithFallback(
|
|
9
|
+
'DatePickerInline',
|
|
10
|
+
DatePickerInlineDefault,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export { type DatePickerInlineProps, getStateValue } from './DatePickerInline';
|
|
14
|
+
export { default as DatePickerInlineBase } from './DatePickerInlineBase';
|
|
15
|
+
export type {
|
|
16
|
+
BaseDatePickerProps,
|
|
17
|
+
CalendarDate,
|
|
18
|
+
CalendarDates,
|
|
19
|
+
DatePickerInlineBaseProps,
|
|
20
|
+
DatePickerMultiProps,
|
|
21
|
+
DatePickerRangeProps,
|
|
22
|
+
DatePickerSingleProps,
|
|
23
|
+
ModeType,
|
|
24
|
+
MultiChange,
|
|
25
|
+
MultiConfirm,
|
|
26
|
+
RangeChange,
|
|
27
|
+
SingleChange,
|
|
28
|
+
ValidRangeType,
|
|
29
|
+
} from './types';
|
|
30
|
+
export {
|
|
31
|
+
dateDayNameStyles,
|
|
32
|
+
datePickerDayEmptyStyles,
|
|
33
|
+
datePickerDayRangeStyles,
|
|
34
|
+
datePickerDayStyles,
|
|
35
|
+
datePickerHeaderStyles,
|
|
36
|
+
datePickerMonthStyles,
|
|
37
|
+
datePickerStyles,
|
|
38
|
+
datePickerWeekStyles,
|
|
39
|
+
datePickerYearItemStyles,
|
|
40
|
+
datePickerYearPickerStyles,
|
|
41
|
+
} from './utils';
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { MemoExoticComponent } from 'react';
|
|
2
|
+
import type { ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import type { CalendarHeaderProps } from './DatePickerInlineHeader';
|
|
5
|
+
import type { DisableWeekDaysType } from './dateUtils';
|
|
6
|
+
|
|
7
|
+
export interface BaseMonthProps {
|
|
8
|
+
locale: undefined | string;
|
|
9
|
+
scrollMode: 'horizontal' | 'vertical';
|
|
10
|
+
disableWeekDays?: DisableWeekDaysType;
|
|
11
|
+
mode: ModeType;
|
|
12
|
+
index: number;
|
|
13
|
+
onPressDate: (date: Date) => any;
|
|
14
|
+
validRange?: ValidRangeType;
|
|
15
|
+
customMonthStyles?: Record<string, any>;
|
|
16
|
+
|
|
17
|
+
// some of these should be required in final implementation
|
|
18
|
+
date?: CalendarDate;
|
|
19
|
+
dates?: CalendarDates;
|
|
20
|
+
startDate?: CalendarDate;
|
|
21
|
+
endDate?: CalendarDate;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface MonthRangeProps extends BaseMonthProps {
|
|
25
|
+
mode: 'range';
|
|
26
|
+
startDate: CalendarDate;
|
|
27
|
+
endDate: CalendarDate;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface MonthSingleProps extends BaseMonthProps {
|
|
31
|
+
mode: 'single';
|
|
32
|
+
date: CalendarDate;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface MonthMultiProps extends BaseMonthProps {
|
|
36
|
+
mode: 'multiple';
|
|
37
|
+
dates: CalendarDates;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type ModeType = 'single' | 'range' | 'multiple';
|
|
41
|
+
|
|
42
|
+
export type ValidRangeType = {
|
|
43
|
+
startDate?: Date;
|
|
44
|
+
endDate?: Date;
|
|
45
|
+
disabledDates?: Date[];
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type BaseDatePickerProps = {
|
|
49
|
+
locale?: string;
|
|
50
|
+
disableWeekDays?: DisableWeekDaysType;
|
|
51
|
+
validRange?: ValidRangeType;
|
|
52
|
+
startYear?: number;
|
|
53
|
+
endYear?: number;
|
|
54
|
+
HeaderComponent?: MemoExoticComponent<CalendarHeaderProps | any>;
|
|
55
|
+
monthStyle?: Record<string, any>;
|
|
56
|
+
|
|
57
|
+
// here they are optional but in final implemenation they are required
|
|
58
|
+
date?: CalendarDate;
|
|
59
|
+
dates?: CalendarDates;
|
|
60
|
+
startDate?: CalendarDate;
|
|
61
|
+
endDate?: CalendarDate;
|
|
62
|
+
dateMode?: 'start' | 'end';
|
|
63
|
+
style?: ViewStyle;
|
|
64
|
+
onToggle?: () => void;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type CalendarDate = Date | null | undefined;
|
|
68
|
+
export type CalendarDates = Date[] | undefined | null;
|
|
69
|
+
|
|
70
|
+
export type RangeChange = (params: { startDate: CalendarDate; endDate: CalendarDate }) => any;
|
|
71
|
+
|
|
72
|
+
export type SingleChange = (params: { date: CalendarDate }) => void;
|
|
73
|
+
|
|
74
|
+
export type MultiChange = (params: {
|
|
75
|
+
dates: CalendarDates;
|
|
76
|
+
datePressed: Date;
|
|
77
|
+
change: 'added' | 'removed';
|
|
78
|
+
}) => any;
|
|
79
|
+
|
|
80
|
+
export type MultiConfirm = (params: { dates: Date[] }) => void;
|
|
81
|
+
|
|
82
|
+
export interface DatePickerSingleProps extends BaseDatePickerProps {
|
|
83
|
+
mode?: 'single';
|
|
84
|
+
date?: CalendarDate;
|
|
85
|
+
onChange?: SingleChange;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface DatePickerRangeProps extends BaseDatePickerProps {
|
|
89
|
+
mode?: 'range';
|
|
90
|
+
startDate?: CalendarDate;
|
|
91
|
+
endDate?: CalendarDate;
|
|
92
|
+
onChange?: RangeChange;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface DatePickerMultiProps extends BaseDatePickerProps {
|
|
96
|
+
mode?: 'multiple';
|
|
97
|
+
dates?: CalendarDates;
|
|
98
|
+
onChange?: MultiChange;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type DatePickerInlineBaseProps =
|
|
102
|
+
| DatePickerSingleProps
|
|
103
|
+
| DatePickerRangeProps
|
|
104
|
+
| DatePickerMultiProps;
|