Skip to content

Commit

Permalink
[docs] Revise and expand Joy UI "Tutorial" doc (mui#34569)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelsycamore authored and alexfauquette committed Oct 14, 2022
1 parent 28bbc89 commit 4c8ba81
Show file tree
Hide file tree
Showing 2 changed files with 245 additions and 107 deletions.
96 changes: 96 additions & 0 deletions docs/data/joy/getting-started/tutorial/LoginFinal.js
@@ -0,0 +1,96 @@
import * as React from 'react';
import { CssVarsProvider, useColorScheme } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Typography from '@mui/joy/Typography';
import TextField from '@mui/joy/TextField';
import Button from '@mui/joy/Button';
import Link from '@mui/joy/Link';

const ModeToggle = () => {
const { mode, setMode } = useColorScheme();
const [mounted, setMounted] = React.useState(false);

// necessary for server-side rendering
// because mode is undefined on the server
React.useEffect(() => {
setMounted(true);
}, []);
if (!mounted) {
return null;
}

return (
<Button
variant="outlined"
onClick={() => {
if (mode === 'light') {
setMode('dark');
} else {
setMode('light');
}
}}
>
{mode === 'light' ? 'Turn dark' : 'Turn light'}
</Button>
);
};

export default function App() {
return (
<CssVarsProvider>
<main>
<ModeToggle />
<Sheet
sx={{
maxWidth: 400,
mx: 'auto', // margin left & right
my: 4, // margin top & botom
py: 3, // padding top & bottom
px: 2, // padding left & right
display: 'flex',
flexDirection: 'column',
gap: 2,
borderRadius: 'sm',
boxShadow: 'md',
}}
variant="outlined"
>
<div>
<Typography level="h4" component="h1">
<b>Welcome!</b>
</Typography>
<Typography level="body2">Sign in to continue.</Typography>
</div>
<TextField
// html input attribute
name="email"
type="email"
placeholder="johndoe@email.com"
// pass down to FormLabel as children
label="Email"
/>
<TextField
name="password"
type="password"
placeholder="password"
label="Password"
/>
<Button
sx={{
mt: 1, // margin top
}}
>
Log in
</Button>
<Typography
endDecorator={<Link href="/sign-up">Sign up</Link>}
fontSize="sm"
sx={{ alignSelf: 'center' }}
>
Don&apos;t have an account?
</Typography>
</Sheet>
</main>
</CssVarsProvider>
);
}

0 comments on commit 4c8ba81

Please sign in to comment.