-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[examples] Add Theme Mode Switch to Next.js TS example (#43576)
Signed-off-by: Siriwat K <[email protected]> Co-authored-by: Siriwat K <[email protected]>
- Loading branch information
1 parent
e3d0e26
commit 6497d21
Showing
3 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
examples/material-ui-nextjs-ts/src/components/ModeSwitch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import FormControl from '@mui/material/FormControl'; | ||
import InputLabel from '@mui/material/InputLabel'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import Select from '@mui/material/Select'; | ||
import { useColorScheme } from '@mui/material/styles'; | ||
|
||
export default function ModeSwitch() { | ||
const { mode, setMode } = useColorScheme(); | ||
if (!mode) { | ||
return null; | ||
} | ||
return ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'flex-end', | ||
mt: 1, | ||
p: 1, | ||
}} | ||
> | ||
<FormControl> | ||
<InputLabel id="mode-select-label">Theme</InputLabel> | ||
<Select | ||
labelId="mode-select-label" | ||
id="mode-select" | ||
value={mode} | ||
onChange={(event) => setMode(event.target.value as typeof mode)} | ||
label="Theme" | ||
> | ||
<MenuItem value="system">System</MenuItem> | ||
<MenuItem value="light">Light</MenuItem> | ||
<MenuItem value="dark">Dark</MenuItem> | ||
</Select> | ||
</FormControl> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters