react-native-molecules 0.5.0-beta.2 → 0.5.0-beta.20

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.
Files changed (157) hide show
  1. package/README.md +1 -1
  2. package/components/Accordion/Accordion.tsx +2 -6
  3. package/components/Accordion/AccordionItem.tsx +16 -12
  4. package/components/Accordion/AccordionItemContent.tsx +6 -1
  5. package/components/Accordion/AccordionItemHeader.tsx +1 -1
  6. package/components/Accordion/utils.ts +6 -0
  7. package/components/ActivityIndicator/ActivityIndicator.tsx +6 -15
  8. package/components/Appbar/AppbarBase.tsx +18 -13
  9. package/components/Button/Button.tsx +209 -264
  10. package/components/Button/index.tsx +9 -3
  11. package/components/Button/types.ts +16 -2
  12. package/components/Button/utils.ts +230 -208
  13. package/components/Checkbox/CheckboxBase.tsx +23 -128
  14. package/components/Checkbox/utils.ts +0 -25
  15. package/components/Chip/Chip.tsx +40 -52
  16. package/components/Chip/utils.ts +3 -7
  17. package/components/DateField/DateField.tsx +110 -0
  18. package/components/DateField/index.tsx +6 -0
  19. package/components/{DatePickerInput/inputUtils.ts → DateField/useDateFieldState.ts} +17 -49
  20. package/components/DatePicker/DateCalendar.tsx +83 -0
  21. package/components/DatePicker/DatePickerActions.tsx +73 -0
  22. package/components/DatePicker/DatePickerModal.tsx +234 -0
  23. package/components/DatePicker/DatePickerPopover.tsx +79 -0
  24. package/components/DatePicker/DatePickerProvider.tsx +152 -0
  25. package/components/DatePicker/DatePickerTrigger.tsx +23 -0
  26. package/components/DatePicker/context.tsx +82 -0
  27. package/components/DatePicker/index.tsx +44 -0
  28. package/components/DatePicker/utils.ts +293 -0
  29. package/components/DatePickerInline/DatePickerContext.tsx +1 -0
  30. package/components/DatePickerInline/DatePickerDockedHeader.tsx +113 -0
  31. package/components/DatePickerInline/DatePickerInline.tsx +16 -15
  32. package/components/DatePickerInline/DatePickerInlineBase.tsx +7 -1
  33. package/components/DatePickerInline/Day.tsx +25 -1
  34. package/components/DatePickerInline/DayRange.tsx +2 -4
  35. package/components/DatePickerInline/HeaderItem.tsx +42 -27
  36. package/components/DatePickerInline/Month.tsx +45 -65
  37. package/components/DatePickerInline/MonthPicker.tsx +25 -41
  38. package/components/DatePickerInline/Swiper.native.tsx +21 -4
  39. package/components/DatePickerInline/Swiper.tsx +168 -13
  40. package/components/DatePickerInline/Week.tsx +6 -1
  41. package/components/DatePickerInline/YearPicker.tsx +206 -53
  42. package/components/DatePickerInline/dateUtils.tsx +17 -12
  43. package/components/DatePickerInline/types.ts +3 -0
  44. package/components/DatePickerInline/utils.ts +66 -29
  45. package/components/Drawer/Drawer.tsx +17 -6
  46. package/components/ElementGroup/ElementGroup.tsx +16 -14
  47. package/components/FilePicker/FilePicker.tsx +48 -78
  48. package/components/FilePicker/index.tsx +2 -1
  49. package/components/FilePicker/utils.ts +9 -0
  50. package/components/HelperText/HelperText.tsx +0 -35
  51. package/components/Icon/iconFactory.tsx +3 -3
  52. package/components/Icon/index.tsx +1 -1
  53. package/components/Icon/types.ts +17 -6
  54. package/components/IconButton/IconButton.tsx +42 -57
  55. package/components/IconButton/utils.ts +142 -33
  56. package/components/ListItem/ListItem.tsx +3 -1
  57. package/components/ListItem/utils.ts +1 -1
  58. package/components/LoadingIndicator/LoadingIndicator.tsx +253 -0
  59. package/components/LoadingIndicator/LoadingIndicator.web.tsx +136 -0
  60. package/components/LoadingIndicator/index.tsx +13 -0
  61. package/components/LoadingIndicator/utils.ts +117 -0
  62. package/components/Menu/Menu.tsx +3 -18
  63. package/components/NavigationRail/NavigationRail.tsx +15 -9
  64. package/components/Popover/Popover.tsx +122 -145
  65. package/components/Popover/PopoverRoot.tsx +74 -0
  66. package/components/Popover/common.ts +50 -34
  67. package/components/Popover/index.ts +18 -1
  68. package/components/Popover/usePlatformMeasure.native.ts +90 -0
  69. package/components/Popover/usePlatformMeasure.ts +118 -0
  70. package/components/Popover/utils.ts +34 -0
  71. package/components/Select/Select.tsx +368 -507
  72. package/components/Select/context.tsx +72 -0
  73. package/components/Select/index.ts +8 -14
  74. package/components/Select/types.ts +2 -4
  75. package/components/Select/utils.ts +144 -0
  76. package/components/Slot/Slot.tsx +244 -0
  77. package/components/Slot/compose-refs.tsx +62 -0
  78. package/components/Slot/index.tsx +8 -0
  79. package/components/Surface/Surface.android.tsx +34 -8
  80. package/components/Surface/Surface.ios.tsx +36 -29
  81. package/components/Surface/Surface.tsx +31 -4
  82. package/components/Surface/utils.ts +44 -30
  83. package/components/Switch/Switch.tsx +8 -2
  84. package/components/Tabs/TabItem.tsx +35 -58
  85. package/components/Tabs/TabLabel.tsx +5 -9
  86. package/components/Tabs/Tabs.tsx +154 -148
  87. package/components/Tabs/utils.ts +15 -2
  88. package/components/TextInput/TextInput.tsx +658 -575
  89. package/components/TextInput/index.tsx +19 -3
  90. package/components/TextInput/types.ts +76 -27
  91. package/components/TextInput/utils.ts +225 -145
  92. package/components/TimeField/TimeField.tsx +75 -0
  93. package/components/TimeField/index.tsx +6 -0
  94. package/components/TimeField/useTimeFieldState.ts +70 -0
  95. package/components/{TimePickerField/sanitizeTime.ts → TimeField/utils.ts} +77 -10
  96. package/components/TimePicker/TimeInput.tsx +87 -37
  97. package/components/TimePicker/TimeInputs.tsx +137 -49
  98. package/components/TimePicker/TimePicker.tsx +73 -10
  99. package/components/TimePicker/TimePickerModal.tsx +186 -0
  100. package/components/TimePicker/context.tsx +17 -0
  101. package/components/TimePicker/index.tsx +15 -3
  102. package/components/TimePicker/utils.ts +93 -0
  103. package/components/Tooltip/Tooltip.tsx +42 -67
  104. package/components/Tooltip/TooltipContent.tsx +32 -5
  105. package/components/Tooltip/TooltipTrigger.tsx +20 -20
  106. package/components/Tooltip/index.tsx +1 -1
  107. package/components/TouchableRipple/TouchableRipple.native.tsx +50 -14
  108. package/components/TouchableRipple/TouchableRipple.tsx +137 -47
  109. package/hocs/withPortal.tsx +1 -1
  110. package/hooks/index.tsx +0 -6
  111. package/hooks/useActionState.tsx +19 -8
  112. package/hooks/useControlledValue.tsx +20 -4
  113. package/hooks/useFilePicker.tsx +6 -16
  114. package/hooks/useWhatHasUpdated.tsx +48 -0
  115. package/package.json +17 -13
  116. package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +5 -2
  117. package/styles/shadow.ts +2 -1
  118. package/styles/themes/LightTheme.tsx +1 -1
  119. package/utils/DocumentPicker/documentPicker.ts +78 -27
  120. package/utils/DocumentPicker/types.ts +0 -1
  121. package/utils/extractPropertiesFromStyles.ts +25 -0
  122. package/utils/extractSubcomponents.ts +89 -0
  123. package/utils/lodash.ts +77 -5
  124. package/components/DatePickerDocked/DatePickerDocked.tsx +0 -30
  125. package/components/DatePickerDocked/DatePickerDockedHeader.tsx +0 -129
  126. package/components/DatePickerDocked/index.tsx +0 -17
  127. package/components/DatePickerDocked/types.ts +0 -11
  128. package/components/DatePickerDocked/utils.ts +0 -157
  129. package/components/DatePickerInput/DatePickerInput.tsx +0 -139
  130. package/components/DatePickerInput/DatePickerInputModal.tsx +0 -48
  131. package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +0 -77
  132. package/components/DatePickerInput/DateRangeInput.tsx +0 -88
  133. package/components/DatePickerInput/index.tsx +0 -10
  134. package/components/DatePickerInput/types.ts +0 -28
  135. package/components/DatePickerInput/utils.ts +0 -15
  136. package/components/DatePickerModal/AnimatedCrossView.tsx +0 -94
  137. package/components/DatePickerModal/CalendarEdit.tsx +0 -139
  138. package/components/DatePickerModal/DatePickerModal.tsx +0 -85
  139. package/components/DatePickerModal/DatePickerModalContent.tsx +0 -155
  140. package/components/DatePickerModal/DatePickerModalContentHeader.tsx +0 -213
  141. package/components/DatePickerModal/DatePickerModalHeader.tsx +0 -74
  142. package/components/DatePickerModal/DatePickerModalHeaderBackground.tsx +0 -13
  143. package/components/DatePickerModal/index.tsx +0 -16
  144. package/components/DatePickerModal/types.ts +0 -92
  145. package/components/DatePickerModal/utils.ts +0 -122
  146. package/components/DateTimePicker/DateTimePicker.tsx +0 -172
  147. package/components/DateTimePicker/index.tsx +0 -10
  148. package/components/DateTimePicker/utils.ts +0 -12
  149. package/components/Popover/Popover.native.tsx +0 -185
  150. package/components/TimePickerField/TimePickerField.tsx +0 -152
  151. package/components/TimePickerField/index.tsx +0 -10
  152. package/components/TimePickerField/utils.ts +0 -94
  153. package/components/TimePickerModal/TimePickerModal.tsx +0 -115
  154. package/components/TimePickerModal/index.tsx +0 -10
  155. package/components/TimePickerModal/utils.ts +0 -47
  156. package/hooks/useSearchable.tsx +0 -74
  157. package/hooks/useSubcomponents.tsx +0 -59
