-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
179 lines (166 loc) · 4.68 KB
/
Copy pathApp.tsx
File metadata and controls
179 lines (166 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/** Demonstrates Zyzz themes and styles in React Native. @module */
import { useState } from 'react'
import {
Platform,
Button,
ScrollView,
StatusBar,
Switch,
Text,
View,
useColorScheme,
} from 'react-native'
import { Provider } from 'zyzz/react-native/react'
import { style, variants } from './Theme.js'
/** Renders the native example with theme and appearance controls. */
export default function App() {
const appearance = useColorScheme()
const system = appearance === 'dark' ? 'dark' : 'light'
const [scheme, setScheme] = useState<'system' | 'light' | 'dark'>('system')
const [theme, setTheme] = useState<'blue' | 'green'>('blue')
const resolved = scheme === 'system' ? system : scheme
return (
<Provider colorScheme={resolved} set={theme}>
<Samples
scheme={scheme}
colorScheme={resolved}
theme={theme}
onScheme={() =>
setScheme(
scheme === 'system'
? 'light'
: scheme === 'light'
? 'dark'
: 'system',
)
}
onTheme={() => setTheme(theme === 'blue' ? 'green' : 'blue')}
/>
</Provider>
)
}
function Samples({
scheme,
colorScheme,
theme,
onScheme,
onTheme,
}: {
scheme: string
colorScheme: 'light' | 'dark'
theme: 'blue' | 'green'
onScheme: () => void
onTheme: () => void
}) {
const [expanded, setExpanded] = useState(false)
const width = expanded ? 120 : 60
const accent =
theme === 'blue'
? colorScheme === 'light'
? '#2563eb'
: '#93c5fd'
: colorScheme === 'light'
? '#15803d'
: '#86efac'
return (
<ScrollView
{...styles.page()}
indicatorStyle={colorScheme === 'dark' ? 'white' : 'black'}
>
<StatusBar
barStyle={colorScheme === 'dark' ? 'light-content' : 'dark-content'}
/>
<View {...styles.content()}>
<Text accessibilityRole="header" {...styles.title()}>
Zyzz native example
</Text>
<Text {...styles.description()}>
Expo SDK 57 · React Native 0.86.3 · {Platform.OS} {Platform.Version}
</Text>
<Text {...styles.description()}>
Explore themes, light and dark mode, variants, and dynamic styles.
</Text>
<Button
color={accent}
title={`Scheme: ${scheme} (${colorScheme})`}
onPress={onScheme}
/>
<Button color={accent} title={`Theme: ${theme}`} onPress={onTheme} />
<View {...styles.toggle()}>
<Text {...styles.label()}>Larger variant and payload</Text>
<Switch
accessibilityLabel="Larger variant and payload"
value={expanded}
onValueChange={setExpanded}
/>
</View>
<Text accessibilityRole="header" {...styles.label()}>
Static style and platform override
</Text>
<View testID="zyzz-static" {...styles.box()} />
<Text accessibilityRole="header" {...styles.label()}>
Variant padding
</Text>
<View testID="zyzz-variant" {...styles.card({ spacious: expanded })}>
<Text {...styles.foreground()}>Sample</Text>
</View>
<Text accessibilityRole="header" {...styles.label()}>
Scalar callback width
</Text>
<View
testID="zyzz-payload"
{...styles.meter({ width: `${width}px` })}
/>
</View>
</ScrollView>
)
}
namespace styles {
export const box = style({
backgroundColor: 'accent',
height: '64px',
width: '96px',
targets: { android: { borderRadius: 4 }, ios: { borderRadius: 16 } },
})
export const card = variants({
base: { backgroundColor: 'surface', borderRadius: '8px', padding: '8px' },
variants: {
spacious: { false: { padding: '8px' }, true: { padding: '20px' } },
},
defaultVariants: { spacious: false },
})
export const content = style({
gap: '20px',
padding: '24px',
paddingTop: '72px',
})
export const description = style({
color: 'muted',
fontSize: '14px',
lineHeight: '21px',
})
export const foreground = style({ color: 'ink' })
export const label = style({
color: 'ink',
fontSize: '16px',
fontWeight: 600,
})
export const meter = style((values: { width: `${number}px` }) => ({
backgroundColor: 'accent',
height: '16px',
width: `${values.width} !custom`,
}))
export const page = style({ backgroundColor: 'page' })
export const title = style({
color: 'ink',
fontSize: '28px',
fontWeight: 700,
})
export const toggle = style({
alignItems: 'center',
flexDirection: 'row',
flexWrap: 'wrap',
gap: '12px',
justifyContent: 'space-between',
})
}