Skip to content

Commit

Permalink
Add common examples
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjORbj committed Aug 25, 2022
1 parent 7b38b59 commit 4d8e0f3
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 3 deletions.
12 changes: 9 additions & 3 deletions docs/data/joy/components/alert/AlertSizes.tsx.preview
@@ -1,3 +1,9 @@
<Alert size="sm" startDecorator={<AddShoppingCartIcon/>}>This is an alert in the small size.</Alert>
<Alert size="md" startDecorator={<AddShoppingCartIcon/>}>This is an alert in the medium size.</Alert>
<Alert size="lg" startDecorator={<AddShoppingCartIcon/>}>This is an alert in the large size.</Alert>
<Alert size="sm" startDecorator={<AddShoppingCartIcon />}>
This is an alert in the small size.
</Alert>
<Alert size="md" startDecorator={<AddShoppingCartIcon />}>
This is an alert in the medium size.
</Alert>
<Alert size="lg" startDecorator={<AddShoppingCartIcon />}>
This is an alert in the large size.
</Alert>
47 changes: 47 additions & 0 deletions docs/data/joy/components/alert/AlertVariousStates.js
@@ -0,0 +1,47 @@
import InfoIcon from '@mui/icons-material/Info';
import WarningIcon from '@mui/icons-material/Warning';
import ReportIcon from '@mui/icons-material/Report';
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
import IconButton from '@mui/joy/IconButton';
import Typography from '@mui/joy/Typography';

export default function AlertVariousStates() {
const items = [
{ title: 'Success', color: 'success', icon: <CheckCircleIcon /> },
{ title: 'Warning', color: 'warning', icon: <WarningIcon /> },
{ title: 'Error', color: 'danger', icon: <ReportIcon /> },
{ title: 'Info', color: 'info', icon: <InfoIcon /> },
];

return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
{items.map(({ title, color, icon }) => (
<Alert
key={title}
sx={{ alignItems: 'flex-start', pt: 0.5 }}
startDecorator={
<IconButton variant="soft" size="sm" color={color}>
{icon}
</IconButton>
}
variant="soft"
color={color}
endDecorator={
<IconButton variant="soft" size="sm" color={color}>
<CloseRoundedIcon />
</IconButton>
}
>
<Box sx={{ display: 'flex', flexDirection: 'column', pt: 0.5, pb: 1 }}>
<Typography fontWeight="lg">{title}</Typography>
<Typography fontSize="sm">{`${title} message.`}</Typography>
</Box>
</Alert>
))}
</Box>
);
}
51 changes: 51 additions & 0 deletions docs/data/joy/components/alert/AlertVariousStates.tsx
@@ -0,0 +1,51 @@
import InfoIcon from '@mui/icons-material/Info';
import WarningIcon from '@mui/icons-material/Warning';
import ReportIcon from '@mui/icons-material/Report';
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
import IconButton from '@mui/joy/IconButton';
import Typography from '@mui/joy/Typography';
import { ColorPaletteProp } from '@mui/joy/styles';

export default function AlertVariousStates() {
const items: {
title: string;
color: ColorPaletteProp;
icon: React.ReactElement;
}[] = [
{ title: 'Success', color: 'success', icon: <CheckCircleIcon /> },
{ title: 'Warning', color: 'warning', icon: <WarningIcon /> },
{ title: 'Error', color: 'danger', icon: <ReportIcon /> },
{ title: 'Info', color: 'info', icon: <InfoIcon /> },
];
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
{items.map(({ title, color, icon }) => (
<Alert
key={title}
sx={{ alignItems: 'flex-start', pt: 0.5 }}
startDecorator={
<IconButton variant="soft" size="sm" color={color}>
{icon}
</IconButton>
}
variant="soft"
color={color}
endDecorator={
<IconButton variant="soft" size="sm" color={color}>
<CloseRoundedIcon />
</IconButton>
}
>
<Box sx={{ display: 'flex', flexDirection: 'column', pt: 0.5, pb: 1 }}>
<Typography fontWeight="lg">{title}</Typography>
<Typography fontSize="sm">{`${title} message.`}</Typography>
</Box>
</Alert>
))}
</Box>
);
}
85 changes: 85 additions & 0 deletions docs/data/joy/components/alert/AlertWithDangerState.js
@@ -0,0 +1,85 @@
import WarningIcon from '@mui/icons-material/Warning';
import CloseIcon from '@mui/icons-material/Close';
import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
import IconButton from '@mui/joy/IconButton';
import Typography from '@mui/joy/Typography';
import Button from '@mui/joy/Button';

