Skip to content

Commit

Permalink
[docs][joy-ui] Refine the Rental dashboard template (#39059)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanivan authored Oct 2, 2023
1 parent 2a2088b commit 6c70f79
Show file tree
Hide file tree
Showing 20 changed files with 470 additions and 757 deletions.
205 changes: 79 additions & 126 deletions docs/data/joy/getting-started/templates/rental-dashboard/App.tsx
Original file line number Diff line number Diff line change
@@ -1,145 +1,98 @@
import * as React from 'react';
import { CssVarsProvider } from '@mui/joy/styles';
import GlobalStyles from '@mui/joy/GlobalStyles';
import CssBaseline from '@mui/joy/CssBaseline';
import Box from '@mui/joy/Box';
import Divider from '@mui/joy/Divider';
import Grid from '@mui/joy/Grid';
import Stack from '@mui/joy/Stack';
import useScript from './useScript';
import FirstSidebar from './components/FirstSidebar';
import Header from './components/Header';

import NavBar from './components/NavBar';
import RentalCard from './components/RentalCard';
import Main from './components/Main';
import HeaderSection from './components/HeaderSection';
import Search from './components/Search';
import Filters from './components/Filters';
import Toggles from './components/Toggles';
import Pagination from './components/Pagination';

const useEnhancedEffect =
typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;

export default function RentalDashboard() {
const status = useScript(`https://unpkg.com/feather-icons`);

useEnhancedEffect(() => {
// Feather icon setup: https://github.com/feathericons/feather#4-replace
// @ts-ignore
if (typeof feather !== 'undefined') {
// @ts-ignore
feather.replace();
}
}, [status]);

return (
<CssVarsProvider disableTransitionOnChange>
<GlobalStyles
styles={(theme) => ({
'[data-feather], .feather': {
color: `var(--Icon-color, ${theme.vars.palette.text.icon})`,
margin: 'var(--Icon-margin)',
fontSize: `var(--Icon-fontSize, ${theme.vars.fontSize.xl})`,
width: '1em',
height: '1em',
},
})}
/>
<CssBaseline />
<Box sx={{ display: 'flex', minHeight: '100dvh' }}>
<Header />
<FirstSidebar />
<Main>
<Grid
container
sx={{
width: '100%',
height: '100dvh',
<NavBar />
<Box
component="main"
sx={{
height: 'calc(100vh - 55px)', // 55px is the height of the NavBar
display: 'grid',
gridTemplateColumns: { xs: 'auto', md: '60% 40%' },
gridTemplateRows: 'auto 1fr auto',
}}
>
<Stack
sx={{
backgroundColor: 'background.surface',
px: { xs: 2, md: 4 },
py: 2,
borderBottom: '1px solid',
borderColor: 'divider',
}}
>
<HeaderSection />
<Search />
</Stack>

<Box
sx={{
gridRow: 'span 3',
display: { xs: 'none', md: 'flex' },
backgroundColor: 'background.level1',
backgroundSize: 'cover',
backgroundImage:
'url("https://images.unsplash.com/photo-1569336415962-a4bd9f69cd83?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3731&q=80")',
}}
/>

<Stack spacing={2} sx={{ px: { xs: 2, md: 4 }, pt: 2, minHeight: 0 }}>
<Filters />
<Stack spacing={2} sx={{ overflow: 'auto' }}>
<RentalCard
title="A Stylish Apt, 5 min walk to Queen Victoria Market"
category="Entire apartment rental in Collingwood"
rareFind
image="https://images.unsplash.com/photo-1568605114967-8130f3a36994?auto=format&fit=crop&w=400"
/>
<RentalCard
title="Designer NY style loft"
category="Entire loft in central business district"
liked
image="https://images.unsplash.com/photo-1600596542815-ffad4c1539a9?auto=format&fit=crop&w=400"
/>
<RentalCard
title="5 minute walk from University of Melbourne"
category="Entire rental unit in Carlton"
image="https://images.unsplash.com/photo-1537726235470-8504e3beef77?auto=format&fit=crop&w=400"
/>
<RentalCard
title="Magnificent apartment next to public transport"
category="Entire apartment rental in Collingwood"
image="https://images.unsplash.com/photo-1618221195710-dd6b41faaea6?auto=format&fit=crop&w=400"
/>
<RentalCard
title="Next to shoppng mall and public transport"
category="Entire apartment rental in Collingwood"
image="https://images.unsplash.com/photo-1582268611958-ebfd161ef9cf?auto=format&fit=crop&w=400"
/>
<RentalCard
title="Endless ocean view"
category="A private room in a shared apartment in Docklands"
image="https://images.unsplash.com/photo-1564013799919-ab600027ffc6?auto=format&fit=crop&w=400"
/>
<RentalCard
title="A Stylish Apt, 5 min walk to Queen Victoria Market"
category="one bedroom apartment in Collingwood"
image="https://images.unsplash.com/photo-1481437156560-3205f6a55735?auto=format&fit=crop&w=400"
/>
</Stack>
</Stack>

margin: 0,
}}
>
<Grid
xs={12}
lg={8}
sx={{
overflowY: 'scroll',
height: '100%',
px: { xs: 2, md: 4 },
pt: { xs: 8, md: 4 },
pb: 5,
}}
>
<Stack spacing={2}>
<HeaderSection />
<Divider />
<Box
sx={{
width: '100%',
height: 360,
backgroundSize: 'cover',
backgroundImage:
'url("https://images.unsplash.com/photo-1478860409698-8707f313ee8b?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=4000&q=80")',
}}
display={{ xs: 'block', md: 'none' }}
/>
<Filters />
<Search />
<Toggles />
<RentalCard
title="A Stylish Apt, 5 min walk to Queen Victoria Market"
category="Entire apartment rental in Collingwood"
rareFind
image="https://images.unsplash.com/photo-1568605114967-8130f3a36994?auto=format&fit=crop&w=400"
/>
<RentalCard
title="Designer NY style loft"
category="Entire loft in central business district"
liked
image="https://images.unsplash.com/photo-1600596542815-ffad4c1539a9?auto=format&fit=crop&w=400"
/>
<RentalCard
title="5 minute walk from University of Melbourne"
category="Entire rental unit in Carlton"
image="https://images.unsplash.com/photo-1537726235470-8504e3beef77?auto=format&fit=crop&w=400"
/>
<RentalCard
title="Magnificent apartment next to public transport"
category="Entire apartment rental in Collingwood"
image="https://images.unsplash.com/photo-1618221195710-dd6b41faaea6?auto=format&fit=crop&w=400"
/>
<Divider />
<Pagination />
</Stack>
</Grid>
<Grid
xs={4}
sx={{
display: { xs: 'none', lg: 'block' },
}}
>
<Box
sx={{
borderLeft: '1px solid',
borderColor: 'divider',
padding: 1.5,
height: '100dvh',
}}
>
<Box
sx={{
backgroundColor: 'background.level1',
height: '100%',
borderRadius: 'sm',
backgroundSize: 'cover',
backgroundImage:
'url("https://images.unsplash.com/photo-1478860409698-8707f313ee8b?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=4000&q=80")',
}}
/>
</Box>
</Grid>
</Grid>
</Main>
<Pagination />
</Box>
</CssVarsProvider>
);
Expand Down
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>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ import Autocomplete from '@mui/joy/Autocomplete';
import AutocompleteOption from '@mui/joy/AutocompleteOption';
import AspectRatio from '@mui/joy/AspectRatio';
import FormControl, { FormControlProps } from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import Typography from '@mui/joy/Typography';

export default function ContrySelector({ sx, ...props }: FormControlProps) {
return (
<FormControl
{...props}
sx={[{ display: { sm: 'contents' } }, ...(Array.isArray(sx) ? sx : [sx])]}
>
<FormControl {...props} sx={sx}>
<FormLabel>Country</FormLabel>
<Autocomplete
aria-label="Country"
autoHighlight
isOptionEqualToValue={(option, value) => option.code === value.code}
defaultValue={{ code: 'US', label: 'United States', phone: '1' }}
defaultValue={{ code: 'AU', label: 'Australia', phone: '61' }}
options={countries}
renderOption={(optionProps, option) => (
<AutocompleteOption {...optionProps}>
Expand Down
Loading

0 comments on commit 6c70f79

Please sign in to comment.