-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathBannerExample.tsx
More file actions
182 lines (169 loc) · 4.88 KB
/
BannerExample.tsx
File metadata and controls
182 lines (169 loc) · 4.88 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
180
181
182
import * as React from 'react';
import { StyleSheet, View } from 'react-native';
//@ts-ignore
import BrowserOnly from '@docusaurus/BrowserOnly';
//@ts-ignore
import { useColorMode } from '@docusaurus/theme-common';
import {
Avatar,
Button,
FAB,
DarkTheme as DarkTheme,
LightTheme as DefaultTheme,
ProgressBar,
PaperProvider,
RadioButton,
Switch,
Text,
TextInput,
useTheme,
} from 'react-native-paper';
const styles = StyleSheet.create({
container: {
padding: 24,
borderWidth: 1,
borderRadius: 16,
marginTop: 16,
marginBottom: 32,
overflow: 'hidden',
},
row: {
alignItems: 'flex-start',
flexWrap: 'wrap',
},
});
const Stack: React.FC<
React.PropsWithChildren<{
direction?: 'row' | 'column';
spacing?: number;
style?: any;
}>
> = ({ direction = 'column', spacing = 0, style, children }) => {
return (
<View style={[{ flexDirection: direction, margin: -spacing }, style]}>
{React.Children.map(children, (child, index) => (
<View key={index} style={{ flexDirection: direction, margin: spacing }}>
{child}
</View>
))}
</View>
);
};
const BannerExample = () => {
const theme = useTheme();
const [isSwitchOn, setIsSwitchOn] = React.useState(false);
const [text, setText] = React.useState('');
const [checked, setChecked] = React.useState('first');
const onToggleSwitch = () => setIsSwitchOn(!isSwitchOn);
return (
<View
style={[
styles.container,
{
backgroundColor: theme.colors.surface,
borderColor: theme.colors.surfaceVariant,
},
]}
>
<Stack spacing={16}>
<Stack direction="row" spacing={8} style={styles.row}>
<Button loading onPress={() => {}}>
Loading
</Button>
<Button mode="contained-tonal" icon="camera" onPress={() => {}}>
Icon
</Button>
<Button icon="camera" mode="contained" onPress={() => {}}>
Press me
</Button>
<FAB icon="plus" size="small" onPress={() => {}} />
<FAB icon="plus" size="medium" onPress={() => {}} />
<FAB icon="plus" size="large" onPress={() => {}} />
<Avatar.Text label="MD" />
<Avatar.Icon icon="folder" />
</Stack>
<ProgressBar indeterminate />
<Stack spacing={8}>
<Text variant="displayLarge">Display Large</Text>
<Text variant="displayMedium">Display Medium</Text>
<Text>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Est
tenetur neque laudantium, repellendus at excepturi quasi qui culpa.
Incidunt nesciunt unde perspiciatis atque rerum blanditiis sint
ratione, sequi totam temporibus.
</Text>
</Stack>
<Stack direction="row" spacing={8}>
<Switch value={!isSwitchOn} onValueChange={onToggleSwitch} />
<Switch value={isSwitchOn} onValueChange={onToggleSwitch} />
</Stack>
<Stack direction="row" spacing={8} style={styles.row}>
<TextInput
label="Email"
value={text}
onChangeText={(text) => setText(text)}
/>
<TextInput
label="Email"
mode="outlined"
value={text}
onChangeText={(text) => setText(text)}
/>
</Stack>
<Stack direction="row" spacing={8}>
<RadioButton
value="first"
status={checked === 'first' ? 'checked' : 'unchecked'}
onPress={() => setChecked('first')}
/>
<RadioButton
value="second"
status={checked === 'second' ? 'checked' : 'unchecked'}
onPress={() => setChecked('second')}
/>
<RadioButton
value="third"
status={checked === 'third' ? 'checked' : 'unchecked'}
onPress={() => setChecked('third')}
/>
</Stack>
</Stack>
</View>
);
};
const Shimmer = () => {
/* Docusaurus won't call StyleSheet.create() server-side */
/* eslint-disable react-native/no-inline-styles, react-native/no-color-literals */
return (
<View
style={{
display: 'flex',
minHeight: 500,
borderWidth: 1,
borderColor: 'rgba(125, 82, 96, 0.4)',
borderStyle: 'solid',
borderRadius: 16,
alignContent: 'center',
justifyContent: 'center',
padding: 30,
marginTop: 36,
marginBottom: 32,
}}
/>
);
};
const ThemedBannerExample = () => {
const isDarkTheme = useColorMode().colorMode === 'dark';
return (
<PaperProvider theme={isDarkTheme ? DarkTheme : DefaultTheme}>
<BannerExample />
</PaperProvider>
);
};
export default function ClientSideBannerExample() {
return (
<BrowserOnly fallback={<Shimmer />}>
{() => <ThemedBannerExample />}
</BrowserOnly>
);
}