|
1 | 1 | import { StatusBar } from 'expo-status-bar';
|
2 |
| -import { StyleSheet, Text, View } from 'react-native'; |
| 2 | +import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'; |
| 3 | +import { createTokens, type VariantProps } from 'jacaranda' |
| 4 | + |
| 5 | +const { styles } = createTokens({ |
| 6 | + colors: { |
| 7 | + white: '#ffffff', |
| 8 | + black: '#000000', |
| 9 | + primary50: '#ecfeff', |
| 10 | + primary100: '#cffafe', |
| 11 | + primary200: '#a5f3fc', |
| 12 | + primary300: '#67e8f9', |
| 13 | + primary400: '#22d3ee', |
| 14 | + primary500: '#06b6d4', |
| 15 | + primary600: '#0e93d1', |
| 16 | + primary700: '#1570ad', |
| 17 | + // Secondary |
| 18 | + secondary50: '#ecfdf5', |
| 19 | + secondary100: '#d9f9eb', |
| 20 | + secondary200: '#bbfde8', |
| 21 | + secondary300: '#86f9d9', |
| 22 | + secondary400: '#0d9488', |
| 23 | + secondary500: '#027a7b', |
| 24 | + secondary600: '#016464', |
| 25 | + secondary700: '#014747', |
| 26 | + }, |
| 27 | + spacing: { |
| 28 | + 1: 4, |
| 29 | + 2: 8, |
| 30 | + 3: 12, |
| 31 | + 4: 16, |
| 32 | + 5: 20, |
| 33 | + 6: 24, |
| 34 | + 7: 28, |
| 35 | + 8: 32, |
| 36 | + } |
| 37 | +}) |
| 38 | + |
| 39 | +type ButtonProps = VariantProps<typeof buttonStyles> & { |
| 40 | + children?: React.ReactNode; |
| 41 | +}; |
| 42 | + |
| 43 | +const Button = (props: ButtonProps) => { |
| 44 | + return <TouchableOpacity style={buttonStyles(props)}> |
| 45 | + <Text>{props.children}</Text> |
| 46 | + </TouchableOpacity> |
| 47 | +} |
| 48 | + |
| 49 | +const buttonStyles = styles({ |
| 50 | + base: { |
| 51 | + paddingHorizontal: '$spacing.8', |
| 52 | + paddingVertical: '$spacing.3', |
| 53 | + borderRadius: '$spacing.2', |
| 54 | + }, |
| 55 | + variants: { |
| 56 | + color: { |
| 57 | + primary: { |
| 58 | + backgroundColor: '$colors.primary500', |
| 59 | + }, |
| 60 | + secondary: { |
| 61 | + backgroundColor: '$colors.secondary500', |
| 62 | + }, |
| 63 | + } |
| 64 | + }, |
| 65 | + defaultVariants: { |
| 66 | + color: 'primary' |
| 67 | + } |
| 68 | +}) |
| 69 | + |
| 70 | +type TypographyProps = VariantProps<typeof typographyStyles> & { |
| 71 | + children?: React.ReactNode; |
| 72 | +}; |
| 73 | + |
| 74 | +const Typography = (props: TypographyProps) => { |
| 75 | + return <Text style={typographyStyles(props)}>{props.children}</Text> |
| 76 | +} |
| 77 | + |
| 78 | +const typographyStyles = styles({ |
| 79 | + base: {}, |
| 80 | + variants: { |
| 81 | + color: { |
| 82 | + white: { color: '$colors.white' }, |
| 83 | + black: { color: '$colors.black' }, |
| 84 | + }, |
| 85 | + size: { |
| 86 | + sm: { fontSize: 10 }, |
| 87 | + md: { fontSize: 16 }, |
| 88 | + lg: { fontSize: 24 }, |
| 89 | + } |
| 90 | + }, |
| 91 | + defaultVariants: { |
| 92 | + size: 'md', |
| 93 | + color: 'white' |
| 94 | + } |
| 95 | +}) |
3 | 96 |
|
4 | 97 | export default function App() {
|
5 | 98 | return (
|
6 |
| - <View style={styles.container}> |
| 99 | + <View style={sty.container}> |
7 | 100 | <Text>Open up App.tsx to start working on your app!</Text>
|
8 | 101 | <StatusBar style="auto" />
|
| 102 | + <Button color="secondary"> |
| 103 | + <Typography color="white">Hello</Typography> |
| 104 | + </Button> |
| 105 | + <Button color="primary"> |
| 106 | + <Typography color="black">Hello</Typography> |
| 107 | + </Button> |
9 | 108 | </View>
|
10 | 109 | );
|
11 | 110 | }
|
12 | 111 |
|
13 |
| -const styles = StyleSheet.create({ |
| 112 | +const sty = StyleSheet.create({ |
14 | 113 | container: {
|
15 | 114 | flex: 1,
|
16 | 115 | backgroundColor: '#fff',
|
|
0 commit comments