Skip to content

Commit ecc94f3

Browse files
Add Tabs Component to RN
1 parent c851380 commit ecc94f3

File tree

9 files changed

+2827
-2530
lines changed

9 files changed

+2827
-2530
lines changed

packages/components/__generated__/ActivityLogsFragment.graphql.ts

+67-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, { FC } from 'react'
2+
3+
import { useTheme } from '../../../../providers/native'
4+
import { Button } from '../../buttons'
5+
import { Text } from '../../typographies'
6+
import { View } from '../../views'
7+
import { createStyles } from './styles'
8+
import { TabProps } from './types'
9+
10+
const Tabs: FC<TabProps> = ({
11+
onChange = () => {},
12+
currentValue,
13+
value,
14+
label,
15+
selectedColor = 'high',
16+
unselectedColor = 'low',
17+
}) => {
18+
const isSelected = value === currentValue
19+
const theme = useTheme()
20+
const styles = createStyles(theme, isSelected)
21+
22+
return (
23+
<View style={styles.baseTabContainer}>
24+
<Button mode="text" onPress={() => onChange(value)}>
25+
<Text variant="subtitle2" color={isSelected ? selectedColor : unselectedColor}>
26+
{label}
27+
</Text>
28+
</Button>
29+
</View>
30+
)
31+
}
32+
33+
export default Tabs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { StyleSheet } from 'react-native'
2+
3+
import { Theme } from '../../../../styles/native'
4+
5+
export const createStyles = (theme: Theme, isSelected: boolean) =>
6+
StyleSheet.create({
7+
baseTabContainer: {
8+
borderBottomColor: theme.colors.object.high,
9+
borderBottomWidth: isSelected ? 2 : 0,
10+
},
11+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ObjectToken } from '../../../../styles/native'
2+
3+
export interface TabProps {
4+
onChange?: (value: string) => void
5+
currentValue?: string
6+
value: string
7+
label: string
8+
selectedColor?: keyof ObjectToken
9+
unselectedColor?: keyof ObjectToken
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, { FC } from 'react'
2+
3+
import { useTheme } from '../../../../providers/native'
4+
import { View } from '../../views'
5+
import { TabProps } from '../Tab/types'
6+
import { createStyles } from './styles'
7+
import { TabsProps } from './types'
8+
9+
const Tabs: FC<TabsProps> = ({ onChange, value, children, style, ...props }) => {
10+
const theme = useTheme()
11+
const styles = createStyles(theme)
12+
13+
const renderChildren = () =>
14+
React.Children.map(children, (child) => {
15+
if (React.isValidElement(child)) {
16+
return React.cloneElement(child as React.ReactElement<TabProps>, {
17+
onChange,
18+
currentValue: value,
19+
})
20+
}
21+
return null
22+
})
23+
24+
return (
25+
<View style={[styles.baseTabsContainer, style]} {...props}>
26+
{renderChildren()}
27+
</View>
28+
)
29+
}
30+
31+
export default Tabs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { StyleSheet } from 'react-native'
2+
3+
import { Theme } from '../../../../styles/native'
4+
5+
export const createStyles = (theme: Theme) =>
6+
StyleSheet.create({
7+
baseTabsContainer: {
8+
display: 'flex',
9+
flexDirection: 'row',
10+
justifyContent: 'flex-start',
11+
alignItems: 'center',
12+
gap: 24,
13+
borderBottomColor: theme.colors.surface.disabled,
14+
borderBottomWidth: 1,
15+
},
16+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ViewProps } from '../../views'
2+
import { TabProps } from '../Tab/types'
3+
4+
export interface TabsProps extends ViewProps {
5+
onChange: (value: string) => void
6+
value: string
7+
children: React.ReactElement<TabProps>[]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { default as Tabs } from './Tabs'
2+
export type * from './Tabs/types'
3+
export { default as Tab } from './Tab'
4+
export type * from './Tab/types'

0 commit comments

Comments
 (0)