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,112 @@
|
|
|
1
|
+
import { forwardRef, memo, useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { useTheme } from '../../hooks';
|
|
5
|
+
import { resolveStateVariant } from '../../utils';
|
|
6
|
+
import { TextInput, type TextInputProps } from '../TextInput';
|
|
7
|
+
import { TouchableRipple } from '../TouchableRipple';
|
|
8
|
+
import { inputTypes, type PossibleClockTypes, type PossibleInputTypes } from './timeUtils';
|
|
9
|
+
import { timePickerInputStyles } from './utils';
|
|
10
|
+
|
|
11
|
+
interface TimeInputProps
|
|
12
|
+
extends Omit<
|
|
13
|
+
Omit<TextInputProps, 'value' | 'variant' | 'onChangeText' | 'onPress'>,
|
|
14
|
+
'onFocus'
|
|
15
|
+
> {
|
|
16
|
+
value: number;
|
|
17
|
+
clockType: PossibleClockTypes;
|
|
18
|
+
onPress?: (type: PossibleClockTypes) => any;
|
|
19
|
+
pressed: boolean;
|
|
20
|
+
onChanged: (n: number) => any;
|
|
21
|
+
inputType: PossibleInputTypes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function TimeInput(
|
|
25
|
+
{
|
|
26
|
+
value,
|
|
27
|
+
clockType,
|
|
28
|
+
pressed,
|
|
29
|
+
onPress,
|
|
30
|
+
onChanged,
|
|
31
|
+
inputType,
|
|
32
|
+
inputStyle,
|
|
33
|
+
style,
|
|
34
|
+
...rest
|
|
35
|
+
}: TimeInputProps,
|
|
36
|
+
ref: any,
|
|
37
|
+
) {
|
|
38
|
+
const onInnerChange = (text: string) => {
|
|
39
|
+
onChanged(Number(text));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const theme = useTheme();
|
|
43
|
+
const [inputFocused, setInputFocused] = useState<boolean>(false);
|
|
44
|
+
|
|
45
|
+
const highlighted = inputType === inputTypes.picker ? pressed : inputFocused;
|
|
46
|
+
|
|
47
|
+
const state = resolveStateVariant({
|
|
48
|
+
highlighted,
|
|
49
|
+
});
|
|
50
|
+
timePickerInputStyles.useVariants({
|
|
51
|
+
state: state as any,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const formattedValue = useMemo(() => {
|
|
55
|
+
let _formattedValue = `${value}`;
|
|
56
|
+
|
|
57
|
+
if (!inputFocused) {
|
|
58
|
+
_formattedValue = `${value}`.length === 1 ? `0${value}` : `${value}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return _formattedValue;
|
|
62
|
+
}, [value, inputFocused]);
|
|
63
|
+
|
|
64
|
+
const { rippleColor, containerStyle, textInputContainerStyle, textInputStyle, buttonStyle } =
|
|
65
|
+
useMemo(() => {
|
|
66
|
+
const { container, input, button } = timePickerInputStyles;
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
rippleColor: timePickerInputStyles.root?._rippleColor,
|
|
70
|
+
containerStyle: container,
|
|
71
|
+
textInputContainerStyle: [{ paddingHorizontal: 0 }, style],
|
|
72
|
+
textInputStyle: [input, inputStyle],
|
|
73
|
+
buttonStyle: [StyleSheet.absoluteFill, button],
|
|
74
|
+
};
|
|
75
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
76
|
+
}, [inputStyle, style, state]);
|
|
77
|
+
|
|
78
|
+
const onFocus = useCallback(() => setInputFocused(true), []);
|
|
79
|
+
const onBlur = useCallback(() => setInputFocused(false), []);
|
|
80
|
+
const onPressInput = useCallback(() => onPress?.(clockType), [clockType, onPress]);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<View style={containerStyle}>
|
|
84
|
+
<TextInput
|
|
85
|
+
variant="plain"
|
|
86
|
+
ref={ref}
|
|
87
|
+
inputStyle={textInputStyle}
|
|
88
|
+
style={textInputContainerStyle}
|
|
89
|
+
onFocus={onFocus}
|
|
90
|
+
onBlur={onBlur}
|
|
91
|
+
keyboardAppearance={theme.dark ? 'dark' : 'default'}
|
|
92
|
+
value={formattedValue}
|
|
93
|
+
maxLength={2}
|
|
94
|
+
onChangeText={onInnerChange}
|
|
95
|
+
{...rest}
|
|
96
|
+
/>
|
|
97
|
+
<>
|
|
98
|
+
{onPress && inputType === inputTypes.picker ? (
|
|
99
|
+
<TouchableRipple
|
|
100
|
+
style={buttonStyle}
|
|
101
|
+
rippleColor={rippleColor}
|
|
102
|
+
onPress={onPressInput}
|
|
103
|
+
borderless={true}>
|
|
104
|
+
<View />
|
|
105
|
+
</TouchableRipple>
|
|
106
|
+
) : null}
|
|
107
|
+
</>
|
|
108
|
+
</View>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export default memo(forwardRef(TimeInput));
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// @typescript-eslint/no-unused-vars
|
|
2
|
+
// WORK IN PROGRESS
|
|
3
|
+
|
|
4
|
+
import { memo, useCallback, useRef } from 'react';
|
|
5
|
+
import { TextInput as TextInputNative, useWindowDimensions, View } from 'react-native';
|
|
6
|
+
|
|
7
|
+
import { useLatest } from '../../hooks';
|
|
8
|
+
import { resolveStateVariant } from '../../utils';
|
|
9
|
+
import AmPmSwitcher from './AmPmSwitcher';
|
|
10
|
+
import TimeInput from './TimeInput';
|
|
11
|
+
import {
|
|
12
|
+
clockTypes,
|
|
13
|
+
type PossibleClockTypes,
|
|
14
|
+
type PossibleInputTypes,
|
|
15
|
+
toHourInputFormat,
|
|
16
|
+
} from './timeUtils';
|
|
17
|
+
import { timePickerInputsStyles } from './utils';
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
inputType: PossibleInputTypes;
|
|
21
|
+
focused: PossibleClockTypes;
|
|
22
|
+
hours: number;
|
|
23
|
+
minutes: number;
|
|
24
|
+
onFocusInput: (type: PossibleClockTypes) => any;
|
|
25
|
+
onChange: (hoursMinutesAndFocused: {
|
|
26
|
+
hours: number;
|
|
27
|
+
minutes: number;
|
|
28
|
+
focused?: undefined | PossibleClockTypes;
|
|
29
|
+
}) => any;
|
|
30
|
+
is24Hour: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function TimeInputs({
|
|
34
|
+
hours,
|
|
35
|
+
minutes,
|
|
36
|
+
onFocusInput,
|
|
37
|
+
focused,
|
|
38
|
+
inputType,
|
|
39
|
+
onChange,
|
|
40
|
+
is24Hour,
|
|
41
|
+
}: Props) {
|
|
42
|
+
const dimensions = useWindowDimensions();
|
|
43
|
+
const isLandscape = dimensions.width > dimensions.height;
|
|
44
|
+
|
|
45
|
+
timePickerInputsStyles.useVariants({
|
|
46
|
+
state: resolveStateVariant({
|
|
47
|
+
landScape: isLandscape,
|
|
48
|
+
}) as any,
|
|
49
|
+
});
|
|
50
|
+
const startInput = useRef<TextInputNative | null>(null);
|
|
51
|
+
const endInput = useRef<TextInputNative | null>(null);
|
|
52
|
+
|
|
53
|
+
const onSubmitStartInput = useCallback(() => {
|
|
54
|
+
if (endInput.current) {
|
|
55
|
+
endInput.current.focus();
|
|
56
|
+
}
|
|
57
|
+
}, [endInput]);
|
|
58
|
+
|
|
59
|
+
const onSubmitEndInput = useCallback(() => {
|
|
60
|
+
// TODO: close modal and persist time
|
|
61
|
+
}, []);
|
|
62
|
+
|
|
63
|
+
const minutesRef = useLatest(minutes);
|
|
64
|
+
const onChangeHours = useCallback(
|
|
65
|
+
(newHours: number) => {
|
|
66
|
+
onChange({
|
|
67
|
+
hours: newHours,
|
|
68
|
+
minutes: minutesRef.current,
|
|
69
|
+
focused: clockTypes.hours,
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
[onChange, minutesRef],
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const onHourChange = useCallback(
|
|
76
|
+
(newHoursFromInput: number) => {
|
|
77
|
+
let newHours = newHoursFromInput;
|
|
78
|
+
if (newHoursFromInput >= 24) {
|
|
79
|
+
newHours = 0;
|
|
80
|
+
}
|
|
81
|
+
onChange({
|
|
82
|
+
hours: newHours,
|
|
83
|
+
minutes,
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
[minutes, onChange],
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const onMinuteChange = useCallback(
|
|
90
|
+
(newMinutesFromInput: number) => {
|
|
91
|
+
let newMinutes = newMinutesFromInput;
|
|
92
|
+
|
|
93
|
+
if (newMinutesFromInput > 59) {
|
|
94
|
+
newMinutes = 0;
|
|
95
|
+
}
|
|
96
|
+
onChange({
|
|
97
|
+
hours: hours,
|
|
98
|
+
minutes: newMinutes,
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
[hours, onChange],
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<View style={timePickerInputsStyles.inputContainer}>
|
|
106
|
+
<TimeInput
|
|
107
|
+
ref={startInput}
|
|
108
|
+
placeholder={'00'}
|
|
109
|
+
value={toHourInputFormat(hours, is24Hour)}
|
|
110
|
+
clockType={clockTypes.hours}
|
|
111
|
+
pressed={focused === clockTypes.hours}
|
|
112
|
+
onPress={onFocusInput}
|
|
113
|
+
inputType={inputType}
|
|
114
|
+
returnKeyType={'next'}
|
|
115
|
+
onSubmitEditing={onSubmitStartInput}
|
|
116
|
+
blurOnSubmit={false}
|
|
117
|
+
onChanged={onHourChange}
|
|
118
|
+
// onChangeText={onChangeStartInput}
|
|
119
|
+
/>
|
|
120
|
+
<View style={timePickerInputsStyles.hoursAndMinutesSeparator}>
|
|
121
|
+
<View style={timePickerInputsStyles.spaceDot} />
|
|
122
|
+
<View style={timePickerInputsStyles.dot} />
|
|
123
|
+
<View style={timePickerInputsStyles.betweenDot} />
|
|
124
|
+
<View style={timePickerInputsStyles.dot} />
|
|
125
|
+
<View style={timePickerInputsStyles.spaceDot} />
|
|
126
|
+
</View>
|
|
127
|
+
<TimeInput
|
|
128
|
+
ref={endInput}
|
|
129
|
+
placeholder={'00'}
|
|
130
|
+
value={minutes}
|
|
131
|
+
clockType={clockTypes.minutes}
|
|
132
|
+
pressed={focused === clockTypes.minutes}
|
|
133
|
+
onPress={onFocusInput}
|
|
134
|
+
inputType={inputType}
|
|
135
|
+
onSubmitEditing={onSubmitEndInput}
|
|
136
|
+
onChanged={onMinuteChange}
|
|
137
|
+
/>
|
|
138
|
+
{!is24Hour && (
|
|
139
|
+
<>
|
|
140
|
+
<View style={timePickerInputsStyles.spaceBetweenInputsAndSwitcher} />
|
|
141
|
+
<AmPmSwitcher hours={hours} onChange={onChangeHours} />
|
|
142
|
+
</>
|
|
143
|
+
)}
|
|
144
|
+
</View>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export default memo(TimeInputs);
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { memo, useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import { type StyleProp, View, type ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { useControlledValue } from '../../hooks';
|
|
5
|
+
import { format, parse } from '../../utils/date-fns';
|
|
6
|
+
import AnalogClock from './AnalogClock';
|
|
7
|
+
import { DisplayModeContext } from './DisplayModeContext';
|
|
8
|
+
import TimeInputs from './TimeInputs';
|
|
9
|
+
import {
|
|
10
|
+
inputTypes,
|
|
11
|
+
type PossibleClockTypes,
|
|
12
|
+
type PossibleInputTypes,
|
|
13
|
+
toHourInputFormat,
|
|
14
|
+
} from './timeUtils';
|
|
15
|
+
import { timePickerStyles } from './utils';
|
|
16
|
+
|
|
17
|
+
type onChangeFunc = ({
|
|
18
|
+
hours,
|
|
19
|
+
minutes,
|
|
20
|
+
focused,
|
|
21
|
+
}: {
|
|
22
|
+
hours: number;
|
|
23
|
+
minutes: number;
|
|
24
|
+
focused?: undefined | PossibleClockTypes;
|
|
25
|
+
}) => any;
|
|
26
|
+
|
|
27
|
+
export type Props = {
|
|
28
|
+
/**
|
|
29
|
+
* hh:mm format
|
|
30
|
+
* */
|
|
31
|
+
time: string;
|
|
32
|
+
onTimeChange: (params: { time: string; focused?: undefined | PossibleClockTypes }) => any;
|
|
33
|
+
|
|
34
|
+
is24Hour?: boolean;
|
|
35
|
+
inputType?: PossibleInputTypes;
|
|
36
|
+
focused?: PossibleClockTypes;
|
|
37
|
+
|
|
38
|
+
onFocusInput?: (type: PossibleClockTypes) => any;
|
|
39
|
+
isLandscape?: boolean;
|
|
40
|
+
style?: StyleProp<ViewStyle>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function TimePicker({
|
|
44
|
+
is24Hour = false,
|
|
45
|
+
time,
|
|
46
|
+
focused: focusedProp,
|
|
47
|
+
onFocusInput: onFocusInputProp,
|
|
48
|
+
inputType = 'keyboard',
|
|
49
|
+
onTimeChange,
|
|
50
|
+
isLandscape = false,
|
|
51
|
+
style,
|
|
52
|
+
}: Props) {
|
|
53
|
+
const { hours, minutes } = useMemo(() => {
|
|
54
|
+
const date = time ? parse(time, 'HH:mm', new Date()) : new Date();
|
|
55
|
+
|
|
56
|
+
return { hours: +format(date, 'HH'), minutes: +format(date, 'mm') };
|
|
57
|
+
}, [time]);
|
|
58
|
+
|
|
59
|
+
const [focused, onFocusInput] = useControlledValue({
|
|
60
|
+
value: focusedProp,
|
|
61
|
+
defaultValue: 'hours',
|
|
62
|
+
onChange: onFocusInputProp,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Initialize display Mode according the hours value
|
|
66
|
+
const [displayMode, setDisplayMode] = useState<'AM' | 'PM' | undefined>(() =>
|
|
67
|
+
!is24Hour ? (hours >= 12 ? 'PM' : 'AM') : undefined,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
timePickerStyles.useVariants({
|
|
71
|
+
variant: (isLandscape
|
|
72
|
+
? inputType === 'keyboard'
|
|
73
|
+
? 'landScapeWithoutClock'
|
|
74
|
+
: 'landScape'
|
|
75
|
+
: 'default') as any,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const onChange = useCallback<onChangeFunc>(
|
|
79
|
+
params => {
|
|
80
|
+
const newDisplayMode = params.hours >= 12 ? 'PM' : 'AM';
|
|
81
|
+
|
|
82
|
+
if (newDisplayMode !== displayMode) setDisplayMode(newDisplayMode);
|
|
83
|
+
|
|
84
|
+
onTimeChange?.({
|
|
85
|
+
time: `${`${params.hours}`.padStart(2, '0')}:${`${params.minutes}`.padStart(
|
|
86
|
+
2,
|
|
87
|
+
'0',
|
|
88
|
+
)}`,
|
|
89
|
+
focused: params.focused,
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
[displayMode, onTimeChange],
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const memoizedValue = useMemo(
|
|
96
|
+
() => ({ mode: displayMode, setMode: setDisplayMode }),
|
|
97
|
+
[displayMode],
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<DisplayModeContext.Provider value={memoizedValue}>
|
|
102
|
+
<View style={[timePickerStyles.container, style]}>
|
|
103
|
+
<TimeInputs
|
|
104
|
+
inputType={inputType}
|
|
105
|
+
hours={hours}
|
|
106
|
+
minutes={minutes}
|
|
107
|
+
is24Hour={is24Hour}
|
|
108
|
+
onChange={onChange}
|
|
109
|
+
onFocusInput={onFocusInput}
|
|
110
|
+
focused={focused}
|
|
111
|
+
/>
|
|
112
|
+
<>
|
|
113
|
+
{inputType === inputTypes.picker ? (
|
|
114
|
+
<View style={timePickerStyles.clockContainer}>
|
|
115
|
+
<AnalogClock
|
|
116
|
+
hours={toHourInputFormat(hours, is24Hour)}
|
|
117
|
+
minutes={minutes}
|
|
118
|
+
focused={focused}
|
|
119
|
+
is24Hour={is24Hour}
|
|
120
|
+
onChange={onChange}
|
|
121
|
+
/>
|
|
122
|
+
</View>
|
|
123
|
+
) : null}
|
|
124
|
+
</>
|
|
125
|
+
</View>
|
|
126
|
+
</DisplayModeContext.Provider>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export default memo(TimePicker);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
|
|
2
|
+
import TimePickerDefault from './TimePicker';
|
|
3
|
+
|
|
4
|
+
registerMoleculesComponents({
|
|
5
|
+
TimePicker: TimePickerDefault,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const TimePicker = getRegisteredComponentWithFallback('TimePicker', TimePickerDefault);
|
|
9
|
+
|
|
10
|
+
export type { Props as TimePickerProps } from './TimePicker';
|
|
11
|
+
export {
|
|
12
|
+
timePickerAmPmSwitcherStyles,
|
|
13
|
+
timePickerClockHoursStyles,
|
|
14
|
+
timePickerClockMinutesStyles,
|
|
15
|
+
timePickerClockStyles,
|
|
16
|
+
timePickerInputsStyles,
|
|
17
|
+
timePickerInputStyles,
|
|
18
|
+
timePickerStyles,
|
|
19
|
+
} from './utils';
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// 250? when bigger?
|
|
2
|
+
export const circleSize = 215;
|
|
3
|
+
|
|
4
|
+
export type PossibleHourTypes = 'am' | 'pm';
|
|
5
|
+
export type HourTypeMap = {
|
|
6
|
+
[hourType in PossibleHourTypes]: PossibleHourTypes;
|
|
7
|
+
};
|
|
8
|
+
export const hourTypes: HourTypeMap = {
|
|
9
|
+
am: 'am',
|
|
10
|
+
pm: 'pm',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function getHourType(hours: number): PossibleHourTypes | undefined {
|
|
14
|
+
if (hours >= 0 && hours <= 12) {
|
|
15
|
+
return hourTypes.am;
|
|
16
|
+
}
|
|
17
|
+
if (hours > 12 && hours <= 24) {
|
|
18
|
+
return hourTypes.pm;
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type PossibleInputTypes = 'keyboard' | 'picker';
|
|
24
|
+
export type InputTypeMap = {
|
|
25
|
+
[inputType in PossibleInputTypes]: PossibleInputTypes;
|
|
26
|
+
};
|
|
27
|
+
export const inputTypes: InputTypeMap = {
|
|
28
|
+
keyboard: 'keyboard',
|
|
29
|
+
picker: 'picker',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const reverseInputTypes: InputTypeMap = {
|
|
33
|
+
keyboard: 'picker',
|
|
34
|
+
picker: 'keyboard',
|
|
35
|
+
};
|
|
36
|
+
type InputIconMap = {
|
|
37
|
+
[inputType in PossibleInputTypes]: string;
|
|
38
|
+
};
|
|
39
|
+
export const inputTypeIcons: InputIconMap = {
|
|
40
|
+
keyboard: 'keyboard-outline',
|
|
41
|
+
picker: 'clock-outline',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const getTimeInputTypeIcon = (
|
|
45
|
+
inputType: PossibleInputTypes,
|
|
46
|
+
inputIconMap?: InputIconMap,
|
|
47
|
+
) => {
|
|
48
|
+
return (
|
|
49
|
+
inputIconMap?.[reverseInputTypes[inputType]] ||
|
|
50
|
+
inputTypeIcons?.[reverseInputTypes[inputType]]
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type PossibleClockTypes = 'hours' | 'minutes';
|
|
55
|
+
export type ClockTypeMap = {
|
|
56
|
+
[clockType in PossibleClockTypes]: PossibleClockTypes;
|
|
57
|
+
};
|
|
58
|
+
export const clockTypes: ClockTypeMap = {
|
|
59
|
+
minutes: 'minutes',
|
|
60
|
+
hours: 'hours',
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Code inspiration and copied from: https://github.com/ShaneGH/analogue-time-picker/blob/master/src/utils/angle.ts
|
|
64
|
+
|
|
65
|
+
const outerHeight = 34;
|
|
66
|
+
const _30 = Math.PI / 6;
|
|
67
|
+
const _12 = Math.PI / 30;
|
|
68
|
+
const _360 = Math.PI * 2;
|
|
69
|
+
const _90 = Math.PI / 2;
|
|
70
|
+
|
|
71
|
+
/** Snap an angle to a given step. E.g. if angle = 22° and step = 10°, round down to 20° */
|
|
72
|
+
export function snap(angle: number, step: number) {
|
|
73
|
+
let a = angle;
|
|
74
|
+
while (a < 0) a += _360;
|
|
75
|
+
const diff = a % step;
|
|
76
|
+
|
|
77
|
+
if (diff <= step / 2) {
|
|
78
|
+
return angle - diff;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return angle - diff + step;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// detect am / pm based on offset
|
|
85
|
+
export function getHourTypeFromOffset(left: number, top: number, size: number): PossibleHourTypes {
|
|
86
|
+
const w = size / 2;
|
|
87
|
+
const x = w - left;
|
|
88
|
+
const y = size / 2 - top;
|
|
89
|
+
|
|
90
|
+
const distance = Math.sqrt(x * x + y * y);
|
|
91
|
+
const maxPm = w - outerHeight;
|
|
92
|
+
|
|
93
|
+
return distance > maxPm ? hourTypes.am : hourTypes.pm;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Calculate the minute from the hand angle
|
|
97
|
+
export function getMinutes(handAngle: number) {
|
|
98
|
+
handAngle = snap(handAngle, _12);
|
|
99
|
+
|
|
100
|
+
let minute = parseInt((((handAngle - _90) % _360) / _12).toFixed(), 10);
|
|
101
|
+
while (minute < 0) minute += 60;
|
|
102
|
+
while (minute >= 60) minute -= 60;
|
|
103
|
+
|
|
104
|
+
return minute;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Calculate the hour from the hand angle
|
|
108
|
+
export function getHours(handAngle: number, hourType: PossibleHourTypes | undefined) {
|
|
109
|
+
handAngle = snap(handAngle, _30);
|
|
110
|
+
|
|
111
|
+
let hour = parseInt((((handAngle - _90) % _360) / _30).toFixed(), 10);
|
|
112
|
+
if (hour < 0) hour += 12;
|
|
113
|
+
if (hour >= 12) hour -= 12;
|
|
114
|
+
|
|
115
|
+
if (hourType === hourTypes.am) {
|
|
116
|
+
if (hour <= 0) {
|
|
117
|
+
hour += 12;
|
|
118
|
+
} else if (hour >= 12) {
|
|
119
|
+
hour -= 12;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (hourType === hourTypes.pm) {
|
|
123
|
+
if (hour <= 0) {
|
|
124
|
+
hour += 12;
|
|
125
|
+
} else if (hour > 12) {
|
|
126
|
+
hour -= 12;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return hour;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Get the angle of the left/top co-ordinate from the center of the width.height box */
|
|
134
|
+
export function getAngle(left: number, top: number, size: number) {
|
|
135
|
+
const x = size / 2 - left;
|
|
136
|
+
const y = size / 2 - top;
|
|
137
|
+
|
|
138
|
+
// tan O = y / x
|
|
139
|
+
let angle = x ? Math.atan(y / x) : y < 0 ? -_90 : _90;
|
|
140
|
+
if (x < 0) {
|
|
141
|
+
// reflect along vertical axis
|
|
142
|
+
angle = -angle + 2 * (_90 + angle);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return angle;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function toHourInputFormat(hours: number, is24Hour: boolean): number {
|
|
149
|
+
if (hours === 24) {
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
if (is24Hour) {
|
|
153
|
+
return hours;
|
|
154
|
+
}
|
|
155
|
+
if (hours > 12) {
|
|
156
|
+
return hours - 12;
|
|
157
|
+
}
|
|
158
|
+
return hours;
|
|
159
|
+
}
|