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
@@ -1,139 +0,0 @@
1
- import { forwardRef, memo, useCallback, useMemo, useRef, useState } from 'react';
2
- import { StyleSheet } from 'react-native';
3
-
4
- import { useLatest, useToggle } from '../../hooks';
5
- import { noop } from '../../utils/lodash';
6
- import { DatePickerDocked } from '../DatePickerDocked';
7
- import { IconButton } from '../IconButton';
8
- import DatePickerInputModal from './DatePickerInputModal';
9
- import DatePickerInputWithoutModal from './DatePickerInputWithoutModal';
10
- import type { DatePickerInputProps } from './types';
11
-
12
- function DatePickerInput(
13
- {
14
- withModal = true,
15
- calendarIcon = 'calendar',
16
- value,
17
- locale,
18
- inputMode,
19
- validRange,
20
- onChange = noop,
21
- disabled = false,
22
- pickerMode = 'modal',
23
- startYear,
24
- endYear,
25
- dockedPopoverContentProps,
26
- //locale = 'en',
27
- ...rest
28
- }: DatePickerInputProps,
29
- ref: any,
30
- ) {
31
- const triggerRef = useRef(null);
32
- const { state: isOpen, onToggle } = useToggle(false);
33
- const [visible, setVisible] = useState<boolean>(false);
34
-
35
- const onDismiss = useCallback(() => {
36
- setVisible(false);
37
- }, [setVisible]);
38
-
39
- const onChangeRef = useLatest(onChange);
40
-
41
- const onInnerConfirm = useCallback(
42
- ({ date }: any) => {
43
- setVisible(false);
44
- onChangeRef.current(date);
45
- },
46
- [setVisible, onChangeRef],
47
- );
48
-
49
- const onPressCalendarIcon = useCallback(() => {
50
- if (pickerMode === 'docked') {
51
- onToggle();
52
- }
53
- setVisible(true);
54
- }, [pickerMode, onToggle]);
55
-
56
- const renderers = useMemo(() => {
57
- return {
58
- modal: (
59
- <DatePickerInputModal
60
- date={value}
61
- mode="single"
62
- isOpen={visible}
63
- onClose={onDismiss}
64
- onConfirm={onInnerConfirm}
65
- locale={locale}
66
- validRange={validRange}
67
- />
68
- ),
69
- docked: (
70
- <DatePickerDocked
71
- date={value}
72
- locale={locale}
73
- startYear={startYear}
74
- endYear={endYear}
75
- onChange={onInnerConfirm}
76
- isOpen={isOpen}
77
- onClose={onDismiss}
78
- onToggle={onToggle}
79
- triggerRef={triggerRef}
80
- popoverContentProps={dockedPopoverContentProps}
81
- />
82
- ),
83
- };
84
- }, [
85
- dockedPopoverContentProps,
86
- endYear,
87
- isOpen,
88
- locale,
89
- onDismiss,
90
- onInnerConfirm,
91
- onToggle,
92
- startYear,
93
- validRange,
94
- value,
95
- visible,
96
- ]);
97
-
98
- const rightElement = useMemo(
99
- () => (
100
- <>
101
- {withModal || pickerMode === 'docked' ? (
102
- <>
103
- <IconButton
104
- ref={triggerRef}
105
- style={styles.calendarButton}
106
- name={calendarIcon}
107
- onPress={onPressCalendarIcon}
108
- disabled={disabled}
109
- />
110
- {renderers[pickerMode]}
111
- </>
112
- ) : null}
113
- </>
114
- ),
115
- [calendarIcon, disabled, onPressCalendarIcon, pickerMode, renderers, withModal],
116
- );
117
-
118
- return (
119
- <DatePickerInputWithoutModal
120
- ref={ref}
121
- {...rest}
122
- disabled={disabled}
123
- value={value}
124
- inputMode={inputMode}
125
- validRange={validRange}
126
- onChange={onChange}
127
- // locale={locale}
128
- inputButtons={rightElement}
129
- />
130
- );
131
- }
132
-
133
- const styles = StyleSheet.create({
134
- calendarButton: {
135
- marginRight: -4,
136
- },
137
- });
138
-
139
- export default memo(forwardRef(DatePickerInput));
@@ -1,48 +0,0 @@
1
- import { memo, useCallback, useEffect, useState } from 'react';
2
-
3
- import type { DatePickerModalProps } from '../DatePickerModal';
4
- import { DatePickerModal } from '../DatePickerModal/DatePickerModal';
5
-
6
- const DatePickerInputModal = ({
7
- date,
8
- onConfirm: onConfirmProp,
9
- onClose: onCloseProp,
10
- ...rest
11
- }: DatePickerModalProps) => {
12
- // want to control this by the input and only pass the value when onConfirm is clicked
13
- const [value, onValueChange] = useState(date);
14
-
15
- const onChange = useCallback(
16
- (val: any) => {
17
- onValueChange(val?.date);
18
- },
19
- [onValueChange],
20
- );
21
-
22
- const onConfirm = useCallback(() => {
23
- onConfirmProp?.({ date: value } as any);
24
- }, [onConfirmProp, value]);
25
-
26
- const onClose = useCallback(() => {
27
- onValueChange(date); // revert back before close it
28
-
29
- onCloseProp?.();
30
- }, [date, onCloseProp]);
31
-
32
- useEffect(() => {
33
- onValueChange(date);
34
- }, [date]);
35
-
36
- return (
37
- <DatePickerModal
38
- {...rest}
39
- onClose={onClose}
40
- onConfirm={onConfirm}
41
- date={value}
42
- onChange={onChange}
43
- mode="single"
44
- />
45
- );
46
- };
47
-
48
- export default memo(DatePickerInputModal);
@@ -1,77 +0,0 @@
1
- import { forwardRef, memo, useCallback, useImperativeHandle, useMemo, useRef } from 'react';
2
-
3
- import { TextInputWithMask } from '../TextInputWithMask';
4
- import useDateInput from './inputUtils';
5
- import type { DatePickerInputWithoutModalProps } from './types';
6
- import { datePickerInputStyles } from './utils';
7
-
8
- function DatePickerInputWithoutModal(
9
- {
10
- label,
11
- value,
12
- onChange: onChangeProp,
13
- // locale = 'en',
14
- validRange,
15
- inputMode,
16
- inputButtons,
17
- dateFormat = 'dd/MM/yyyy',
18
- style,
19
- onBlur: onBlurProp,
20
- onFocus: onFocusProp,
21
- ...rest
22
- }: DatePickerInputWithoutModalProps,
23
- ref: any,
24
- ) {
25
- const inputRef = useRef(null);
26
- const isBlurredRef = useRef(true);
27
-
28
- const onChange = useCallback(
29
- (date: Date | null) => {
30
- // because onChange was already trigger not need to trigger again on
31
- if (!isBlurredRef.current) {
32
- onChangeProp?.(date);
33
- }
34
-
35
- if (!date && isBlurredRef.current) (inputRef.current as any)?.setDisplayValue('');
36
- },
37
- [onChangeProp],
38
- );
39
-
40
- const { formattedValue, onChangeText, onBlur, onFocus } = useDateInput({
41
- // locale,
42
- value,
43
- validRange,
44
- inputMode,
45
- onChange,
46
- dateFormat,
47
- onBlur: onBlurProp,
48
- onFocus: onFocusProp,
49
- isBlurredRef,
50
- });
51
-
52
- const inputStyle = useMemo(() => [datePickerInputStyles.root, style], [style]);
53
-
54
- useImperativeHandle(ref, () => inputRef.current);
55
-
56
- return (
57
- <TextInputWithMask
58
- placeholder={dateFormat}
59
- style={inputStyle}
60
- {...rest}
61
- onBlur={onBlur}
62
- onFocus={onFocus}
63
- ref={inputRef}
64
- label={label}
65
- value={formattedValue}
66
- keyboardType={'number-pad'}
67
- mask={dateFormat}
68
- onChangeText={onChangeText}
69
- // keyboardAppearance={theme.dark ? 'dark' : 'default'}
70
- // error={formattedValue ? !!error : false}
71
- right={inputButtons}
72
- // supportingText={formattedValue ? error || undefined : undefined}
73
- />
74
- );
75
- }
76
-
77
- export default memo(forwardRef(DatePickerInputWithoutModal));
@@ -1,88 +0,0 @@
1
- import { useCallback, useState } from 'react';
2
- import { StyleSheet, View } from 'react-native';
3
-
4
- import DatePickerModal from '../DatePickerModal/DatePickerModal';
5
- import { IconButton } from '../IconButton';
6
- import { Text } from '../Text';
7
-
8
- // WORK IN PROGRESS
9
- // PLEASE IGNORE THIS FILE
10
- export default function DateRangeInput({
11
- locale,
12
- calendarIcon = 'calendar',
13
- }: {
14
- locale: string;
15
- calendarIcon?: string;
16
- }) {
17
- const [visible, setVisible] = useState<boolean>(false);
18
- const onDismiss = useCallback(() => {
19
- setVisible(false);
20
- }, [setVisible]);
21
- const onConfirm = useCallback(
22
- ({ startDate, endDate }: { startDate: any; endDate: any }) => {
23
- setVisible(false);
24
- // eslint-disable-next-line no-console
25
- console.log({ startDate, endDate });
26
- },
27
- [setVisible],
28
- );
29
-
30
- return (
31
- <View style={styles.container}>
32
- <View style={styles.textContainer}>
33
- {/*<DatePickerInput*/}
34
- {/* value={''}*/}
35
- {/* keyboardType={'numeric'}*/}
36
- {/* placeholder={'DD-MM-YYY'}*/}
37
- {/* mask={'DD-MM-YYY'}*/}
38
- {/* onChangeText={() => {}}*/}
39
- {/*/>*/}
40
- <Text>Van</Text>
41
- </View>
42
- <View>
43
- <Text style={styles.text1}>to</Text>
44
- <Text style={styles.text2} accessible={false}>
45
- tot
46
- </Text>
47
- </View>
48
- <View style={styles.textContainer}>
49
- {/*<DatePickerInput*/}
50
- {/* // value={''}*/}
51
- {/* // keyboardType={'numeric'}*/}
52
- {/* // placeholder={'DD-MM-YYY'}*/}
53
- {/* // mask={'DD-MM-YYY'}*/}
54
- {/* // onChangeText={() => {}}*/}
55
- {/*/>*/}
56
- <Text>Tot</Text>
57
- </View>
58
- <View>
59
- <IconButton name={calendarIcon} onPress={() => setVisible(true)} />
60
- <Text style={styles.text2} accessible={false}>
61
- tot
62
- </Text>
63
- </View>
64
- <DatePickerModal
65
- locale={locale}
66
- mode="range"
67
- isOpen={visible}
68
- onClose={onDismiss}
69
- onConfirm={onConfirm}
70
- startDate={undefined}
71
- endDate={undefined}
72
- />
73
- </View>
74
- );
75
- }
76
-
77
- const styles = StyleSheet.create({
78
- container: { flexDirection: 'row', alignItems: 'center' },
79
- textContainer: { flex: 1 },
80
- text1: {
81
- fontSize: 16,
82
- marginLeft: 12,
83
- marginRight: 12,
84
- },
85
- text2: {
86
- opacity: 0,
87
- },
88
- });
@@ -1,10 +0,0 @@
1
- import { getRegisteredComponentWithFallback } from '../../core';
2
- import DatePickerInputDefault from './DatePickerInput';
3
-
4
- export const DatePickerInput = getRegisteredComponentWithFallback(
5
- 'DatePickerInput',
6
- DatePickerInputDefault,
7
- );
8
-
9
- export type { DatePickerInputProps } from './types';
10
- export { datePickerInputStyles } from './utils';
@@ -1,28 +0,0 @@
1
- import type { ViewProps } from 'react-native';
2
-
3
- import type { ValidRangeType } from '../DatePickerInline';
4
- import type { TextInputProps } from '../TextInput';
5
-
6
- export interface DatePickerInputProps
7
- extends Omit<TextInputProps, 'value' | 'onChange' | 'onChangeText' | 'inputMode'> {
8
- inputMode: 'start' | 'end';
9
- locale?: string;
10
- onChange?: (date: Date | null) => void;
11
- value?: Date | null;
12
- validRange?: ValidRangeType | undefined;
13
- withModal?: boolean;
14
- calendarIcon?: string;
15
- /**
16
- * date format of the input
17
- * should be date-fns accepted format
18
- * We currently only accept the variations of dd MM yyyy
19
- * */
20
- dateFormat?: string;
21
- pickerMode?: 'docked' | 'modal';
22
- startYear?: number;
23
- endYear?: number;
24
- dockedPopoverContentProps?: ViewProps;
25
- }
26
- export interface DatePickerInputWithoutModalProps extends Omit<DatePickerInputProps, 'withModal'> {
27
- inputButtons?: any;
28
- }
@@ -1,15 +0,0 @@
1
- import { StyleSheet } from 'react-native-unistyles';
2
-
3
- import { getRegisteredComponentStylesWithFallback } from '../../core';
4
-
5
- const datePickerInputStylesDefault = StyleSheet.create({
6
- root: {
7
- minWidth: 150,
8
- justifyContent: 'center',
9
- },
10
- });
11
-
12
- export const datePickerInputStyles = getRegisteredComponentStylesWithFallback(
13
- 'DatePickerInput',
14
- datePickerInputStylesDefault,
15
- );
@@ -1,94 +0,0 @@
1
- import { useEffect, useMemo, useRef } from 'react';
2
- import { Animated, View } from 'react-native';
3
- import { StyleSheet } from 'react-native-unistyles';
4
-
5
- export default function AnimatedCrossView({
6
- // visible,
7
- collapsed,
8
- calendar,
9
- calendarEdit,
10
- }: {
11
- calendar: any;
12
- calendarEdit: any;
13
- // visible: boolean
14
- collapsed: boolean;
15
- }) {
16
- const calendarOpacity = useRef<Animated.Value>(new Animated.Value(collapsed ? 1 : 0));
17
- useEffect(() => {
18
- // if (visible) {
19
- Animated.timing(calendarOpacity.current, {
20
- toValue: collapsed ? 1 : 0,
21
- duration: 250,
22
- useNativeDriver: true,
23
- }).start();
24
- // }
25
- }, [collapsed]);
26
-
27
- const { calendarStyle, calendarEditStyle } = useMemo(() => {
28
- return {
29
- calendarStyle: [
30
- styles.calendar,
31
- {
32
- opacity: calendarOpacity.current,
33
- transform: [
34
- {
35
- scaleY: calendarOpacity.current.interpolate({
36
- inputRange: [0, 1],
37
- outputRange: [0.85, 1],
38
- }),
39
- },
40
- {
41
- scaleX: calendarOpacity.current.interpolate({
42
- inputRange: [0, 1],
43
- outputRange: [0.95, 1],
44
- }),
45
- },
46
- ],
47
- },
48
- ],
49
- calendarEditStyle: [
50
- styles.calendarEdit,
51
- {
52
- opacity: calendarOpacity.current.interpolate({
53
- inputRange: [0, 1],
54
- outputRange: [1, 0],
55
- }),
56
- transform: [
57
- {
58
- scale: calendarOpacity.current.interpolate({
59
- inputRange: [0, 1],
60
- outputRange: [1, 0.95],
61
- }),
62
- },
63
- ],
64
- },
65
- ],
66
- };
67
- }, []);
68
-
69
- // TODO Create AnimatedCrossView Component
70
- return (
71
- <View style={styles.root}>
72
- <Animated.View pointerEvents={collapsed ? 'auto' : 'none'} style={calendarStyle}>
73
- {calendar}
74
- </Animated.View>
75
- <Animated.View pointerEvents={collapsed ? 'none' : 'auto'} style={calendarEditStyle}>
76
- {calendarEdit}
77
- </Animated.View>
78
- </View>
79
- );
80
- }
81
-
82
- const styles = StyleSheet.create(theme => ({
83
- root: { flex: 1 },
84
- calendarEdit: {
85
- position: 'absolute',
86
-
87
- left: 0,
88
- right: 0,
89
- backgroundColor: theme.colors.surface,
90
- },
91
- calendar: {
92
- flex: 1,
93
- },
94
- }));
@@ -1,139 +0,0 @@
1
- import { memo, useCallback, useEffect, useRef } from 'react';
2
- import { Keyboard, TextInput as TextInputNative, View } from 'react-native';
3
-
4
- import type { ModeType, ValidRangeType } from '../DatePickerInline';
5
- import DatePickerInputWithoutModal from '../DatePickerInput/DatePickerInputWithoutModal';
6
- import type { LocalState, LocalStateRange, LocalStateSingle } from './types';
7
- import { datePickerModalEditStyles } from './utils';
8
-
9
- type Props = {
10
- mode: ModeType;
11
- label?: string;
12
- startLabel?: string;
13
- endLabel?: string;
14
- state: LocalState;
15
- collapsed: boolean;
16
- onChange: (s: LocalState) => any;
17
- validRange: ValidRangeType | undefined;
18
- // locale: string;
19
- };
20
-
21
- function CalendarEdit({
22
- mode,
23
- state,
24
- label = '',
25
- startLabel = 'Start',
26
- endLabel = 'End',
27
- collapsed,
28
- onChange,
29
- validRange,
30
- }: // locale,
31
- Props) {
32
- const dateInput = useRef<TextInputNative | null>(null);
33
- const startInput = useRef<TextInputNative | null>(null);
34
- const endInput = useRef<TextInputNative | null>(null);
35
-
36
- // when switching views focus, or un-focus text input
37
- useEffect(() => {
38
- // hide open keyboard
39
- if (collapsed) {
40
- Keyboard.dismiss();
41
- }
42
-
43
- const inputsToFocus = [dateInput.current, startInput.current].filter(
44
- n => n,
45
- ) as TextInputNative[];
46
-
47
- const inputsToBlur = [dateInput.current, startInput.current, endInput.current].filter(
48
- n => n,
49
- ) as TextInputNative[];
50
-
51
- if (collapsed) {
52
- inputsToBlur.forEach(ip => ip.blur());
53
- } else {
54
- inputsToFocus.forEach(ip => ip.focus());
55
- }
56
- }, [mode, startInput, endInput, dateInput, collapsed]);
57
-
58
- const onSubmitStartInput = useCallback(() => {
59
- if (endInput.current) {
60
- endInput.current.focus();
61
- }
62
- }, [endInput]);
63
-
64
- const onSubmitEndInput = useCallback(() => {
65
- // TODO: close modal and persist range
66
- }, []);
67
-
68
- const onSubmitInput = useCallback(() => {
69
- // TODO: close modal and persist range
70
- }, []);
71
-
72
- const onSingleInputChange = useCallback(
73
- (date: Date | null) => onChange({ ...state, date }),
74
- [onChange, state],
75
- );
76
-
77
- const onStartDateChange = useCallback(
78
- (startDate: Date | null) => onChange({ ...state, startDate }),
79
- [onChange, state],
80
- );
81
-
82
- const onEndDateChange = useCallback(
83
- (endDate: Date | null) => onChange({ ...state, endDate }),
84
- [onChange, state],
85
- );
86
-
87
- return (
88
- <View style={datePickerModalEditStyles.container}>
89
- <>
90
- {mode === 'single' ? (
91
- <DatePickerInputWithoutModal
92
- inputMode="start"
93
- ref={dateInput}
94
- label={label}
95
- value={(state as LocalStateSingle).date}
96
- onChange={onSingleInputChange}
97
- onSubmitEditing={onSubmitInput}
98
- validRange={validRange}
99
- // locale={locale}
100
- autoComplete={'off'}
101
- />
102
- ) : null}
103
- </>
104
-
105
- <>
106
- {mode === 'range' ? (
107
- <View style={datePickerModalEditStyles.inner}>
108
- <DatePickerInputWithoutModal
109
- inputMode="start"
110
- ref={startInput}
111
- label={startLabel}
112
- value={(state as LocalStateRange).startDate}
113
- onChange={onStartDateChange}
114
- returnKeyType={'next'}
115
- onSubmitEditing={onSubmitStartInput}
116
- validRange={validRange}
117
- // locale={locale}
118
- autoComplete={'off'}
119
- />
120
- <View style={datePickerModalEditStyles.separator} />
121
- <DatePickerInputWithoutModal
122
- inputMode="end"
123
- ref={endInput}
124
- label={endLabel}
125
- value={(state as LocalStateRange).endDate}
126
- onChange={onEndDateChange}
127
- onSubmitEditing={onSubmitEndInput}
128
- validRange={validRange}
129
- // locale={locale}
130
- autoComplete="off"
131
- />
132
- </View>
133
- ) : null}
134
- </>
135
- </View>
136
- );
137
- }
138
-
139
- export default memo(CalendarEdit);