-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
/
index.tsx
353 lines (342 loc) · 9.09 KB
/
index.tsx
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import * as React from 'react';
import Tooltip from '@mui/material/Tooltip';
import IconButton from '@mui/material/IconButton';
import TextField from '@mui/material/TextField';
import Stack from '@mui/material/Stack';
import MD2Button, { ButtonProps as MD2ButtonProps } from '@mui/material/Button';
import { unstable_capitalize as capitalize } from '@mui/utils';
import DeleteIcon from '@mui/icons-material/Delete';
import SendIcon from '@mui/icons-material/Send';
import Button, { ButtonProps } from '@mui/material-next/Button';
import { CssVarsProvider, useColorScheme, extendTheme } from '@mui/material-next/styles';
import DarkIcon from '@mui/icons-material/DarkModeOutlined';
import LightIcon from '@mui/icons-material/LightModeOutlined';
import CssBaseline from '@mui/material/CssBaseline';
function ModeSwitcher() {
const { mode, setMode } = useColorScheme();
const [mounted, setMounted] = React.useState(false);
React.useEffect(() => {
setMounted(true);
}, []);
if (!mounted) {
return null;
}
return (
<Tooltip title={`Change to ${mode === 'light' ? 'dark' : 'light'} mode`}>
<IconButton
onClick={() => {
if (mode === 'light') {
setMode('dark');
} else {
setMode('light');
}
}}
>
{mode === 'light' ? <DarkIcon /> : <LightIcon />}
</IconButton>
</Tooltip>
);
}
const variants: ButtonProps['variant'][] = [
'elevated',
'filled',
'filledTonal',
'outlined',
'text',
];
const colors: ButtonProps['color'][] = ['primary', 'secondary', 'tertiary'];
const sizes: ButtonProps['size'][] = ['small', 'medium', 'large'];
const md2Variants: MD2ButtonProps['variant'][] = ['contained', 'outlined', 'text'];
const md2Colors: MD2ButtonProps['color'][] = [
'primary',
'secondary',
'success',
'error',
'info',
'warning',
];
function DemoComponents() {
const [radius, setRadius] = React.useState<string>('10');
const [gap, setGap] = React.useState<string>('0.5');
return (
<Stack direction="column" gap={1}>
<h4>Enabled</h4>
<Stack direction="row" gap={1}>
{variants.map((variant) => (
<Button key={variant} variant={variant}>
{capitalize(variant as string)}
</Button>
))}
</Stack>
<h4>Enabled without a ripple effect</h4>
<Stack direction="row" gap={1}>
{variants.map((variant) => (
<Button key={variant} variant={variant} disableRipple>
{capitalize(variant as string)}
</Button>
))}
</Stack>
<h4>Disabled</h4>
<Stack direction="row" gap={1}>
{variants.map((variant) => (
<Button key={variant} variant={variant} disabled>
{capitalize(variant as string)}
</Button>
))}
</Stack>
<h4>Colors</h4>
<Stack direction="row" gap={1}>
{colors.map((color) => (
<Button key={color} variant="filled" color={color}>
{capitalize(color as string)}
</Button>
))}
</Stack>
<Stack direction="row" gap={1}>
{colors.map((color) => (
<Button key={color} variant="outlined" color={color}>
{capitalize(color as string)}
</Button>
))}
</Stack>
<Stack direction="row" gap={1}>
{colors.map((color) => (
<Button key={color} variant="text" color={color}>
{capitalize(color as string)}
</Button>
))}
</Stack>
<h4>Extended buttons</h4>
<Stack direction="row" gap={1}>
{colors.map((color) => (
<Button key={color} variant="filled" color={color} endIcon={<SendIcon />}>
Send
</Button>
))}
<Button variant="filled" disabled endIcon={<SendIcon />}>
Send
</Button>
</Stack>
<Stack direction="row" gap={1}>
{colors.map((color) => (
<Button key={color} variant="outlined" color={color} startIcon={<DeleteIcon />}>
Delete
</Button>
))}
<Button variant="outlined" disabled startIcon={<DeleteIcon />}>
Delete
</Button>
</Stack>
<h4>Sizes</h4>
<Stack direction="row" gap={1} alignItems="end">
{sizes.map((size) => (
<Button key={size} variant="filled" size={size} endIcon={<SendIcon />}>
{capitalize(size as string)}
</Button>
))}
</Stack>
<Stack direction="row" gap={1} alignItems="end">
{sizes.map((size) => (
<Button key={size} variant="outlined" size={size} startIcon={<DeleteIcon />}>
{capitalize(size as string)}
</Button>
))}
</Stack>
<h4>sx prop showcase</h4>
<Stack>
<Stack direction="row" gap={1} sx={{ py: 1 }}>
<Button
sx={{
color: 'onError',
bgcolor: 'error',
border: 1,
borderColor: 'tertiary',
borderRadius: 'medium',
}}
>
Button
</Button>
<Button
sx={{
color: 'error.100',
bgcolor: 'error.40',
border: 1,
borderColor: 'tertiary.40',
borderRadius: 2,
}}
>
Button
</Button>
<MD2Button sx={{ borderRadius: 2, color: 'error.main' }}>MD2 Button</MD2Button>
</Stack>
</Stack>
<h4>CSS vars playground</h4>
<Stack>
<Stack direction="row" gap={1} sx={{ py: 1 }}>
<TextField
label="--Button-radius"
value={radius}
type="number"
onChange={(e) => {
setRadius(e.target.value);
}}
/>
<TextField
label="--Button-gap"
value={gap}
type="number"
onChange={(e) => {
setGap(e.target.value);
}}
/>
</Stack>
<Stack direction="row" gap={1} alignItems="end">
{sizes.map((size) => (
<Button
sx={{ '--Button-radius': `${radius}px`, '--Button-gap': `${gap}rem` }}
key={size}
variant="outlined"
size={size}
startIcon={<DeleteIcon />}
>
{capitalize(size as string)}
</Button>
))}
</Stack>
</Stack>
<h4>Material Design 2 Buttons</h4>
<Stack direction="row" gap={1} alignItems="end">
{md2Variants.map((variant) => (
<MD2Button key={variant} variant={variant}>
{capitalize(variant as string)}
</MD2Button>
))}
</Stack>
<Stack direction="row" gap={1} alignItems="end">
{md2Colors.map((color) => (
<MD2Button key={color} variant="contained" color={color}>
{capitalize(color as string)}
</MD2Button>
))}
</Stack>
</Stack>
);
}
const customPalette = {
primary: {
'0': '#000000',
'10': '#3e001f',
'20': '#640036',
'30': '#8d004e',
'40': '#b70b68',
'50': '#d83181',
'60': '#fa4d9b',
'70': '#ff83b3',
'80': '#ffb0ca',
'90': '#ffd9e3',
'95': '#ffecf0',
'99': '#fffbff',
'100': '#ffffff',
},
secondary: {
'0': '#000000',
'10': '#2b151d',
'20': '#422932',
'30': '#5a3f48',
'40': '#74565f',
'50': '#8e6f78',
'60': '#a98892',
'70': '#c5a2ac',
'80': '#e2bdc7',
'90': '#ffd9e3',
'95': '#ffecf0',
'99': '#fffbff',
'100': '#ffffff',
},
tertiary: {
'0': '#000000',
'10': '#2f1500',
'20': '#48290c',
'30': '#623f21',
'40': '#7d5636',
'50': '#996e4c',
'60': '#b58763',
'70': '#d2a17c',
'80': '#f0bc95',
'90': '#ffdcc3',
'95': '#ffede3',
'99': '#fffbff',
'100': '#ffffff',
},
neutral: {
'0': '#000000',
'10': '#201a1c',
'20': '#352f30',
'30': '#4c4546',
'40': '#645c5e',
'50': '#7e7577',
'60': '#988e90',
'70': '#b3a9aa',
'80': '#cfc4c5',
'90': '#ebe0e1',
'95': '#faeef0',
'99': '#fffbff',
'100': '#ffffff',
},
neutralVariant: {
'0': '#000000',
'10': '#23191c',
'20': '#392d31',
'30': '#514347',
'40': '#695b5e',
'50': '#837377',
'60': '#9e8c91',
'70': '#b9a7ab',
'80': '#d5c2c6',
'90': '#f2dde2',
'95': '#ffecf0',
'99': '#fffbff',
'100': '#ffffff',
},
error: {
'0': '#000000',
'10': '#410002',
'20': '#690005',
'30': '#93000a',
'40': '#ba1a1a',
'50': '#de3730',
'60': '#ff5449',
'70': '#ff897d',
'80': '#ffb4ab',
'90': '#ffdad6',
'95': '#ffedea',
'99': '#fffbff',
'100': '#ffffff',
},
};
// custom MD3 theme
const cssVarsTheme = extendTheme({
colorSchemes: {
light: {
ref: {
palette: customPalette,
},
},
dark: {
ref: {
palette: customPalette,
},
},
},
});
export default function App() {
return (
<CssVarsProvider theme={cssVarsTheme}>
<CssBaseline />
<Stack sx={{ p: 1 }} alignItems="flex-start">
<ModeSwitcher />
<DemoComponents />
</Stack>
</CssVarsProvider>
);
}