@artsy/palette-mobile 17.2.2 → 17.4.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.
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import themeGet from "@styled-system/theme-get";
|
|
3
3
|
import { MotiPressable } from "moti/interactions";
|
|
4
4
|
import { useMemo } from "react";
|
|
5
|
+
import { PixelRatio } from "react-native";
|
|
5
6
|
import styled, { css } from "styled-components";
|
|
6
7
|
import { CloseIcon } from "../../svgs";
|
|
7
8
|
import { Flex } from "../Flex";
|
|
@@ -50,7 +51,7 @@ const Thumbnail = styled(Image) `
|
|
|
50
51
|
const PILL_STATES = {
|
|
51
52
|
default: css `
|
|
52
53
|
border-radius: 15px;
|
|
53
|
-
height:
|
|
54
|
+
height: ${PixelRatio.getFontScale() * 30}px;
|
|
54
55
|
padding: 0 15px;
|
|
55
56
|
`,
|
|
56
57
|
selected: css `
|
|
@@ -7,7 +7,9 @@ interface Indicator {
|
|
|
7
7
|
export interface TabsContainerProps extends CollapsibleProps {
|
|
8
8
|
indicators?: Indicator[];
|
|
9
9
|
onTabPress?: (tabName: string) => void;
|
|
10
|
+
stickyTabBarComponent?: React.ReactNode;
|
|
10
11
|
tabScrollEnabled?: boolean;
|
|
12
|
+
variant?: "pills" | "tabs";
|
|
11
13
|
}
|
|
12
14
|
export declare const TabsContainer: React.FC<TabsContainerProps>;
|
|
13
15
|
export {};
|
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { debounce } from "lodash";
|
|
3
|
+
import { useState } from "react";
|
|
2
4
|
import { Platform } from "react-native";
|
|
3
5
|
import { Tabs as BaseTabs, MaterialTabBar, MaterialTabItem, } from "react-native-collapsible-tab-view";
|
|
6
|
+
import { runOnJS, useAnimatedReaction } from "react-native-reanimated";
|
|
4
7
|
import { DEFAULT_ACTIVE_OPACITY } from "../../constants";
|
|
5
8
|
import { useColor } from "../../utils/hooks/useColor";
|
|
6
9
|
import { useSpace } from "../../utils/hooks/useSpace";
|
|
7
10
|
import { Box } from "../Box";
|
|
8
11
|
import { Flex } from "../Flex";
|
|
12
|
+
import { Pill } from "../Pill";
|
|
9
13
|
const TAB_BAR_HEIGHT = 50;
|
|
10
|
-
|
|
14
|
+
const PillTabItem = ({ focusedTab: focusedTabProp, ...props }) => {
|
|
15
|
+
const [focusedTab, setFocusedTab] = useState(focusedTabProp.value);
|
|
16
|
+
// We want to debounce the focusedTab value to avoid showing two pills at once
|
|
17
|
+
const debouncedFocusedTab = debounce(setFocusedTab, 30);
|
|
18
|
+
useAnimatedReaction(() => focusedTabProp.value, (value) => {
|
|
19
|
+
runOnJS(debouncedFocusedTab)(value);
|
|
20
|
+
});
|
|
21
|
+
return (_jsx(Pill, { selected: props.name === focusedTab, onPress: () => {
|
|
22
|
+
props.onTabPress?.(props.name);
|
|
23
|
+
}, variant: "link", children: props.name }, props.name));
|
|
24
|
+
};
|
|
25
|
+
const DefaultTabItem = (props) => {
|
|
26
|
+
const Indicator = props.indicators.find((indicator) => {
|
|
27
|
+
return indicator.tabName === props.name;
|
|
28
|
+
});
|
|
29
|
+
return (_jsxs(Box, { flex: 1, children: [_jsx(Flex, { position: "absolute", width: "100%", children: !!Indicator?.Component && _jsx(Indicator.Component, { ...props }) }), _jsx(MaterialTabItem, { pressOpacity: DEFAULT_ACTIVE_OPACITY, ...props })] }));
|
|
30
|
+
};
|
|
31
|
+
export const TabsContainer = ({ children, indicators = [], initialTabName, onTabPress, renderHeader, stickyTabBarComponent, tabScrollEnabled = false, variant = "tabs", ...tabContainerProps }) => {
|
|
11
32
|
const space = useSpace();
|
|
12
33
|
const color = useColor();
|
|
13
34
|
const isIOS = Platform.OS === "ios";
|
|
14
|
-
return (_jsx(BaseTabs.Container, {
|
|
35
|
+
return (_jsx(BaseTabs.Container, { renderHeader: renderHeader, headerContainerStyle: {
|
|
15
36
|
shadowOpacity: 0,
|
|
16
37
|
shadowRadius: 0,
|
|
17
38
|
elevation: 0,
|
|
@@ -19,6 +40,17 @@ export const TabsContainer = ({ children, indicators = [], initialTabName, rende
|
|
|
19
40
|
}, initialTabName: initialTabName, containerStyle: {
|
|
20
41
|
paddingTop: space(2),
|
|
21
42
|
}, renderTabBar: (tabBarProps) => {
|
|
43
|
+
if (variant === "pills") {
|
|
44
|
+
return (_jsxs(Flex, { flexDirection: "row", gap: 2, alignItems: "center", py: 1, children: [_jsx(MaterialTabBar, { ...tabBarProps, scrollEnabled: true, TabItemComponent: (props) => (_jsx(PillTabItem, { ...props, onTabPress: (tab) => {
|
|
45
|
+
onTabPress?.(tab);
|
|
46
|
+
tabBarProps.onTabPress(tab);
|
|
47
|
+
}, focusedTab: tabBarProps.focusedTab })), indicatorStyle: {
|
|
48
|
+
backgroundColor: "transparent",
|
|
49
|
+
}, contentContainerStyle: {
|
|
50
|
+
gap: space(1),
|
|
51
|
+
paddingHorizontal: space(2),
|
|
52
|
+
} }), stickyTabBarComponent] }));
|
|
53
|
+
}
|
|
22
54
|
return (_jsx(_Fragment, { children: _jsx(MaterialTabBar, { ...tabBarProps, scrollEnabled: tabScrollEnabled, onTabPress: (tab) => {
|
|
23
55
|
tabBarProps.onTabPress(tab);
|
|
24
56
|
onTabPress?.(tab);
|
|
@@ -26,12 +58,7 @@ export const TabsContainer = ({ children, indicators = [], initialTabName, rende
|
|
|
26
58
|
height: TAB_BAR_HEIGHT,
|
|
27
59
|
borderBottomWidth: 1,
|
|
28
60
|
borderColor: color("mono30"),
|
|
29
|
-
}, TabItemComponent: (props) => {
|
|
30
|
-
const Indicator = indicators.find((indicator) => {
|
|
31
|
-
return indicator.tabName === props.name;
|
|
32
|
-
});
|
|
33
|
-
return (_jsxs(Box, { flex: 1, children: [_jsx(Flex, { position: "absolute", width: "100%", children: !!Indicator?.Component && _jsx(Indicator.Component, { ...props }) }), _jsx(MaterialTabItem, { pressOpacity: DEFAULT_ACTIVE_OPACITY, ...props })] }));
|
|
34
|
-
}, contentContainerStyle: {}, activeColor: color("onBackground"), inactiveColor: color("onBackgroundMedium"), labelStyle: { marginHorizontal: 0 }, indicatorStyle: {
|
|
61
|
+
}, TabItemComponent: (props) => _jsx(DefaultTabItem, { ...props, indicators: indicators }), contentContainerStyle: {}, activeColor: color("onBackground"), inactiveColor: color("onBackgroundMedium"), labelStyle: { marginHorizontal: 0 }, indicatorStyle: {
|
|
35
62
|
backgroundColor: color("onBackground"),
|
|
36
63
|
height: 1,
|
|
37
64
|
// on android this line breaks the active indicator and it is not visible
|
|
@@ -41,5 +68,5 @@ export const TabsContainer = ({ children, indicators = [], initialTabName, rende
|
|
|
41
68
|
// to prevent linebreaks on the tab titles
|
|
42
69
|
paddingHorizontal: 0,
|
|
43
70
|
} }) }));
|
|
44
|
-
}, children: children }));
|
|
71
|
+
}, ...tabContainerProps, children: children }));
|
|
45
72
|
};
|
package/package.json
CHANGED