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,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
cloneElement,
|
|
4
|
+
forwardRef,
|
|
5
|
+
isValidElement,
|
|
6
|
+
type JSXElementConstructor,
|
|
7
|
+
memo,
|
|
8
|
+
type ReactElement,
|
|
9
|
+
useCallback,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
useState,
|
|
13
|
+
} from 'react';
|
|
14
|
+
import { type LayoutChangeEvent, View, type ViewProps, type ViewStyle } from 'react-native';
|
|
15
|
+
|
|
16
|
+
import { useActionState } from '../../hooks';
|
|
17
|
+
import { resolveStateVariant } from '../../utils';
|
|
18
|
+
import { StateLayer } from '../StateLayer';
|
|
19
|
+
import { TouchableRipple, type TouchableRippleProps } from '../TouchableRipple';
|
|
20
|
+
import { tabsItemStyles } from './utils';
|
|
21
|
+
|
|
22
|
+
export type TabItemProps = Omit<TouchableRippleProps, 'children' | 'ref'> & {
|
|
23
|
+
/**
|
|
24
|
+
* name of the tab. This should be unique like a route name
|
|
25
|
+
* */
|
|
26
|
+
name: string;
|
|
27
|
+
/**
|
|
28
|
+
* Allows to define if TabItem is active.
|
|
29
|
+
* */
|
|
30
|
+
active?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* variant according to m3 guidelines
|
|
33
|
+
* */
|
|
34
|
+
variant?: 'primary' | 'secondary';
|
|
35
|
+
|
|
36
|
+
contentsContainerStyle?: ViewStyle;
|
|
37
|
+
contentsContainerProps?: Omit<ViewProps, 'children' | 'style' | 'onLayout'>;
|
|
38
|
+
onLayoutContent?: (e: LayoutChangeEvent) => void;
|
|
39
|
+
accessibilityLabel?: string;
|
|
40
|
+
children: ReactElement<
|
|
41
|
+
{
|
|
42
|
+
active: boolean;
|
|
43
|
+
hovered: boolean;
|
|
44
|
+
variant: 'primary' | 'secondary';
|
|
45
|
+
},
|
|
46
|
+
JSXElementConstructor<{
|
|
47
|
+
active: boolean;
|
|
48
|
+
hovered: boolean;
|
|
49
|
+
variant: 'primary' | 'secondary';
|
|
50
|
+
}>
|
|
51
|
+
>;
|
|
52
|
+
stateLayerProps?: ViewProps;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const TabItem = (
|
|
56
|
+
{
|
|
57
|
+
active = false,
|
|
58
|
+
variant = 'primary',
|
|
59
|
+
style,
|
|
60
|
+
onLayout,
|
|
61
|
+
onLayoutContent,
|
|
62
|
+
contentsContainerStyle: contentsContainerStyleProp,
|
|
63
|
+
contentsContainerProps,
|
|
64
|
+
accessibilityLabel,
|
|
65
|
+
children,
|
|
66
|
+
stateLayerProps,
|
|
67
|
+
...rest
|
|
68
|
+
}: TabItemProps,
|
|
69
|
+
ref: any,
|
|
70
|
+
) => {
|
|
71
|
+
const { hovered, actionsRef } = useActionState({ ref, actionsToListen: ['hover'] });
|
|
72
|
+
const [itemHeight, setItemHeight] = useState(0);
|
|
73
|
+
|
|
74
|
+
const state = resolveStateVariant({
|
|
75
|
+
activeAndHovered: active && hovered,
|
|
76
|
+
hovered,
|
|
77
|
+
active,
|
|
78
|
+
});
|
|
79
|
+
tabsItemStyles.useVariants({
|
|
80
|
+
variant,
|
|
81
|
+
state,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const { containerStyle } = useMemo(() => {
|
|
85
|
+
const minHeight = 48;
|
|
86
|
+
return {
|
|
87
|
+
containerStyle: [
|
|
88
|
+
tabsItemStyles.root,
|
|
89
|
+
{
|
|
90
|
+
minHeight: Math.max(minHeight, itemHeight),
|
|
91
|
+
},
|
|
92
|
+
style,
|
|
93
|
+
],
|
|
94
|
+
};
|
|
95
|
+
}, [itemHeight, style]);
|
|
96
|
+
|
|
97
|
+
const useLayoutContentRef = useRef(onLayoutContent);
|
|
98
|
+
const onLayoutHandled = useCallback((e: LayoutChangeEvent) => {
|
|
99
|
+
useLayoutContentRef.current?.(e);
|
|
100
|
+
setItemHeight(e.nativeEvent.layout.height);
|
|
101
|
+
}, []);
|
|
102
|
+
|
|
103
|
+
const { accessibilityState, accessibilityValue } = useMemo(
|
|
104
|
+
() => ({
|
|
105
|
+
accessibilityState: { selected: active },
|
|
106
|
+
accessibilityValue:
|
|
107
|
+
typeof accessibilityLabel === 'string' ? { text: accessibilityLabel } : undefined,
|
|
108
|
+
}),
|
|
109
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
110
|
+
[active, accessibilityLabel, state],
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<TouchableRipple
|
|
115
|
+
style={containerStyle}
|
|
116
|
+
accessibilityRole="tab"
|
|
117
|
+
accessibilityState={accessibilityState}
|
|
118
|
+
accessibilityValue={accessibilityValue}
|
|
119
|
+
{...rest}
|
|
120
|
+
ref={actionsRef}
|
|
121
|
+
onLayout={onLayout}>
|
|
122
|
+
<>
|
|
123
|
+
<View
|
|
124
|
+
style={[tabsItemStyles.contentsContainer, contentsContainerStyleProp]}
|
|
125
|
+
{...contentsContainerProps}
|
|
126
|
+
onLayout={onLayoutHandled}>
|
|
127
|
+
{Children.map(children, child => {
|
|
128
|
+
if (!isValidElement(child)) return null;
|
|
129
|
+
return cloneElement(child, {
|
|
130
|
+
active,
|
|
131
|
+
hovered,
|
|
132
|
+
variant,
|
|
133
|
+
});
|
|
134
|
+
})}
|
|
135
|
+
</View>
|
|
136
|
+
|
|
137
|
+
<StateLayer
|
|
138
|
+
{...stateLayerProps}
|
|
139
|
+
style={[tabsItemStyles.stateLayer, stateLayerProps?.style]}
|
|
140
|
+
/>
|
|
141
|
+
</>
|
|
142
|
+
</TouchableRipple>
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const _TabItem = memo(forwardRef(TabItem));
|
|
147
|
+
|
|
148
|
+
_TabItem.displayName = 'Tabs_Item';
|
|
149
|
+
|
|
150
|
+
export default _TabItem;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type FC, memo, useMemo } from 'react';
|
|
2
|
+
import { type TextProps, type TextStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { Icon, type IconProps, type IconType } from '../Icon';
|
|
5
|
+
import { Text } from '../Text';
|
|
6
|
+
import { tabsLabelStyles } from './utils';
|
|
7
|
+
|
|
8
|
+
const DEFAULT_ICON_SIZE = 24;
|
|
9
|
+
|
|
10
|
+
export type TabLabelProps = {
|
|
11
|
+
/**
|
|
12
|
+
* label of the tab
|
|
13
|
+
* */
|
|
14
|
+
label?: string;
|
|
15
|
+
labelStyle?: TextStyle;
|
|
16
|
+
labelProps?: Omit<TextProps, 'children' | 'style'>;
|
|
17
|
+
/**
|
|
18
|
+
* icon properties
|
|
19
|
+
* */
|
|
20
|
+
iconName?: string;
|
|
21
|
+
iconType?: IconType;
|
|
22
|
+
iconProps?: Omit<IconProps, 'name' | 'type'>;
|
|
23
|
+
iconStyle?: TextStyle;
|
|
24
|
+
|
|
25
|
+
activeColor?: string;
|
|
26
|
+
|
|
27
|
+
active: boolean;
|
|
28
|
+
hovered: boolean;
|
|
29
|
+
|
|
30
|
+
variant: 'primary' | 'secondary';
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const TabLabel = memo((props: TabLabelProps) => {
|
|
34
|
+
const {
|
|
35
|
+
activeColor: activeColorProp,
|
|
36
|
+
iconName,
|
|
37
|
+
iconStyle: iconStyleProp,
|
|
38
|
+
iconType,
|
|
39
|
+
iconProps,
|
|
40
|
+
labelStyle: labelStyleProp,
|
|
41
|
+
labelProps,
|
|
42
|
+
label,
|
|
43
|
+
active,
|
|
44
|
+
} = props;
|
|
45
|
+
|
|
46
|
+
// tabsLabelStyles.useVariants({
|
|
47
|
+
// variant,
|
|
48
|
+
// state: resolveStateVariant({
|
|
49
|
+
// activeAndHovered: !!active && !!hovered,
|
|
50
|
+
// hovered,
|
|
51
|
+
// active,
|
|
52
|
+
// }),
|
|
53
|
+
// })
|
|
54
|
+
|
|
55
|
+
const { labelStyle, iconStyle } = useMemo(() => {
|
|
56
|
+
const color = active && !!activeColorProp ? { color: activeColorProp } : null;
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
labelStyle: [tabsLabelStyles.label, labelStyleProp, color],
|
|
60
|
+
iconStyle: [tabsLabelStyles.icon, iconStyleProp, color],
|
|
61
|
+
};
|
|
62
|
+
}, [active, activeColorProp, iconStyleProp, labelStyleProp]);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<>
|
|
66
|
+
{iconName && (
|
|
67
|
+
<Icon
|
|
68
|
+
style={iconStyle}
|
|
69
|
+
name={iconName}
|
|
70
|
+
type={iconType}
|
|
71
|
+
size={DEFAULT_ICON_SIZE}
|
|
72
|
+
{...iconProps}
|
|
73
|
+
/>
|
|
74
|
+
)}
|
|
75
|
+
<Text style={labelStyle} numberOfLines={1} {...labelProps}>
|
|
76
|
+
{label}
|
|
77
|
+
</Text>
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
TabLabel.displayName = 'TabLabel';
|
|
83
|
+
|
|
84
|
+
export default TabLabel as unknown as FC<Omit<TabLabelProps, 'active' | 'hovered' | 'variant'>>;
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
cloneElement,
|
|
4
|
+
FC,
|
|
5
|
+
isValidElement,
|
|
6
|
+
memo,
|
|
7
|
+
ReactElement,
|
|
8
|
+
useCallback,
|
|
9
|
+
useEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
useState,
|
|
13
|
+
} from 'react';
|
|
14
|
+
import {
|
|
15
|
+
Animated,
|
|
16
|
+
StyleProp,
|
|
17
|
+
ViewStyle,
|
|
18
|
+
ViewProps,
|
|
19
|
+
ScrollView as RNScrollView,
|
|
20
|
+
LayoutChangeEvent,
|
|
21
|
+
NativeSyntheticEvent,
|
|
22
|
+
NativeScrollEvent,
|
|
23
|
+
View,
|
|
24
|
+
ScrollView,
|
|
25
|
+
} from 'react-native';
|
|
26
|
+
import type { TabItemProps } from './TabItem';
|
|
27
|
+
import { useControlledValue } from '../../hooks';
|
|
28
|
+
import { noop } from '../../utils/lodash';
|
|
29
|
+
import { HorizontalDivider, type HorizontalDividerProps } from '../HorizontalDivider';
|
|
30
|
+
import { tabsStyles } from './utils';
|
|
31
|
+
|
|
32
|
+
export type TabsProps = ViewProps & {
|
|
33
|
+
/**
|
|
34
|
+
* child tab name
|
|
35
|
+
* */
|
|
36
|
+
value?: string;
|
|
37
|
+
/**
|
|
38
|
+
* defaultValue to preselected for uncontrolled mode
|
|
39
|
+
* */
|
|
40
|
+
defaultValue?: string;
|
|
41
|
+
/**
|
|
42
|
+
* to enable scroll
|
|
43
|
+
* */
|
|
44
|
+
scrollable?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* on name change callback.
|
|
47
|
+
* */
|
|
48
|
+
onChange?: (value: string) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Disable the active indicator below.
|
|
51
|
+
* */
|
|
52
|
+
disableIndicator?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Additional styling for tab indicator.
|
|
55
|
+
* */
|
|
56
|
+
indicatorStyle?: StyleProp<ViewStyle>;
|
|
57
|
+
|
|
58
|
+
indicatorProps?: Omit<ViewStyle, 'style'>;
|
|
59
|
+
|
|
60
|
+
dividerStyle?: ViewStyle;
|
|
61
|
+
|
|
62
|
+
dividerProps?: Omit<HorizontalDividerProps, 'style'>;
|
|
63
|
+
|
|
64
|
+
/** Define the background Variant. */
|
|
65
|
+
variant?: 'primary' | 'secondary';
|
|
66
|
+
activeColor?: string;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const emptyObj = {};
|
|
70
|
+
|
|
71
|
+
export const TabBase = ({
|
|
72
|
+
children,
|
|
73
|
+
value: valueProp,
|
|
74
|
+
defaultValue,
|
|
75
|
+
scrollable = false,
|
|
76
|
+
onChange: onChangeProp = noop,
|
|
77
|
+
indicatorStyle: indicatorStyleProp = emptyObj,
|
|
78
|
+
disableIndicator,
|
|
79
|
+
style,
|
|
80
|
+
variant = 'primary',
|
|
81
|
+
indicatorProps,
|
|
82
|
+
dividerStyle: dividerStyleProp = emptyObj,
|
|
83
|
+
dividerProps,
|
|
84
|
+
activeColor: activeColorProp,
|
|
85
|
+
testID,
|
|
86
|
+
...rest
|
|
87
|
+
}: TabsProps) => {
|
|
88
|
+
tabsStyles.useVariants({
|
|
89
|
+
variant,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const validChildren = useMemo(
|
|
93
|
+
() =>
|
|
94
|
+
Children.toArray(children).filter(
|
|
95
|
+
child => isValidElement(child) && (child?.type as FC).displayName === 'Tabs_Item',
|
|
96
|
+
),
|
|
97
|
+
[children],
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const nameToIndexMap = useMemo(
|
|
101
|
+
() =>
|
|
102
|
+
validChildren.reduce((acc, child, currentIndex) => {
|
|
103
|
+
acc[(child as ReactElement).props?.name] = currentIndex;
|
|
104
|
+
|
|
105
|
+
return acc;
|
|
106
|
+
}, {} as Record<string, number>),
|
|
107
|
+
[validChildren],
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const [value, onChange] = useControlledValue({
|
|
111
|
+
value: valueProp,
|
|
112
|
+
onChange: onChangeProp,
|
|
113
|
+
defaultValue: defaultValue || (validChildren[0] as ReactElement)?.props?.name,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const valueIndex = nameToIndexMap[value];
|
|
117
|
+
|
|
118
|
+
const positionAnimationRef = useRef(new Animated.Value(0));
|
|
119
|
+
const widthAnimationRef = useRef(new Animated.Value(0));
|
|
120
|
+
const scrollViewRef = useRef<RNScrollView>(null);
|
|
121
|
+
const scrollViewPosition = useRef(0);
|
|
122
|
+
|
|
123
|
+
const tabItemPositions = useRef<Array<{ width: number; contentWidth: number }>>([]);
|
|
124
|
+
const [tabContainerWidth, setTabContainerWidth] = useState(0);
|
|
125
|
+
|
|
126
|
+
const itemPositionsMap = useMemo(() => {
|
|
127
|
+
return tabItemPositions.current.reduce((acc, item, index) => {
|
|
128
|
+
const previousItemsWidth = tabItemPositions.current
|
|
129
|
+
.slice(0, index)
|
|
130
|
+
.reduce((totalWidth, _item) => {
|
|
131
|
+
totalWidth += _item.width || 0;
|
|
132
|
+
|
|
133
|
+
return totalWidth;
|
|
134
|
+
}, 0);
|
|
135
|
+
|
|
136
|
+
acc[index] =
|
|
137
|
+
variant === 'primary'
|
|
138
|
+
? previousItemsWidth + (item.width - item.contentWidth) / 2
|
|
139
|
+
: previousItemsWidth;
|
|
140
|
+
|
|
141
|
+
return acc;
|
|
142
|
+
}, {} as Record<number, number>);
|
|
143
|
+
// to make useMemo in sync with the ref
|
|
144
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
145
|
+
}, [variant, tabItemPositions.current.length]);
|
|
146
|
+
|
|
147
|
+
const itemWidthsMap = useMemo(() => {
|
|
148
|
+
return tabItemPositions.current.reduce((acc, item, index) => {
|
|
149
|
+
acc[index] = variant === 'primary' ? item.contentWidth : item.width;
|
|
150
|
+
|
|
151
|
+
return acc;
|
|
152
|
+
}, {} as Record<number, number>);
|
|
153
|
+
// to make useMemo in sync with the ref
|
|
154
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
155
|
+
}, [variant, tabItemPositions.current.length]);
|
|
156
|
+
|
|
157
|
+
const scrollHandler = useCallback(
|
|
158
|
+
(currValue: number) => {
|
|
159
|
+
if (tabItemPositions.current.length > currValue) {
|
|
160
|
+
const itemStartPosition = currValue === 0 ? 0 : itemPositionsMap[currValue - 1];
|
|
161
|
+
const itemEndPosition = itemPositionsMap[currValue];
|
|
162
|
+
|
|
163
|
+
const scrollCurrentPosition = scrollViewPosition.current;
|
|
164
|
+
const tabContainerCurrentWidth = tabContainerWidth;
|
|
165
|
+
|
|
166
|
+
let scrollX = scrollCurrentPosition;
|
|
167
|
+
|
|
168
|
+
if (itemStartPosition < scrollCurrentPosition) {
|
|
169
|
+
scrollX += itemStartPosition - scrollCurrentPosition;
|
|
170
|
+
} else if (scrollCurrentPosition + tabContainerCurrentWidth < itemEndPosition) {
|
|
171
|
+
scrollX += itemEndPosition - (scrollCurrentPosition + tabContainerCurrentWidth);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
scrollViewRef.current!.scrollTo({
|
|
175
|
+
x: scrollX,
|
|
176
|
+
y: 0,
|
|
177
|
+
animated: true,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
[itemPositionsMap, tabContainerWidth],
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
Animated.timing(positionAnimationRef.current, {
|
|
186
|
+
toValue: valueIndex,
|
|
187
|
+
useNativeDriver: false,
|
|
188
|
+
duration: 170,
|
|
189
|
+
}).start();
|
|
190
|
+
|
|
191
|
+
scrollable && requestAnimationFrame(() => scrollHandler(valueIndex));
|
|
192
|
+
}, [positionAnimationRef, scrollHandler, valueIndex, scrollable]);
|
|
193
|
+
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
Animated.timing(widthAnimationRef.current, {
|
|
196
|
+
toValue: valueIndex,
|
|
197
|
+
useNativeDriver: false,
|
|
198
|
+
duration: 170,
|
|
199
|
+
}).start();
|
|
200
|
+
}, [positionAnimationRef, scrollHandler, valueIndex]);
|
|
201
|
+
|
|
202
|
+
const onScrollHandler = useCallback((event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
203
|
+
scrollViewPosition.current = event.nativeEvent.contentOffset.x;
|
|
204
|
+
}, []);
|
|
205
|
+
|
|
206
|
+
const transitionInterpolateWithMap = useCallback(
|
|
207
|
+
(obj: Record<any, number>) => {
|
|
208
|
+
const countItems = validChildren.length;
|
|
209
|
+
if (countItems < 2 || !tabItemPositions.current.length) {
|
|
210
|
+
// if there's only one item, use the value of that
|
|
211
|
+
return Object.values(obj)[0] || 0;
|
|
212
|
+
}
|
|
213
|
+
const inputRange = Array.from(Array(countItems).keys());
|
|
214
|
+
const outputRange = Object.values(obj);
|
|
215
|
+
|
|
216
|
+
return positionAnimationRef.current.interpolate({
|
|
217
|
+
inputRange,
|
|
218
|
+
outputRange,
|
|
219
|
+
});
|
|
220
|
+
},
|
|
221
|
+
[validChildren.length],
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const indicatorTransitionInterpolate = useMemo(() => {
|
|
225
|
+
return transitionInterpolateWithMap(itemPositionsMap);
|
|
226
|
+
}, [transitionInterpolateWithMap, itemPositionsMap]);
|
|
227
|
+
|
|
228
|
+
const widthTransitionInterpolate = useMemo(() => {
|
|
229
|
+
return transitionInterpolateWithMap(itemWidthsMap);
|
|
230
|
+
}, [transitionInterpolateWithMap, itemWidthsMap]);
|
|
231
|
+
|
|
232
|
+
const { containerStyle, itemsContainerStyle, dividerStyle, indicatorStyle } = useMemo(() => {
|
|
233
|
+
const { indicator, itemsContainer, divider } = tabsStyles;
|
|
234
|
+
const { activeColor, ...restStyle } = tabsStyles.root;
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
containerStyle: [restStyle, style],
|
|
238
|
+
itemsContainerStyle: itemsContainer,
|
|
239
|
+
dividerStyle: [divider, dividerStyleProp],
|
|
240
|
+
indicatorStyle: [
|
|
241
|
+
indicator,
|
|
242
|
+
{
|
|
243
|
+
backgroundColor: activeColorProp || activeColor,
|
|
244
|
+
transform: [
|
|
245
|
+
{
|
|
246
|
+
translateX: indicatorTransitionInterpolate,
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
width: widthTransitionInterpolate,
|
|
250
|
+
},
|
|
251
|
+
indicatorStyleProp,
|
|
252
|
+
],
|
|
253
|
+
};
|
|
254
|
+
}, [
|
|
255
|
+
style,
|
|
256
|
+
dividerStyleProp,
|
|
257
|
+
activeColorProp,
|
|
258
|
+
indicatorTransitionInterpolate,
|
|
259
|
+
widthTransitionInterpolate,
|
|
260
|
+
indicatorStyleProp,
|
|
261
|
+
]);
|
|
262
|
+
|
|
263
|
+
const Container = scrollable ? ScrollView : View;
|
|
264
|
+
const containerProps = scrollable
|
|
265
|
+
? {
|
|
266
|
+
horizontal: true,
|
|
267
|
+
ref: scrollViewRef,
|
|
268
|
+
onScroll: onScrollHandler,
|
|
269
|
+
showsHorizontalScrollIndicator: false,
|
|
270
|
+
style: itemsContainerStyle,
|
|
271
|
+
}
|
|
272
|
+
: {};
|
|
273
|
+
|
|
274
|
+
const onLayout = useCallback(({ nativeEvent: { layout } }: LayoutChangeEvent) => {
|
|
275
|
+
setTabContainerWidth(layout.width);
|
|
276
|
+
}, []);
|
|
277
|
+
|
|
278
|
+
const onLayoutItem = useCallback((event: LayoutChangeEvent, index: number) => {
|
|
279
|
+
const { width } = event.nativeEvent.layout;
|
|
280
|
+
|
|
281
|
+
const currentItemPosition = tabItemPositions.current[index];
|
|
282
|
+
|
|
283
|
+
tabItemPositions.current[index] = {
|
|
284
|
+
...currentItemPosition,
|
|
285
|
+
width: width,
|
|
286
|
+
};
|
|
287
|
+
}, []);
|
|
288
|
+
|
|
289
|
+
const onLayoutText = useCallback((event: LayoutChangeEvent, index: number) => {
|
|
290
|
+
const { width } = event.nativeEvent.layout;
|
|
291
|
+
|
|
292
|
+
const currentItemPosition = tabItemPositions.current[index];
|
|
293
|
+
|
|
294
|
+
tabItemPositions.current[index] = {
|
|
295
|
+
...currentItemPosition,
|
|
296
|
+
contentWidth: width,
|
|
297
|
+
};
|
|
298
|
+
}, []);
|
|
299
|
+
|
|
300
|
+
return (
|
|
301
|
+
<View
|
|
302
|
+
{...rest}
|
|
303
|
+
testID={testID}
|
|
304
|
+
style={containerStyle}
|
|
305
|
+
accessibilityRole="tablist"
|
|
306
|
+
onLayout={onLayout}>
|
|
307
|
+
<>
|
|
308
|
+
<Container
|
|
309
|
+
testID={testID && `${testID}--inner-container`}
|
|
310
|
+
{...containerProps}
|
|
311
|
+
style={itemsContainerStyle}>
|
|
312
|
+
{validChildren.map((child, index) => (
|
|
313
|
+
<ChildItem
|
|
314
|
+
key={(child as ReactElement).props?.name}
|
|
315
|
+
testID={testID && `${testID}--tab-item`}
|
|
316
|
+
index={index}
|
|
317
|
+
value={value}
|
|
318
|
+
child={child as ReactElement<TabItemProps>}
|
|
319
|
+
onChange={onChange}
|
|
320
|
+
onLayout={onLayoutItem}
|
|
321
|
+
onLayoutContent={onLayoutText}
|
|
322
|
+
variant={variant}
|
|
323
|
+
/>
|
|
324
|
+
))}
|
|
325
|
+
|
|
326
|
+
{!disableIndicator && (
|
|
327
|
+
<Animated.View
|
|
328
|
+
testID={testID && `${testID}--active-indicator`}
|
|
329
|
+
{...indicatorProps}
|
|
330
|
+
style={indicatorStyle}
|
|
331
|
+
/>
|
|
332
|
+
)}
|
|
333
|
+
</Container>
|
|
334
|
+
|
|
335
|
+
<HorizontalDivider
|
|
336
|
+
testID={testID && `${testID}--divider`}
|
|
337
|
+
{...dividerProps}
|
|
338
|
+
style={dividerStyle}
|
|
339
|
+
/>
|
|
340
|
+
</>
|
|
341
|
+
</View>
|
|
342
|
+
);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
type ChildItemProps = {
|
|
346
|
+
variant: TabsProps['variant'];
|
|
347
|
+
child: ReactElement<TabItemProps>;
|
|
348
|
+
onChange: TabsProps['onChange'];
|
|
349
|
+
onLayout: (event: LayoutChangeEvent, index: number) => void;
|
|
350
|
+
onLayoutContent: (event: LayoutChangeEvent, index: number) => void;
|
|
351
|
+
value: string;
|
|
352
|
+
index: number;
|
|
353
|
+
testID?: string;
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
const ChildItem = memo(
|
|
357
|
+
({
|
|
358
|
+
value,
|
|
359
|
+
child,
|
|
360
|
+
onChange,
|
|
361
|
+
onLayout: onLayoutProp,
|
|
362
|
+
onLayoutContent: onLayoutContentProp,
|
|
363
|
+
variant,
|
|
364
|
+
index,
|
|
365
|
+
testID,
|
|
366
|
+
}: ChildItemProps) => {
|
|
367
|
+
const name = child.props?.name;
|
|
368
|
+
|
|
369
|
+
const onPress = useCallback(() => {
|
|
370
|
+
onChange?.(name);
|
|
371
|
+
}, [name, onChange]);
|
|
372
|
+
|
|
373
|
+
const onLayout = useCallback(
|
|
374
|
+
(e: LayoutChangeEvent) => {
|
|
375
|
+
onLayoutProp(e, index);
|
|
376
|
+
},
|
|
377
|
+
[index, onLayoutProp],
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
const onLayoutContent = useCallback(
|
|
381
|
+
(e: LayoutChangeEvent) => {
|
|
382
|
+
onLayoutContentProp(e, index);
|
|
383
|
+
},
|
|
384
|
+
[index, onLayoutContentProp],
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
return cloneElement(child, {
|
|
388
|
+
onPress,
|
|
389
|
+
onLayout,
|
|
390
|
+
active: name === value,
|
|
391
|
+
onLayoutContent,
|
|
392
|
+
variant,
|
|
393
|
+
testID: child.props.testID ?? testID,
|
|
394
|
+
});
|
|
395
|
+
},
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
TabBase.displayName = 'Tabs';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
|
|
2
|
+
import type { TabItemProps } from './TabItem';
|
|
3
|
+
import { default as TabItem } from './TabItem';
|
|
4
|
+
import type { TabLabelProps } from './TabLabel';
|
|
5
|
+
import { default as TabLabel } from './TabLabel';
|
|
6
|
+
import type { TabsProps } from './Tabs';
|
|
7
|
+
import { TabBase } from './Tabs';
|
|
8
|
+
|
|
9
|
+
export const TabsDefault = Object.assign(TabBase, {
|
|
10
|
+
Item: TabItem,
|
|
11
|
+
Label: TabLabel,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
registerMoleculesComponents({
|
|
15
|
+
Tabs: TabsDefault,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const Tabs = getRegisteredComponentWithFallback('Tabs', TabsDefault);
|
|
19
|
+
|
|
20
|
+
export type { TabItemProps, TabLabelProps, TabsProps };
|
|
21
|
+
export { tabsItemStyles, tabsLabelStyles, tabsStyles } from './utils';
|