@oxyhq/bloom 0.1.14 → 0.1.16
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/lib/commonjs/accordion/Accordion.js +230 -0
- package/lib/commonjs/accordion/Accordion.js.map +1 -0
- package/lib/commonjs/accordion/index.js +31 -0
- package/lib/commonjs/accordion/index.js.map +1 -0
- package/lib/commonjs/accordion/types.js +6 -0
- package/lib/commonjs/accordion/types.js.map +1 -0
- package/lib/commonjs/avatar/Avatar.js +19 -7
- package/lib/commonjs/avatar/Avatar.js.map +1 -1
- package/lib/commonjs/badge/Badge.js +173 -0
- package/lib/commonjs/badge/Badge.js.map +1 -0
- package/lib/commonjs/badge/index.js +13 -0
- package/lib/commonjs/badge/index.js.map +1 -0
- package/lib/commonjs/badge/types.js +6 -0
- package/lib/commonjs/badge/types.js.map +1 -0
- package/lib/commonjs/bottom-sheet/index.js +32 -14
- package/lib/commonjs/bottom-sheet/index.js.map +1 -1
- package/lib/commonjs/card/Card.js +165 -0
- package/lib/commonjs/card/Card.js.map +1 -0
- package/lib/commonjs/card/index.js +43 -0
- package/lib/commonjs/card/index.js.map +1 -0
- package/lib/commonjs/card/types.js +6 -0
- package/lib/commonjs/card/types.js.map +1 -0
- package/lib/commonjs/checkbox/Checkbox.js +177 -0
- package/lib/commonjs/checkbox/Checkbox.js.map +1 -0
- package/lib/commonjs/checkbox/index.js +13 -0
- package/lib/commonjs/checkbox/index.js.map +1 -0
- package/lib/commonjs/checkbox/types.js +6 -0
- package/lib/commonjs/checkbox/types.js.map +1 -0
- package/lib/commonjs/chip/Chip.js +180 -0
- package/lib/commonjs/chip/Chip.js.map +1 -0
- package/lib/commonjs/chip/index.js +13 -0
- package/lib/commonjs/chip/index.js.map +1 -0
- package/lib/commonjs/chip/types.js +6 -0
- package/lib/commonjs/chip/types.js.map +1 -0
- package/lib/commonjs/index.js +56 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/tabs/Tabs.js +202 -0
- package/lib/commonjs/tabs/Tabs.js.map +1 -0
- package/lib/commonjs/tabs/index.js +25 -0
- package/lib/commonjs/tabs/index.js.map +1 -0
- package/lib/commonjs/tabs/types.js +6 -0
- package/lib/commonjs/tabs/types.js.map +1 -0
- package/lib/module/accordion/Accordion.js +225 -0
- package/lib/module/accordion/Accordion.js.map +1 -0
- package/lib/module/accordion/index.js +4 -0
- package/lib/module/accordion/index.js.map +1 -0
- package/lib/module/accordion/types.js +4 -0
- package/lib/module/accordion/types.js.map +1 -0
- package/lib/module/avatar/Avatar.js +19 -7
- package/lib/module/avatar/Avatar.js.map +1 -1
- package/lib/module/badge/Badge.js +168 -0
- package/lib/module/badge/Badge.js.map +1 -0
- package/lib/module/badge/index.js +4 -0
- package/lib/module/badge/index.js.map +1 -0
- package/lib/module/badge/types.js +4 -0
- package/lib/module/badge/types.js.map +1 -0
- package/lib/module/bottom-sheet/index.js +32 -14
- package/lib/module/bottom-sheet/index.js.map +1 -1
- package/lib/module/card/Card.js +160 -0
- package/lib/module/card/Card.js.map +1 -0
- package/lib/module/card/index.js +4 -0
- package/lib/module/card/index.js.map +1 -0
- package/lib/module/card/types.js +4 -0
- package/lib/module/card/types.js.map +1 -0
- package/lib/module/checkbox/Checkbox.js +172 -0
- package/lib/module/checkbox/Checkbox.js.map +1 -0
- package/lib/module/checkbox/index.js +4 -0
- package/lib/module/checkbox/index.js.map +1 -0
- package/lib/module/checkbox/types.js +4 -0
- package/lib/module/checkbox/types.js.map +1 -0
- package/lib/module/chip/Chip.js +175 -0
- package/lib/module/chip/Chip.js.map +1 -0
- package/lib/module/chip/index.js +4 -0
- package/lib/module/chip/index.js.map +1 -0
- package/lib/module/chip/types.js +4 -0
- package/lib/module/chip/types.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/tabs/Tabs.js +197 -0
- package/lib/module/tabs/Tabs.js.map +1 -0
- package/lib/module/tabs/index.js +4 -0
- package/lib/module/tabs/index.js.map +1 -0
- package/lib/module/tabs/types.js +4 -0
- package/lib/module/tabs/types.js.map +1 -0
- package/lib/typescript/commonjs/__tests__/BloomThemeProvider.test.d.ts +2 -0
- package/lib/typescript/commonjs/__tests__/BloomThemeProvider.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/__tests__/BottomSheet.test.d.ts +2 -0
- package/lib/typescript/commonjs/__tests__/BottomSheet.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/__tests__/Button.test.d.ts +2 -0
- package/lib/typescript/commonjs/__tests__/Button.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/__tests__/theme.test.d.ts +2 -0
- package/lib/typescript/commonjs/__tests__/theme.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/accordion/Accordion.d.ts +7 -0
- package/lib/typescript/commonjs/accordion/Accordion.d.ts.map +1 -0
- package/lib/typescript/commonjs/accordion/index.d.ts +3 -0
- package/lib/typescript/commonjs/accordion/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/accordion/types.d.ts +38 -0
- package/lib/typescript/commonjs/accordion/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/avatar/Avatar.d.ts.map +1 -1
- package/lib/typescript/commonjs/avatar/types.d.ts +4 -0
- package/lib/typescript/commonjs/avatar/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/badge/Badge.d.ts +4 -0
- package/lib/typescript/commonjs/badge/Badge.d.ts.map +1 -0
- package/lib/typescript/commonjs/badge/index.d.ts +3 -0
- package/lib/typescript/commonjs/badge/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/badge/types.d.ts +29 -0
- package/lib/typescript/commonjs/badge/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/bottom-sheet/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/card/Card.d.ts +9 -0
- package/lib/typescript/commonjs/card/Card.d.ts.map +1 -0
- package/lib/typescript/commonjs/card/index.d.ts +3 -0
- package/lib/typescript/commonjs/card/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/card/types.d.ts +34 -0
- package/lib/typescript/commonjs/card/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/checkbox/Checkbox.d.ts +4 -0
- package/lib/typescript/commonjs/checkbox/Checkbox.d.ts.map +1 -0
- package/lib/typescript/commonjs/checkbox/index.d.ts +3 -0
- package/lib/typescript/commonjs/checkbox/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/checkbox/types.d.ts +25 -0
- package/lib/typescript/commonjs/checkbox/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/chip/Chip.d.ts +4 -0
- package/lib/typescript/commonjs/chip/Chip.d.ts.map +1 -0
- package/lib/typescript/commonjs/chip/index.d.ts +3 -0
- package/lib/typescript/commonjs/chip/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/chip/types.d.ts +31 -0
- package/lib/typescript/commonjs/chip/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +6 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/tabs/Tabs.d.ts +6 -0
- package/lib/typescript/commonjs/tabs/Tabs.d.ts.map +1 -0
- package/lib/typescript/commonjs/tabs/index.d.ts +3 -0
- package/lib/typescript/commonjs/tabs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/tabs/types.d.ts +34 -0
- package/lib/typescript/commonjs/tabs/types.d.ts.map +1 -0
- package/lib/typescript/module/__tests__/BloomThemeProvider.test.d.ts +2 -0
- package/lib/typescript/module/__tests__/BloomThemeProvider.test.d.ts.map +1 -0
- package/lib/typescript/module/__tests__/BottomSheet.test.d.ts +2 -0
- package/lib/typescript/module/__tests__/BottomSheet.test.d.ts.map +1 -0
- package/lib/typescript/module/__tests__/Button.test.d.ts +2 -0
- package/lib/typescript/module/__tests__/Button.test.d.ts.map +1 -0
- package/lib/typescript/module/__tests__/theme.test.d.ts +2 -0
- package/lib/typescript/module/__tests__/theme.test.d.ts.map +1 -0
- package/lib/typescript/module/accordion/Accordion.d.ts +7 -0
- package/lib/typescript/module/accordion/Accordion.d.ts.map +1 -0
- package/lib/typescript/module/accordion/index.d.ts +3 -0
- package/lib/typescript/module/accordion/index.d.ts.map +1 -0
- package/lib/typescript/module/accordion/types.d.ts +38 -0
- package/lib/typescript/module/accordion/types.d.ts.map +1 -0
- package/lib/typescript/module/avatar/Avatar.d.ts.map +1 -1
- package/lib/typescript/module/avatar/types.d.ts +4 -0
- package/lib/typescript/module/avatar/types.d.ts.map +1 -1
- package/lib/typescript/module/badge/Badge.d.ts +4 -0
- package/lib/typescript/module/badge/Badge.d.ts.map +1 -0
- package/lib/typescript/module/badge/index.d.ts +3 -0
- package/lib/typescript/module/badge/index.d.ts.map +1 -0
- package/lib/typescript/module/badge/types.d.ts +29 -0
- package/lib/typescript/module/badge/types.d.ts.map +1 -0
- package/lib/typescript/module/bottom-sheet/index.d.ts.map +1 -1
- package/lib/typescript/module/card/Card.d.ts +9 -0
- package/lib/typescript/module/card/Card.d.ts.map +1 -0
- package/lib/typescript/module/card/index.d.ts +3 -0
- package/lib/typescript/module/card/index.d.ts.map +1 -0
- package/lib/typescript/module/card/types.d.ts +34 -0
- package/lib/typescript/module/card/types.d.ts.map +1 -0
- package/lib/typescript/module/checkbox/Checkbox.d.ts +4 -0
- package/lib/typescript/module/checkbox/Checkbox.d.ts.map +1 -0
- package/lib/typescript/module/checkbox/index.d.ts +3 -0
- package/lib/typescript/module/checkbox/index.d.ts.map +1 -0
- package/lib/typescript/module/checkbox/types.d.ts +25 -0
- package/lib/typescript/module/checkbox/types.d.ts.map +1 -0
- package/lib/typescript/module/chip/Chip.d.ts +4 -0
- package/lib/typescript/module/chip/Chip.d.ts.map +1 -0
- package/lib/typescript/module/chip/index.d.ts +3 -0
- package/lib/typescript/module/chip/index.d.ts.map +1 -0
- package/lib/typescript/module/chip/types.d.ts +31 -0
- package/lib/typescript/module/chip/types.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +6 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/tabs/Tabs.d.ts +6 -0
- package/lib/typescript/module/tabs/Tabs.d.ts.map +1 -0
- package/lib/typescript/module/tabs/index.d.ts +3 -0
- package/lib/typescript/module/tabs/index.d.ts.map +1 -0
- package/lib/typescript/module/tabs/types.d.ts +34 -0
- package/lib/typescript/module/tabs/types.d.ts.map +1 -0
- package/package.json +79 -1
- package/src/__tests__/BloomThemeProvider.test.tsx +160 -0
- package/src/__tests__/BottomSheet.test.tsx +109 -0
- package/src/__tests__/Button.test.tsx +98 -0
- package/src/__tests__/theme.test.ts +148 -0
- package/src/accordion/Accordion.tsx +261 -0
- package/src/accordion/index.ts +8 -0
- package/src/accordion/types.ts +42 -0
- package/src/avatar/Avatar.tsx +16 -6
- package/src/avatar/types.ts +4 -0
- package/src/badge/Badge.tsx +151 -0
- package/src/badge/index.ts +8 -0
- package/src/badge/types.ts +30 -0
- package/src/bottom-sheet/index.tsx +30 -11
- package/src/card/Card.tsx +197 -0
- package/src/card/index.ts +10 -0
- package/src/card/types.ts +40 -0
- package/src/checkbox/Checkbox.tsx +166 -0
- package/src/checkbox/index.ts +2 -0
- package/src/checkbox/types.ts +26 -0
- package/src/chip/Chip.tsx +156 -0
- package/src/chip/index.ts +2 -0
- package/src/chip/types.ts +32 -0
- package/src/index.ts +8 -0
- package/src/tabs/Tabs.tsx +218 -0
- package/src/tabs/index.ts +2 -0
- package/src/tabs/types.ts +37 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import React, { memo, useMemo, useRef, useCallback } from 'react';
|
|
2
|
+
import { View, Text, Pressable, Animated, type ViewStyle, type TextStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { useTheme } from '../theme/use-theme';
|
|
5
|
+
import { animation, borderRadius, space } from '../styles/tokens';
|
|
6
|
+
import type { ChipProps, ChipColor, ChipVariant } from './types';
|
|
7
|
+
|
|
8
|
+
const SIZE_CONFIG = {
|
|
9
|
+
small: { height: 24, fontSize: 12, paddingHorizontal: 8, iconGap: 4, iconSize: 14 },
|
|
10
|
+
medium: { height: 32, fontSize: 14, paddingHorizontal: 12, iconGap: 6, iconSize: 16 },
|
|
11
|
+
large: { height: 40, fontSize: 16, paddingHorizontal: 16, iconGap: 8, iconSize: 18 },
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
const PRESS_SCALE = 0.95;
|
|
15
|
+
|
|
16
|
+
function useChipColors(
|
|
17
|
+
color: ChipColor,
|
|
18
|
+
variant: ChipVariant,
|
|
19
|
+
selected: boolean,
|
|
20
|
+
theme: ReturnType<typeof useTheme>,
|
|
21
|
+
): { bg: string; fg: string; border: string } {
|
|
22
|
+
const colorMap: Record<ChipColor, string> = {
|
|
23
|
+
default: theme.colors.textSecondary,
|
|
24
|
+
primary: theme.colors.primary,
|
|
25
|
+
success: theme.colors.success,
|
|
26
|
+
warning: theme.colors.warning,
|
|
27
|
+
error: theme.colors.error,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const base = selected ? theme.colors.primary : colorMap[color];
|
|
31
|
+
|
|
32
|
+
switch (variant) {
|
|
33
|
+
case 'solid':
|
|
34
|
+
return { bg: base, fg: '#fff', border: base };
|
|
35
|
+
case 'outlined':
|
|
36
|
+
return { bg: 'transparent', fg: base, border: base };
|
|
37
|
+
case 'soft':
|
|
38
|
+
return { bg: base + '18', fg: base, border: 'transparent' };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const ChipComponent: React.FC<ChipProps> = ({
|
|
43
|
+
children,
|
|
44
|
+
variant = 'outlined',
|
|
45
|
+
color = 'default',
|
|
46
|
+
size = 'medium',
|
|
47
|
+
startIcon,
|
|
48
|
+
endIcon,
|
|
49
|
+
onPress,
|
|
50
|
+
onClose,
|
|
51
|
+
selected = false,
|
|
52
|
+
disabled = false,
|
|
53
|
+
style,
|
|
54
|
+
textStyle,
|
|
55
|
+
accessibilityLabel,
|
|
56
|
+
testID,
|
|
57
|
+
}) => {
|
|
58
|
+
const theme = useTheme();
|
|
59
|
+
const scaleAnim = useRef(new Animated.Value(1)).current;
|
|
60
|
+
const colors = useChipColors(color, variant, selected, theme);
|
|
61
|
+
const sizeConfig = SIZE_CONFIG[size];
|
|
62
|
+
|
|
63
|
+
const onPressIn = useCallback(() => {
|
|
64
|
+
Animated.spring(scaleAnim, {
|
|
65
|
+
toValue: PRESS_SCALE,
|
|
66
|
+
useNativeDriver: true,
|
|
67
|
+
...animation.spring.snappy,
|
|
68
|
+
}).start();
|
|
69
|
+
}, [scaleAnim]);
|
|
70
|
+
|
|
71
|
+
const onPressOut = useCallback(() => {
|
|
72
|
+
Animated.spring(scaleAnim, {
|
|
73
|
+
toValue: 1,
|
|
74
|
+
useNativeDriver: true,
|
|
75
|
+
...animation.spring.gentle,
|
|
76
|
+
}).start();
|
|
77
|
+
}, [scaleAnim]);
|
|
78
|
+
|
|
79
|
+
const containerStyle = useMemo((): ViewStyle => ({
|
|
80
|
+
height: sizeConfig.height,
|
|
81
|
+
borderRadius: sizeConfig.height / 2,
|
|
82
|
+
paddingHorizontal: sizeConfig.paddingHorizontal,
|
|
83
|
+
backgroundColor: colors.bg,
|
|
84
|
+
borderWidth: variant === 'outlined' ? 1 : 0,
|
|
85
|
+
borderColor: colors.border,
|
|
86
|
+
flexDirection: 'row',
|
|
87
|
+
alignItems: 'center',
|
|
88
|
+
gap: sizeConfig.iconGap,
|
|
89
|
+
alignSelf: 'flex-start',
|
|
90
|
+
}), [sizeConfig, colors, variant]);
|
|
91
|
+
|
|
92
|
+
const labelStyle = useMemo((): TextStyle => ({
|
|
93
|
+
fontSize: sizeConfig.fontSize,
|
|
94
|
+
fontWeight: '500',
|
|
95
|
+
color: colors.fg,
|
|
96
|
+
}), [sizeConfig, colors]);
|
|
97
|
+
|
|
98
|
+
const closeButton = onClose ? (
|
|
99
|
+
<Pressable
|
|
100
|
+
onPress={onClose}
|
|
101
|
+
hitSlop={{ top: 6, bottom: 6, left: 6, right: 6 }}
|
|
102
|
+
accessibilityLabel="Remove"
|
|
103
|
+
accessibilityRole="button"
|
|
104
|
+
>
|
|
105
|
+
<Text style={{ fontSize: sizeConfig.iconSize, color: colors.fg, lineHeight: sizeConfig.iconSize }}>
|
|
106
|
+
{'\u00D7'}
|
|
107
|
+
</Text>
|
|
108
|
+
</Pressable>
|
|
109
|
+
) : null;
|
|
110
|
+
|
|
111
|
+
const content = (
|
|
112
|
+
<>
|
|
113
|
+
{startIcon}
|
|
114
|
+
{typeof children === 'string' ? (
|
|
115
|
+
<Text style={[labelStyle, textStyle]}>{children}</Text>
|
|
116
|
+
) : (
|
|
117
|
+
children
|
|
118
|
+
)}
|
|
119
|
+
{endIcon}
|
|
120
|
+
{closeButton}
|
|
121
|
+
</>
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
if (onPress) {
|
|
125
|
+
return (
|
|
126
|
+
<Animated.View style={{ transform: [{ scale: scaleAnim }] }}>
|
|
127
|
+
<Pressable
|
|
128
|
+
style={[containerStyle, disabled && { opacity: 0.5 }, style]}
|
|
129
|
+
onPress={onPress}
|
|
130
|
+
onPressIn={onPressIn}
|
|
131
|
+
onPressOut={onPressOut}
|
|
132
|
+
disabled={disabled}
|
|
133
|
+
accessibilityLabel={accessibilityLabel}
|
|
134
|
+
accessibilityRole="button"
|
|
135
|
+
accessibilityState={{ disabled, selected }}
|
|
136
|
+
testID={testID}
|
|
137
|
+
>
|
|
138
|
+
{content}
|
|
139
|
+
</Pressable>
|
|
140
|
+
</Animated.View>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<View
|
|
146
|
+
style={[containerStyle, disabled && { opacity: 0.5 }, style]}
|
|
147
|
+
accessibilityLabel={accessibilityLabel}
|
|
148
|
+
testID={testID}
|
|
149
|
+
>
|
|
150
|
+
{content}
|
|
151
|
+
</View>
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const Chip = memo(ChipComponent);
|
|
156
|
+
Chip.displayName = 'Chip';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { StyleProp, ViewStyle, TextStyle } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export type ChipVariant = 'solid' | 'outlined' | 'soft';
|
|
4
|
+
export type ChipColor = 'default' | 'primary' | 'success' | 'warning' | 'error';
|
|
5
|
+
export type ChipSize = 'small' | 'medium' | 'large';
|
|
6
|
+
|
|
7
|
+
export interface ChipProps {
|
|
8
|
+
/** Text content of the chip. */
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
/** Visual variant. */
|
|
11
|
+
variant?: ChipVariant;
|
|
12
|
+
/** Semantic color. */
|
|
13
|
+
color?: ChipColor;
|
|
14
|
+
/** Size preset. */
|
|
15
|
+
size?: ChipSize;
|
|
16
|
+
/** Icon rendered before the label. */
|
|
17
|
+
startIcon?: React.ReactNode;
|
|
18
|
+
/** Icon or close button rendered after the label. */
|
|
19
|
+
endIcon?: React.ReactNode;
|
|
20
|
+
/** Called when the chip is pressed. Makes the chip interactive. */
|
|
21
|
+
onPress?: () => void;
|
|
22
|
+
/** Called when the close/end icon is pressed. */
|
|
23
|
+
onClose?: () => void;
|
|
24
|
+
/** Whether the chip is in a selected state. */
|
|
25
|
+
selected?: boolean;
|
|
26
|
+
/** Whether the chip is disabled. */
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
style?: StyleProp<ViewStyle>;
|
|
29
|
+
textStyle?: StyleProp<TextStyle>;
|
|
30
|
+
accessibilityLabel?: string;
|
|
31
|
+
testID?: string;
|
|
32
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -52,6 +52,14 @@ export { SearchInput } from './search-input';
|
|
|
52
52
|
export { BottomSheet } from './bottom-sheet';
|
|
53
53
|
export type { BottomSheetRef, BottomSheetProps } from './bottom-sheet';
|
|
54
54
|
|
|
55
|
+
// Data display
|
|
56
|
+
export * from './card';
|
|
57
|
+
export * from './badge';
|
|
58
|
+
export * from './chip';
|
|
59
|
+
export * as Tabs from './tabs';
|
|
60
|
+
export * from './checkbox';
|
|
61
|
+
export * as Accordion from './accordion';
|
|
62
|
+
|
|
55
63
|
// Overlay components
|
|
56
64
|
export * as Admonition from './admonition';
|
|
57
65
|
export * as Menu from './menu';
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
createContext,
|
|
3
|
+
memo,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import {
|
|
11
|
+
View,
|
|
12
|
+
Text,
|
|
13
|
+
Pressable,
|
|
14
|
+
Animated,
|
|
15
|
+
ScrollView,
|
|
16
|
+
type ViewStyle,
|
|
17
|
+
type TextStyle,
|
|
18
|
+
type LayoutChangeEvent,
|
|
19
|
+
} from 'react-native';
|
|
20
|
+
|
|
21
|
+
import { useTheme } from '../theme/use-theme';
|
|
22
|
+
import { animation, borderRadius, space } from '../styles/tokens';
|
|
23
|
+
import type { TabsProps, TabProps, TabPanelProps, TabsVariant } from './types';
|
|
24
|
+
|
|
25
|
+
interface TabsContextValue {
|
|
26
|
+
value: string;
|
|
27
|
+
onValueChange: (value: string) => void;
|
|
28
|
+
variant: TabsVariant;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const TabsContext = createContext<TabsContextValue>({
|
|
32
|
+
value: '',
|
|
33
|
+
onValueChange: () => {},
|
|
34
|
+
variant: 'underline',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const TabsBarComponent: React.FC<TabsProps> = ({
|
|
38
|
+
value,
|
|
39
|
+
onValueChange,
|
|
40
|
+
variant = 'underline',
|
|
41
|
+
children,
|
|
42
|
+
style,
|
|
43
|
+
testID,
|
|
44
|
+
}) => {
|
|
45
|
+
const theme = useTheme();
|
|
46
|
+
|
|
47
|
+
const contextValue = useMemo(
|
|
48
|
+
() => ({ value, onValueChange, variant }),
|
|
49
|
+
[value, onValueChange, variant],
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const containerStyle = useMemo((): ViewStyle => {
|
|
53
|
+
const base: ViewStyle = {
|
|
54
|
+
flexDirection: 'row',
|
|
55
|
+
alignItems: 'center',
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
switch (variant) {
|
|
59
|
+
case 'underline':
|
|
60
|
+
base.borderBottomWidth = 1;
|
|
61
|
+
base.borderBottomColor = theme.colors.borderLight;
|
|
62
|
+
break;
|
|
63
|
+
case 'filled':
|
|
64
|
+
base.backgroundColor = theme.colors.backgroundSecondary;
|
|
65
|
+
base.borderRadius = borderRadius.sm;
|
|
66
|
+
base.padding = 2;
|
|
67
|
+
break;
|
|
68
|
+
case 'outlined':
|
|
69
|
+
base.borderWidth = 1;
|
|
70
|
+
base.borderColor = theme.colors.border;
|
|
71
|
+
base.borderRadius = borderRadius.sm;
|
|
72
|
+
base.padding = 2;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return base;
|
|
77
|
+
}, [variant, theme]);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<TabsContext.Provider value={contextValue}>
|
|
81
|
+
<ScrollView
|
|
82
|
+
horizontal
|
|
83
|
+
showsHorizontalScrollIndicator={false}
|
|
84
|
+
contentContainerStyle={[containerStyle, style]}
|
|
85
|
+
testID={testID}
|
|
86
|
+
>
|
|
87
|
+
{children}
|
|
88
|
+
</ScrollView>
|
|
89
|
+
</TabsContext.Provider>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const TabComponent: React.FC<TabProps> = ({
|
|
94
|
+
value,
|
|
95
|
+
label,
|
|
96
|
+
icon,
|
|
97
|
+
disabled = false,
|
|
98
|
+
style,
|
|
99
|
+
textStyle,
|
|
100
|
+
}) => {
|
|
101
|
+
const theme = useTheme();
|
|
102
|
+
const { value: selectedValue, onValueChange, variant } = useContext(TabsContext);
|
|
103
|
+
const isSelected = value === selectedValue;
|
|
104
|
+
const scaleAnim = useRef(new Animated.Value(1)).current;
|
|
105
|
+
|
|
106
|
+
const handlePress = useCallback(() => {
|
|
107
|
+
if (!disabled) {
|
|
108
|
+
onValueChange(value);
|
|
109
|
+
}
|
|
110
|
+
}, [value, disabled, onValueChange]);
|
|
111
|
+
|
|
112
|
+
const onPressIn = useCallback(() => {
|
|
113
|
+
Animated.spring(scaleAnim, {
|
|
114
|
+
toValue: 0.97,
|
|
115
|
+
useNativeDriver: true,
|
|
116
|
+
...animation.spring.snappy,
|
|
117
|
+
}).start();
|
|
118
|
+
}, [scaleAnim]);
|
|
119
|
+
|
|
120
|
+
const onPressOut = useCallback(() => {
|
|
121
|
+
Animated.spring(scaleAnim, {
|
|
122
|
+
toValue: 1,
|
|
123
|
+
useNativeDriver: true,
|
|
124
|
+
...animation.spring.gentle,
|
|
125
|
+
}).start();
|
|
126
|
+
}, [scaleAnim]);
|
|
127
|
+
|
|
128
|
+
const tabStyle = useMemo((): ViewStyle => {
|
|
129
|
+
const base: ViewStyle = {
|
|
130
|
+
flexDirection: 'row',
|
|
131
|
+
alignItems: 'center',
|
|
132
|
+
justifyContent: 'center',
|
|
133
|
+
paddingHorizontal: space.lg,
|
|
134
|
+
paddingVertical: space.sm,
|
|
135
|
+
gap: space.xs,
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
switch (variant) {
|
|
139
|
+
case 'underline':
|
|
140
|
+
if (isSelected) {
|
|
141
|
+
base.borderBottomWidth = 2;
|
|
142
|
+
base.borderBottomColor = theme.colors.primary;
|
|
143
|
+
base.marginBottom = -1; // overlap container border
|
|
144
|
+
}
|
|
145
|
+
break;
|
|
146
|
+
case 'filled':
|
|
147
|
+
if (isSelected) {
|
|
148
|
+
base.backgroundColor = theme.colors.card;
|
|
149
|
+
base.borderRadius = borderRadius.xs + 2;
|
|
150
|
+
base.shadowColor = theme.colors.shadow;
|
|
151
|
+
base.shadowOffset = { width: 0, height: 1 };
|
|
152
|
+
base.shadowOpacity = 0.1;
|
|
153
|
+
base.shadowRadius = 2;
|
|
154
|
+
base.elevation = 1;
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
case 'outlined':
|
|
158
|
+
if (isSelected) {
|
|
159
|
+
base.backgroundColor = theme.colors.primary;
|
|
160
|
+
base.borderRadius = borderRadius.xs + 2;
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return base;
|
|
166
|
+
}, [variant, isSelected, theme]);
|
|
167
|
+
|
|
168
|
+
const labelStyle = useMemo((): TextStyle => {
|
|
169
|
+
const base: TextStyle = {
|
|
170
|
+
fontSize: 14,
|
|
171
|
+
fontWeight: isSelected ? '600' : '500',
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
if (variant === 'outlined' && isSelected) {
|
|
175
|
+
base.color = '#fff';
|
|
176
|
+
} else if (isSelected) {
|
|
177
|
+
base.color = theme.colors.primary;
|
|
178
|
+
} else {
|
|
179
|
+
base.color = theme.colors.textSecondary;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return base;
|
|
183
|
+
}, [variant, isSelected, theme]);
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<Animated.View style={{ transform: [{ scale: scaleAnim }] }}>
|
|
187
|
+
<Pressable
|
|
188
|
+
style={[tabStyle, disabled && { opacity: 0.4 }, style]}
|
|
189
|
+
onPress={handlePress}
|
|
190
|
+
onPressIn={onPressIn}
|
|
191
|
+
onPressOut={onPressOut}
|
|
192
|
+
disabled={disabled}
|
|
193
|
+
accessibilityRole="tab"
|
|
194
|
+
accessibilityState={{ selected: isSelected, disabled }}
|
|
195
|
+
>
|
|
196
|
+
{icon}
|
|
197
|
+
<Text style={[labelStyle, textStyle]}>{label}</Text>
|
|
198
|
+
</Pressable>
|
|
199
|
+
</Animated.View>
|
|
200
|
+
);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const TabPanelComponent: React.FC<TabPanelProps> = ({ value, children, style }) => {
|
|
204
|
+
const { value: selectedValue } = useContext(TabsContext);
|
|
205
|
+
|
|
206
|
+
if (value !== selectedValue) return null;
|
|
207
|
+
|
|
208
|
+
return <View style={style}>{children}</View>;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export const TabsBar = memo(TabsBarComponent);
|
|
212
|
+
TabsBar.displayName = 'TabsBar';
|
|
213
|
+
|
|
214
|
+
export const Tab = memo(TabComponent);
|
|
215
|
+
Tab.displayName = 'Tab';
|
|
216
|
+
|
|
217
|
+
export const TabPanel = memo(TabPanelComponent);
|
|
218
|
+
TabPanel.displayName = 'TabPanel';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { StyleProp, ViewStyle, TextStyle } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export type TabsVariant = 'underline' | 'filled' | 'outlined';
|
|
4
|
+
|
|
5
|
+
export interface TabsProps {
|
|
6
|
+
/** The currently selected tab value. */
|
|
7
|
+
value: string;
|
|
8
|
+
/** Called when a tab is selected. */
|
|
9
|
+
onValueChange: (value: string) => void;
|
|
10
|
+
/** Visual variant for the tab bar. */
|
|
11
|
+
variant?: TabsVariant;
|
|
12
|
+
/** The tab items. Must be Tab components. */
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
style?: StyleProp<ViewStyle>;
|
|
15
|
+
testID?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface TabProps {
|
|
19
|
+
/** Unique value identifying this tab. */
|
|
20
|
+
value: string;
|
|
21
|
+
/** Tab label text. */
|
|
22
|
+
label: string;
|
|
23
|
+
/** Icon rendered before the label. */
|
|
24
|
+
icon?: React.ReactNode;
|
|
25
|
+
/** Whether this tab is disabled. */
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
style?: StyleProp<ViewStyle>;
|
|
28
|
+
textStyle?: StyleProp<TextStyle>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface TabPanelProps {
|
|
32
|
+
/** The tab value this panel corresponds to. */
|
|
33
|
+
value: string;
|
|
34
|
+
/** Panel content. */
|
|
35
|
+
children: React.ReactNode;
|
|
36
|
+
style?: StyleProp<ViewStyle>;
|
|
37
|
+
}
|