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,285 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
+
|
|
3
|
+
import { getRegisteredMoleculesComponentStyles, registerComponentsStyles } from '../../core';
|
|
4
|
+
import { circleSize } from './timeUtils';
|
|
5
|
+
|
|
6
|
+
const timePickerStylesDefault = StyleSheet.create(theme => ({
|
|
7
|
+
container: {
|
|
8
|
+
alignItems: 'center',
|
|
9
|
+
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
landScape: {
|
|
13
|
+
flexDirection: 'row',
|
|
14
|
+
alignItems: 'center',
|
|
15
|
+
justifyContent: 'center',
|
|
16
|
+
width: 24 * 3 + 96 * 2 + 52 + circleSize,
|
|
17
|
+
},
|
|
18
|
+
landScapeWithoutClock: {
|
|
19
|
+
flexDirection: 'row',
|
|
20
|
+
alignItems: 'center',
|
|
21
|
+
justifyContent: 'center',
|
|
22
|
+
width: 24 * 3 + 96 * 2 + 12,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
clockContainer: {
|
|
28
|
+
paddingLeft: theme.spacings['3'],
|
|
29
|
+
paddingRight: theme.spacings['3'],
|
|
30
|
+
alignItems: 'center',
|
|
31
|
+
|
|
32
|
+
variants: {
|
|
33
|
+
variant: {
|
|
34
|
+
default: {
|
|
35
|
+
marginTop: theme.spacings['9'],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
const timePickerInputsStylesDefault = StyleSheet.create(theme => ({
|
|
43
|
+
spaceBetweenInputsAndSwitcher: { width: 12 },
|
|
44
|
+
inputContainer: {
|
|
45
|
+
flexDirection: 'row',
|
|
46
|
+
alignItems: 'center',
|
|
47
|
+
|
|
48
|
+
variants: {
|
|
49
|
+
state: {
|
|
50
|
+
landScape: {
|
|
51
|
+
flex: 1,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
hoursAndMinutesSeparator: {
|
|
57
|
+
fontSize: 65,
|
|
58
|
+
width: 24,
|
|
59
|
+
alignItems: 'center',
|
|
60
|
+
},
|
|
61
|
+
spaceDot: {
|
|
62
|
+
flex: 1,
|
|
63
|
+
},
|
|
64
|
+
dot: {
|
|
65
|
+
width: 7,
|
|
66
|
+
height: 7,
|
|
67
|
+
borderRadius: theme.shapes.corner.full,
|
|
68
|
+
backgroundColor: theme.colors.onSurface,
|
|
69
|
+
},
|
|
70
|
+
betweenDot: {
|
|
71
|
+
height: 12,
|
|
72
|
+
},
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
const timePickerInputStylesDefault = StyleSheet.create(theme => ({
|
|
76
|
+
root: {
|
|
77
|
+
rippleColor: theme.colors.onPrimaryContainer,
|
|
78
|
+
} as any,
|
|
79
|
+
|
|
80
|
+
container: {
|
|
81
|
+
position: 'relative',
|
|
82
|
+
},
|
|
83
|
+
input: {
|
|
84
|
+
fontSize: theme.typescale.displayLarge.fontSize,
|
|
85
|
+
lineHeight: theme.typescale.displayLarge.lineHeight,
|
|
86
|
+
textAlign: 'center',
|
|
87
|
+
textAlignVertical: 'center',
|
|
88
|
+
width: 96,
|
|
89
|
+
height: 80,
|
|
90
|
+
backgroundColor: theme.colors.surfaceVariant,
|
|
91
|
+
color: theme.colors.onSurface,
|
|
92
|
+
borderRadius: theme.shapes.corner.small,
|
|
93
|
+
|
|
94
|
+
variants: {
|
|
95
|
+
state: {
|
|
96
|
+
highlighted: {
|
|
97
|
+
backgroundColor: theme.colors.primaryContainer,
|
|
98
|
+
color: theme.colors.primary,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
button: {
|
|
104
|
+
overflow: 'hidden',
|
|
105
|
+
borderRadius: theme.shapes.corner.small,
|
|
106
|
+
},
|
|
107
|
+
}));
|
|
108
|
+
|
|
109
|
+
const timePickerClockStylesDefault = StyleSheet.create(theme => ({
|
|
110
|
+
clock: {
|
|
111
|
+
height: circleSize,
|
|
112
|
+
width: circleSize,
|
|
113
|
+
position: 'relative',
|
|
114
|
+
justifyContent: 'center',
|
|
115
|
+
alignItems: 'center',
|
|
116
|
+
borderRadius: theme.shapes.corner.full,
|
|
117
|
+
backgroundColor: theme.colors.surfaceVariant,
|
|
118
|
+
},
|
|
119
|
+
middlePoint: {
|
|
120
|
+
borderRadius: theme.spacings['1'],
|
|
121
|
+
height: 8,
|
|
122
|
+
width: 8,
|
|
123
|
+
backgroundColor: theme.colors.primary,
|
|
124
|
+
},
|
|
125
|
+
center: { justifyContent: 'center', alignItems: 'center' },
|
|
126
|
+
endPoint: {
|
|
127
|
+
borderRadius: theme.shapes.corner.full,
|
|
128
|
+
height: 30,
|
|
129
|
+
width: 30,
|
|
130
|
+
position: 'absolute',
|
|
131
|
+
right: 0,
|
|
132
|
+
bottom: -14,
|
|
133
|
+
backgroundColor: theme.colors.primary,
|
|
134
|
+
},
|
|
135
|
+
line: {
|
|
136
|
+
position: 'absolute',
|
|
137
|
+
marginBottom: -1,
|
|
138
|
+
height: 2,
|
|
139
|
+
borderRadius: theme.shapes.corner.extraSmall,
|
|
140
|
+
backgroundColor: theme.colors.primary,
|
|
141
|
+
},
|
|
142
|
+
}));
|
|
143
|
+
|
|
144
|
+
const timePickerClockHoursStylesDefault = StyleSheet.create(theme => ({
|
|
145
|
+
root: {
|
|
146
|
+
activeTextColor: theme.colors.onPrimary,
|
|
147
|
+
} as any,
|
|
148
|
+
|
|
149
|
+
outerHourRoot: {
|
|
150
|
+
position: 'absolute',
|
|
151
|
+
justifyContent: 'center',
|
|
152
|
+
alignItems: 'center',
|
|
153
|
+
zIndex: 20,
|
|
154
|
+
width: 50,
|
|
155
|
+
height: 50,
|
|
156
|
+
marginLeft: -25,
|
|
157
|
+
marginTop: -25,
|
|
158
|
+
|
|
159
|
+
borderRadius: theme.shapes.corner.full,
|
|
160
|
+
},
|
|
161
|
+
outerHourInner: {
|
|
162
|
+
borderRadius: theme.shapes.corner.full,
|
|
163
|
+
},
|
|
164
|
+
innerHourRoot: {
|
|
165
|
+
position: 'absolute',
|
|
166
|
+
zIndex: 20,
|
|
167
|
+
justifyContent: 'center',
|
|
168
|
+
alignItems: 'center',
|
|
169
|
+
width: 40,
|
|
170
|
+
height: 40,
|
|
171
|
+
marginLeft: -20,
|
|
172
|
+
marginTop: -20,
|
|
173
|
+
borderRadius: theme.shapes.corner.full,
|
|
174
|
+
},
|
|
175
|
+
innerHourInner: {
|
|
176
|
+
borderRadius: theme.shapes.corner.full,
|
|
177
|
+
},
|
|
178
|
+
innerHourText: { fontSize: 13 },
|
|
179
|
+
}));
|
|
180
|
+
|
|
181
|
+
const timePickerClockMinutesStylesDefault = StyleSheet.create(theme => ({
|
|
182
|
+
root: {
|
|
183
|
+
activeTextColor: theme.colors.onPrimary,
|
|
184
|
+
} as any,
|
|
185
|
+
|
|
186
|
+
outerHourRoot: {
|
|
187
|
+
position: 'absolute',
|
|
188
|
+
justifyContent: 'center',
|
|
189
|
+
alignItems: 'center',
|
|
190
|
+
zIndex: 20,
|
|
191
|
+
width: 50,
|
|
192
|
+
height: 50,
|
|
193
|
+
marginLeft: -25,
|
|
194
|
+
marginTop: -25,
|
|
195
|
+
|
|
196
|
+
borderRadius: theme.shapes.corner.full,
|
|
197
|
+
},
|
|
198
|
+
outerHourInner: {
|
|
199
|
+
borderRadius: theme.shapes.corner.full,
|
|
200
|
+
},
|
|
201
|
+
innerHourRoot: {
|
|
202
|
+
position: 'absolute',
|
|
203
|
+
zIndex: 20,
|
|
204
|
+
justifyContent: 'center',
|
|
205
|
+
alignItems: 'center',
|
|
206
|
+
width: 40,
|
|
207
|
+
height: 40,
|
|
208
|
+
marginLeft: -20,
|
|
209
|
+
marginTop: -20,
|
|
210
|
+
borderRadius: theme.shapes.corner.full,
|
|
211
|
+
},
|
|
212
|
+
innerHourInner: {
|
|
213
|
+
borderRadius: theme.shapes.corner.full,
|
|
214
|
+
},
|
|
215
|
+
innerHourText: {
|
|
216
|
+
fontSize: theme.typescale.labelLarge.fontSize,
|
|
217
|
+
},
|
|
218
|
+
textWhite: { color: '#fff' },
|
|
219
|
+
}));
|
|
220
|
+
|
|
221
|
+
const timePickerAmPmSwitcherStylesDefault = StyleSheet.create(theme => ({
|
|
222
|
+
container: {
|
|
223
|
+
width: 50,
|
|
224
|
+
height: 80,
|
|
225
|
+
borderWidth: 1,
|
|
226
|
+
overflow: 'hidden',
|
|
227
|
+
borderColor: theme.colors.outline,
|
|
228
|
+
borderRadius: theme.shapes.corner.small,
|
|
229
|
+
},
|
|
230
|
+
switchSeparator: {
|
|
231
|
+
height: 1,
|
|
232
|
+
width: 48,
|
|
233
|
+
backgroundColor: theme.colors.outline,
|
|
234
|
+
},
|
|
235
|
+
switchButton: {
|
|
236
|
+
flex: 1,
|
|
237
|
+
},
|
|
238
|
+
switchButtonInner: {
|
|
239
|
+
flex: 1,
|
|
240
|
+
alignItems: 'center',
|
|
241
|
+
justifyContent: 'center',
|
|
242
|
+
backgroundColor: theme.colors.surface,
|
|
243
|
+
|
|
244
|
+
variants: {
|
|
245
|
+
state: {
|
|
246
|
+
selected: {
|
|
247
|
+
backgroundColor: theme.colors.tertiaryContainer,
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
text: {
|
|
253
|
+
...theme.typescale.bodyMedium,
|
|
254
|
+
color: theme.colors.onSurface,
|
|
255
|
+
|
|
256
|
+
variants: {
|
|
257
|
+
state: {
|
|
258
|
+
selected: {
|
|
259
|
+
color: theme.colors.onTertiaryContainer,
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
}));
|
|
265
|
+
|
|
266
|
+
registerComponentsStyles({
|
|
267
|
+
TimePicker: timePickerStylesDefault,
|
|
268
|
+
TimePicker_Inputs: timePickerInputsStylesDefault,
|
|
269
|
+
TimePicker_Input: timePickerInputStylesDefault,
|
|
270
|
+
TimePicker_Clock: timePickerClockStylesDefault,
|
|
271
|
+
TimePicker_ClockHours: timePickerClockHoursStylesDefault,
|
|
272
|
+
TimePicker_ClockMinutes: timePickerClockMinutesStylesDefault,
|
|
273
|
+
TimePicker_AmPmSwitcher: timePickerAmPmSwitcherStylesDefault,
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
export const timePickerStyles = getRegisteredMoleculesComponentStyles('TimePicker');
|
|
277
|
+
export const timePickerInputsStyles = getRegisteredMoleculesComponentStyles('TimePicker_Inputs');
|
|
278
|
+
export const timePickerInputStyles = getRegisteredMoleculesComponentStyles('TimePicker_Input');
|
|
279
|
+
export const timePickerClockStyles = getRegisteredMoleculesComponentStyles('TimePicker_Clock');
|
|
280
|
+
export const timePickerClockHoursStyles =
|
|
281
|
+
getRegisteredMoleculesComponentStyles('TimePicker_ClockHours');
|
|
282
|
+
export const timePickerClockMinutesStyles =
|
|
283
|
+
getRegisteredMoleculesComponentStyles('TimePicker_ClockMinutes');
|
|
284
|
+
export const timePickerAmPmSwitcherStyles =
|
|
285
|
+
getRegisteredMoleculesComponentStyles('TimePicker_AmPmSwitcher');
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { forwardRef, memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import type { BlurEvent, FocusEvent } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { useToggle } from '../../hooks';
|
|
5
|
+
import { IconButton, type IconButtonProps } from '../IconButton';
|
|
6
|
+
import { TextInput, type TextInputProps } from '../TextInput';
|
|
7
|
+
import type { TimePickerModalProps } from '../TimePickerModal';
|
|
8
|
+
import { TimePickerModal } from '../TimePickerModal/TimePickerModal';
|
|
9
|
+
import { sanitizeTime } from './sanitizeTime';
|
|
10
|
+
import { getFormattedTime, getOutputTime, styles, timeFormat } from './utils';
|
|
11
|
+
|
|
12
|
+
export type Props = TextInputProps & {
|
|
13
|
+
time: string;
|
|
14
|
+
onTimeChange: (time: string) => void;
|
|
15
|
+
is24Hour?: boolean;
|
|
16
|
+
withModal?: boolean;
|
|
17
|
+
modalProps?: Omit<TimePickerModalProps, 'time' | 'onConfirm' | 'isOpen' | 'onClose' | 'ref'>;
|
|
18
|
+
iconButtonProps?: Omit<Partial<IconButtonProps>, 'onPress' | 'ref'>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const TimePickerField = (
|
|
22
|
+
{
|
|
23
|
+
time,
|
|
24
|
+
onTimeChange: onTimeChangeProp,
|
|
25
|
+
is24Hour = false,
|
|
26
|
+
withModal = true,
|
|
27
|
+
style,
|
|
28
|
+
onBlur: onBlurProp,
|
|
29
|
+
modalProps = {},
|
|
30
|
+
iconButtonProps = {},
|
|
31
|
+
disabled,
|
|
32
|
+
onFocus: onFocusProp,
|
|
33
|
+
...rest
|
|
34
|
+
}: Props,
|
|
35
|
+
ref: any,
|
|
36
|
+
) => {
|
|
37
|
+
const componentStyles = useMemo(() => [styles.root, style], [style]);
|
|
38
|
+
|
|
39
|
+
const [timeString, setTimeString] = useState(() => getFormattedTime({ time, is24Hour }));
|
|
40
|
+
const isBlurredRef = useRef(true);
|
|
41
|
+
|
|
42
|
+
const currentTimeFormat = useMemo(() => timeFormat[!is24Hour ? '12' : '24'], [is24Hour]);
|
|
43
|
+
|
|
44
|
+
const { state: isOpen, handleOpen: onOpenModal, handleClose: onCloseModal } = useToggle(false);
|
|
45
|
+
|
|
46
|
+
const onChangeText = useCallback(
|
|
47
|
+
(_text: string) => {
|
|
48
|
+
const text = sanitizeTime(_text, is24Hour);
|
|
49
|
+
setTimeString(_text);
|
|
50
|
+
|
|
51
|
+
if (disabled || !text) return;
|
|
52
|
+
|
|
53
|
+
const outputTime = getOutputTime({ time: text || time, is24Hour });
|
|
54
|
+
|
|
55
|
+
onTimeChangeProp(outputTime);
|
|
56
|
+
},
|
|
57
|
+
[disabled, is24Hour, onTimeChangeProp, time],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const onConfirmTime = useCallback(
|
|
61
|
+
(newTime: string) => {
|
|
62
|
+
onCloseModal();
|
|
63
|
+
|
|
64
|
+
onTimeChangeProp(newTime);
|
|
65
|
+
},
|
|
66
|
+
[onTimeChangeProp, onCloseModal],
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const onBlur = useCallback(
|
|
70
|
+
(e: BlurEvent) => {
|
|
71
|
+
isBlurredRef.current = true;
|
|
72
|
+
onBlurProp?.(e);
|
|
73
|
+
|
|
74
|
+
if (disabled) return;
|
|
75
|
+
|
|
76
|
+
// const outputTime = getOutputTime({ time: timeString || time, is24Hour });
|
|
77
|
+
// onTimeChangeProp(outputTime);
|
|
78
|
+
|
|
79
|
+
// if (time === outputTime) {
|
|
80
|
+
setTimeString(sanitizeTime(getFormattedTime({ time, is24Hour }), is24Hour));
|
|
81
|
+
// }
|
|
82
|
+
},
|
|
83
|
+
[disabled, is24Hour, onBlurProp, time],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const onFocus = useCallback(
|
|
87
|
+
(e: FocusEvent) => {
|
|
88
|
+
isBlurredRef.current = false;
|
|
89
|
+
|
|
90
|
+
onFocusProp?.(e);
|
|
91
|
+
},
|
|
92
|
+
[onFocusProp],
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const rightElement = useMemo(() => {
|
|
96
|
+
if (!withModal) return null;
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<>
|
|
100
|
+
<IconButton
|
|
101
|
+
name="clock-outline"
|
|
102
|
+
onPress={onOpenModal}
|
|
103
|
+
disabled={disabled}
|
|
104
|
+
{...iconButtonProps}
|
|
105
|
+
/>
|
|
106
|
+
<TimePickerModal
|
|
107
|
+
{...modalProps}
|
|
108
|
+
time={getFormattedTime({ time: time, is24Hour: true })}
|
|
109
|
+
isOpen={isOpen}
|
|
110
|
+
onClose={onCloseModal}
|
|
111
|
+
onConfirm={onConfirmTime}
|
|
112
|
+
is24Hour={is24Hour}
|
|
113
|
+
/>
|
|
114
|
+
</>
|
|
115
|
+
);
|
|
116
|
+
}, [
|
|
117
|
+
disabled,
|
|
118
|
+
iconButtonProps,
|
|
119
|
+
is24Hour,
|
|
120
|
+
isOpen,
|
|
121
|
+
modalProps,
|
|
122
|
+
onCloseModal,
|
|
123
|
+
onConfirmTime,
|
|
124
|
+
onOpenModal,
|
|
125
|
+
time,
|
|
126
|
+
withModal,
|
|
127
|
+
]);
|
|
128
|
+
|
|
129
|
+
// only change masked string when the input is not focus so as to not interrup the user
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (!isBlurredRef.current) return;
|
|
132
|
+
|
|
133
|
+
setTimeString(getFormattedTime({ time, is24Hour }));
|
|
134
|
+
}, [is24Hour, time]);
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<TextInput
|
|
138
|
+
ref={ref}
|
|
139
|
+
placeholder={currentTimeFormat.format}
|
|
140
|
+
{...rest}
|
|
141
|
+
disabled={disabled}
|
|
142
|
+
value={timeString}
|
|
143
|
+
onFocus={onFocus}
|
|
144
|
+
onChangeText={onChangeText}
|
|
145
|
+
style={componentStyles}
|
|
146
|
+
onBlur={onBlur}
|
|
147
|
+
right={rightElement}
|
|
148
|
+
/>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export default memo(forwardRef(TimePickerField));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
|
|
2
|
+
import TimePickerFieldDefault from './TimePickerField';
|
|
3
|
+
|
|
4
|
+
registerMoleculesComponents({
|
|
5
|
+
TimePickerField: TimePickerFieldDefault,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const TimePickerField = getRegisteredComponentWithFallback(
|
|
9
|
+
'TimePickerField',
|
|
10
|
+
TimePickerFieldDefault,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export { type Props as TimePickerFieldProps } from './TimePickerField';
|
|
14
|
+
export { sanitizeTimeString, styles } from './utils';
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export const sanitizeTime = (value: string, is24hour = false) => {
|
|
2
|
+
// Remove all non-numeric and non-colon characters except am/pm
|
|
3
|
+
const sanitizedValue = value.replace(/[^0-9:apm]/gi, '');
|
|
4
|
+
|
|
5
|
+
const singleDigitHour = sanitizedValue.match(/^(\d{1,2})$/);
|
|
6
|
+
if (singleDigitHour) {
|
|
7
|
+
const hours = parseInt(singleDigitHour[1], 10);
|
|
8
|
+
if (!is24hour && hours >= 1 && hours <= 12) {
|
|
9
|
+
return `${hours}:00am`;
|
|
10
|
+
} else if (is24hour && hours >= 0 && hours < 24) {
|
|
11
|
+
return `${hours.toString().padStart(2, '0')}:00`;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (is24hour) {
|
|
16
|
+
// Check if it's a valid 24-hour time format (HH:MM)
|
|
17
|
+
const match24Hour = sanitizedValue.match(/^(\d{1,2}):?(\d{2})$/);
|
|
18
|
+
|
|
19
|
+
if (match24Hour) {
|
|
20
|
+
const hours = parseInt(match24Hour[1], 10);
|
|
21
|
+
const minutes = parseInt(match24Hour[2], 10);
|
|
22
|
+
|
|
23
|
+
if (hours >= 0 && hours < 24 && minutes >= 0 && minutes < 60) {
|
|
24
|
+
return `${hours.toString().padStart(2, '0')}:${minutes
|
|
25
|
+
.toString()
|
|
26
|
+
.padStart(2, '0')}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Convert 12-hour time to 24-hour time format if necessary
|
|
31
|
+
const match12Hour = sanitizedValue.match(/^(\d{1,2}):?(\d{2})\s*([ap]m)$/i);
|
|
32
|
+
if (match12Hour) {
|
|
33
|
+
let hours = parseInt(match12Hour[1], 10);
|
|
34
|
+
const minutes = parseInt(match12Hour[2], 10);
|
|
35
|
+
const period = match12Hour[3].toLowerCase();
|
|
36
|
+
|
|
37
|
+
if (hours >= 1 && hours <= 12 && minutes >= 0 && minutes < 60) {
|
|
38
|
+
if (period === 'pm' && hours < 12) {
|
|
39
|
+
hours += 12;
|
|
40
|
+
} else if (period === 'am' && hours === 12) {
|
|
41
|
+
hours = 0;
|
|
42
|
+
}
|
|
43
|
+
return `${hours.toString().padStart(2, '0')}:${minutes
|
|
44
|
+
.toString()
|
|
45
|
+
.padStart(2, '0')}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Convert 24-hour time to 12-hour time format if necessary
|
|
52
|
+
const match24Hour = sanitizedValue.match(/^(\d{1,2}):?(\d{2})$/);
|
|
53
|
+
if (match24Hour) {
|
|
54
|
+
let hours = parseInt(match24Hour[1], 10);
|
|
55
|
+
const minutes = parseInt(match24Hour[2], 10);
|
|
56
|
+
let period = 'am';
|
|
57
|
+
|
|
58
|
+
if (hours >= 0 && hours < 24 && minutes >= 0 && minutes < 60) {
|
|
59
|
+
if (hours >= 12) {
|
|
60
|
+
period = 'pm';
|
|
61
|
+
if (hours > 12) {
|
|
62
|
+
hours -= 12;
|
|
63
|
+
}
|
|
64
|
+
} else if (hours === 0) {
|
|
65
|
+
hours = 12;
|
|
66
|
+
}
|
|
67
|
+
return `${hours}:${minutes.toString().padStart(2, '0')}${period}`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Check if it's a valid 12-hour time format (HH:MM am/pm)
|
|
72
|
+
const match12Hour = sanitizedValue.match(/^(\d{1,2}):?(\d{2})\s*([ap]m)$/i);
|
|
73
|
+
if (match12Hour) {
|
|
74
|
+
const hours = parseInt(match12Hour[1], 10);
|
|
75
|
+
const minutes = parseInt(match12Hour[2], 10);
|
|
76
|
+
const period = match12Hour[3].toLowerCase();
|
|
77
|
+
|
|
78
|
+
if (hours >= 1 && hours <= 12 && minutes >= 0 && minutes < 60) {
|
|
79
|
+
return `${hours}:${minutes.toString().padStart(2, '0')}${period}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// If no match, return empty string as invalid input
|
|
84
|
+
return '';
|
|
85
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { format, parse, set } from 'date-fns';
|
|
2
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
3
|
+
|
|
4
|
+
export declare type MaskItem = string | RegExp | [RegExp];
|
|
5
|
+
export declare type MaskArray = Array<MaskItem>;
|
|
6
|
+
export declare type Mask = MaskArray | ((value?: string) => MaskArray);
|
|
7
|
+
|
|
8
|
+
import { getRegisteredMoleculesComponentStyles, registerComponentsStyles } from '../../core';
|
|
9
|
+
|
|
10
|
+
const timepickerFieldStylesDefault = StyleSheet.create({
|
|
11
|
+
root: {},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
registerComponentsStyles({
|
|
15
|
+
TimePickerField: timepickerFieldStylesDefault,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const styles = getRegisteredMoleculesComponentStyles('TimePickerField');
|
|
19
|
+
|
|
20
|
+
export const timeMask24Hour: Mask = (text: string = '') => {
|
|
21
|
+
const cleanTime = text.replace(/\D+/g, '');
|
|
22
|
+
|
|
23
|
+
const hourFirstDigit = /[012]/; // only 0,1 or 2
|
|
24
|
+
let hourSecondDigit = /\d/; // any number
|
|
25
|
+
|
|
26
|
+
if (cleanTime.charAt(0) === '2') {
|
|
27
|
+
hourSecondDigit = /[0123]/; // only 0,1,2 or 3
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const minuteFirstDigit = /[012345]/; // only 0,1,2,3,4 or 5
|
|
31
|
+
const minuteSecondDigit = /\d/; // any number
|
|
32
|
+
|
|
33
|
+
return [hourFirstDigit, hourSecondDigit, ':', minuteFirstDigit, minuteSecondDigit];
|
|
34
|
+
};
|
|
35
|
+
export const timeMask12Hour: Mask = (text: string = '') => {
|
|
36
|
+
const cleanTime = text.replace(/\D+/g, '');
|
|
37
|
+
|
|
38
|
+
const hourFirstDigit = /[01]/; // only 0,1 or 2
|
|
39
|
+
let hourSecondDigit = /\d/; // any number
|
|
40
|
+
|
|
41
|
+
if (cleanTime.charAt(0) === '1') {
|
|
42
|
+
hourSecondDigit = /[012]/; // only 0,1,2 or 3
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const minuteFirstDigit = /[012345]/; // only 0,1,2,3,4 or 5
|
|
46
|
+
const minuteSecondDigit = /\d/; // any number
|
|
47
|
+
|
|
48
|
+
return [hourFirstDigit, hourSecondDigit, ':', minuteFirstDigit, minuteSecondDigit, /[ap]/, 'm'];
|
|
49
|
+
};
|
|
50
|
+
export const timeFormat = {
|
|
51
|
+
'24': {
|
|
52
|
+
format: 'HH:mm',
|
|
53
|
+
mask: timeMask24Hour,
|
|
54
|
+
},
|
|
55
|
+
'12': {
|
|
56
|
+
format: 'hh:mmaaa',
|
|
57
|
+
mask: timeMask12Hour,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const referenceDate = new Date('2022-01-01T00:00:00.000Z');
|
|
62
|
+
|
|
63
|
+
export const sanitizeTimeString = (time: string): string => time.replace(/[^\d:]/g, '');
|
|
64
|
+
|
|
65
|
+
export const getFormattedTime = ({ time, is24Hour }: { time: string; is24Hour: boolean }) => {
|
|
66
|
+
if (!time) {
|
|
67
|
+
return '';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const [hour = '0', minute = '0'] = sanitizeTimeString(time).split(':');
|
|
71
|
+
|
|
72
|
+
const newHour = hour.padStart(2, '0');
|
|
73
|
+
const newMinute = minute.padStart(2, '0');
|
|
74
|
+
|
|
75
|
+
return format(
|
|
76
|
+
set(referenceDate, { hours: +newHour, minutes: +newMinute }),
|
|
77
|
+
timeFormat[is24Hour ? '24' : '12'].format,
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const getOutputTime = ({ time, is24Hour }: { time: string; is24Hour: boolean }) => {
|
|
82
|
+
if (!time) return '';
|
|
83
|
+
|
|
84
|
+
const formattedTime = sanitizeTimeString(getFormattedTime({ time, is24Hour }));
|
|
85
|
+
const isPM = time.replace(/[\d:]/g, '').includes('p');
|
|
86
|
+
|
|
87
|
+
return format(
|
|
88
|
+
parse(
|
|
89
|
+
formattedTime + (is24Hour ? '' : isPM ? 'pm' : 'am'),
|
|
90
|
+
timeFormat[is24Hour ? '24' : '12'].format,
|
|
91
|
+
referenceDate,
|
|
92
|
+
),
|
|
93
|
+
'HH:mm',
|
|
94
|
+
);
|
|
95
|
+
};
|