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,14 @@
|
|
|
1
|
+
export { default as Select } from './Select';
|
|
2
|
+
export type {
|
|
3
|
+
DefaultItemT,
|
|
4
|
+
SelectContentProps,
|
|
5
|
+
SelectContextValue,
|
|
6
|
+
SelectDropdownContextValue,
|
|
7
|
+
SelectDropdownProps,
|
|
8
|
+
SelectGroupProps,
|
|
9
|
+
SelectOptionProps,
|
|
10
|
+
SelectProviderProps,
|
|
11
|
+
SelectSearchInputProps,
|
|
12
|
+
SelectTriggerProps,
|
|
13
|
+
SelectValueProps,
|
|
14
|
+
} from './types';
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
GestureResponderEvent,
|
|
4
|
+
ScrollViewProps,
|
|
5
|
+
TextInputProps,
|
|
6
|
+
ViewProps,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
|
|
9
|
+
import type { PopoverProps } from '../Popover';
|
|
10
|
+
|
|
11
|
+
export type DefaultItemT = {
|
|
12
|
+
id: string | number;
|
|
13
|
+
label?: string;
|
|
14
|
+
selectable?: boolean;
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// SelectContext types
|
|
19
|
+
export type SelectContextValue<Option extends DefaultItemT = DefaultItemT> = {
|
|
20
|
+
value: Option | Option[] | null;
|
|
21
|
+
multiple: boolean;
|
|
22
|
+
onAdd: (item: Option) => void;
|
|
23
|
+
onRemove: (item: Option) => void;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
error?: boolean;
|
|
26
|
+
labelKey?: string;
|
|
27
|
+
options: Option[];
|
|
28
|
+
searchQuery: string;
|
|
29
|
+
setSearchQuery: (query: string) => void;
|
|
30
|
+
filteredOptions: Option[];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// SelectDropdownContext types
|
|
34
|
+
export type SelectDropdownContextValue = {
|
|
35
|
+
isOpen: boolean;
|
|
36
|
+
onClose: () => void;
|
|
37
|
+
onOpen: () => void;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// SelectProvider props
|
|
41
|
+
export type SelectProviderProps<Option extends DefaultItemT = DefaultItemT> = {
|
|
42
|
+
children: ReactNode;
|
|
43
|
+
value?: Option['id'] | Option['id'][] | null;
|
|
44
|
+
defaultValue?: Option['id'] | Option['id'][] | null;
|
|
45
|
+
onChange?: (
|
|
46
|
+
value: Option['id'] | Option['id'][] | null,
|
|
47
|
+
item: Option,
|
|
48
|
+
event?: GestureResponderEvent,
|
|
49
|
+
) => void;
|
|
50
|
+
multiple?: boolean;
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
error?: boolean;
|
|
53
|
+
labelKey?: string;
|
|
54
|
+
options: Option[];
|
|
55
|
+
searchKey?: string;
|
|
56
|
+
onSearchChange?: (query: string) => void;
|
|
57
|
+
hideSelected?: boolean;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Select.Trigger props
|
|
61
|
+
export type SelectTriggerProps = ViewProps & {
|
|
62
|
+
children?: ReactNode;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Select.Value props
|
|
66
|
+
export type SelectValueProps = ViewProps & {
|
|
67
|
+
placeholder?: string;
|
|
68
|
+
renderValue?: (value: DefaultItemT | DefaultItemT[] | null) => ReactNode;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Select.Dropdown props
|
|
72
|
+
export type SelectDropdownProps = Omit<
|
|
73
|
+
PopoverProps,
|
|
74
|
+
'isOpen' | 'onClose' | 'triggerRef' | 'children'
|
|
75
|
+
> & {
|
|
76
|
+
children: ReactNode;
|
|
77
|
+
WrapperComponent?: ComponentType<any>;
|
|
78
|
+
wrapperComponentProps?: Record<string, any>;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Select.Content props
|
|
82
|
+
export type SelectContentProps<Option extends DefaultItemT = DefaultItemT> = Omit<
|
|
83
|
+
ScrollViewProps,
|
|
84
|
+
'children'
|
|
85
|
+
> & {
|
|
86
|
+
children: (item: Option, isSelected: boolean) => ReactNode;
|
|
87
|
+
ContainerComponent?: ComponentType<any>;
|
|
88
|
+
emptyState?: ReactNode;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Select.Group props
|
|
92
|
+
export type SelectGroupProps = ViewProps & {
|
|
93
|
+
children: ReactNode;
|
|
94
|
+
label?: string;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Select.Option props
|
|
98
|
+
export type SelectOptionProps<Option extends DefaultItemT = DefaultItemT> = ViewProps & {
|
|
99
|
+
/**
|
|
100
|
+
* Unique id for the option
|
|
101
|
+
*/
|
|
102
|
+
value: Option['id'];
|
|
103
|
+
children?: ReactNode;
|
|
104
|
+
renderItem?: (item: Option, isSelected: boolean) => ReactNode;
|
|
105
|
+
onPress?: (item: Option, event: GestureResponderEvent) => void;
|
|
106
|
+
/**
|
|
107
|
+
* When true, the option can't be selected (similar to HTML option disabled)
|
|
108
|
+
*/
|
|
109
|
+
disabled?: boolean;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Select.SearchInput props
|
|
113
|
+
export type SelectSearchInputProps = TextInputProps & {
|
|
114
|
+
onQueryChange?: (query: string) => void;
|
|
115
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { forwardRef, memo } from 'react';
|
|
2
|
+
import { View, type ViewProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { stateLayerStyles } from './utils';
|
|
5
|
+
|
|
6
|
+
export type Props = ViewProps;
|
|
7
|
+
|
|
8
|
+
const StateLayer = ({ style, ...rest }: Props, ref: any) => {
|
|
9
|
+
return <View {...rest} style={[stateLayerStyles.root, style]} ref={ref} />;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default memo(forwardRef(StateLayer));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
|
|
2
|
+
import StateLayerDefault from './StateLayer';
|
|
3
|
+
|
|
4
|
+
registerMoleculesComponents({
|
|
5
|
+
StateLayer: StateLayerDefault,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const StateLayer = getRegisteredComponentWithFallback('StateLayer', StateLayerDefault);
|
|
9
|
+
|
|
10
|
+
export type { Props as StateLayerProps } from './StateLayer';
|
|
11
|
+
export { stateLayerStyles } from './utils';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
+
|
|
3
|
+
import { getRegisteredMoleculesComponentStyles, registerComponentsStyles } from '../../core';
|
|
4
|
+
|
|
5
|
+
const stateLayerStylesDefault = StyleSheet.create({
|
|
6
|
+
root: {
|
|
7
|
+
...StyleSheet.absoluteFillObject,
|
|
8
|
+
backgroundColor: 'transparent',
|
|
9
|
+
zIndex: -1,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
registerComponentsStyles({
|
|
14
|
+
StateLayer: stateLayerStylesDefault,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const stateLayerStyles = getRegisteredMoleculesComponentStyles('StateLayer');
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { memo, type ReactNode, useContext, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useContrastColor } from '../../hooks/useContrastColor';
|
|
4
|
+
import { BackgroundContext } from '../../utils/backgroundContext';
|
|
5
|
+
|
|
6
|
+
export const BackgroundContextWrapper = memo(
|
|
7
|
+
({ backgroundColor, children }: { backgroundColor: string; children: ReactNode }) => {
|
|
8
|
+
const contrastColor = useContrastColor(backgroundColor, undefined, undefined);
|
|
9
|
+
|
|
10
|
+
const parentContext = useContext(BackgroundContext);
|
|
11
|
+
const isTransparent = backgroundColor === 'transparent';
|
|
12
|
+
|
|
13
|
+
const surfaceContextValue = useMemo(
|
|
14
|
+
() => ({
|
|
15
|
+
backgroundColor,
|
|
16
|
+
color: contrastColor,
|
|
17
|
+
}),
|
|
18
|
+
[backgroundColor, contrastColor],
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<BackgroundContext.Provider value={isTransparent ? parentContext : surfaceContextValue}>
|
|
23
|
+
{children}
|
|
24
|
+
</BackgroundContext.Provider>
|
|
25
|
+
);
|
|
26
|
+
},
|
|
27
|
+
);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { forwardRef, memo, type ReactNode, useMemo } from 'react';
|
|
2
|
+
import { Animated, type StyleProp, View, type ViewProps, type ViewStyle } from 'react-native';
|
|
3
|
+
import { useUnistyles } from 'react-native-unistyles';
|
|
4
|
+
|
|
5
|
+
import { inputRange } from '../../styles/shadow';
|
|
6
|
+
import type { MD3Elevation } from '../../types/theme';
|
|
7
|
+
import { BackgroundContextWrapper } from './BackgroundContextWrapper';
|
|
8
|
+
import { defaultStyles, extractProperties, getElevationAndroid } from './utils';
|
|
9
|
+
|
|
10
|
+
export type Props = ViewProps & {
|
|
11
|
+
/**
|
|
12
|
+
* Content of the `Surface`.
|
|
13
|
+
*/
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
backgroundColor?: string;
|
|
16
|
+
style?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
|
|
17
|
+
elevation?: MD3Elevation;
|
|
18
|
+
/**
|
|
19
|
+
* TestID used for testing purposes
|
|
20
|
+
*/
|
|
21
|
+
testID?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const elevationLevel = [0, 1, 2, 6, 8, 12];
|
|
25
|
+
|
|
26
|
+
const Surface = ({ elevation = 1, style, children, testID, ...props }: Props, ref: any) => {
|
|
27
|
+
const { theme } = useUnistyles();
|
|
28
|
+
|
|
29
|
+
const backgroundColor = (() => {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
return theme.colors.elevation?.[`level${elevation}`];
|
|
32
|
+
})();
|
|
33
|
+
|
|
34
|
+
const { memoizedStyles, surfaceBackground } = useMemo(() => {
|
|
35
|
+
return {
|
|
36
|
+
memoizedStyles: [
|
|
37
|
+
{
|
|
38
|
+
backgroundColor,
|
|
39
|
+
},
|
|
40
|
+
defaultStyles.root,
|
|
41
|
+
style,
|
|
42
|
+
{
|
|
43
|
+
elevation: getElevationAndroid(elevation, inputRange, elevationLevel),
|
|
44
|
+
},
|
|
45
|
+
] as StyleProp<ViewStyle>,
|
|
46
|
+
surfaceBackground: extractProperties(
|
|
47
|
+
[defaultStyles.root as ViewStyle, style],
|
|
48
|
+
['backgroundColor'],
|
|
49
|
+
).backgroundColor,
|
|
50
|
+
};
|
|
51
|
+
}, [backgroundColor, elevation, style]);
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<BackgroundContextWrapper backgroundColor={surfaceBackground}>
|
|
55
|
+
<View ref={ref} {...props} testID={testID} style={memoizedStyles}>
|
|
56
|
+
{children}
|
|
57
|
+
</View>
|
|
58
|
+
</BackgroundContextWrapper>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default memo(forwardRef(Surface));
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { type ComponentPropsWithRef, forwardRef, memo, type ReactNode, useMemo } from 'react';
|
|
2
|
+
import { Animated, type StyleProp, View, type ViewStyle } from 'react-native';
|
|
3
|
+
import { useUnistyles } from 'react-native-unistyles';
|
|
4
|
+
|
|
5
|
+
import type { MD3Elevation } from '../../types/theme';
|
|
6
|
+
import { BackgroundContextWrapper } from './BackgroundContextWrapper';
|
|
7
|
+
import { defaultStyles, extractProperties, getStyleForShadowLayer } from './utils';
|
|
8
|
+
|
|
9
|
+
export type Props = ComponentPropsWithRef<typeof View> & {
|
|
10
|
+
/**
|
|
11
|
+
* Content of the `Surface`.
|
|
12
|
+
*/
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
backgroundColor?: string;
|
|
15
|
+
style?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
|
|
16
|
+
/**
|
|
17
|
+
* @supported Available in v5.x with theme version 3
|
|
18
|
+
* Changes shadows and background on iOS and Android.
|
|
19
|
+
* Used to create UI hierarchy between components.
|
|
20
|
+
*
|
|
21
|
+
* Note: In version 2 the `elevation` prop was accepted via `style` prop i.e. `style={{ elevation: 4 }}`.
|
|
22
|
+
* It's no longer supported with theme version 3 and you should use `elevation` property instead.
|
|
23
|
+
*/
|
|
24
|
+
elevation?: MD3Elevation;
|
|
25
|
+
/**
|
|
26
|
+
* TestID used for testing purposes
|
|
27
|
+
*/
|
|
28
|
+
testID?: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Surface is a basic container that can give depth to an element with elevation shadow.
|
|
33
|
+
* On dark theme with `adaptive` mode, surface is constructed by also placing a semi-transparent white overlay over a component surface.
|
|
34
|
+
* See [Dark Theme](https://callstack.github.io/react-native-paper/theming.html#dark-theme) for more information.
|
|
35
|
+
* Overlay and shadow can be applied by specifying the `elevation` property both on Android and iOS.
|
|
36
|
+
*
|
|
37
|
+
* <div class="screenshots">
|
|
38
|
+
* <figure>
|
|
39
|
+
* <img class="medium" src="screenshots/surface-android.png" />
|
|
40
|
+
* <figcaption>Surface on Android</figcaption>
|
|
41
|
+
* </figure>
|
|
42
|
+
* <figure>
|
|
43
|
+
* <img class="medium" src="screenshots/surface-ios.png" />
|
|
44
|
+
* <figcaption>Surface on iOS</figcaption>
|
|
45
|
+
* </figure>
|
|
46
|
+
* </div>
|
|
47
|
+
*
|
|
48
|
+
* ## Usage
|
|
49
|
+
* ```js
|
|
50
|
+
* import * as React from 'react';
|
|
51
|
+
* import { Surface, Text } from 'react-native-paper';
|
|
52
|
+
* import { StyleSheet } from 'react-native';
|
|
53
|
+
*
|
|
54
|
+
* const MyComponent = () => (
|
|
55
|
+
* <Surface style={styles.surface} elevation={4}>
|
|
56
|
+
* <Text>Surface</Text>
|
|
57
|
+
* </Surface>
|
|
58
|
+
* );
|
|
59
|
+
*
|
|
60
|
+
* export default MyComponent;
|
|
61
|
+
*
|
|
62
|
+
* const styles = StyleSheet.create({
|
|
63
|
+
* surface: {
|
|
64
|
+
* padding: 8,
|
|
65
|
+
* height: 80,
|
|
66
|
+
* width: 80,
|
|
67
|
+
* alignItems: 'center',
|
|
68
|
+
* justifyContent: 'center',
|
|
69
|
+
* },
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
const Surface = ({ elevation = 1, style, children, testID, ...props }: Props, ref: any) => {
|
|
74
|
+
const { theme } = useUnistyles();
|
|
75
|
+
const backgroundColor = (() => {
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
return theme.colors.elevation?.[`level${elevation}`];
|
|
78
|
+
})();
|
|
79
|
+
|
|
80
|
+
const { surfaceBackground, sharedStyle, layer0Style, layer1Style } = useMemo(() => {
|
|
81
|
+
const { position, alignSelf, top, left, right, bottom, borderRadius } = extractProperties(
|
|
82
|
+
[defaultStyles.root as ViewStyle, style],
|
|
83
|
+
['position', 'alignSelf', 'top', 'left', 'right', 'bottom', 'borderRadius'],
|
|
84
|
+
);
|
|
85
|
+
const absoluteStyle = { position, alignSelf, top, right, bottom, left };
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
surfaceBackground: extractProperties(
|
|
89
|
+
[defaultStyles.root as ViewStyle, style],
|
|
90
|
+
['backgroundColor'],
|
|
91
|
+
).backgroundColor,
|
|
92
|
+
sharedStyle: [
|
|
93
|
+
{ backgroundColor, borderRadius },
|
|
94
|
+
defaultStyles.root,
|
|
95
|
+
style,
|
|
96
|
+
{
|
|
97
|
+
position: undefined,
|
|
98
|
+
alignSelf: undefined,
|
|
99
|
+
top: undefined,
|
|
100
|
+
left: undefined,
|
|
101
|
+
right: undefined,
|
|
102
|
+
bottom: undefined,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
layer0Style: [getStyleForShadowLayer(0, elevation), absoluteStyle, { borderRadius }],
|
|
106
|
+
layer1Style: [getStyleForShadowLayer(1, elevation), { borderRadius }],
|
|
107
|
+
};
|
|
108
|
+
}, [backgroundColor, elevation, style]);
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<BackgroundContextWrapper backgroundColor={surfaceBackground}>
|
|
112
|
+
<View ref={ref} style={layer0Style}>
|
|
113
|
+
<View style={layer1Style}>
|
|
114
|
+
<View {...props} testID={testID} style={sharedStyle}>
|
|
115
|
+
{children}
|
|
116
|
+
</View>
|
|
117
|
+
</View>
|
|
118
|
+
</View>
|
|
119
|
+
</BackgroundContextWrapper>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export default memo(forwardRef(Surface));
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { forwardRef, memo, type ReactNode, useMemo } from 'react';
|
|
2
|
+
import { type StyleProp, View, type ViewProps, type ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import shadow from '../../styles/shadow';
|
|
5
|
+
import type { MD3Elevation } from '../../types/theme';
|
|
6
|
+
import { BackgroundContextWrapper } from './BackgroundContextWrapper';
|
|
7
|
+
import { defaultStyles } from './utils';
|
|
8
|
+
|
|
9
|
+
export type Props = ViewProps & {
|
|
10
|
+
/**
|
|
11
|
+
* Content of the `Surface`.
|
|
12
|
+
*/
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
style?: StyleProp<ViewStyle>;
|
|
15
|
+
elevation?: MD3Elevation;
|
|
16
|
+
backgroundColor?: string;
|
|
17
|
+
/**
|
|
18
|
+
* TestID used for testing purposes
|
|
19
|
+
*/
|
|
20
|
+
testID?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// for Web
|
|
24
|
+
const Surface = (
|
|
25
|
+
{ elevation = 1, style, children, testID, backgroundColor, ...props }: Props,
|
|
26
|
+
ref: any,
|
|
27
|
+
) => {
|
|
28
|
+
const { surfaceStyle } = useMemo(() => {
|
|
29
|
+
return {
|
|
30
|
+
surfaceStyle: [
|
|
31
|
+
elevation ? shadow(elevation) : null,
|
|
32
|
+
defaultStyles.root,
|
|
33
|
+
style,
|
|
34
|
+
backgroundColor ? { backgroundColor } : {},
|
|
35
|
+
] as StyleProp<ViewStyle>,
|
|
36
|
+
};
|
|
37
|
+
}, [backgroundColor, elevation, style]);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<BackgroundContextWrapper backgroundColor={backgroundColor!}>
|
|
41
|
+
<View ref={ref} {...props} testID={testID} style={surfaceStyle}>
|
|
42
|
+
{children}
|
|
43
|
+
</View>
|
|
44
|
+
</BackgroundContextWrapper>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default memo(forwardRef(Surface));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
|
|
2
|
+
import SurfaceDefault from './Surface';
|
|
3
|
+
|
|
4
|
+
registerMoleculesComponents({
|
|
5
|
+
Surface: SurfaceDefault,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const Surface = getRegisteredComponentWithFallback('Surface', SurfaceDefault);
|
|
9
|
+
|
|
10
|
+
export * from './BackgroundContextWrapper';
|
|
11
|
+
export type { Props as SurfaceProps } from './Surface';
|
|
12
|
+
export { defaultStyles as surfaceStyles } from './utils';
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Animated } from 'react-native';
|
|
2
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
3
|
+
|
|
4
|
+
import { getRegisteredMoleculesComponentStyles, registerComponentsStyles } from '../../core';
|
|
5
|
+
import { inputRange } from '../../styles/shadow';
|
|
6
|
+
|
|
7
|
+
const defaultStylesDefault = StyleSheet.create(theme => ({
|
|
8
|
+
root: {
|
|
9
|
+
backgroundColor: theme.colors.surface,
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
registerComponentsStyles({
|
|
14
|
+
Surface: defaultStylesDefault,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const defaultStyles = getRegisteredMoleculesComponentStyles('Surface');
|
|
18
|
+
|
|
19
|
+
// TODO - abstract this
|
|
20
|
+
export function extractProperties(
|
|
21
|
+
_objectsArray: Record<string, any>,
|
|
22
|
+
propertiesToExtract: string[],
|
|
23
|
+
) {
|
|
24
|
+
const extracted: Record<string, any> = {};
|
|
25
|
+
|
|
26
|
+
const objectsArray = _objectsArray.flat();
|
|
27
|
+
|
|
28
|
+
for (let i = objectsArray.length - 1; i >= 0; i--) {
|
|
29
|
+
const obj = objectsArray[i];
|
|
30
|
+
|
|
31
|
+
for (const prop of propertiesToExtract) {
|
|
32
|
+
if (!obj) continue;
|
|
33
|
+
if (prop in obj) {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
extracted[prop] = obj[prop];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return extracted;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const _shadowColor = '#000';
|
|
44
|
+
|
|
45
|
+
const iOSShadowOutputRanges = [
|
|
46
|
+
{
|
|
47
|
+
shadowOpacity: 0.15,
|
|
48
|
+
height: [0, 1, 2, 4, 6, 8],
|
|
49
|
+
shadowRadius: [0, 3, 6, 8, 10, 12],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
shadowOpacity: 0.3,
|
|
53
|
+
height: [0, 1, 1, 1, 2, 4],
|
|
54
|
+
shadowRadius: [0, 1, 2, 3, 3, 4],
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
export const getStyleForAnimatedShadowLayer = (
|
|
59
|
+
layer: 0 | 1,
|
|
60
|
+
elevation: Animated.Value,
|
|
61
|
+
shadowColor = _shadowColor,
|
|
62
|
+
) => {
|
|
63
|
+
return {
|
|
64
|
+
shadowColor,
|
|
65
|
+
shadowOpacity: elevation.interpolate({
|
|
66
|
+
inputRange: [0, 1],
|
|
67
|
+
outputRange: [0, iOSShadowOutputRanges[layer].shadowOpacity],
|
|
68
|
+
extrapolate: 'clamp',
|
|
69
|
+
}),
|
|
70
|
+
shadowOffset: {
|
|
71
|
+
width: 0,
|
|
72
|
+
height: elevation.interpolate({
|
|
73
|
+
inputRange,
|
|
74
|
+
outputRange: iOSShadowOutputRanges[layer].height,
|
|
75
|
+
}),
|
|
76
|
+
},
|
|
77
|
+
shadowRadius: elevation.interpolate({
|
|
78
|
+
inputRange,
|
|
79
|
+
outputRange: iOSShadowOutputRanges[layer].shadowRadius,
|
|
80
|
+
}),
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const getStyleForShadowLayer = (
|
|
85
|
+
layer: 0 | 1,
|
|
86
|
+
elevation: number,
|
|
87
|
+
shadowColor = _shadowColor,
|
|
88
|
+
) => {
|
|
89
|
+
return {
|
|
90
|
+
shadowColor,
|
|
91
|
+
shadowOpacity: elevation ? iOSShadowOutputRanges[layer].shadowOpacity : 0,
|
|
92
|
+
shadowOffset: {
|
|
93
|
+
width: 0,
|
|
94
|
+
height: iOSShadowOutputRanges[layer].height[elevation],
|
|
95
|
+
},
|
|
96
|
+
shadowRadius: iOSShadowOutputRanges[layer].shadowRadius[elevation],
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const getElevationAndroid = (
|
|
101
|
+
elevation: number,
|
|
102
|
+
_inputRange: number[],
|
|
103
|
+
elevationLevel: number[],
|
|
104
|
+
) => {
|
|
105
|
+
return elevationLevel[elevation];
|
|
106
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { forwardRef, memo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Switch as NativeSwitch,
|
|
4
|
+
type SwitchProps,
|
|
5
|
+
type TextStyle,
|
|
6
|
+
type ViewStyle,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
|
|
9
|
+
import { useControlledValue } from '../../hooks';
|
|
10
|
+
import type { IconType } from '../Icon';
|
|
11
|
+
|
|
12
|
+
export type Props = SwitchProps & {
|
|
13
|
+
checkedIcon?: string;
|
|
14
|
+
unCheckedIcon?: string;
|
|
15
|
+
size?: number;
|
|
16
|
+
checkedIconType?: IconType;
|
|
17
|
+
uncheckedIconType?: IconType;
|
|
18
|
+
thumbStyle?: ViewStyle;
|
|
19
|
+
thumbContainerStyle?: ViewStyle;
|
|
20
|
+
switchOverlayStyle?: ViewStyle;
|
|
21
|
+
iconStyle?: TextStyle;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const Switch = (
|
|
25
|
+
{
|
|
26
|
+
trackColor,
|
|
27
|
+
thumbColor,
|
|
28
|
+
onValueChange,
|
|
29
|
+
disabled,
|
|
30
|
+
value: valueProp,
|
|
31
|
+
// Accept but ignore these props for API compatibility
|
|
32
|
+
checkedIcon: _checkedIcon,
|
|
33
|
+
unCheckedIcon: _unCheckedIcon,
|
|
34
|
+
size: _size,
|
|
35
|
+
checkedIconType: _checkedIconType,
|
|
36
|
+
uncheckedIconType: _uncheckedIconType,
|
|
37
|
+
thumbStyle: _thumbStyle,
|
|
38
|
+
thumbContainerStyle: _thumbContainerStyle,
|
|
39
|
+
switchOverlayStyle: _switchOverlayStyle,
|
|
40
|
+
iconStyle: _iconStyle,
|
|
41
|
+
style,
|
|
42
|
+
...rest
|
|
43
|
+
}: Props,
|
|
44
|
+
ref: any,
|
|
45
|
+
) => {
|
|
46
|
+
const [value, onChange] = useControlledValue({
|
|
47
|
+
value: valueProp,
|
|
48
|
+
onChange: onValueChange as any,
|
|
49
|
+
defaultValue: !!valueProp,
|
|
50
|
+
disabled,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<NativeSwitch
|
|
55
|
+
ref={ref}
|
|
56
|
+
value={value}
|
|
57
|
+
onValueChange={onChange}
|
|
58
|
+
disabled={disabled}
|
|
59
|
+
trackColor={trackColor}
|
|
60
|
+
thumbColor={thumbColor}
|
|
61
|
+
style={style}
|
|
62
|
+
{...rest}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export default memo(forwardRef(Switch));
|