-
-
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.
[docs][joy-ui] Refine the Rental dashboard template (#39059)
- Loading branch information
Showing
20 changed files
with
470 additions
and
757 deletions.
There are no files selected for viewing
205 changes: 79 additions & 126 deletions
205
docs/data/joy/getting-started/templates/rental-dashboard/App.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
73 changes: 43 additions & 30 deletions
73
docs/data/joy/getting-started/templates/rental-dashboard/components/ColorSchemeToggle.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 |
---|---|---|
@@ -1,48 +1,61 @@ | ||
import * as React from 'react'; | ||
import { useColorScheme } from '@mui/joy/styles'; | ||
import { ListItem, ListItemButton, ListItemButtonProps } from '@mui/joy'; | ||
import IconButton, { IconButtonProps } from '@mui/joy/IconButton'; | ||
|
||
import DarkModeRoundedIcon from '@mui/icons-material/DarkModeRounded'; | ||
import LightModeIcon from '@mui/icons-material/LightMode'; | ||
|
||
export default function ColorSchemeToggle({ | ||
onClick, | ||
sx, | ||
...props | ||
}: ListItemButtonProps) { | ||
}: IconButtonProps) { | ||
const { mode, setMode } = useColorScheme(); | ||
const [mounted, setMounted] = React.useState(false); | ||
React.useEffect(() => { | ||
setMounted(true); | ||
}, []); | ||
if (!mounted) { | ||
return <ListItemButton {...props} sx={sx} disabled />; | ||
return ( | ||
<IconButton | ||
size="sm" | ||
variant="outlined" | ||
color="neutral" | ||
{...props} | ||
sx={sx} | ||
disabled | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<ListItem> | ||
<ListItemButton | ||
id="toggle-mode" | ||
onClick={(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => { | ||
if (mode === 'light') { | ||
setMode('dark'); | ||
} else { | ||
setMode('light'); | ||
} | ||
onClick?.(event); | ||
}} | ||
sx={[ | ||
{ | ||
'& > *:first-child': { | ||
display: mode === 'dark' ? 'none' : 'initial', | ||
}, | ||
'& > *:last-child': { | ||
display: mode === 'light' ? 'none' : 'initial', | ||
}, | ||
<IconButton | ||
id="toggle-mode" | ||
size="sm" | ||
variant="outlined" | ||
color="neutral" | ||
{...props} | ||
onClick={(event) => { | ||
if (mode === 'light') { | ||
setMode('dark'); | ||
} else { | ||
setMode('light'); | ||
} | ||
onClick?.(event); | ||
}} | ||
sx={[ | ||
{ | ||
'& > *:first-of-type': { | ||
display: mode === 'dark' ? 'none' : 'initial', | ||
}, | ||
'& > *:last-of-type': { | ||
display: mode === 'light' ? 'none' : 'initial', | ||
}, | ||
...(Array.isArray(sx) ? sx : [sx]), | ||
]} | ||
> | ||
<i data-feather="moon" /> | ||
<i data-feather="sun" /> | ||
</ListItemButton> | ||
</ListItem> | ||
}, | ||
...(Array.isArray(sx) ? sx : [sx]), | ||
]} | ||
> | ||
<DarkModeRoundedIcon /> | ||
<LightModeIcon /> | ||
</IconButton> | ||
); | ||
} |
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
Oops, something went wrong.