react-native-molecules 0.5.0-beta.3 → 0.5.0-beta.31
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 +2 -6
- package/components/Accordion/AccordionItem.tsx +16 -12
- package/components/Accordion/AccordionItemContent.tsx +6 -1
- package/components/Accordion/AccordionItemHeader.tsx +1 -1
- package/components/Accordion/utils.ts +6 -0
- package/components/ActivityIndicator/ActivityIndicator.tsx +6 -15
- package/components/Appbar/AppbarBase.tsx +18 -13
- package/components/Button/Button.tsx +211 -264
- package/components/Button/index.tsx +9 -3
- package/components/Button/types.ts +16 -2
- package/components/Button/utils.ts +230 -208
- package/components/Card/Card.tsx +1 -1
- package/components/Checkbox/Checkbox.tsx +125 -88
- package/components/Checkbox/CheckboxBase.ios.tsx +14 -23
- package/components/Checkbox/CheckboxBase.tsx +21 -137
- package/components/Checkbox/context.tsx +14 -0
- package/components/Checkbox/index.tsx +11 -4
- package/components/Checkbox/types.ts +63 -29
- package/components/Checkbox/utils.ts +25 -108
- package/components/Chip/Chip.tsx +41 -52
- package/components/Chip/utils.ts +3 -7
- package/components/DateField/DateField.tsx +111 -0
- package/components/DateField/index.tsx +6 -0
- package/components/{DatePickerInput/inputUtils.ts → DateField/useDateFieldState.ts} +19 -51
- package/components/DatePicker/DateCalendar.tsx +83 -0
- package/components/DatePicker/DatePickerActions.tsx +73 -0
- package/components/DatePicker/DatePickerModal.tsx +246 -0
- package/components/DatePicker/DatePickerPopover.tsx +79 -0
- package/components/DatePicker/DatePickerProvider.tsx +158 -0
- package/components/DatePicker/DatePickerTrigger.tsx +23 -0
- package/components/DatePicker/context.tsx +83 -0
- package/components/DatePicker/index.tsx +45 -0
- package/components/DatePicker/utils.ts +295 -0
- package/components/DatePickerInline/DatePickerDockedHeader.tsx +117 -0
- package/components/DatePickerInline/DatePickerInline.tsx +17 -16
- package/components/DatePickerInline/DatePickerInlineBase.tsx +11 -5
- package/components/DatePickerInline/DatePickerInlineHeader.tsx +50 -20
- package/components/DatePickerInline/Day.tsx +25 -1
- package/components/DatePickerInline/DayNames.tsx +13 -10
- package/components/DatePickerInline/DayRange.tsx +2 -4
- package/components/DatePickerInline/HeaderItem.tsx +44 -29
- package/components/DatePickerInline/Month.tsx +48 -67
- package/components/DatePickerInline/MonthPicker.tsx +80 -92
- package/components/DatePickerInline/Swiper.native.tsx +21 -4
- package/components/DatePickerInline/Swiper.tsx +169 -14
- package/components/DatePickerInline/SwiperUtils.ts +1 -1
- package/components/DatePickerInline/Week.tsx +6 -1
- package/components/DatePickerInline/YearPicker.tsx +220 -78
- package/components/DatePickerInline/dateUtils.tsx +18 -13
- package/components/DatePickerInline/store.tsx +27 -0
- package/components/DatePickerInline/types.ts +6 -2
- package/components/DatePickerInline/utils.ts +66 -29
- package/components/Divider/Divider.tsx +192 -0
- package/components/Divider/index.tsx +10 -0
- package/components/Drawer/Drawer.tsx +17 -6
- package/components/Drawer/DrawerItemGroup.tsx +3 -7
- package/components/ElementGroup/ElementGroup.tsx +1 -1
- package/components/FilePicker/FilePicker.tsx +48 -78
- package/components/FilePicker/index.tsx +2 -1
- package/components/FilePicker/utils.ts +9 -0
- package/components/HelperText/HelperText.tsx +0 -35
- package/components/Icon/iconFactory.tsx +5 -4
- package/components/Icon/index.tsx +1 -1
- package/components/Icon/types.ts +17 -6
- package/components/IconButton/IconButton.tsx +84 -84
- package/components/IconButton/index.tsx +1 -0
- package/components/IconButton/types.ts +10 -0
- package/components/IconButton/utils.ts +167 -33
- package/components/List/List.tsx +276 -0
- package/components/List/context.tsx +27 -0
- package/components/List/index.ts +8 -0
- package/components/List/types.ts +117 -0
- package/components/List/utils.ts +79 -0
- package/components/LoadingIndicator/LoadingIndicator.tsx +253 -0
- package/components/LoadingIndicator/LoadingIndicator.web.tsx +136 -0
- package/components/LoadingIndicator/index.tsx +13 -0
- package/components/LoadingIndicator/utils.ts +117 -0
- package/components/Menu/Menu.tsx +162 -39
- package/components/Menu/index.tsx +10 -7
- package/components/Menu/utils.ts +21 -70
- package/components/NavigationRail/NavigationRail.tsx +15 -9
- package/components/Popover/Popover.tsx +119 -145
- package/components/Popover/PopoverRoot.tsx +60 -0
- package/components/Popover/common.ts +54 -34
- package/components/Popover/index.ts +12 -1
- package/components/Popover/usePlatformMeasure.native.ts +90 -0
- package/components/Popover/usePlatformMeasure.ts +120 -0
- package/components/Popover/utils.ts +34 -0
- package/components/Portal/Portal.tsx +1 -2
- package/components/Radio/Radio.tsx +188 -0
- package/components/Radio/RadioBase.ios.tsx +69 -0
- package/components/Radio/RadioBase.tsx +136 -0
- package/components/Radio/context.tsx +23 -0
- package/components/Radio/index.tsx +20 -0
- package/components/Radio/types.ts +101 -0
- package/components/Radio/utils.ts +115 -0
- package/components/Rating/Rating.tsx +1 -1
- package/components/Select/Select.tsx +521 -785
- package/components/Select/context.tsx +81 -0
- package/components/Select/index.ts +26 -14
- package/components/Select/types.ts +65 -58
- package/components/Select/utils.ts +126 -0
- package/components/Slot/Slot.tsx +224 -0
- package/components/Slot/compose-refs.tsx +62 -0
- package/components/Slot/index.tsx +8 -0
- package/components/Surface/Surface.android.tsx +32 -7
- package/components/Surface/Surface.ios.tsx +34 -29
- package/components/Surface/Surface.tsx +31 -4
- package/components/Surface/utils.ts +44 -6
- package/components/Switch/Switch.ios.tsx +1 -1
- package/components/Switch/Switch.tsx +10 -3
- package/components/Tabs/TabItem.tsx +35 -58
- package/components/Tabs/TabLabel.tsx +5 -9
- package/components/Tabs/Tabs.tsx +156 -150
- package/components/Tabs/utils.ts +15 -2
- package/components/Text/textFactory.tsx +17 -5
- package/components/TextInput/TextInput.tsx +663 -579
- package/components/TextInput/index.tsx +19 -3
- package/components/TextInput/types.ts +77 -28
- package/components/TextInput/utils.ts +235 -145
- package/components/TimeField/TimeField.tsx +75 -0
- package/components/TimeField/index.tsx +6 -0
- package/components/TimeField/useTimeFieldState.ts +70 -0
- package/components/{TimePickerField/sanitizeTime.ts → TimeField/utils.ts} +77 -10
- package/components/TimePicker/AnalogClock.tsx +1 -1
- package/components/TimePicker/TimeInput.tsx +87 -42
- package/components/TimePicker/TimeInputs.tsx +138 -50
- package/components/TimePicker/TimePicker.tsx +74 -11
- package/components/TimePicker/TimePickerModal.tsx +186 -0
- package/components/TimePicker/context.tsx +17 -0
- package/components/TimePicker/index.tsx +15 -3
- package/components/TimePicker/utils.ts +93 -4
- package/components/Tooltip/Tooltip.tsx +42 -67
- package/components/Tooltip/TooltipContent.tsx +32 -5
- package/components/Tooltip/TooltipTrigger.tsx +21 -24
- package/components/Tooltip/index.tsx +1 -1
- package/components/TouchableRipple/TouchableRipple.native.tsx +83 -16
- package/components/TouchableRipple/TouchableRipple.tsx +150 -102
- package/components/TouchableRipple/rippleFromForegroundColor.ts +21 -0
- package/hocs/index.tsx +1 -1
- package/hocs/withKeyboardAccessibility.tsx +2 -3
- package/hocs/withPortal.tsx +1 -1
- package/hooks/index.tsx +2 -12
- package/hooks/useActionState.tsx +19 -8
- package/hooks/useContrastColor.ts +1 -2
- package/hooks/useFilePicker.tsx +7 -17
- package/hooks/useHandleNumberFormat.tsx +2 -2
- package/hooks/useMediaQuery.tsx +1 -2
- package/package.json +95 -111
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +6 -3
- package/shortcuts-manager/ShortcutsManager/utils.tsx +1 -1
- package/shortcuts-manager/useSetScopes/useSetScopes.tsx +1 -1
- package/shortcuts-manager/useShortcut/useShortcut.tsx +1 -1
- package/styles/shadow.ts +2 -1
- package/styles/themes/LightTheme.tsx +1 -1
- package/utils/DocumentPicker/documentPicker.ts +78 -27
- package/utils/DocumentPicker/types.ts +0 -1
- package/utils/extractSubcomponents.ts +89 -0
- package/utils/extractTextStyles.ts +1 -2
- package/utils/formatNumberWithMask/formatNumberWithMask.ts +2 -1
- package/utils/index.ts +0 -3
- package/utils/normalizeToNumberString/normalizeToNumberString.ts +1 -1
- package/components/DatePickerDocked/DatePickerDocked.tsx +0 -30
- package/components/DatePickerDocked/DatePickerDockedHeader.tsx +0 -129
- package/components/DatePickerDocked/index.tsx +0 -17
- package/components/DatePickerDocked/types.ts +0 -11
- package/components/DatePickerDocked/utils.ts +0 -157
- package/components/DatePickerInline/DatePickerContext.tsx +0 -21
- package/components/DatePickerInput/DatePickerInput.tsx +0 -139
- package/components/DatePickerInput/DatePickerInputModal.tsx +0 -48
- package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +0 -77
- package/components/DatePickerInput/DateRangeInput.tsx +0 -88
- package/components/DatePickerInput/index.tsx +0 -10
- package/components/DatePickerInput/types.ts +0 -28
- package/components/DatePickerInput/utils.ts +0 -15
- package/components/DatePickerModal/AnimatedCrossView.tsx +0 -94
- package/components/DatePickerModal/CalendarEdit.tsx +0 -139
- package/components/DatePickerModal/DatePickerModal.tsx +0 -85
- package/components/DatePickerModal/DatePickerModalContent.tsx +0 -155
- package/components/DatePickerModal/DatePickerModalContentHeader.tsx +0 -213
- package/components/DatePickerModal/DatePickerModalHeader.tsx +0 -74
- package/components/DatePickerModal/DatePickerModalHeaderBackground.tsx +0 -13
- package/components/DatePickerModal/index.tsx +0 -16
- package/components/DatePickerModal/types.ts +0 -92
- package/components/DatePickerModal/utils.ts +0 -122
- package/components/DateTimePicker/DateTimePicker.tsx +0 -172
- package/components/DateTimePicker/index.tsx +0 -10
- package/components/DateTimePicker/utils.ts +0 -12
- package/components/HorizontalDivider/HorizontalDivider.tsx +0 -103
- package/components/HorizontalDivider/index.tsx +0 -9
- package/components/ListItem/ListItem.tsx +0 -136
- package/components/ListItem/ListItemDescription.tsx +0 -25
- package/components/ListItem/ListItemTitle.tsx +0 -25
- package/components/ListItem/index.tsx +0 -14
- package/components/ListItem/utils.ts +0 -115
- package/components/Menu/MenuDivider.tsx +0 -13
- package/components/Menu/MenuItem.tsx +0 -128
- package/components/Popover/Popover.native.tsx +0 -185
- package/components/RadioButton/RadioButton.tsx +0 -138
- package/components/RadioButton/RadioButtonAndroid.tsx +0 -188
- package/components/RadioButton/RadioButtonGroup.tsx +0 -98
- package/components/RadioButton/RadioButtonIOS.tsx +0 -106
- package/components/RadioButton/RadioButtonItem.tsx +0 -232
- package/components/RadioButton/index.ts +0 -22
- package/components/RadioButton/utils.ts +0 -165
- package/components/TimePickerField/TimePickerField.tsx +0 -152
- package/components/TimePickerField/index.tsx +0 -10
- package/components/TimePickerField/utils.ts +0 -94
- package/components/TimePickerModal/TimePickerModal.tsx +0 -115
- package/components/TimePickerModal/index.tsx +0 -10
- package/components/TimePickerModal/utils.ts +0 -47
- package/components/VerticalDivider/VerticalDivider.tsx +0 -100
- package/components/VerticalDivider/index.tsx +0 -9
- package/context-bridge/index.tsx +0 -87
- package/fast-context/index.tsx +0 -190
- package/hocs/typedMemo.tsx +0 -5
- package/hooks/useControlledValue.tsx +0 -68
- package/hooks/useLatest.tsx +0 -9
- package/hooks/useMergedRefs.ts +0 -14
- package/hooks/usePrevious.ts +0 -13
- package/hooks/useSearchable.tsx +0 -74
- package/hooks/useSubcomponents.tsx +0 -59
- package/hooks/useToggle.tsx +0 -24
- package/utils/color.ts +0 -22
- package/utils/compare/index.ts +0 -54
- package/utils/lodash.ts +0 -49
- package/utils/repository.ts +0 -53
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { memo, useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { KeyboardAvoidingView, Platform, View } from 'react-native';
|
|
3
|
-
|
|
4
|
-
import { format } from '../../utils/date-fns';
|
|
5
|
-
import { Button } from '../Button';
|
|
6
|
-
import { IconButton } from '../IconButton';
|
|
7
|
-
import { Modal, type ModalProps } from '../Modal';
|
|
8
|
-
import { Portal } from '../Portal';
|
|
9
|
-
import { Text } from '../Text';
|
|
10
|
-
import TimePicker from '../TimePicker/TimePicker';
|
|
11
|
-
import {
|
|
12
|
-
clockTypes,
|
|
13
|
-
getTimeInputTypeIcon,
|
|
14
|
-
inputTypes,
|
|
15
|
-
type PossibleClockTypes,
|
|
16
|
-
type PossibleInputTypes,
|
|
17
|
-
reverseInputTypes,
|
|
18
|
-
} from '../TimePicker/timeUtils';
|
|
19
|
-
import { styles } from './utils';
|
|
20
|
-
|
|
21
|
-
export type Props = Omit<ModalProps, 'children'> & {
|
|
22
|
-
is24Hour?: boolean;
|
|
23
|
-
label?: string;
|
|
24
|
-
uppercase?: boolean;
|
|
25
|
-
cancelLabel?: string;
|
|
26
|
-
confirmLabel?: string;
|
|
27
|
-
time?: string;
|
|
28
|
-
onConfirm: (time: string) => any;
|
|
29
|
-
keyboardIcon?: string;
|
|
30
|
-
clockIcon?: string;
|
|
31
|
-
isLandscape?: boolean;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export function TimePickerModal({
|
|
35
|
-
isOpen,
|
|
36
|
-
onClose,
|
|
37
|
-
onConfirm: onConfirmProp,
|
|
38
|
-
time: timeProp,
|
|
39
|
-
label = 'Select time',
|
|
40
|
-
uppercase = false,
|
|
41
|
-
cancelLabel = 'Cancel',
|
|
42
|
-
confirmLabel = 'Ok',
|
|
43
|
-
is24Hour,
|
|
44
|
-
keyboardIcon = 'keyboard-outline',
|
|
45
|
-
clockIcon = 'clock-outline',
|
|
46
|
-
isLandscape = false,
|
|
47
|
-
style,
|
|
48
|
-
...rest
|
|
49
|
-
}: Props) {
|
|
50
|
-
const [inputType, setInputType] = useState<PossibleInputTypes>(inputTypes.picker);
|
|
51
|
-
const [focused, setFocused] = useState<PossibleClockTypes>(clockTypes.hours);
|
|
52
|
-
const [time, setTime] = useState(() => timeProp || format(new Date(), 'HH:mm'));
|
|
53
|
-
|
|
54
|
-
const modelStyle = useMemo(() => [styles.modalContent, style], [style]);
|
|
55
|
-
|
|
56
|
-
const onFocusInput = useCallback((type: PossibleClockTypes) => setFocused(type), []);
|
|
57
|
-
|
|
58
|
-
const onChange = useCallback(
|
|
59
|
-
(params: { focused?: PossibleClockTypes | undefined; time: string }) => {
|
|
60
|
-
if (params.focused) {
|
|
61
|
-
setFocused(params.focused);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
setTime(params.time);
|
|
65
|
-
},
|
|
66
|
-
[setFocused, setTime],
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const onConfirm = useCallback(() => onConfirmProp(time), [onConfirmProp, time]);
|
|
70
|
-
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
setTime(timeProp || format(new Date(), 'HH:mm'));
|
|
73
|
-
}, [timeProp]);
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<Portal>
|
|
77
|
-
<Modal {...rest} isOpen={isOpen} style={modelStyle} onClose={onClose}>
|
|
78
|
-
<KeyboardAvoidingView
|
|
79
|
-
style={styles.keyboardView}
|
|
80
|
-
behavior={Platform.OS === 'ios' ? 'padding' : undefined}>
|
|
81
|
-
<View style={styles.labelContainer}>
|
|
82
|
-
<Text style={styles.label}>{uppercase ? label.toUpperCase() : label}</Text>
|
|
83
|
-
</View>
|
|
84
|
-
<View style={styles.timePickerContainer}>
|
|
85
|
-
<TimePicker
|
|
86
|
-
is24Hour={is24Hour}
|
|
87
|
-
inputType={inputType}
|
|
88
|
-
focused={focused}
|
|
89
|
-
time={time}
|
|
90
|
-
onTimeChange={onChange}
|
|
91
|
-
onFocusInput={onFocusInput}
|
|
92
|
-
isLandscape={isLandscape}
|
|
93
|
-
/>
|
|
94
|
-
</View>
|
|
95
|
-
<View style={styles.footer}>
|
|
96
|
-
<IconButton
|
|
97
|
-
name={getTimeInputTypeIcon(inputType, {
|
|
98
|
-
keyboard: keyboardIcon,
|
|
99
|
-
picker: clockIcon,
|
|
100
|
-
})}
|
|
101
|
-
onPress={() => setInputType(reverseInputTypes[inputType])}
|
|
102
|
-
style={styles.inputTypeToggle}
|
|
103
|
-
accessibilityLabel="toggle keyboard"
|
|
104
|
-
/>
|
|
105
|
-
<View style={styles.fill} />
|
|
106
|
-
<Button onPress={onClose}>{cancelLabel}</Button>
|
|
107
|
-
<Button onPress={onConfirm}>{confirmLabel}</Button>
|
|
108
|
-
</View>
|
|
109
|
-
</KeyboardAvoidingView>
|
|
110
|
-
</Modal>
|
|
111
|
-
</Portal>
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export default memo(TimePickerModal);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { getRegisteredComponentWithFallback } from '../../core';
|
|
2
|
-
import TimePickerModalDefault from './TimePickerModal';
|
|
3
|
-
|
|
4
|
-
export const TimePickerModal = getRegisteredComponentWithFallback(
|
|
5
|
-
'TimePickerModal',
|
|
6
|
-
TimePickerModalDefault,
|
|
7
|
-
);
|
|
8
|
-
|
|
9
|
-
export type { Props as TimePickerModalProps } from './TimePickerModal';
|
|
10
|
-
export { styles } from './utils';
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
-
|
|
3
|
-
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
4
|
-
|
|
5
|
-
const timepickerModalStylesDefault = StyleSheet.create(theme => ({
|
|
6
|
-
keyboardView: {
|
|
7
|
-
justifyContent: 'center',
|
|
8
|
-
alignItems: 'center',
|
|
9
|
-
flex: 1,
|
|
10
|
-
},
|
|
11
|
-
modalContent: {
|
|
12
|
-
minWidth: 287,
|
|
13
|
-
width: undefined,
|
|
14
|
-
maxWidth: undefined,
|
|
15
|
-
flex: undefined,
|
|
16
|
-
borderRadius: theme.shapes.corner.extraLarge,
|
|
17
|
-
},
|
|
18
|
-
labelContainer: {
|
|
19
|
-
height: 28,
|
|
20
|
-
justifyContent: 'flex-end',
|
|
21
|
-
paddingLeft: theme.spacings['6'],
|
|
22
|
-
paddingRight: theme.spacings['6'],
|
|
23
|
-
alignSelf: 'flex-start',
|
|
24
|
-
},
|
|
25
|
-
label: {
|
|
26
|
-
letterSpacing: 1,
|
|
27
|
-
fontSize: theme.typescale.labelLarge.fontSize,
|
|
28
|
-
color: theme.colors.onSurface,
|
|
29
|
-
fontWeight: theme.typescale.labelLarge.fontWeight,
|
|
30
|
-
},
|
|
31
|
-
timePickerContainer: {
|
|
32
|
-
padding: theme.spacings['6'],
|
|
33
|
-
},
|
|
34
|
-
footer: {
|
|
35
|
-
flexDirection: 'row',
|
|
36
|
-
alignItems: 'center',
|
|
37
|
-
padding: theme.spacings['2'],
|
|
38
|
-
width: '100%',
|
|
39
|
-
},
|
|
40
|
-
inputTypeToggle: { margin: theme.spacings['1'] },
|
|
41
|
-
fill: { flex: 1 },
|
|
42
|
-
}));
|
|
43
|
-
|
|
44
|
-
export const styles = getRegisteredComponentStylesWithFallback(
|
|
45
|
-
'TimePickerModal',
|
|
46
|
-
timepickerModalStylesDefault,
|
|
47
|
-
);
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { memo } from 'react';
|
|
2
|
-
import { View, type ViewProps } from 'react-native';
|
|
3
|
-
import { StyleSheet } from 'react-native-unistyles';
|
|
4
|
-
|
|
5
|
-
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
6
|
-
|
|
7
|
-
export type Props = Omit<ViewProps, 'children'> & {
|
|
8
|
-
/**
|
|
9
|
-
* Top Inset of the Divider.
|
|
10
|
-
*/
|
|
11
|
-
topInset?: number;
|
|
12
|
-
/**
|
|
13
|
-
* Bottom Inset of the Divider.
|
|
14
|
-
*/
|
|
15
|
-
bottomInset?: number;
|
|
16
|
-
/**
|
|
17
|
-
* Whether divider should be bolded.
|
|
18
|
-
*/
|
|
19
|
-
bold?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Horizontal spacing of the Divider
|
|
22
|
-
*/
|
|
23
|
-
spacing?: number;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* A divider is a thin, lightweight separator that groups content in lists and page layouts.
|
|
28
|
-
*
|
|
29
|
-
* <div class="screenshots">
|
|
30
|
-
* <figure>
|
|
31
|
-
* <img class="medium" src="screenshots/divider.png" />
|
|
32
|
-
* </figure>
|
|
33
|
-
* </div>
|
|
34
|
-
*
|
|
35
|
-
* ## Usage
|
|
36
|
-
* ```js
|
|
37
|
-
* import * as React from 'react';
|
|
38
|
-
* import { View } from 'react-native';
|
|
39
|
-
* import { Divider, Text } from 'react-native-paper';
|
|
40
|
-
*
|
|
41
|
-
* const MyComponent = () => (
|
|
42
|
-
* <View>
|
|
43
|
-
* <Text>Lemon</Text>
|
|
44
|
-
* <Divider />
|
|
45
|
-
* <Text>Mango</Text>
|
|
46
|
-
* <Divider />
|
|
47
|
-
* </View>
|
|
48
|
-
* );
|
|
49
|
-
*
|
|
50
|
-
* export default MyComponent;
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
const VerticalDivider = ({
|
|
55
|
-
topInset = 0,
|
|
56
|
-
bottomInset = 0,
|
|
57
|
-
spacing = 0,
|
|
58
|
-
style,
|
|
59
|
-
bold = false,
|
|
60
|
-
...rest
|
|
61
|
-
}: Props) => {
|
|
62
|
-
verticalDividerStyles.useVariants({
|
|
63
|
-
isBold: bold,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<View
|
|
68
|
-
{...rest}
|
|
69
|
-
style={[
|
|
70
|
-
verticalDividerStyles.root,
|
|
71
|
-
style,
|
|
72
|
-
topInset ? { marginTop: topInset } : undefined,
|
|
73
|
-
bottomInset ? { marginBottom: bottomInset } : undefined,
|
|
74
|
-
spacing ? { marginHorizontal: spacing } : undefined,
|
|
75
|
-
]}
|
|
76
|
-
/>
|
|
77
|
-
);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export const verticalDividerStylesDefault = StyleSheet.create(theme => ({
|
|
81
|
-
root: {
|
|
82
|
-
width: StyleSheet.hairlineWidth,
|
|
83
|
-
background: theme.colors.outlineVariant,
|
|
84
|
-
|
|
85
|
-
variants: {
|
|
86
|
-
isBold: {
|
|
87
|
-
true: {
|
|
88
|
-
width: 1,
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
}));
|
|
94
|
-
|
|
95
|
-
export const verticalDividerStyles = getRegisteredComponentStylesWithFallback(
|
|
96
|
-
'VerticalDivider',
|
|
97
|
-
verticalDividerStylesDefault,
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
export default memo(VerticalDivider);
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { getRegisteredComponentWithFallback } from '../../core';
|
|
2
|
-
import VerticalDividerDefault from './VerticalDivider';
|
|
3
|
-
|
|
4
|
-
export const VerticalDivider = getRegisteredComponentWithFallback(
|
|
5
|
-
'VerticalDivider',
|
|
6
|
-
VerticalDividerDefault,
|
|
7
|
-
);
|
|
8
|
-
|
|
9
|
-
export { type Props as VerticalDividerProps, verticalDividerStyles } from './VerticalDivider';
|
package/context-bridge/index.tsx
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { ComponentType, Context as ContextType, PropsWithChildren } from 'react';
|
|
2
|
-
import { Fragment, useContext, useId, useMemo, useRef, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
import typedMemo from '../hocs/typedMemo';
|
|
5
|
-
import { Repository } from '../utils/repository';
|
|
6
|
-
|
|
7
|
-
// https://github.com/pmndrs/its-fine/blob/main/src/index.tsx
|
|
8
|
-
// In development, React will warn about using contexts between renderers.
|
|
9
|
-
// Hide the warning because its-fine fixes this issue
|
|
10
|
-
// https://github.com/facebook/react/pull/12779
|
|
11
|
-
function wrapContext<T>(context: React.Context<T>): React.Context<T> {
|
|
12
|
-
try {
|
|
13
|
-
return Object.defineProperties(context, {
|
|
14
|
-
_currentRenderer: {
|
|
15
|
-
get() {
|
|
16
|
-
return null;
|
|
17
|
-
},
|
|
18
|
-
set() {},
|
|
19
|
-
},
|
|
20
|
-
_currentRenderer2: {
|
|
21
|
-
get() {
|
|
22
|
-
return null;
|
|
23
|
-
},
|
|
24
|
-
set() {},
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
} catch (_) {
|
|
28
|
-
return context;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const createContextBridge = <T extends object>(
|
|
33
|
-
bridgeName: string,
|
|
34
|
-
Wrapper: ComponentType<T>,
|
|
35
|
-
contexts: ContextType<any>[] = [],
|
|
36
|
-
) => {
|
|
37
|
-
const respository = new Repository<ContextType<any>[]>({
|
|
38
|
-
name: bridgeName,
|
|
39
|
-
onRegister: (arg, name, registry) => {
|
|
40
|
-
return [registry[name] ?? [], arg].flat();
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
registerContextToBridge: (updatedContexts: ContextType<any> | ContextType<any>[]) => {
|
|
46
|
-
respository.register(
|
|
47
|
-
'contexts',
|
|
48
|
-
([] as ContextType<any>[])
|
|
49
|
-
.concat(updatedContexts)
|
|
50
|
-
.map(context => wrapContext(context)),
|
|
51
|
-
);
|
|
52
|
-
},
|
|
53
|
-
BridgedComponent: typedMemo((props: PropsWithChildren<T> & { name?: string }) => {
|
|
54
|
-
const { name, ...rest } = props;
|
|
55
|
-
const contextValuesRef = useRef<any[]>([]);
|
|
56
|
-
|
|
57
|
-
const id = useId();
|
|
58
|
-
|
|
59
|
-
const [allContexts] = useState(() =>
|
|
60
|
-
Array.from(new Set([...contexts, ...Object.values(respository.getAll()).flat()])),
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
for (const i in allContexts) {
|
|
64
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
65
|
-
contextValuesRef.current[i] = useContext(allContexts[i]);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const content = useMemo(() => {
|
|
69
|
-
return allContexts.reduce((acc, Context, currentIndex) => {
|
|
70
|
-
return (
|
|
71
|
-
<Context.Provider value={contextValuesRef.current[currentIndex]}>
|
|
72
|
-
{acc}
|
|
73
|
-
</Context.Provider>
|
|
74
|
-
);
|
|
75
|
-
}, <>{props.children}</>);
|
|
76
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
|
-
}, [...contextValuesRef.current, allContexts, props.children]);
|
|
78
|
-
|
|
79
|
-
const _key = name ? name + id : id;
|
|
80
|
-
return (
|
|
81
|
-
<Wrapper name={name} {...(rest as T)}>
|
|
82
|
-
<Fragment key={_key}>{content}</Fragment>
|
|
83
|
-
</Wrapper>
|
|
84
|
-
);
|
|
85
|
-
}),
|
|
86
|
-
};
|
|
87
|
-
};
|
package/fast-context/index.tsx
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Context,
|
|
3
|
-
createContext,
|
|
4
|
-
type ReactNode,
|
|
5
|
-
type RefObject,
|
|
6
|
-
useCallback,
|
|
7
|
-
useContext,
|
|
8
|
-
useEffect,
|
|
9
|
-
useMemo,
|
|
10
|
-
useRef,
|
|
11
|
-
} from 'react';
|
|
12
|
-
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector';
|
|
13
|
-
|
|
14
|
-
import typedMemo from '../hocs/typedMemo';
|
|
15
|
-
import { usePrevious } from '../hooks';
|
|
16
|
-
import { shallowCompare } from '../utils';
|
|
17
|
-
|
|
18
|
-
type StoreDataType = Record<string, any>;
|
|
19
|
-
|
|
20
|
-
type SelectorOutputType<IStore, SelectorOutput> = (store: IStore) => SelectorOutput;
|
|
21
|
-
|
|
22
|
-
type UseStoreDataReturnType<T> = {
|
|
23
|
-
get: () => T;
|
|
24
|
-
set: (value: (prev: T) => Partial<T>) => void;
|
|
25
|
-
store: RefObject<T>;
|
|
26
|
-
subscribe: (callback: () => void) => () => void;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const useStoreData = <IStore extends StoreDataType>(
|
|
30
|
-
value: IStore,
|
|
31
|
-
defaultValue: IStore | null,
|
|
32
|
-
watch: boolean = false,
|
|
33
|
-
): UseStoreDataReturnType<IStore> => {
|
|
34
|
-
const store = useRef<IStore>({ ...defaultValue, ...(value as IStore) });
|
|
35
|
-
const watchRef = useRef(watch);
|
|
36
|
-
|
|
37
|
-
const get = useCallback(() => store.current, [store]);
|
|
38
|
-
|
|
39
|
-
const subscribers = useRef(new Set<() => void>());
|
|
40
|
-
|
|
41
|
-
const set = useCallback(
|
|
42
|
-
(callback: (prev: IStore) => Partial<IStore>) => {
|
|
43
|
-
store.current = { ...store.current, ...callback(store.current) };
|
|
44
|
-
subscribers.current.forEach(subscriber => subscriber());
|
|
45
|
-
},
|
|
46
|
-
[store],
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
const subscribe = useCallback((callback: () => void) => {
|
|
50
|
-
subscribers.current.add(callback);
|
|
51
|
-
|
|
52
|
-
return () => subscribers.current.delete(callback);
|
|
53
|
-
}, []);
|
|
54
|
-
|
|
55
|
-
/** The effect is required to trigger the updates on the consumers */
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
if (!watchRef.current) return;
|
|
58
|
-
set(prev => ({ ...prev, ...value }));
|
|
59
|
-
}, [set, value]);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Cases:
|
|
63
|
-
* 1. when the value updates, we want the data to be updated immediately
|
|
64
|
-
* 2. the data stored in store.current may not be current with regards to the parent and the parent must have dropped the references related to the data.
|
|
65
|
-
* 3. because store.current is a ref, on watch and change, if we update store.current, no side-effect introduced.
|
|
66
|
-
*/
|
|
67
|
-
if (usePrevious(value).current !== value && watchRef.current) {
|
|
68
|
-
store.current = { ...store.current, ...value };
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return useMemo(
|
|
72
|
-
() => ({
|
|
73
|
-
get,
|
|
74
|
-
set,
|
|
75
|
-
subscribe,
|
|
76
|
-
store,
|
|
77
|
-
}),
|
|
78
|
-
[get, set, subscribe],
|
|
79
|
-
);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const createFastContext = <T extends StoreDataType = {}>(
|
|
83
|
-
defaultValue: T | null = null,
|
|
84
|
-
watch: boolean = false,
|
|
85
|
-
) => {
|
|
86
|
-
const context = createContext<UseStoreDataReturnType<T> | null>(null);
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
/**
|
|
90
|
-
* using the value from here will never cause a rerender as context is based on refs.
|
|
91
|
-
*/
|
|
92
|
-
useStoreRef: createUseRefContext(context),
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
*
|
|
96
|
-
* the value is memoized and thus changing the value will have no effect.
|
|
97
|
-
* use key prop to unmount and remount if necessary. alternatively use set from the context to update the value.
|
|
98
|
-
*
|
|
99
|
-
*/
|
|
100
|
-
Provider: createProvider<T>(
|
|
101
|
-
context as Context<UseStoreDataReturnType<T>>,
|
|
102
|
-
defaultValue,
|
|
103
|
-
watch,
|
|
104
|
-
),
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
*
|
|
108
|
-
* @param selector
|
|
109
|
-
* @param equalityCheck
|
|
110
|
-
* @returns tuple, first item is return value of the selector and the second item is setter
|
|
111
|
-
*
|
|
112
|
-
*/
|
|
113
|
-
useContext: <SelectorOutput,>(
|
|
114
|
-
selector: SelectorOutputType<T, SelectorOutput>,
|
|
115
|
-
equalityCheck = shallowCompare,
|
|
116
|
-
) => useStore(context as Context<UseStoreDataReturnType<T>>, selector, equalityCheck),
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
*
|
|
120
|
-
* @param selector
|
|
121
|
-
* @param equalityCheck
|
|
122
|
-
* @returns return value of the selector
|
|
123
|
-
*
|
|
124
|
-
*/
|
|
125
|
-
useContextValue: <SelectorOutput,>(
|
|
126
|
-
selector: SelectorOutputType<T, SelectorOutput>,
|
|
127
|
-
equalityCheck = shallowCompare,
|
|
128
|
-
) => useStoreValue(context as Context<UseStoreDataReturnType<T>>, selector, equalityCheck),
|
|
129
|
-
/**
|
|
130
|
-
* context of the store. Useful for ContextBridge
|
|
131
|
-
*/
|
|
132
|
-
Context: context,
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export const createProvider = <T extends Record<string, any> = {}>(
|
|
137
|
-
StoreContext: Context<UseStoreDataReturnType<T>>,
|
|
138
|
-
defaultValue: T | null,
|
|
139
|
-
watch: boolean,
|
|
140
|
-
) =>
|
|
141
|
-
typedMemo(({ value, children }: { value: T; children: ReactNode }) => {
|
|
142
|
-
return (
|
|
143
|
-
<StoreContext.Provider value={useStoreData<T>(value, defaultValue, watch) as any}>
|
|
144
|
-
{children}
|
|
145
|
-
</StoreContext.Provider>
|
|
146
|
-
);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
export const createUseRefContext = <T,>(_Context: Context<UseStoreDataReturnType<T> | null>) => {
|
|
150
|
-
return () => {
|
|
151
|
-
const value = useContext<UseStoreDataReturnType<T> | null>(_Context);
|
|
152
|
-
if (value === null)
|
|
153
|
-
throw 'Fast Context requires the value to be wrapped in a Provider with a value.';
|
|
154
|
-
|
|
155
|
-
return value;
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export const useStore = <IStore extends StoreDataType, SelectorOutput>(
|
|
160
|
-
_Context: Context<UseStoreDataReturnType<IStore>>,
|
|
161
|
-
selector: SelectorOutputType<IStore, SelectorOutput>,
|
|
162
|
-
equalityFn = Object.is,
|
|
163
|
-
): [SelectorOutput, (value: (prev: IStore) => Partial<IStore>) => void] => {
|
|
164
|
-
const store = useContext(_Context);
|
|
165
|
-
if (!store) {
|
|
166
|
-
throw new Error('Store not found');
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const state = useSyncExternalStoreWithSelector(
|
|
170
|
-
store.subscribe,
|
|
171
|
-
() => {
|
|
172
|
-
return store.get();
|
|
173
|
-
},
|
|
174
|
-
undefined,
|
|
175
|
-
snapshot => {
|
|
176
|
-
return selector(snapshot);
|
|
177
|
-
},
|
|
178
|
-
equalityFn,
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
return [state, store.set];
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
export const useStoreValue = <IStore extends StoreDataType, SelectorOutput>(
|
|
185
|
-
_Context: Context<UseStoreDataReturnType<IStore>>,
|
|
186
|
-
selector: SelectorOutputType<IStore, SelectorOutput>,
|
|
187
|
-
equalityFn = Object.is,
|
|
188
|
-
) => {
|
|
189
|
-
return useStore(_Context, selector, equalityFn)[0];
|
|
190
|
-
};
|
package/hocs/typedMemo.tsx
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
type ReturnType<T> = [T, (value: T, ...args: any[]) => void];
|
|
4
|
-
|
|
5
|
-
type Args<T> = {
|
|
6
|
-
value?: T;
|
|
7
|
-
defaultValue?: T;
|
|
8
|
-
onChange?: (value: T, ...args: any[]) => any;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
manipulateValue?: (value: T | undefined, prevValue: T | undefined) => T;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const defaultManipulateValue = (val: any) => val;
|
|
14
|
-
|
|
15
|
-
const useControlledValue = <T,>({
|
|
16
|
-
value: valueProp,
|
|
17
|
-
defaultValue,
|
|
18
|
-
disabled = false,
|
|
19
|
-
onChange,
|
|
20
|
-
manipulateValue = defaultManipulateValue,
|
|
21
|
-
}: Args<T>): ReturnType<T> => {
|
|
22
|
-
const value = useMemo(
|
|
23
|
-
() =>
|
|
24
|
-
valueProp !== undefined
|
|
25
|
-
? manipulateValue(valueProp, undefined)
|
|
26
|
-
: manipulateValue(defaultValue, undefined),
|
|
27
|
-
[defaultValue, manipulateValue, valueProp],
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const hasWarnedRef = useRef(false);
|
|
31
|
-
|
|
32
|
-
const isUncontrolled = useRef(valueProp).current === undefined;
|
|
33
|
-
const [uncontrolledValue, setValue] = useState(value);
|
|
34
|
-
|
|
35
|
-
const updateValue = useCallback(
|
|
36
|
-
(val: T, ...rest: any[]) => {
|
|
37
|
-
if (disabled) return;
|
|
38
|
-
|
|
39
|
-
if (isUncontrolled) {
|
|
40
|
-
setValue(manipulateValue(val, uncontrolledValue));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
onChange?.(
|
|
44
|
-
manipulateValue(val, isUncontrolled ? uncontrolledValue : valueProp),
|
|
45
|
-
...rest,
|
|
46
|
-
);
|
|
47
|
-
},
|
|
48
|
-
[disabled, isUncontrolled, manipulateValue, onChange, uncontrolledValue, valueProp],
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
if (hasWarnedRef.current) return;
|
|
53
|
-
hasWarnedRef.current = true;
|
|
54
|
-
|
|
55
|
-
if (valueProp !== undefined && isUncontrolled) {
|
|
56
|
-
console.warn(
|
|
57
|
-
'Trying to change the value from uncontrolled to controlled can lead to inconsistencies',
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
}, [isUncontrolled, valueProp]);
|
|
61
|
-
|
|
62
|
-
return useMemo(
|
|
63
|
-
() => [isUncontrolled ? uncontrolledValue : value, updateValue],
|
|
64
|
-
[isUncontrolled, uncontrolledValue, updateValue, value],
|
|
65
|
-
);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export default useControlledValue;
|
package/hooks/useLatest.tsx
DELETED
package/hooks/useMergedRefs.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
|
|
3
|
-
import { mergeRefs } from '../utils';
|
|
4
|
-
import useLatest from './useLatest';
|
|
5
|
-
|
|
6
|
-
export const useMergedRefs: typeof mergeRefs = refs => {
|
|
7
|
-
const latestRefs = useLatest(refs);
|
|
8
|
-
return useCallback(
|
|
9
|
-
value => {
|
|
10
|
-
mergeRefs(latestRefs.current)(value);
|
|
11
|
-
},
|
|
12
|
-
[latestRefs],
|
|
13
|
-
);
|
|
14
|
-
};
|
package/hooks/usePrevious.ts
DELETED