@@ -0,0 +1,75 @@
1
+ import { memo, useCallback, useMemo } from 'react';
2
+
3
+ import type { DatePickerValue, RangeValue } from '../DatePicker/context';
4
+ import { useDatePickerContext } from '../DatePicker/context';
5
+ import { TextInput } from '../TextInput';
6
+ import type { Props as TextInputProps } from '../TextInput/TextInput';
7
+ import { useTimeFieldState } from './useTimeFieldState';
8
+ import { timeFormat } from './utils';
9
+
10
+ export type TimeFieldProps = Omit<TextInputProps, 'value' | 'defaultValue' | 'onChangeText'>;
11
+
12
+ const isRange = (value: DatePickerValue): value is RangeValue =>
13
+ value !== null && typeof value === 'object' && 'start' in value && 'end' in value;
14
+
15
+ const toTimeString = (value: Date | null): string => {
16
+ if (!value) return '';
17
+ const h = value.getHours().toString().padStart(2, '0');
18
+ const m = value.getMinutes().toString().padStart(2, '0');
19
+ return `${h}:${m}`;
20
+ };
21
+
22
+ const applyTimeToDate = (base: Date | null, time: string): Date | null => {
23
+ if (!time) return null;
24
+ const [h, m] = time.split(':').map(n => parseInt(n, 10));
25
+ if (Number.isNaN(h) || Number.isNaN(m)) return base;
26
+ const next = base ? new Date(base) : new Date();
27
+ next.setHours(h, m, 0, 0);
28
+ return next;
29
+ };
30
+
31
+ function TimeField({ ref, disabled: disabledProp, onBlur, onFocus, ...rest }: TimeFieldProps) {
32
+ const { value, commitValue, is24Hour, disabled: providerDisabled } = useDatePickerContext();
33
+
34
+ const disabled = disabledProp ?? providerDisabled;
35
+
36
+ const dateValue = useMemo<Date | null>(() => (isRange(value) ? null : value), [value]);
37
+
38
+ const timeString = useMemo(() => toTimeString(dateValue), [dateValue]);
39
+
40
+ const onChange = useCallback(
41
+ (next: string) => {
42
+ commitValue(applyTimeToDate(dateValue, next));
43
+ },
44
+ [dateValue, commitValue],
45
+ );
46
+
47
+ const {
48
+ timeString: formatted,
49
+ onChangeText,
50
+ onBlur: onInnerBlur,
51
+ onFocus: onInnerFocus,
52
+ } = useTimeFieldState({
53
+ time: timeString,
54
+ is24Hour,
55
+ disabled,
56
+ onChange,
57
+ onBlur,
58
+ onFocus,
59
+ });
60
+
61
+ return (
62
+ <TextInput
63
+ {...rest}
64
+ ref={ref}
65
+ disabled={disabled}
66
+ value={formatted}
67
+ placeholder={timeFormat[is24Hour ? '24' : '12'].format}
68
+ onChangeText={onChangeText}
69
+ onBlur={onInnerBlur}
70
+ onFocus={onInnerFocus}
71
+ />
72
+ );
73
+ }
74
+
75
+ export default memo(TimeField);
@@ -0,0 +1,6 @@
1
+ import { getRegisteredComponentWithFallback } from '../../core';
2
+ import TimeFieldDefault from './TimeField';
3
+
4
+ export const TimeField = getRegisteredComponentWithFallback('TimeField', TimeFieldDefault);
5
+
6
+ export type { TimeFieldProps } from './TimeField';
@@ -0,0 +1,70 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import type { BlurEvent, FocusEvent } from 'react-native';
3
+
4
+ import { getFormattedTime, getOutputTime, sanitizeTime } from './utils';
5
+
6
+ type Props = {
7
+ time: string;
8
+ is24Hour: boolean;
9
+ disabled?: boolean;
10
+ onChange?: (time: string) => void;
11
+ onBlur?: (e: BlurEvent) => void;
12
+ onFocus?: (e: FocusEvent) => void;
13
+ };
14
+
15
+ export function useTimeFieldState({
16
+ time,
17
+ is24Hour,
18
+ disabled,
19
+ onChange,
20
+ onBlur: onBlurProp,
21
+ onFocus: onFocusProp,
22
+ }: Props) {
23
+ const [timeString, setTimeString] = useState(() => getFormattedTime({ time, is24Hour }));
24
+ const isBlurredRef = useRef(true);
25
+
26
+ const onChangeText = useCallback(
27
+ (_text: string) => {
28
+ const text = sanitizeTime(_text, is24Hour);
29
+ setTimeString(_text);
30
+
31
+ if (disabled || !text) return;
32
+
33
+ onChange?.(getOutputTime({ time: text || time, is24Hour }));
34
+ },
35
+ [disabled, is24Hour, onChange, time],
36
+ );
37
+
38
+ const onBlur = useCallback(
39
+ (e: BlurEvent) => {
40
+ isBlurredRef.current = true;
41
+ onBlurProp?.(e);
42
+
43
+ if (disabled) return;
44
+
45
+ setTimeString(sanitizeTime(getFormattedTime({ time, is24Hour }), is24Hour));
46
+ },
47
+ [disabled, is24Hour, onBlurProp, time],
48
+ );
49
+
50
+ const onFocus = useCallback(
51
+ (e: FocusEvent) => {
52
+ isBlurredRef.current = false;
53
+ onFocusProp?.(e);
54
+ },
55
+ [onFocusProp],
56
+ );
57
+
58
+ useEffect(() => {
59
+ if (!isBlurredRef.current) return;
60
+
61
+ setTimeString(getFormattedTime({ time, is24Hour }));
62
+ }, [is24Hour, time]);
63
+
64
+ return {
65
+ timeString,
66
+ onChangeText,
67
+ onBlur,
68
+ onFocus,
69
+ };
70
+ }
@@ -1,19 +1,61 @@
1
- export const sanitizeTime = (value: string, is24hour = false) => {
2
- // Remove all non-numeric and non-colon characters except am/pm
1
+ import { format, parse, set } from 'date-fns';
2
+
3
+ export const timeMask24Hour = (text: string = '') => {
4
+ const cleanTime = text.replace(/\D+/g, '');
5
+
6
+ const hourFirstDigit = /[012]/;
7
+ let hourSecondDigit = /\d/;
8
+
9
+ if (cleanTime.charAt(0) === '2') {
10
+ hourSecondDigit = /[0123]/;
11
+ }
12
+
13
+ return [hourFirstDigit, hourSecondDigit, ':', /[012345]/, /\d/];
14
+ };
15
+
16
+ export const timeMask12Hour = (text: string = '') => {
17
+ const cleanTime = text.replace(/\D+/g, '');
18
+
19
+ const hourFirstDigit = /[01]/;
20
+ let hourSecondDigit = /\d/;
21
+
22
+ if (cleanTime.charAt(0) === '1') {
23
+ hourSecondDigit = /[012]/;
24
+ }
25
+
26
+ return [hourFirstDigit, hourSecondDigit, ':', /[012345]/, /\d/, /[ap]/, 'm'];
27
+ };
28
+
29
+ export const timeFormat = {
30
+ '24': {
31
+ format: 'HH:mm',
32
+ mask: timeMask24Hour,
33
+ },
34
+ '12': {
35
+ format: 'hh:mmaaa',
36
+ mask: timeMask12Hour,
37
+ },
38
+ };
39
+
40
+ const referenceDate = new Date('2022-01-01T00:00:00.000Z');
41
+
42
+ export const sanitizeTimeString = (time: string): string => time.replace(/[^\d:]/g, '');
43
+
44
+ export const sanitizeTime = (value: string, is24Hour = false) => {
3
45
  const sanitizedValue = value.replace(/[^0-9:apm]/gi, '');
4
46
 
5
47
  const singleDigitHour = sanitizedValue.match(/^(\d{1,2})$/);
6
48
  if (singleDigitHour) {
7
49
  const hours = parseInt(singleDigitHour[1], 10);
8
- if (!is24hour && hours >= 1 && hours <= 12) {
50
+ if (!is24Hour && hours >= 1 && hours <= 12) {
9
51
  return `${hours}:00am`;
10
- } else if (is24hour && hours >= 0 && hours < 24) {
52
+ }
53
+ if (is24Hour && hours >= 0 && hours < 24) {
11
54
  return `${hours.toString().padStart(2, '0')}:00`;
12
55
  }
13
56
  }
14
57
 
15
- if (is24hour) {
16
- // Check if it's a valid 24-hour time format (HH:MM)
58
+ if (is24Hour) {
17
59
  const match24Hour = sanitizedValue.match(/^(\d{1,2}):?(\d{2})$/);
18
60
 
19
61
  if (match24Hour) {
@@ -27,7 +69,6 @@ export const sanitizeTime = (value: string, is24hour = false) => {
27
69
  }
28
70
  }
29
71
 
30
- // Convert 12-hour time to 24-hour time format if necessary
31
72
  const match12Hour = sanitizedValue.match(/^(\d{1,2}):?(\d{2})\s*([ap]m)$/i);
32
73
  if (match12Hour) {
33
74
  let hours = parseInt(match12Hour[1], 10);
@@ -40,15 +81,16 @@ export const sanitizeTime = (value: string, is24hour = false) => {
40
81
  } else if (period === 'am' && hours === 12) {
41
82
  hours = 0;
42
83
  }
84
+
43
85
  return `${hours.toString().padStart(2, '0')}:${minutes
44
86
  .toString()
45
87
  .padStart(2, '0')}`;
46
88
  }
47
89
  }
90
+
48
91
  return '';
49
92
  }
50
93
 
51
- // Convert 24-hour time to 12-hour time format if necessary
52
94
  const match24Hour = sanitizedValue.match(/^(\d{1,2}):?(\d{2})$/);
53
95
  if (match24Hour) {
54
96
  let hours = parseInt(match24Hour[1], 10);
@@ -68,7 +110,6 @@ export const sanitizeTime = (value: string, is24hour = false) => {
68
110
  }
69
111
  }
70
112
 
71
- // Check if it's a valid 12-hour time format (HH:MM am/pm)
72
113
  const match12Hour = sanitizedValue.match(/^(\d{1,2}):?(\d{2})\s*([ap]m)$/i);
73
114
  if (match12Hour) {
74
115
  const hours = parseInt(match12Hour[1], 10);
@@ -80,6 +121,32 @@ export const sanitizeTime = (value: string, is24hour = false) => {
80
121
  }
81
122
  }
82
123
 
83
- // If no match, return empty string as invalid input
84
124
  return '';
85
125
  };
126
+
127
+ export const getFormattedTime = ({ time, is24Hour }: { time: string; is24Hour: boolean }) => {
128
+ if (!time) return '';
129
+
130
+ const [hour = '0', minute = '0'] = sanitizeTimeString(time).split(':');
131
+
132
+ return format(
133
+ set(referenceDate, { hours: +hour.padStart(2, '0'), minutes: +minute.padStart(2, '0') }),
134
+ timeFormat[is24Hour ? '24' : '12'].format,
135
+ );
136
+ };
137
+
138
+ export const getOutputTime = ({ time, is24Hour }: { time: string; is24Hour: boolean }) => {
139
+ if (!time) return '';
140
+
141
+ const formattedTime = sanitizeTimeString(getFormattedTime({ time, is24Hour }));
142
+ const isPM = time.replace(/[\d:]/g, '').includes('p');
143
+
144
+ return format(
145
+ parse(
146
+ formattedTime + (is24Hour ? '' : isPM ? 'pm' : 'am'),
147
+ timeFormat[is24Hour ? '24' : '12'].format,
148
+ referenceDate,
149
+ ),
150
+ 'HH:mm',
151
+ );
152
+ };
@@ -1,24 +1,28 @@
1
- import { forwardRef, memo, useCallback, useMemo, useState } from 'react';
2
- import { StyleSheet, View } from 'react-native';
1
+ import { forwardRef, memo, useCallback, useEffect, useMemo, useState } from 'react';
2
+ import {
3
+ type NativeSyntheticEvent,
4
+ StyleSheet,
5
+ TextInput as NativeTextInput,
6
+ type TextInputProps as NativeTextInputProps,
7
+ type TextInputSelectionChangeEventData,
8
+ View,
9
+ } from 'react-native';
3
10
 
4
11
  import { useTheme } from '../../hooks';
5
12
  import { resolveStateVariant } from '../../utils';
6
- import { TextInput, type TextInputProps } from '../TextInput';
7
13
  import { TouchableRipple } from '../TouchableRipple';
8
14
  import { inputTypes, type PossibleClockTypes, type PossibleInputTypes } from './timeUtils';
9
15
  import { timePickerInputStyles } from './utils';
10
16
 
11
- interface TimeInputProps
12
- extends Omit<
13
- Omit<TextInputProps, 'value' | 'variant' | 'onChangeText' | 'onPress'>,
14
- 'onFocus'
15
- > {
17
+ interface TimeInputProps extends Omit<NativeTextInputProps, 'value' | 'onChangeText' | 'onPress'> {
16
18
  value: number;
17
19
  clockType: PossibleClockTypes;
18
20
  onPress?: (type: PossibleClockTypes) => any;
19
21
  pressed: boolean;
20
- onChanged: (n: number) => any;
22
+ onChanged: (n: number, text: string) => any;
21
23
  inputType: PossibleInputTypes;
24
+ error?: boolean;
25
+ inputStyle?: NativeTextInputProps['style'];
22
26
  }
23
27
 
24
28
  function TimeInput(
@@ -29,18 +33,22 @@ function TimeInput(
29
33
  onPress,
30
34
  onChanged,
31
35
  inputType,
36
+ error = false,
32
37
  inputStyle,
33
38
  style,
34
39
  ...rest
35
40
  }: TimeInputProps,
36
41
  ref: any,
37
42
  ) {
38
- const onInnerChange = (text: string) => {
39
- onChanged(Number(text));
40
- };
41
-
42
43
  const theme = useTheme();
43
44
  const [inputFocused, setInputFocused] = useState<boolean>(false);
45
+ const [rawText, setRawText] = useState<string | null>(null);
46
+ const [selection, setSelection] = useState<{ start: number; end: number } | undefined>();
47
+
48
+ const onInnerChange = (text: string) => {
49
+ setRawText(text);
50
+ onChanged(Number(text), text);
51
+ };
44
52
 
45
53
  const highlighted = inputType === inputTypes.picker ? pressed : inputFocused;
46
54
 
@@ -52,46 +60,88 @@ function TimeInput(
52
60
  });
53
61
 
54
62
  const formattedValue = useMemo(() => {
55
- let _formattedValue = `${value}`;
56
-
57
- if (!inputFocused) {
58
- _formattedValue = `${value}`.length === 1 ? `0${value}` : `${value}`;
59
- }
63
+ if (rawText !== null && (inputFocused || error)) return rawText;
60
64
 
61
- return _formattedValue;
62
- }, [value, inputFocused]);
65
+ const str = `${value}`;
66
+ return str.length === 1 ? `0${str}` : str;
67
+ }, [value, inputFocused, rawText, error]);
63
68
 
64
- const { rippleColor, containerStyle, textInputContainerStyle, textInputStyle, buttonStyle } =
65
- useMemo(() => {
66
- const { container, input, button } = timePickerInputStyles;
69
+ const { rippleColor, containerStyle, textInputStyle, buttonStyle } = useMemo(() => {
70
+ const {
71
+ container,
72
+ input,
73
+ keyboardInput,
74
+ keyboardInputHighlighted,
75
+ inputError,
76
+ keyboardInputError,
77
+ button,
78
+ } = timePickerInputStyles;
79
+ const isKeyboardInput = inputType === inputTypes.keyboard;
67
80
 
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]);
81
+ return {
82
+ rippleColor: timePickerInputStyles.root?._rippleColor,
83
+ containerStyle: container,
84
+ textInputStyle: [
85
+ input,
86
+ isKeyboardInput ? keyboardInput : null,
87
+ isKeyboardInput && highlighted ? keyboardInputHighlighted : null,
88
+ error ? inputError : null,
89
+ isKeyboardInput && error ? keyboardInputError : null,
90
+ style,
91
+ inputStyle,
92
+ ],
93
+ buttonStyle: [StyleSheet.absoluteFill, button],
94
+ };
95
+ // eslint-disable-next-line react-hooks/exhaustive-deps
96
+ }, [error, highlighted, inputStyle, inputType, style, state]);
77
97
 
78
98
  const onFocus = useCallback(() => setInputFocused(true), []);
79
- const onBlur = useCallback(() => setInputFocused(false), []);
99
+
100
+ const onBlur = useCallback(() => {
101
+ setInputFocused(false);
102
+ setSelection(undefined);
103
+ if (!error) {
104
+ setRawText(null);
105
+ }
106
+ }, [error]);
107
+
80
108
  const onPressInput = useCallback(() => onPress?.(clockType), [clockType, onPress]);
81
109
 
110
+ const onSelectionChange = useCallback(
111
+ (e: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => {
112
+ if (selection) {
113
+ setSelection(undefined);
114
+ }
115
+
116
+ rest.onSelectionChange?.(e);
117
+ },
118
+ [rest, selection],
119
+ );
120
+
121
+ useEffect(() => {
122
+ if (error && inputFocused && rawText?.length) {
123
+ setSelection({ start: 0, end: rawText.length });
124
+ return;
125
+ }
126
+
127
+ setSelection(undefined);
128
+ }, [error, inputFocused, rawText]);
129
+
82
130
  return (
83
131
  <View style={containerStyle}>
84
- <TextInput
85
- variant="plain"
132
+ <NativeTextInput
86
133
  ref={ref}
87
- inputStyle={textInputStyle}
88
- style={textInputContainerStyle}
89
134
  onFocus={onFocus}
90
135
  onBlur={onBlur}
91
136
  keyboardAppearance={theme.dark ? 'dark' : 'default'}
92
137
  value={formattedValue}
93
138
  maxLength={2}
139
+ placeholderTextColor={theme.colors.onSurfaceVariant}
140
+ selectTextOnFocus={inputType === inputTypes.picker || error}
141
+ selection={selection}
142
+ onSelectionChange={onSelectionChange}
94
143
  onChangeText={onInnerChange}
144
+ style={textInputStyle}
95
145
  {...rest}
96
146
  />
97
147
  <>