react-native-molecules 0.5.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Accordion/Accordion.tsx +89 -0
- package/components/Accordion/AccordionItem.tsx +94 -0
- package/components/Accordion/AccordionItemContent.tsx +17 -0
- package/components/Accordion/AccordionItemHeader.tsx +122 -0
- package/components/Accordion/index.tsx +36 -0
- package/components/Accordion/utils.ts +62 -0
- package/components/ActivityIndicator/ActivityIndicator.ios.tsx +1 -0
- package/components/ActivityIndicator/ActivityIndicator.tsx +200 -0
- package/components/ActivityIndicator/AnimatedSpinner.tsx +121 -0
- package/components/ActivityIndicator/index.tsx +17 -0
- package/components/Appbar/AppbarActions.tsx +13 -0
- package/components/Appbar/AppbarBase.tsx +60 -0
- package/components/Appbar/AppbarCenterAligned.tsx +13 -0
- package/components/Appbar/AppbarLarge.tsx +13 -0
- package/components/Appbar/AppbarLeft.tsx +26 -0
- package/components/Appbar/AppbarMedium.tsx +13 -0
- package/components/Appbar/AppbarRight.tsx +40 -0
- package/components/Appbar/AppbarSmall.tsx +13 -0
- package/components/Appbar/AppbarTitle.tsx +49 -0
- package/components/Appbar/index.tsx +46 -0
- package/components/Appbar/types.ts +19 -0
- package/components/Appbar/utils.ts +127 -0
- package/components/Avatar/Avatar.tsx +189 -0
- package/components/Avatar/index.tsx +11 -0
- package/components/Avatar/utils.ts +35 -0
- package/components/Backdrop/Backdrop.tsx +18 -0
- package/components/Backdrop/index.tsx +11 -0
- package/components/Backdrop/types.ts +3 -0
- package/components/Backdrop/utils.ts +21 -0
- package/components/Badge/Badge.tsx +29 -0
- package/components/Badge/index.tsx +11 -0
- package/components/Badge/utils.ts +38 -0
- package/components/Button/Button.tsx +349 -0
- package/components/Button/index.tsx +11 -0
- package/components/Button/types.ts +5 -0
- package/components/Button/utils.ts +416 -0
- package/components/Card/Card.tsx +160 -0
- package/components/Card/CardActions.tsx +18 -0
- package/components/Card/CardContent.tsx +29 -0
- package/components/Card/CardHeader.tsx +31 -0
- package/components/Card/CardHeadline.tsx +15 -0
- package/components/Card/CardMedia.tsx +36 -0
- package/components/Card/CardSubhead.tsx +15 -0
- package/components/Card/CardText.tsx +13 -0
- package/components/Card/CardTypography.tsx +113 -0
- package/components/Card/index.tsx +38 -0
- package/components/Card/types.ts +1 -0
- package/components/Card/utils.ts +23 -0
- package/components/Checkbox/Checkbox.tsx +123 -0
- package/components/Checkbox/CheckboxBase.ios.tsx +86 -0
- package/components/Checkbox/CheckboxBase.tsx +216 -0
- package/components/Checkbox/index.tsx +11 -0
- package/components/Checkbox/types.ts +72 -0
- package/components/Checkbox/utils.ts +210 -0
- package/components/Chip/Chip.tsx +416 -0
- package/components/Chip/index.tsx +51 -0
- package/components/Chip/utils.ts +100 -0
- package/components/DatePickerDocked/DatePickerDocked.tsx +30 -0
- package/components/DatePickerDocked/DatePickerDockedHeader.tsx +129 -0
- package/components/DatePickerDocked/index.tsx +21 -0
- package/components/DatePickerDocked/types.ts +11 -0
- package/components/DatePickerDocked/utils.ts +155 -0
- package/components/DatePickerInline/AutoSizer.tsx +46 -0
- package/components/DatePickerInline/DatePickerContext.tsx +21 -0
- package/components/DatePickerInline/DatePickerInline.tsx +82 -0
- package/components/DatePickerInline/DatePickerInlineBase.tsx +181 -0
- package/components/DatePickerInline/DatePickerInlineHeader.tsx +108 -0
- package/components/DatePickerInline/Day.tsx +88 -0
- package/components/DatePickerInline/DayName.tsx +17 -0
- package/components/DatePickerInline/DayNames.tsx +32 -0
- package/components/DatePickerInline/DayRange.tsx +48 -0
- package/components/DatePickerInline/HeaderItem.tsx +111 -0
- package/components/DatePickerInline/Month.tsx +233 -0
- package/components/DatePickerInline/MonthPicker.tsx +174 -0
- package/components/DatePickerInline/Swiper.native.tsx +172 -0
- package/components/DatePickerInline/Swiper.tsx +172 -0
- package/components/DatePickerInline/SwiperUtils.ts +40 -0
- package/components/DatePickerInline/Week.tsx +67 -0
- package/components/DatePickerInline/YearPicker.tsx +139 -0
- package/components/DatePickerInline/dateUtils.tsx +334 -0
- package/components/DatePickerInline/index.tsx +41 -0
- package/components/DatePickerInline/types.ts +104 -0
- package/components/DatePickerInline/utils.ts +367 -0
- package/components/DatePickerInput/DatePickerInput.tsx +139 -0
- package/components/DatePickerInput/DatePickerInputModal.tsx +48 -0
- package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +77 -0
- package/components/DatePickerInput/DateRangeInput.tsx +88 -0
- package/components/DatePickerInput/index.tsx +14 -0
- package/components/DatePickerInput/inputUtils.ts +138 -0
- package/components/DatePickerInput/types.ts +28 -0
- package/components/DatePickerInput/utils.ts +16 -0
- package/components/DatePickerModal/AnimatedCrossView.tsx +94 -0
- package/components/DatePickerModal/CalendarEdit.tsx +139 -0
- package/components/DatePickerModal/DatePickerModal.tsx +85 -0
- package/components/DatePickerModal/DatePickerModalContent.tsx +155 -0
- package/components/DatePickerModal/DatePickerModalContentHeader.tsx +213 -0
- package/components/DatePickerModal/DatePickerModalHeader.tsx +74 -0
- package/components/DatePickerModal/DatePickerModalHeaderBackground.tsx +13 -0
- package/components/DatePickerModal/index.tsx +20 -0
- package/components/DatePickerModal/types.ts +92 -0
- package/components/DatePickerModal/utils.ts +121 -0
- package/components/DateTimePicker/DateTimePicker.tsx +172 -0
- package/components/DateTimePicker/index.tsx +14 -0
- package/components/DateTimePicker/utils.ts +13 -0
- package/components/Dialog/Dialog.tsx +66 -0
- package/components/Dialog/DialogActions.tsx +89 -0
- package/components/Dialog/DialogContent.tsx +37 -0
- package/components/Dialog/DialogIcon.tsx +69 -0
- package/components/Dialog/DialogTitle.tsx +68 -0
- package/components/Dialog/index.tsx +37 -0
- package/components/Dialog/utils.ts +80 -0
- package/components/Drawer/Collapsible/DrawerCollapsible.tsx +22 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItem.tsx +38 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItemContent.tsx +16 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItemHeader.tsx +48 -0
- package/components/Drawer/Collapsible/index.tsx +23 -0
- package/components/Drawer/Collapsible/utils.ts +49 -0
- package/components/Drawer/Drawer.tsx +43 -0
- package/components/Drawer/DrawerContent.tsx +35 -0
- package/components/Drawer/DrawerFooter.tsx +27 -0
- package/components/Drawer/DrawerHeader.tsx +27 -0
- package/components/Drawer/DrawerItem.tsx +206 -0
- package/components/Drawer/DrawerItemGroup.tsx +82 -0
- package/components/Drawer/index.tsx +47 -0
- package/components/Drawer/types.ts +3 -0
- package/components/Drawer/utils.ts +8 -0
- package/components/ElementGroup/ElementGroup.tsx +139 -0
- package/components/ElementGroup/index.tsx +11 -0
- package/components/ElementGroup/utils.ts +25 -0
- package/components/FAB/FAB.tsx +176 -0
- package/components/FAB/index.tsx +12 -0
- package/components/FAB/types.ts +1 -0
- package/components/FAB/utils.ts +221 -0
- package/components/FilePicker/FilePicker.tsx +133 -0
- package/components/FilePicker/index.tsx +11 -0
- package/components/FilePicker/utils.ts +13 -0
- package/components/HelperText/HelperText.tsx +139 -0
- package/components/HelperText/index.tsx +11 -0
- package/components/HelperText/utils.ts +29 -0
- package/components/HorizontalDivider/HorizontalDivider.tsx +101 -0
- package/components/HorizontalDivider/index.tsx +13 -0
- package/components/Icon/CrossFadeIcon.tsx +116 -0
- package/components/Icon/Icon.tsx +41 -0
- package/components/Icon/iconFactory.tsx +23 -0
- package/components/Icon/index.tsx +11 -0
- package/components/Icon/types.ts +35 -0
- package/components/IconButton/IconButton.tsx +218 -0
- package/components/IconButton/index.tsx +11 -0
- package/components/IconButton/types.ts +1 -0
- package/components/IconButton/utils.ts +325 -0
- package/components/If/index.tsx +13 -0
- package/components/InputAddon/InputAddon.tsx +27 -0
- package/components/InputAddon/index.tsx +11 -0
- package/components/InputAddon/utils.ts +33 -0
- package/components/Link/Link.tsx +48 -0
- package/components/Link/index.tsx +11 -0
- package/components/Link/utils.ts +37 -0
- package/components/ListItem/ListItem.tsx +136 -0
- package/components/ListItem/ListItemDescription.tsx +25 -0
- package/components/ListItem/ListItemTitle.tsx +25 -0
- package/components/ListItem/index.tsx +18 -0
- package/components/ListItem/utils.ts +113 -0
- package/components/Menu/Menu.tsx +69 -0
- package/components/Menu/MenuDivider.tsx +13 -0
- package/components/Menu/MenuItem.tsx +128 -0
- package/components/Menu/index.tsx +19 -0
- package/components/Menu/utils.ts +92 -0
- package/components/Modal/Modal.tsx +261 -0
- package/components/Modal/index.tsx +11 -0
- package/components/Modal/utils.ts +45 -0
- package/components/NavigationRail/NavigationRail.tsx +32 -0
- package/components/NavigationRail/NavigationRailContent.tsx +25 -0
- package/components/NavigationRail/NavigationRailFooter.tsx +18 -0
- package/components/NavigationRail/NavigationRailHeader.tsx +18 -0
- package/components/NavigationRail/NavigationRailItem.tsx +226 -0
- package/components/NavigationRail/index.tsx +35 -0
- package/components/NavigationRail/utils.ts +170 -0
- package/components/NavigationStack/NavigationStack.tsx +85 -0
- package/components/NavigationStack/NavigationStackItem.tsx +60 -0
- package/components/NavigationStack/index.tsx +20 -0
- package/components/NavigationStack/utils.tsx +16 -0
- package/components/Popover/Popover.native.tsx +185 -0
- package/components/Popover/Popover.tsx +198 -0
- package/components/Popover/common.ts +459 -0
- package/components/Popover/index.ts +2 -0
- package/components/Portal/Portal.tsx +13 -0
- package/components/Portal/index.tsx +12 -0
- package/components/RadioButton/RadioButton.tsx +138 -0
- package/components/RadioButton/RadioButtonAndroid.tsx +188 -0
- package/components/RadioButton/RadioButtonGroup.tsx +98 -0
- package/components/RadioButton/RadioButtonIOS.tsx +106 -0
- package/components/RadioButton/RadioButtonItem.tsx +232 -0
- package/components/RadioButton/index.ts +27 -0
- package/components/RadioButton/utils.ts +164 -0
- package/components/Rating/Rating.tsx +149 -0
- package/components/Rating/RatingItem.tsx +125 -0
- package/components/Rating/index.tsx +13 -0
- package/components/Rating/utils.ts +38 -0
- package/components/Select/Select.tsx +1038 -0
- package/components/Select/index.ts +14 -0
- package/components/Select/types.ts +115 -0
- package/components/StateLayer/StateLayer.tsx +12 -0
- package/components/StateLayer/index.tsx +11 -0
- package/components/StateLayer/utils.ts +17 -0
- package/components/Surface/BackgroundContextWrapper.tsx +27 -0
- package/components/Surface/Surface.android.tsx +62 -0
- package/components/Surface/Surface.ios.tsx +123 -0
- package/components/Surface/Surface.tsx +48 -0
- package/components/Surface/index.tsx +12 -0
- package/components/Surface/utils.ts +106 -0
- package/components/Switch/Switch.ios.tsx +67 -0
- package/components/Switch/Switch.tsx +278 -0
- package/components/Switch/index.tsx +11 -0
- package/components/Switch/utils.ts +283 -0
- package/components/Tabs/TabItem.tsx +150 -0
- package/components/Tabs/TabLabel.tsx +84 -0
- package/components/Tabs/Tabs.tsx +398 -0
- package/components/Tabs/index.tsx +21 -0
- package/components/Tabs/utils.ts +126 -0
- package/components/Text/Text.tsx +23 -0
- package/components/Text/index.tsx +2 -0
- package/components/Text/textFactory.tsx +33 -0
- package/components/TextInput/InputLabel.tsx +181 -0
- package/components/TextInput/TextInput.tsx +693 -0
- package/components/TextInput/index.tsx +16 -0
- package/components/TextInput/types.ts +96 -0
- package/components/TextInput/utils.ts +544 -0
- package/components/TextInputWithMask/TextInputMask.tsx +57 -0
- package/components/TextInputWithMask/index.tsx +11 -0
- package/components/TextInputWithMask/utils.ts +56 -0
- package/components/TimePicker/AmPmSwitcher.tsx +99 -0
- package/components/TimePicker/AnalogClock.tsx +165 -0
- package/components/TimePicker/AnalogClockHours.tsx +163 -0
- package/components/TimePicker/AnalogClockMinutes.tsx +68 -0
- package/components/TimePicker/AnimatedClockSwitcher.tsx +72 -0
- package/components/TimePicker/DisplayModeContext.tsx +6 -0
- package/components/TimePicker/TimeInput.tsx +112 -0
- package/components/TimePicker/TimeInputs.tsx +148 -0
- package/components/TimePicker/TimePicker.tsx +130 -0
- package/components/TimePicker/index.tsx +19 -0
- package/components/TimePicker/timeUtils.ts +159 -0
- package/components/TimePicker/utils.ts +285 -0
- package/components/TimePickerField/TimePickerField.tsx +152 -0
- package/components/TimePickerField/index.tsx +14 -0
- package/components/TimePickerField/sanitizeTime.ts +85 -0
- package/components/TimePickerField/utils.ts +95 -0
- package/components/TimePickerModal/TimePickerModal.tsx +115 -0
- package/components/TimePickerModal/index.tsx +14 -0
- package/components/TimePickerModal/utils.ts +48 -0
- package/components/Tooltip/Tooltip.tsx +137 -0
- package/components/Tooltip/TooltipContent.tsx +12 -0
- package/components/Tooltip/TooltipTrigger.tsx +94 -0
- package/components/Tooltip/index.tsx +20 -0
- package/components/Tooltip/utils.ts +21 -0
- package/components/TouchableRipple/TouchableRipple.native.tsx +105 -0
- package/components/TouchableRipple/TouchableRipple.tsx +286 -0
- package/components/TouchableRipple/index.tsx +14 -0
- package/components/TouchableRipple/utils.ts +15 -0
- package/components/VerticalDivider/VerticalDivider.tsx +99 -0
- package/components/VerticalDivider/index.tsx +13 -0
- package/context-bridge/index.tsx +87 -0
- package/core/componentsRegistry.ts +164 -0
- package/core/index.tsx +2 -0
- package/fast-context/index.tsx +190 -0
- package/hocs/index.tsx +5 -0
- package/hocs/typedMemo.tsx +5 -0
- package/hocs/withKeyboardAccessibility.tsx +231 -0
- package/hocs/withPortal.tsx +16 -0
- package/hooks/createPsuedoHook.tsx +50 -0
- package/hooks/index.tsx +29 -0
- package/hooks/useActionState.native.tsx +22 -0
- package/hooks/useActionState.tsx +34 -0
- package/hooks/useActive.tsx +5 -0
- package/hooks/useBreakpoints.tsx +7 -0
- package/hooks/useColorMode.tsx +17 -0
- package/hooks/useContrastColor.ts +15 -0
- package/hooks/useControlledValue.tsx +68 -0
- package/hooks/useFilePicker.tsx +48 -0
- package/hooks/useFocus.tsx +5 -0
- package/hooks/useHandleNumberFormat.tsx +106 -0
- package/hooks/useHover.tsx +5 -0
- package/hooks/useKeyboardDismissable.ts +66 -0
- package/hooks/useLatest.tsx +9 -0
- package/hooks/useMediaQuery.tsx +64 -0
- package/hooks/useMergedRefs.ts +14 -0
- package/hooks/usePrevious.ts +13 -0
- package/hooks/useQueryFilter.tsx +35 -0
- package/hooks/useSearchable.tsx +74 -0
- package/hooks/useSubcomponents.tsx +59 -0
- package/hooks/useTheme.ts +3 -0
- package/hooks/useToggle.tsx +24 -0
- package/package.json +114 -0
- package/shortcuts-manager/EventsManager.tsx +121 -0
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.native.tsx +9 -0
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +58 -0
- package/shortcuts-manager/ShortcutsManager/index.tsx +2 -0
- package/shortcuts-manager/ShortcutsManager/utils.tsx +30 -0
- package/shortcuts-manager/index.tsx +6 -0
- package/shortcuts-manager/types.ts +24 -0
- package/shortcuts-manager/useIsKeyPressed/index.tsx +1 -0
- package/shortcuts-manager/useIsKeyPressed/useIsKeyPress.tsx +9 -0
- package/shortcuts-manager/useSetScopes/index.tsx +1 -0
- package/shortcuts-manager/useSetScopes/useSetScopes.native.tsx +9 -0
- package/shortcuts-manager/useSetScopes/useSetScopes.tsx +25 -0
- package/shortcuts-manager/useShortcut/index.tsx +2 -0
- package/shortcuts-manager/useShortcut/types.ts +3 -0
- package/shortcuts-manager/useShortcut/useShortcut.native.tsx +9 -0
- package/shortcuts-manager/useShortcut/useShortcut.tsx +61 -0
- package/shortcuts-manager/utils.ts +105 -0
- package/styles/index.ts +4 -0
- package/styles/overlay.ts +69 -0
- package/styles/shadow.ts +21 -0
- package/styles/themes/DarkTheme.tsx +98 -0
- package/styles/themes/LightTheme.tsx +212 -0
- package/styles/themes/tokens.ts +248 -0
- package/styles/utils.ts +11 -0
- package/types/index.ts +129 -0
- package/types/theme.ts +159 -0
- package/utils/DocumentPicker/documentPicker.native.ts +10 -0
- package/utils/DocumentPicker/documentPicker.ts +76 -0
- package/utils/DocumentPicker/index.ts +2 -0
- package/utils/DocumentPicker/types.ts +28 -0
- package/utils/addEventListener.tsx +51 -0
- package/utils/backgroundContext.ts +9 -0
- package/utils/color.ts +22 -0
- package/utils/compare/index.ts +54 -0
- package/utils/composeEventHandlers.ts +9 -0
- package/utils/createNumberMask/createNumberMask.ts +98 -0
- package/utils/createNumberMask/index.ts +5 -0
- package/utils/createSyntheticEvent.ts +31 -0
- package/utils/date-fns.ts +7 -0
- package/utils/dateTimePicker.ts +5 -0
- package/utils/escapeRegex.ts +9 -0
- package/utils/extractTextStyles.ts +52 -0
- package/utils/formatNumberWithMask/formatNumberWithMask.ts +26 -0
- package/utils/formatNumberWithMask/formatWithMask.ts +119 -0
- package/utils/formatNumberWithMask/index.ts +6 -0
- package/utils/getCursorStyle/getCursorStyle.native.ts +1 -0
- package/utils/getCursorStyle/getCursorStyle.ts +1 -0
- package/utils/getCursorStyle/index.ts +1 -0
- package/utils/getOS/getOS.native.ts +7 -0
- package/utils/getOS/getOS.ts +24 -0
- package/utils/getOS/index.ts +1 -0
- package/utils/getyearRange.ts +5 -0
- package/utils/index.ts +20 -0
- package/utils/lodash.ts +50 -0
- package/utils/mergeRefs.ts +13 -0
- package/utils/normalizeBorderRadiuses.ts +24 -0
- package/utils/normalizeSpacings.ts +110 -0
- package/utils/normalizeToNumberString/index.ts +4 -0
- package/utils/normalizeToNumberString/normalizeToNumberString.ts +48 -0
- package/utils/repository.ts +103 -0
- package/utils/resolveColorMode.ts +9 -0
- package/utils/resolveStateVariant.ts +26 -0
- package/utils/tokenStylesParser.ts +7 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { forwardRef, memo, type ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import useFilePicker from '../../hooks/useFilePicker';
|
|
4
|
+
import type { DocumentPickerOptions, DocumentResult } from '../../utils/DocumentPicker';
|
|
5
|
+
import { ActivityIndicator } from '../ActivityIndicator';
|
|
6
|
+
import { IconButton } from '../IconButton';
|
|
7
|
+
import { TextInput, type TextInputProps } from '../TextInput';
|
|
8
|
+
|
|
9
|
+
export type OmitProp =
|
|
10
|
+
| 'editable'
|
|
11
|
+
| 'multiline'
|
|
12
|
+
| 'onChangeText'
|
|
13
|
+
| 'keyboardType'
|
|
14
|
+
| 'defaultValue'
|
|
15
|
+
| 'value'
|
|
16
|
+
| 'left'
|
|
17
|
+
| 'right';
|
|
18
|
+
|
|
19
|
+
export type Props = Omit<TextInputProps, OmitProp> &
|
|
20
|
+
DocumentPickerOptions & {
|
|
21
|
+
/**
|
|
22
|
+
* Allows multiple files to be selected from the system UI.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
multiple?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Displays the Spinner on the right side in place of the default upload icon
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
loading?: boolean;
|
|
31
|
+
left?: ReactNode;
|
|
32
|
+
right?: ReactNode;
|
|
33
|
+
/**
|
|
34
|
+
* To Control the value
|
|
35
|
+
*/
|
|
36
|
+
value?: DocumentResult | DocumentResult[];
|
|
37
|
+
/**
|
|
38
|
+
* The Callback function to return the selected files as an array or object
|
|
39
|
+
*/
|
|
40
|
+
onChange?: (result: DocumentResult | DocumentResult[]) => any;
|
|
41
|
+
/**
|
|
42
|
+
* To replace the default progress indicator
|
|
43
|
+
*/
|
|
44
|
+
progressIndicator?: ReactNode;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const FilePicker = (
|
|
48
|
+
{
|
|
49
|
+
loading,
|
|
50
|
+
right: rightProp,
|
|
51
|
+
progressIndicator,
|
|
52
|
+
type,
|
|
53
|
+
multiple,
|
|
54
|
+
transitionStyle,
|
|
55
|
+
mode,
|
|
56
|
+
presentationStyle,
|
|
57
|
+
value,
|
|
58
|
+
onChange = () => {},
|
|
59
|
+
onCancel,
|
|
60
|
+
onError,
|
|
61
|
+
...rest
|
|
62
|
+
}: Props,
|
|
63
|
+
ref: any,
|
|
64
|
+
) => {
|
|
65
|
+
const [displayText, setDisplayText] = useState('');
|
|
66
|
+
|
|
67
|
+
const { openFilePicker } = useFilePicker({
|
|
68
|
+
type,
|
|
69
|
+
mode,
|
|
70
|
+
multiple,
|
|
71
|
+
transitionStyle,
|
|
72
|
+
presentationStyle,
|
|
73
|
+
onCancel,
|
|
74
|
+
onError,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const onSetInputValue = useCallback(
|
|
78
|
+
(response: DocumentResult | DocumentResult[] | undefined) => {
|
|
79
|
+
if (Array.isArray(response)) {
|
|
80
|
+
if (response.length > 1) {
|
|
81
|
+
setDisplayText(`${response.length} file${response.length > 1 ? 's' : ''}`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setDisplayText(response[0].name || '');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
setDisplayText(response?.name || '');
|
|
90
|
+
},
|
|
91
|
+
[],
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const onPress = useCallback(() => {
|
|
95
|
+
openFilePicker(response => {
|
|
96
|
+
onSetInputValue(response);
|
|
97
|
+
|
|
98
|
+
onChange?.(response);
|
|
99
|
+
});
|
|
100
|
+
}, [onChange, onSetInputValue, openFilePicker]);
|
|
101
|
+
|
|
102
|
+
const rightElement = useMemo(() => {
|
|
103
|
+
if (!loading) {
|
|
104
|
+
return (
|
|
105
|
+
<>
|
|
106
|
+
{rightProp || (
|
|
107
|
+
<IconButton type="material-community" name="upload" onPress={onPress} />
|
|
108
|
+
)}
|
|
109
|
+
</>
|
|
110
|
+
);
|
|
111
|
+
} else {
|
|
112
|
+
return <>{progressIndicator || <ActivityIndicator />}</>;
|
|
113
|
+
}
|
|
114
|
+
}, [loading, onPress, progressIndicator, rightProp]);
|
|
115
|
+
|
|
116
|
+
// if the value changes, we only want file name or the length of the array to display the text
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
onSetInputValue(value);
|
|
119
|
+
}, [onSetInputValue, value]);
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<TextInput
|
|
123
|
+
label="Choose file"
|
|
124
|
+
{...rest}
|
|
125
|
+
value={displayText}
|
|
126
|
+
editable={false}
|
|
127
|
+
right={rightElement}
|
|
128
|
+
ref={ref}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export default memo(forwardRef(FilePicker));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
|
|
2
|
+
import FilePickerDefault from './FilePicker';
|
|
3
|
+
|
|
4
|
+
registerMoleculesComponents({
|
|
5
|
+
FilePicker: FilePickerDefault,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const FilePicker = getRegisteredComponentWithFallback('FilePicker', FilePickerDefault);
|
|
9
|
+
|
|
10
|
+
export type { Props as FilePickerProps } from './FilePicker';
|
|
11
|
+
export { defaultStyles } from './utils';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
+
|
|
3
|
+
import { getRegisteredMoleculesComponentStyles, registerComponentsStyles } from '../../core';
|
|
4
|
+
|
|
5
|
+
const filePickerStylesDefault = StyleSheet.create({
|
|
6
|
+
root: {},
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
registerComponentsStyles({
|
|
10
|
+
FilePicker: filePickerStylesDefault,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const defaultStyles = getRegisteredMoleculesComponentStyles('FilePicker');
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { memo, type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import type { LayoutChangeEvent, StyleProp, TextProps, TextStyle } from 'react-native';
|
|
3
|
+
import { Animated } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import { styles } from './utils';
|
|
6
|
+
|
|
7
|
+
export type Props = TextProps & {
|
|
8
|
+
/**
|
|
9
|
+
* Type of the helper text.
|
|
10
|
+
*/
|
|
11
|
+
variant?: 'error' | 'info';
|
|
12
|
+
/**
|
|
13
|
+
* Whether to display the helper text.
|
|
14
|
+
*/
|
|
15
|
+
visible?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Text content of the HelperText.
|
|
18
|
+
*/
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
style?: StyleProp<TextStyle>;
|
|
21
|
+
/**
|
|
22
|
+
* TestID used for testing purposes
|
|
23
|
+
*/
|
|
24
|
+
testID?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Helper text is used in conjuction with input elements to provide additional hints for the user.
|
|
29
|
+
*
|
|
30
|
+
* <div class="screenshots">
|
|
31
|
+
* <img class="small" src="screenshots/helper-text.gif" />
|
|
32
|
+
* </div>
|
|
33
|
+
*
|
|
34
|
+
* ## Usage
|
|
35
|
+
* ```js
|
|
36
|
+
* import * as React from 'react';
|
|
37
|
+
* import { View } from 'react-native';
|
|
38
|
+
* import { HelperText, TextInput } from 'react-native-paper';
|
|
39
|
+
*
|
|
40
|
+
* const MyComponent = () => {
|
|
41
|
+
* const [text, setText] = React.useState('');
|
|
42
|
+
*
|
|
43
|
+
* const onChangeText = text => setText(text);
|
|
44
|
+
*
|
|
45
|
+
* const hasErrors = () => {
|
|
46
|
+
* return !text.includes('@');
|
|
47
|
+
* };
|
|
48
|
+
*
|
|
49
|
+
* return (
|
|
50
|
+
* <View>
|
|
51
|
+
* <TextInput label="Email" value={text} onChangeText={onChangeText} />
|
|
52
|
+
* <HelperText variant="error" visible={hasErrors()}>
|
|
53
|
+
* Email address is invalid!
|
|
54
|
+
* </HelperText>
|
|
55
|
+
* </View>
|
|
56
|
+
* );
|
|
57
|
+
* };
|
|
58
|
+
*
|
|
59
|
+
* export default MyComponent;
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
const HelperText = ({
|
|
63
|
+
style: styleProp,
|
|
64
|
+
variant = 'info',
|
|
65
|
+
visible = true,
|
|
66
|
+
onLayout,
|
|
67
|
+
maxFontSizeMultiplier = 1.5,
|
|
68
|
+
...rest
|
|
69
|
+
}: Props) => {
|
|
70
|
+
styles.useVariants({
|
|
71
|
+
variant,
|
|
72
|
+
});
|
|
73
|
+
const { current: shown } = useRef<Animated.Value>(new Animated.Value(visible ? 1 : 0));
|
|
74
|
+
|
|
75
|
+
const [textHeight, setTextHeight] = useState(0);
|
|
76
|
+
|
|
77
|
+
const { textStyle } = useMemo(() => {
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
textStyle: [
|
|
82
|
+
styles.root,
|
|
83
|
+
{
|
|
84
|
+
opacity: shown,
|
|
85
|
+
transform:
|
|
86
|
+
visible && variant === 'error'
|
|
87
|
+
? [
|
|
88
|
+
{
|
|
89
|
+
translateY: shown.interpolate({
|
|
90
|
+
inputRange: [0, 1],
|
|
91
|
+
outputRange: [-textHeight / 2, 0],
|
|
92
|
+
}),
|
|
93
|
+
},
|
|
94
|
+
]
|
|
95
|
+
: [],
|
|
96
|
+
},
|
|
97
|
+
styleProp,
|
|
98
|
+
],
|
|
99
|
+
};
|
|
100
|
+
}, [shown, styleProp, textHeight, variant, visible]);
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (visible) {
|
|
104
|
+
// show text
|
|
105
|
+
Animated.timing(shown, {
|
|
106
|
+
toValue: 1,
|
|
107
|
+
duration: 150,
|
|
108
|
+
useNativeDriver: true,
|
|
109
|
+
}).start();
|
|
110
|
+
} else {
|
|
111
|
+
// hide text
|
|
112
|
+
Animated.timing(shown, {
|
|
113
|
+
toValue: 0,
|
|
114
|
+
duration: 180,
|
|
115
|
+
useNativeDriver: true,
|
|
116
|
+
}).start();
|
|
117
|
+
}
|
|
118
|
+
}, [visible, shown]);
|
|
119
|
+
|
|
120
|
+
const handleTextLayout = useCallback(
|
|
121
|
+
(e: LayoutChangeEvent) => {
|
|
122
|
+
onLayout?.(e);
|
|
123
|
+
setTextHeight(e.nativeEvent.layout.height);
|
|
124
|
+
},
|
|
125
|
+
[onLayout],
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<Animated.Text
|
|
130
|
+
onLayout={handleTextLayout}
|
|
131
|
+
style={textStyle}
|
|
132
|
+
maxFontSizeMultiplier={maxFontSizeMultiplier}
|
|
133
|
+
{...rest}>
|
|
134
|
+
{rest.children}
|
|
135
|
+
</Animated.Text>
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export default memo(HelperText);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
|
|
2
|
+
import HelperTextDefault from './HelperText';
|
|
3
|
+
|
|
4
|
+
registerMoleculesComponents({
|
|
5
|
+
HelperText: HelperTextDefault,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const HelperText = getRegisteredComponentWithFallback('HelperText', HelperTextDefault);
|
|
9
|
+
|
|
10
|
+
export { type Props as HelperTextProps } from './HelperText';
|
|
11
|
+
export { helperTextStylesDefault } from './utils';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
+
|
|
3
|
+
import { getRegisteredMoleculesComponentStyles, registerComponentsStyles } from '../../core';
|
|
4
|
+
|
|
5
|
+
export const helperTextStylesDefault = StyleSheet.create(theme => ({
|
|
6
|
+
root: {
|
|
7
|
+
fontSize: theme.typescale.bodySmall.fontSize,
|
|
8
|
+
paddingVertical: theme.spacings['1'],
|
|
9
|
+
paddingHorizontal: theme.spacings['4'],
|
|
10
|
+
|
|
11
|
+
variants: {
|
|
12
|
+
variant: {
|
|
13
|
+
error: {
|
|
14
|
+
color: theme.colors.error,
|
|
15
|
+
},
|
|
16
|
+
info: {
|
|
17
|
+
color: theme.colors.onSurfaceVariant,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
registerComponentsStyles({
|
|
25
|
+
HelperText: helperTextStylesDefault,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const styles =
|
|
29
|
+
getRegisteredMoleculesComponentStyles('HelperText') || helperTextStylesDefault;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import { type StyleProp, View, type ViewProps, type ViewStyle } from 'react-native';
|
|
3
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
4
|
+
|
|
5
|
+
import { getRegisteredMoleculesComponentStyles, registerComponentStyles } from '../../core';
|
|
6
|
+
|
|
7
|
+
export type Props = Omit<ViewProps, 'children'> & {
|
|
8
|
+
/**
|
|
9
|
+
* left inset of the divider.
|
|
10
|
+
*/
|
|
11
|
+
leftInset?: number;
|
|
12
|
+
/**
|
|
13
|
+
* right inset of the divider.
|
|
14
|
+
*/
|
|
15
|
+
rightInset?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Whether divider should be bolded.
|
|
18
|
+
*/
|
|
19
|
+
bold?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Vertical spacing of the Divider
|
|
22
|
+
*/
|
|
23
|
+
spacing?: number;
|
|
24
|
+
style?: StyleProp<ViewStyle>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A divider is a thin, lightweight separator that groups content in lists and page layouts.
|
|
29
|
+
*
|
|
30
|
+
* <div class="screenshots">
|
|
31
|
+
* <figure>
|
|
32
|
+
* <img class="medium" src="screenshots/divider.png" />
|
|
33
|
+
* </figure>
|
|
34
|
+
* </div>
|
|
35
|
+
*
|
|
36
|
+
* ## Usage
|
|
37
|
+
* ```js
|
|
38
|
+
* import * as React from 'react';
|
|
39
|
+
* import { View } from 'react-native';
|
|
40
|
+
* import { Divider, Text } from 'react-native-paper';
|
|
41
|
+
*
|
|
42
|
+
* const MyComponent = () => (
|
|
43
|
+
* <View>
|
|
44
|
+
* <Text>Lemon</Text>
|
|
45
|
+
* <Divider />
|
|
46
|
+
* <Text>Mango</Text>
|
|
47
|
+
* <Divider />
|
|
48
|
+
* </View>
|
|
49
|
+
* );
|
|
50
|
+
*
|
|
51
|
+
* export default MyComponent;
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
const HorizontalDivider = ({
|
|
56
|
+
leftInset = 0,
|
|
57
|
+
rightInset = 0,
|
|
58
|
+
style,
|
|
59
|
+
bold = false,
|
|
60
|
+
spacing = 0,
|
|
61
|
+
...rest
|
|
62
|
+
}: Props) => {
|
|
63
|
+
horizontalDividerStyles.useVariants({
|
|
64
|
+
isBold: bold,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<View
|
|
69
|
+
{...rest}
|
|
70
|
+
style={
|
|
71
|
+
[
|
|
72
|
+
horizontalDividerStyles.root,
|
|
73
|
+
leftInset && { marginLeft: leftInset },
|
|
74
|
+
rightInset && { marginRight: rightInset },
|
|
75
|
+
spacing && { marginVertical: spacing },
|
|
76
|
+
style,
|
|
77
|
+
] as StyleProp<ViewStyle>
|
|
78
|
+
}
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const horizontalDividerStylesDefault = StyleSheet.create(theme => ({
|
|
84
|
+
root: {
|
|
85
|
+
height: StyleSheet.hairlineWidth,
|
|
86
|
+
background: theme.colors.outlineVariant,
|
|
87
|
+
|
|
88
|
+
variants: {
|
|
89
|
+
isBold: {
|
|
90
|
+
true: {
|
|
91
|
+
height: 1,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
registerComponentStyles('HorizontalDivider', horizontalDividerStylesDefault);
|
|
99
|
+
export const horizontalDividerStyles = getRegisteredMoleculesComponentStyles('HorizontalDivider');
|
|
100
|
+
|
|
101
|
+
export default memo(HorizontalDivider);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
|
|
2
|
+
import HorizontalDividerDefault from './HorizontalDivider';
|
|
3
|
+
|
|
4
|
+
registerMoleculesComponents({
|
|
5
|
+
HorizontalDivider: HorizontalDividerDefault,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const HorizontalDivider = getRegisteredComponentWithFallback(
|
|
9
|
+
'HorizontalDivider',
|
|
10
|
+
HorizontalDividerDefault,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export { type Props as HorizontalDividerProps, horizontalDividerStyles } from './HorizontalDivider';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { Animated, StyleSheet, View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import Icon, { styles as iconStyles } from './Icon';
|
|
5
|
+
import type { IconProps } from './types';
|
|
6
|
+
|
|
7
|
+
type Props = IconProps;
|
|
8
|
+
|
|
9
|
+
const CrossFadeIcon = ({ color, size, name, style, ...rest }: Omit<Props, 'ref'>) => {
|
|
10
|
+
// const { animationScale: scale } = useComponentStyles('Icon', style);
|
|
11
|
+
const { animationScale: scale } = iconStyles.root;
|
|
12
|
+
const [currentIcon, setCurrentIcon] = useState<string>(name);
|
|
13
|
+
const [previousIcon, setPreviousIcon] = useState<string | null>(null);
|
|
14
|
+
const { current: fade } = useRef<Animated.Value>(new Animated.Value(1));
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (currentIcon !== name) {
|
|
18
|
+
setPreviousIcon(() => currentIcon);
|
|
19
|
+
setCurrentIcon(() => name);
|
|
20
|
+
}
|
|
21
|
+
}, [currentIcon, name]);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (previousIcon && previousIcon !== currentIcon) {
|
|
25
|
+
fade.setValue(1);
|
|
26
|
+
|
|
27
|
+
Animated.timing(fade, {
|
|
28
|
+
duration: scale * 200,
|
|
29
|
+
toValue: 0,
|
|
30
|
+
useNativeDriver: true,
|
|
31
|
+
}).start();
|
|
32
|
+
}
|
|
33
|
+
}, [currentIcon, previousIcon, fade, scale]);
|
|
34
|
+
|
|
35
|
+
const opacityPrev = fade;
|
|
36
|
+
const opacityNext = previousIcon
|
|
37
|
+
? fade.interpolate({
|
|
38
|
+
inputRange: [0, 1],
|
|
39
|
+
outputRange: [1, 0],
|
|
40
|
+
})
|
|
41
|
+
: 1;
|
|
42
|
+
|
|
43
|
+
const rotatePrev = fade.interpolate({
|
|
44
|
+
inputRange: [0, 1],
|
|
45
|
+
outputRange: ['-90deg', '0deg'],
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const rotateNext = previousIcon
|
|
49
|
+
? fade.interpolate({
|
|
50
|
+
inputRange: [0, 1],
|
|
51
|
+
outputRange: ['0deg', '-180deg'],
|
|
52
|
+
})
|
|
53
|
+
: '0deg';
|
|
54
|
+
|
|
55
|
+
const containerStyles = useMemo(
|
|
56
|
+
() => [
|
|
57
|
+
styles.content,
|
|
58
|
+
style,
|
|
59
|
+
{
|
|
60
|
+
height: size,
|
|
61
|
+
width: size,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
[size, style],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const prevIconStyles = useMemo(
|
|
68
|
+
() => [
|
|
69
|
+
styles.icon,
|
|
70
|
+
{
|
|
71
|
+
opacity: opacityPrev,
|
|
72
|
+
transform: [{ rotate: rotatePrev }],
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
[opacityPrev, rotatePrev],
|
|
76
|
+
);
|
|
77
|
+
const nextIconStyles = useMemo(
|
|
78
|
+
() => [
|
|
79
|
+
styles.icon,
|
|
80
|
+
{
|
|
81
|
+
opacity: opacityNext,
|
|
82
|
+
transform: [{ rotate: rotateNext }],
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
[opacityNext, rotateNext],
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<View style={containerStyles}>
|
|
90
|
+
{previousIcon ? (
|
|
91
|
+
<Animated.View style={prevIconStyles}>
|
|
92
|
+
<Icon name={previousIcon} size={size} color={color} {...rest} />
|
|
93
|
+
</Animated.View>
|
|
94
|
+
) : null}
|
|
95
|
+
<Animated.View style={nextIconStyles}>
|
|
96
|
+
<Icon name={currentIcon} size={size} color={color} />
|
|
97
|
+
</Animated.View>
|
|
98
|
+
</View>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const styles = StyleSheet.create({
|
|
103
|
+
content: {
|
|
104
|
+
alignItems: 'center',
|
|
105
|
+
justifyContent: 'center',
|
|
106
|
+
},
|
|
107
|
+
icon: {
|
|
108
|
+
position: 'absolute',
|
|
109
|
+
top: 0,
|
|
110
|
+
left: 0,
|
|
111
|
+
right: 0,
|
|
112
|
+
bottom: 0,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export default CrossFadeIcon;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { forwardRef, memo, useMemo } from 'react';
|
|
2
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
3
|
+
import type { Mappings } from 'react-native-unistyles/lib/typescript/src/core/withUnistyles/types';
|
|
4
|
+
|
|
5
|
+
import { getRegisteredMoleculesComponentStyles, registerComponentStyles } from '../../core';
|
|
6
|
+
import { tokenStylesParser } from '../../utils/tokenStylesParser';
|
|
7
|
+
import iconFactory from './iconFactory';
|
|
8
|
+
import type { IconProps } from './types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Neutral component. Doesn't have platform specific styles
|
|
12
|
+
*/
|
|
13
|
+
const Icon = (
|
|
14
|
+
{
|
|
15
|
+
type = 'material-community',
|
|
16
|
+
style,
|
|
17
|
+
color,
|
|
18
|
+
...rest
|
|
19
|
+
}: IconProps & { uniProps?: Mappings<any> },
|
|
20
|
+
ref: any,
|
|
21
|
+
) => {
|
|
22
|
+
const IconComponent = iconFactory(type);
|
|
23
|
+
const componentStyles = useMemo(
|
|
24
|
+
() => [styles.root, style, tokenStylesParser.getColor(color as string)],
|
|
25
|
+
[style, color],
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return <IconComponent ref={ref} style={componentStyles} {...rest} />;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const iconStylesDefault = StyleSheet.create(theme => ({
|
|
32
|
+
root: {
|
|
33
|
+
color: theme.colors.onSurface,
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
registerComponentStyles('Icon', iconStylesDefault);
|
|
38
|
+
|
|
39
|
+
export const styles = getRegisteredMoleculesComponentStyles('Icon');
|
|
40
|
+
|
|
41
|
+
export default memo(forwardRef(Icon));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// import { textFactory } from '../Text/textFactory';
|
|
2
|
+
import { memoize } from '../../utils/lodash';
|
|
3
|
+
import { IconPacks, type IconType } from './types';
|
|
4
|
+
|
|
5
|
+
const customIcons: any = {};
|
|
6
|
+
|
|
7
|
+
export const registerCustomIconType = (id: string, customIcon: any) => {
|
|
8
|
+
customIcons[id] = customIcon;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default memoize((type: IconType) => {
|
|
12
|
+
switch (type) {
|
|
13
|
+
case IconPacks.MaterialCommunity:
|
|
14
|
+
return require('@react-native-vector-icons/material-design-icons').default;
|
|
15
|
+
case IconPacks.Feather:
|
|
16
|
+
return require('@react-native-vector-icons/feather').default;
|
|
17
|
+
default:
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(customIcons, type)) {
|
|
19
|
+
return customIcons[type];
|
|
20
|
+
}
|
|
21
|
+
return require('@react-native-vector-icons/material-design-icons').default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
|
|
2
|
+
import IconDefault from './Icon';
|
|
3
|
+
|
|
4
|
+
registerMoleculesComponents({
|
|
5
|
+
Icon: IconDefault,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const Icon = getRegisteredComponentWithFallback('Icon', IconDefault);
|
|
9
|
+
|
|
10
|
+
export { registerCustomIconType } from './iconFactory';
|
|
11
|
+
export type { IconPacks, IconProps, IconType } from './types';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ColorValue, TextProps } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export enum IconPacks {
|
|
4
|
+
MaterialCommunity = 'material-community',
|
|
5
|
+
Feather = 'feather',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface VectorIconProps extends TextProps {
|
|
9
|
+
/**
|
|
10
|
+
* Size of the icon, can also be passed as fontSize in the style object.
|
|
11
|
+
*
|
|
12
|
+
* @default 12
|
|
13
|
+
*/
|
|
14
|
+
size?: number | undefined;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Name of the icon to show
|
|
18
|
+
*
|
|
19
|
+
* See Icon Explorer app
|
|
20
|
+
* {@link https://github.com/oblador/react-native-vector-icons/tree/master/Examples/IconExplorer}
|
|
21
|
+
*/
|
|
22
|
+
name: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Color of the icon
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
color?: ColorValue | number | undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type IconType = `${IconPacks}`; // in TS 4.1+, we can do this to make enum values as a union type
|
|
32
|
+
|
|
33
|
+
export type IconProps = VectorIconProps & {
|
|
34
|
+
type?: IconType;
|
|
35
|
+
};
|