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
@@ -132,31 +132,6 @@ const checkboxStylesDefault = StyleSheet.create(theme => ({
132
132
  },
133
133
  ],
134
134
  },
135
- fillContainer: {
136
- alignItems: 'center',
137
- justifyContent: 'center',
138
- },
139
- animatedFill: {
140
- width: 24 / 2 + (PADDING - 2),
141
- height: 24 / 2 + (PADDING - 2),
142
-
143
- variants: {
144
- size: {
145
- sm: {
146
- width: iconSizeMap.sm / 2 + (PADDING - 2),
147
- height: iconSizeMap.sm / 2 + (PADDING - 2),
148
- },
149
- md: {
150
- width: iconSizeMap.md / 2 + (PADDING - 2),
151
- height: iconSizeMap.md / 2 + (PADDING - 2),
152
- },
153
- lg: {
154
- width: iconSizeMap.lg / 2 + (PADDING - 2),
155
- height: iconSizeMap.lg / 2 + (PADDING - 2),
156
- },
157
- },
158
- },
159
- },
160
135
  icon: {
161
136
  color: theme.colors.onSurfaceVariant,
162
137
 
@@ -97,10 +97,6 @@ export type Props = Omit<TouchableRippleProps, 'children'> &
97
97
  * Whether to show the ActivityIndicator or not
98
98
  */
99
99
  loading?: boolean;
100
- /**
101
- * container style
102
- */
103
- containerStyle?: ViewStyle;
104
100
  /**
105
101
  * left element container style
106
102
  */
@@ -132,7 +128,6 @@ export type Props = Omit<TouchableRippleProps, 'children'> &
132
128
  const Chip = (
133
129
  {
134
130
  style,
135
- containerStyle: containerStyleProp,
136
131
  label: _label,
137
132
  labelCharacterLimit = 20,
138
133
  variant = 'outlined',
@@ -158,11 +153,13 @@ const Chip = (
158
153
  leftElementIconProps,
159
154
  invertLabelColor,
160
155
  backgroundColor,
156
+ onPress,
161
157
  ...rest
162
158
  }: Props,
163
159
  ref: any,
164
160
  ) => {
165
161
  const { hovered, actionsRef } = useActionState({ ref, actionsToListen: ['hover'] });
162
+ const Wrapper = onPress ? TouchableRipple : View;
166
163
 
167
164
  const state = resolveStateVariant({
168
165
  disabled: !!disabled,
@@ -192,47 +189,39 @@ const Chip = (
192
189
  // selectedColorProp ? { selectedColor: selectedColorProp } : {},
193
190
  // ]);
194
191
 
195
- const {
196
- containerStyle,
197
- touchableRippleStyle,
198
- leftElementStyle,
199
- rightElementStyle,
200
- labelStyle,
201
- stateLayerStyle,
202
- } = useMemo(() => {
203
- return {
204
- containerStyle: [
205
- styles.container,
206
- selected && selectionBackgroundColor
207
- ? { backgroundColor: selectionBackgroundColor }
208
- : {},
209
- containerStyleProp,
210
- ],
211
- touchableRippleStyle: [styles.touchableRippleContainer, style],
212
- leftElementStyle: [styles.leftElement, leftElementContainerStyle],
213
- rightElementStyle: [styles.rightElement, rightElementContainerStyle],
214
- labelStyle: [
215
- styles.label,
216
- selected && selectedColor ? { color: selectedColor } : {},
217
- labelStyleProp,
218
- ],
219
- stateLayerStyle: [styles.stateLayer, stateLayerProps?.style],
220
- };
221
- // eslint-disable-next-line react-hooks/exhaustive-deps
222
- }, [
223
- leftElementContainerStyle,
224
- rightElementContainerStyle,
225
- selected,
226
- selectedColor,
227
- selectionBackgroundColor,
228
- stateLayerProps?.style,
229
- style,
230
- containerStyleProp,
231
- labelStyleProp,
232
- state,
233
- size,
234
- variant,
235
- ]);
192
+ const { containerStyle, leftElementStyle, rightElementStyle, labelStyle, stateLayerStyle } =
193
+ useMemo(() => {
194
+ return {
195
+ containerStyle: [
196
+ styles.container,
197
+ selected && selectionBackgroundColor
198
+ ? { backgroundColor: selectionBackgroundColor }
199
+ : {},
200
+ style,
201
+ ],
202
+ leftElementStyle: [styles.leftElement, leftElementContainerStyle],
203
+ rightElementStyle: [styles.rightElement, rightElementContainerStyle],
204
+ labelStyle: [
205
+ styles.label,
206
+ selected && selectedColor ? { color: selectedColor } : {},
207
+ labelStyleProp,
208
+ ],
209
+ stateLayerStyle: [styles.stateLayer, stateLayerProps?.style],
210
+ };
211
+ // eslint-disable-next-line react-hooks/exhaustive-deps
212
+ }, [
213
+ leftElementContainerStyle,
214
+ rightElementContainerStyle,
215
+ selected,
216
+ selectedColor,
217
+ selectionBackgroundColor,
218
+ stateLayerProps?.style,
219
+ style,
220
+ labelStyleProp,
221
+ state,
222
+ size,
223
+ variant,
224
+ ]);
236
225
 
237
226
  const { accessibilityState, elevation } = useMemo(
238
227
  () => ({
@@ -251,14 +240,13 @@ const Chip = (
251
240
  {...containerProps}
252
241
  elevation={elevation}
253
242
  style={containerStyle}
254
- backgroundColor={backgroundColor}>
255
- <TouchableRipple
243
+ backgroundColor={backgroundColor}
244
+ asChild>
245
+ <Wrapper
256
246
  borderless
257
247
  {...rest}
258
248
  disabled={disabled}
259
- style={touchableRippleStyle}
260
249
  accessibilityLabel={accessibilityLabel}
261
- accessibilityRole="button"
262
250
  accessibilityState={accessibilityState}
263
251
  ref={actionsRef}
264
252
  testID={testID}>
@@ -297,7 +285,7 @@ const Chip = (
297
285
  style={stateLayerStyle}
298
286
  />
299
287
  </>
300
- </TouchableRipple>
288
+ </Wrapper>
301
289
  </Surface>
302
290
  );
303
291
  };
@@ -362,7 +350,7 @@ const RightElement = memo(
362
350
  {onClose ? (
363
351
  <IconButtonWithContrastColor
364
352
  name="close"
365
- size={18}
353
+ size={14}
366
354
  accessibilityLabel="Close"
367
355
  disabled={disabled}
368
356
  onPress={onClose}
@@ -6,6 +6,9 @@ const chipStylesDefault = StyleSheet.create(theme => ({
6
6
  container: {
7
7
  borderRadius: theme.shapes.corner.small,
8
8
  backgroundColor: theme.colors.surface,
9
+ paddingHorizontal: theme.spacings['2'],
10
+ flexDirection: 'row',
11
+ alignItems: 'center',
9
12
 
10
13
  variants: {
11
14
  variant: {
@@ -47,13 +50,6 @@ const chipStylesDefault = StyleSheet.create(theme => ({
47
50
  },
48
51
  },
49
52
  },
50
- touchableRippleContainer: {
51
- flex: 1,
52
- paddingHorizontal: theme.spacings['2'],
53
- borderRadius: theme.shapes.corner.small,
54
- flexDirection: 'row',
55
- alignItems: 'center',
56
- },
57
53
  label: {
58
54
  display: 'flex',
59
55
  color: theme.colors.onSurfaceVariant,
@@ -0,0 +1,110 @@
1
+ import { memo, useCallback, useMemo, useRef } from 'react';
2
+
3
+ import type { DatePickerValue, RangeValue } from '../DatePicker/context';
4
+ import { useDatePickerContext } from '../DatePicker/context';
5
+ import type { TextInputProps } from '../TextInput';
6
+ import { TextInputWithMask } from '../TextInputWithMask';
7
+ import { useDateFieldState } from './useDateFieldState';
8
+
9
+ export type DateFieldInputMode = 'start' | 'end';
10
+
11
+ export type DateFieldProps = Omit<
12
+ TextInputProps,
13
+ 'value' | 'defaultValue' | 'onChangeText' | 'inputMode'
14
+ > & {
15
+ inputMode?: DateFieldInputMode;
16
+ dateFormat?: string;
17
+ };
18
+
19
+ const DEFAULT_DATE_FORMAT = 'dd/MM/yyyy';
20
+
21
+ const isRange = (value: DatePickerValue): value is RangeValue =>
22
+ value !== null && typeof value === 'object' && 'start' in value && 'end' in value;
23
+
24
+ const preserveTime = (next: Date | null, prev: Date | null): Date | null => {
25
+ if (!next || !prev) return next;
26
+
27
+ const combined = new Date(next);
28
+
29
+ combined.setHours(
30
+ prev.getHours(),
31
+ prev.getMinutes(),
32
+ prev.getSeconds(),
33
+ prev.getMilliseconds(),
34
+ );
35
+ return combined;
36
+ };
37
+
38
+ function DateField({
39
+ ref,
40
+ inputMode = 'start',
41
+ dateFormat = DEFAULT_DATE_FORMAT,
42
+ disabled: disabledProp,
43
+ onBlur,
44
+ onFocus,
45
+ ...rest
46
+ }: DateFieldProps) {
47
+ const {
48
+ mode,
49
+ value,
50
+ commitValue,
51
+ validRange,
52
+ disabled: providerDisabled,
53
+ } = useDatePickerContext();
54
+ const isBlurredRef = useRef(true);
55
+
56
+ const disabled = disabledProp ?? providerDisabled;
57
+
58
+ const fieldValue = useMemo<Date | null>(() => {
59
+ if (mode === 'range') {
60
+ if (!isRange(value)) return null;
61
+ return inputMode === 'end' ? value.end : value.start;
62
+ }
63
+ return isRange(value) ? null : value;
64
+ }, [value, mode, inputMode]);
65
+
66
+ const onChange = useCallback(
67
+ (next: Date | null) => {
68
+ if (mode === 'range') {
69
+ const current: RangeValue = isRange(value) ? value : { start: null, end: null };
70
+ commitValue({ ...current, [inputMode]: next });
71
+ return;
72
+ }
73
+ commitValue(preserveTime(next, isRange(value) ? null : value));
74
+ },
75
+ [mode, value, inputMode, commitValue],
76
+ );
77
+
78
+ const {
79
+ formattedValue,
80
+ onChangeText,
81
+ onBlur: onInnerBlur,
82
+ onFocus: onInnerFocus,
83
+ } = useDateFieldState({
84
+ value: fieldValue,
85
+ validRange,
86
+ inputMode,
87
+ dateFormat,
88
+ onChange,
89
+ onBlur,
90
+ onFocus,
91
+ isBlurredRef,
92
+ });
93
+
94
+ return (
95
+ <TextInputWithMask
96
+ {...rest}
97
+ ref={ref}
98
+ disabled={disabled}
99
+ value={formattedValue}
100
+ placeholder={dateFormat}
101
+ keyboardType="number-pad"
102
+ mask={dateFormat}
103
+ onChangeText={onChangeText}
104
+ onBlur={onInnerBlur}
105
+ onFocus={onInnerFocus}
106
+ />
107
+ );
108
+ }
109
+
110
+ export default memo(DateField);
@@ -0,0 +1,6 @@
1
+ import { getRegisteredComponentWithFallback } from '../../core';
2
+ import DateFieldDefault from './DateField';
3
+
4
+ export const DateField = getRegisteredComponentWithFallback('DateField', DateFieldDefault);
5
+
6
+ export type { DateFieldInputMode, DateFieldProps } from './DateField';
@@ -10,34 +10,31 @@ import { useRangeChecker } from '../DatePickerInline/dateUtils';
10
10
  const formatValue = (value: Date | null | undefined, dateFormat: string) =>
11
11
  !isNil(value) ? format(value, dateFormat) || '' : '';
12
12
 
13
- export default function useDateInput({
14
- // locale,
15
- value,
16
- validRange,
17
- inputMode = 'start',
18
- onChange,
19
- dateFormat,
20
- onBlur: onBlurProp,
21
- onFocus: onFocusProp,
22
- isBlurredRef,
23
- }: {
24
- onChange?: (d: Date | null) => void;
25
- onBlur?: (e: BlurEvent) => void;
26
- onFocus?: (e: FocusEvent) => void;
27
- // locale: undefined | string;
13
+ type Props = {
28
14
  value?: Date | null;
29
15
  validRange?: ValidRangeType;
30
16
  inputMode: 'start' | 'end';
31
17
  dateFormat: string;
32
18
  isBlurredRef: RefObject<boolean>;
33
- }) {
34
- const { isDisabled, isWithinValidRange } = useRangeChecker(validRange);
19
+ onChange?: (value: Date | null) => void;
20
+ onBlur?: (e: BlurEvent) => void;
21
+ onFocus?: (e: FocusEvent) => void;
22
+ };
35
23
 
24
+ export function useDateFieldState({
25
+ value,
26
+ validRange,
27
+ inputMode,
28
+ dateFormat,
29
+ isBlurredRef,
30
+ onChange,
31
+ onBlur: onBlurProp,
32
+ onFocus: onFocusProp,
33
+ }: Props) {
34
+ const { isDisabled, isWithinValidRange } = useRangeChecker(validRange);
36
35
  const [formattedValue, setFormattedValue] = useState(() => formatValue(value, dateFormat));
37
36
  const formattedValueRef = useLatest(formattedValue);
38
37
 
39
- // const [error, setError] = useState<null | string>(null);
40
-
41
38
  const onChangeText = useCallback(
42
39
  (date: string) => {
43
40
  const parsedDate = parse(date, dateFormat, new Date());
@@ -51,45 +48,18 @@ export default function useDateInput({
51
48
  );
52
49
 
53
50
  if (!isValid(parsedDate)) {
54
- // TODO: Translate
55
- // setError(`Date format must be ${dateFormat}`);
56
51
  onChange?.(date ? value ?? null : null);
57
-
58
52
  return;
59
53
  }
60
54
 
61
55
  const finalDate = inputMode === 'end' ? endOfDay(parsedDate) : parsedDate;
62
56
 
63
- if (isDisabled(finalDate)) {
64
- // TODO: Translate
65
- // setError('Day is not allowed');
57
+ if (isDisabled(finalDate) || !isWithinValidRange(finalDate)) {
66
58
  onChange?.(null);
67
-
68
- return;
69
- }
70
- if (!isWithinValidRange(finalDate)) {
71
- // TODO: Translate
72
- // const errors =
73
- // validStart && validEnd
74
- // ? [
75
- // `${`Must be between ${format(validStart, dateFormat)} - ${format(
76
- // validEnd,
77
- // dateFormat,
78
- // )})`}`,
79
- // ]
80
- // : [
81
- // validStart ? `Must be later then ${validStart}` : '',
82
- // validEnd ? `Must be earlier then ${validEnd}` : '',
83
- // ];
84
-
85
- // setError(errors.filter(n => n).join(' '));
86
- onChange?.(null);
87
-
88
59
  return;
89
60
  }
90
61
 
91
62
  onChange?.(finalDate);
92
- // setError(null);
93
63
  },
94
64
  [
95
65
  dateFormat,
@@ -128,8 +98,6 @@ export default function useDateInput({
128
98
  }, [value, dateFormat, isBlurredRef]);
129
99
 
130
100
  return {
131
- onChange,
132
- // error,
133
101
  formattedValue,
134
102
  onChangeText,
135
103
  onBlur,
@@ -0,0 +1,83 @@
1
+ import { memo } from 'react';
2
+
3
+ import { getRegisteredComponentWithFallback } from '../../core';
4
+ import {
5
+ DatePickerInline,
6
+ type DatePickerInlineProps,
7
+ type RangeChange,
8
+ type SingleChange,
9
+ } from '../DatePickerInline';
10
+ import { useOptionalDatePickerContext } from './context';
11
+
12
+ export type DateCalendarProps = DatePickerInlineProps;
13
+
14
+ const DateCalendarDefault = memo((props: DateCalendarProps) => {
15
+ const ctx = useOptionalDatePickerContext();
16
+
17
+ const hasExplicitState =
18
+ props.date !== undefined ||
19
+ props.startDate !== undefined ||
20
+ props.endDate !== undefined ||
21
+ props.dates !== undefined ||
22
+ props.onChange !== undefined;
23
+
24
+ const isRange = props.mode === 'range' || ctx?.mode === 'range';
25
+ const effectiveHeaderLayout = props.headerLayout ?? (ctx ? 'docked' : 'inline');
26
+ const showOutsideDays =
27
+ props.showOutsideDays ?? (effectiveHeaderLayout === 'docked' && !isRange);
28
+
29
+ if (!ctx || hasExplicitState) {
30
+ return <DatePickerInline {...props} showOutsideDays={showOutsideDays} />;
31
+ }
32
+
33
+ const locale = props.locale ?? ctx.locale;
34
+ const validRange = props.validRange ?? ctx.validRange;
35
+
36
+ if (ctx.mode === 'range') {
37
+ const range =
38
+ ctx.draftValue && typeof ctx.draftValue === 'object' && 'start' in ctx.draftValue
39
+ ? ctx.draftValue
40
+ : { start: null, end: null };
41
+ const onChange: RangeChange = ({ startDate, endDate }) => {
42
+ ctx.setValue({ start: startDate ?? null, end: endDate ?? null });
43
+ };
44
+ return (
45
+ <DatePickerInline
46
+ {...props}
47
+ mode="range"
48
+ startDate={range.start ?? undefined}
49
+ endDate={range.end ?? undefined}
50
+ onChange={onChange}
51
+ locale={locale}
52
+ validRange={validRange}
53
+ headerLayout={props.headerLayout ?? 'docked'}
54
+ showOutsideDays={showOutsideDays}
55
+ />
56
+ );
57
+ }
58
+
59
+ const single =
60
+ ctx.draftValue && typeof ctx.draftValue === 'object' && 'start' in ctx.draftValue
61
+ ? null
62
+ : ctx.draftValue;
63
+ const onChange: SingleChange = ({ date }) => {
64
+ ctx.setValue(date ?? null);
65
+ };
66
+
67
+ return (
68
+ <DatePickerInline
69
+ {...props}
70
+ mode="single"
71
+ date={single ?? undefined}
72
+ onChange={onChange}
73
+ locale={locale}
74
+ validRange={validRange}
75
+ headerLayout={props.headerLayout ?? 'docked'}
76
+ showOutsideDays={showOutsideDays}
77
+ />
78
+ );
79
+ });
80
+
81
+ DateCalendarDefault.displayName = 'DateCalendar';
82
+
83
+ export const DateCalendar = getRegisteredComponentWithFallback('DateCalendar', DateCalendarDefault);
@@ -0,0 +1,73 @@
1
+ import { useCallback } from 'react';
2
+ import { View } from 'react-native';
3
+ import { StyleSheet } from 'react-native-unistyles';
4
+
5
+ import {
6
+ getRegisteredComponentStylesWithFallback,
7
+ getRegisteredComponentWithFallback,
8
+ } from '../../core';
9
+ import { Button } from '../Button';
10
+ import { useDatePickerContext } from './context';
11
+
12
+ export type DatePickerActionsProps = {
13
+ cancelLabel?: string;
14
+ confirmLabel?: string;
15
+ onCancel?: () => void;
16
+ onConfirm?: () => void;
17
+ };
18
+
19
+ function DatePickerActionsDefault({
20
+ cancelLabel = 'Cancel',
21
+ confirmLabel = 'OK',
22
+ onCancel,
23
+ onConfirm,
24
+ }: DatePickerActionsProps) {
25
+ const { draft, commit, cancel } = useDatePickerContext();
26
+
27
+ const handleCancel = useCallback(() => {
28
+ onCancel?.();
29
+ cancel();
30
+ }, [onCancel, cancel]);
31
+
32
+ const handleConfirm = useCallback(() => {
33
+ onConfirm?.();
34
+ commit();
35
+ }, [onConfirm, commit]);
36
+
37
+ if (!draft) return null;
38
+
39
+ return (
40
+ <View style={datePickerActionsStyles.footer}>
41
+ <Button variant="text" onPress={handleCancel}>
42
+ <Button.Text>{cancelLabel}</Button.Text>
43
+ </Button>
44
+ <Button variant="text" onPress={handleConfirm}>
45
+ <Button.Text>{confirmLabel}</Button.Text>
46
+ </Button>
47
+ </View>
48
+ );
49
+ }
50
+
51
+ export default DatePickerActionsDefault;
52
+
53
+ export const DatePickerActions = getRegisteredComponentWithFallback(
54
+ 'DatePickerActions',
55
+ DatePickerActionsDefault,
56
+ );
57
+
58
+ const datePickerActionsStylesDefault = StyleSheet.create(theme => ({
59
+ footer: {
60
+ flexDirection: 'row',
61
+ alignItems: 'center',
62
+ justifyContent: 'flex-end',
63
+ columnGap: theme.spacings['2'],
64
+ paddingHorizontal: theme.spacings['4'],
65
+ paddingTop: theme.spacings['0'],
66
+ paddingBottom: theme.spacings['2'],
67
+ },
68
+ }));
69
+
70
+ const datePickerActionsStyles = getRegisteredComponentStylesWithFallback(
71
+ 'DatePickerActions',
72
+ datePickerActionsStylesDefault,
73
+ );