-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLayout.tsx
176 lines (171 loc) · 4.68 KB
/
Layout.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
import {
ColorPaletteProp,
Select,
Option,
Stack,
Checkbox,
FormControl,
FormLabel,
Button,
useColorScheme,
Slider,
} from "@mui/joy";
import { useState } from "react";
import { useBoolean } from "usehooks-ts";
import Spectrum, { SpectrumVariantProp } from "./Spectrum";
import { LuMoon, LuSun, LuSunMoon } from "react-icons/lu";
import { motion } from "framer-motion";
export const modes = ["light", "dark", "system"] as const;
export type Mode = (typeof modes)[number];
export default function Layout() {
const { mode, setMode } = useColorScheme();
const [variant, setVariant] = useState<SpectrumVariantProp>("soft");
const [color, setColor] = useState<ColorPaletteProp>("primary");
const { value: interpolate, toggle: toggleInterpolate } = useBoolean(true);
const { value: ghost, toggle: toggleGhost } = useBoolean(true);
return (
<Stack
component="main"
alignItems="center"
justifyContent="space-between"
height="100%"
width="100%"
paddingTop="3.25rem"
>
<Button
color="neutral"
variant="plain"
sx={{
position: "fixed",
top: 0,
left: 0,
margin: "0.5rem",
}}
startDecorator={
{ light: <LuSun />, dark: <LuMoon />, system: <LuSunMoon /> }[
mode as Mode
]
}
onClick={() => {
const currentModeIndex = modes.findIndex((m) => m === mode);
const nextMode = modes[(currentModeIndex + 1) % modes.length];
setMode(nextMode);
}}
>
<motion.span
layoutId="mode-selector-value"
style={{
textTransform: "capitalize",
}}
>
{mode}
</motion.span>
<motion.span layoutId="mode-selector-label"> theme</motion.span>
</Button>
<Stack
alignItems="center"
justifyContent="center"
width="100%"
minHeight="7rem"
flex={1}
px={6}
>
<Spectrum
{...{
interpolate,
ghost,
variant,
color,
}}
ghostDuration={10000}
/>
</Stack>
<Stack
direction="row"
alignItems="end"
justifyContent="center"
m={2}
p={2}
gap={2}
flexWrap="wrap"
sx={{
backgroundColor: "var(--joy-palette-background-surface)",
border: "1px solid var(--joy-palette-divider)",
borderRadius: "1.375rem",
"& > *": {
flex: 1,
},
}}
>
<FormControl
sx={{
minWidth: "min(7rem, 100vw)",
}}
>
<FormLabel>Variant</FormLabel>
<Select
value={variant}
onChange={(_, newValue) => newValue && setVariant(newValue)}
>
{["outlined", "soft"].map((value) => (
<Option key={value} value={value}>
{value}
</Option>
))}
</Select>
</FormControl>
<FormControl
sx={{
minWidth: "min(7rem, 100vw)",
}}
>
<FormLabel>Colour</FormLabel>
<Select
value={color}
onChange={(_, newValue) => newValue && setColor(newValue)}
>
{["primary", "neutral", "danger", "success", "warning"].map(
(value) => (
<Option key={value} value={value}>
{value}
</Option>
)
)}
</Select>
</FormControl>
<Checkbox
label="Interpolate colours"
aria-label="Interpolate colours"
checked={interpolate}
onChange={toggleInterpolate}
sx={{
whiteSpace: "nowrap",
height: "36px",
display: "flex",
alignItems: "center",
padding: "0.5rem 0.75rem 0.5rem 0.5rem",
backgroundColor: "var(--joy-palette-neutral-softBg)",
border: "1px solid var(--joy-palette-neutral-outlinedBorder)",
borderRadius: "0.375rem",
}}
/>
<Checkbox
label="Display ghost"
aria-label="Display ghost"
checked={ghost}
onChange={toggleGhost}
sx={{
whiteSpace: "nowrap",
height: "2.25rem",
display: "flex",
alignItems: "center",
padding: "0.5rem 0.75rem 0.5rem 0.5rem",
backgroundColor: "var(--joy-palette-neutral-softBg)",
border: "1px solid var(--joy-palette-neutral-outlinedBorder)",
borderRadius: "0.375rem",
}}
/>
</Stack>
</Stack>
);
}