export default function AlertWithDangerState() {
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
<Alert
startDecorator={
<IconButton variant="soft" size="sm" color="danger">
<WarningIcon />
</IconButton>
}
variant="soft"
color="danger"
endDecorator={
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Button variant="soft" color="danger" sx={{ mr: 1 }} fontWeight="md">
Undo
</Button>
<IconButton variant="soft" size="sm" color="danger">
<CloseIcon />
</IconButton>
</Box>
}
>
<Typography color="danger" fontWeight="md">
This file was successfully deleted
</Typography>
</Alert>
<Alert
startDecorator={
<IconButton variant="solid" size="sm" color="danger">
<WarningIcon />
</IconButton>
}
variant="solid"
color="danger"
endDecorator={
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Button variant="solid" color="danger" sx={{ mr: 1 }} fontWeight="md">
Undo
</Button>
<IconButton variant="solid" size="sm" color="danger">
<CloseIcon />
</IconButton>
</Box>
}
>
<Typography sx={{ color: 'white' }} fontWeight="md">
This file was successfully deleted
</Typography>
</Alert>

<Alert
startDecorator={
<IconButton variant="plain" size="sm" color="danger">
<WarningIcon />
</IconButton>
}
variant="outlined"
color="danger"
endDecorator={
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Button variant="plain" color="danger" sx={{ mr: 1 }} fontWeight="md">
Undo
</Button>
<IconButton variant="solid" size="sm" color="danger">
<CloseIcon />
</IconButton>
</Box>
}
>
<Typography color="danger" fontWeight="md">
This file was successfully deleted
</Typography>
</Alert>
</Box>
);
}
85 changes: 85 additions & 0 deletions docs/data/joy/components/alert/AlertWithDangerState.tsx
@@ -0,0 +1,85 @@
import WarningIcon from '@mui/icons-material/Warning';
import CloseIcon from '@mui/icons-material/Close';
import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
import IconButton from '@mui/joy/IconButton';
import Typography from '@mui/joy/Typography';
import Button from '@mui/joy/Button';

export default function AlertWithDangerState() {
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
<Alert
startDecorator={
<IconButton variant="soft" size="sm" color="danger">
<WarningIcon />
</IconButton>
}
variant="soft"
color="danger"
endDecorator={
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Button variant="soft" color="danger" sx={{ mr: 1 }} fontWeight="md">
Undo
</Button>
<IconButton variant="soft" size="sm" color="danger">
<CloseIcon />
</IconButton>
</Box>
}
>
<Typography color="danger" fontWeight="md">
This file was successfully deleted
</Typography>
</Alert>
<Alert
startDecorator={
<IconButton variant="solid" size="sm" color="danger">
<WarningIcon />
</IconButton>
}
variant="solid"
color="danger"
endDecorator={
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Button variant="solid" color="danger" sx={{ mr: 1 }} fontWeight="md">
Undo
</Button>
<IconButton variant="solid" size="sm" color="danger">
<CloseIcon />
</IconButton>
</Box>
}
>
<Typography sx={{ color: 'white' }} fontWeight="md">
This file was successfully deleted
</Typography>
</Alert>

<Alert
startDecorator={
<IconButton variant="plain" size="sm" color="danger">
<WarningIcon />
</IconButton>
}
variant="outlined"
color="danger"
endDecorator={
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Button variant="plain" color="danger" sx={{ mr: 1 }} fontWeight="md">
Undo
</Button>
<IconButton variant="solid" size="sm" color="danger">
<CloseIcon />
</IconButton>
</Box>
}
>
<Typography color="danger" fontWeight="md">
This file was successfully deleted
</Typography>
</Alert>
</Box>
);
}
10 changes: 10 additions & 0 deletions docs/data/joy/components/alert/alert.md
Expand Up @@ -52,6 +52,16 @@ Use the `startDecorator` and/or `endDecorator` props to insert actionable button

{{"demo": "AlertWithDecorators.js"}}

## Common examples

### Various states

{{"demo": "AlertVariousStates.js"}}

### Danger alerts

{{"demo": "AlertWithDangerState.js"}}

## Accessibility

Here are a few tips to make sure you have an accessible alert component:
Expand Down

0 comments on commit 4d8e0f3

Please sign in to comment.