Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Alert][joy] Add Alert component #33859

Merged
merged 32 commits into from Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2121e04
Add initial alert implementation
hbjORbj Aug 8, 2022
64ede21
Add initial demos
hbjORbj Aug 8, 2022
2118999
Run docs script
hbjORbj Aug 8, 2022
769bd06
change default rendering variant
danilo-leal Aug 9, 2022
fd664b7
tweaks to the component and demos
danilo-leal Aug 9, 2022
b8ff128
fix variants demo
danilo-leal Aug 9, 2022
6823d74
add longer dummy text
danilo-leal Aug 9, 2022
4bc6069
missing .tsx file as well
danilo-leal Aug 9, 2022
554a473
add action prop demo
danilo-leal Aug 9, 2022
47b19aa
small copywriting tweak to the a11y section
danilo-leal Aug 9, 2022
0255dd0
Run docs script
hbjORbj Aug 9, 2022
cf75e01
Change default value for variant to soft
hbjORbj Aug 9, 2022
bdf9d3f
Run proptypes doc
hbjORbj Aug 9, 2022
3c5d831
Alert is a feedback component, not data-display
hbjORbj Aug 9, 2022
4b9f7d4
Remove some props / change style / add css variables
hbjORbj Aug 25, 2022
24bb0e7
Delete demos with props no longer supported
hbjORbj Aug 25, 2022
a464331
Add more demos
hbjORbj Aug 25, 2022
c4e4d3d
Add common examples
hbjORbj Aug 25, 2022
64ed0ff
update variables
siriwatknp Aug 26, 2022
5ff20d3
simplify demos
siriwatknp Aug 26, 2022
e0ad1fc
Add component prop
hbjORbj Aug 26, 2022
679083c
Improve demos
hbjORbj Aug 26, 2022
80dd01f
Run docs script
hbjORbj Aug 26, 2022
b7421c9
update demo
siriwatknp Aug 26, 2022
4317232
Run docs script
hbjORbj Aug 28, 2022
58af723
update font-weight
siriwatknp Aug 29, 2022
29f3028
Address Jun's comments
hbjORbj Aug 29, 2022
aead935
Run docs script
hbjORbj Aug 29, 2022
e7f097e
Add tests
hbjORbj Aug 29, 2022
833a885
Fix typo
hbjORbj Aug 29, 2022
3fe0052
Allow string for variant prop
hbjORbj Aug 29, 2022
54f150b
Apply suggestions from code review
siriwatknp Aug 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
78 changes: 78 additions & 0 deletions docs/data/joy/components/alert/AlertColors.js
@@ -0,0 +1,78 @@
import Alert from '@mui/joy/Alert';
import Box from '@mui/joy/Box';
import Radio from '@mui/joy/Radio';
import RadioGroup from '@mui/joy/RadioGroup';
import Sheet from '@mui/joy/Sheet';

import Typography from '@mui/joy/Typography';
import * as React from 'react';

export default function AlertColors() {
const [variant, setVariant] = React.useState('solid');
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: 3,
}}
>
<Box
sx={{
display: 'grid',
gridTemplateColumns: 'repeat(3, minmax(150px, 1fr))',
gap: 1,
}}
>
<Alert variant={variant} color="primary">
Primary
</Alert>
<Alert variant={variant} color="neutral">
Neutral
</Alert>
<Alert variant={variant} color="danger">
Danger
</Alert>
<Alert variant={variant} color="info">
Info
</Alert>
<Alert variant={variant} color="success">
Success
</Alert>
<Alert variant={variant} color="warning">
Warning
</Alert>
</Box>
<Sheet
sx={{
background: 'transparent',
pl: 4,
borderLeft: '1px solid',
borderColor: 'divider',
}}
>
<Typography
level="body2"
fontWeight="xl"
id="variant-label"
textColor="text.primary"
mb={1}
>
Variant:
</Typography>
<RadioGroup
size="sm"
aria-labelledby="variant-label"
name="variant"
value={variant}
onChange={(event) => setVariant(event.target.value)}
>
<Radio label="Solid" value="solid" />
<Radio label="Soft" value="soft" />
<Radio label="Outlined" value="outlined" />
<Radio label="Plain" value="plain" />
</RadioGroup>
</Sheet>
</Box>
);
}
78 changes: 78 additions & 0 deletions docs/data/joy/components/alert/AlertColors.tsx
@@ -0,0 +1,78 @@
import Alert from '@mui/joy/Alert';
import Box from '@mui/joy/Box';
import Radio from '@mui/joy/Radio';
import RadioGroup from '@mui/joy/RadioGroup';
import Sheet from '@mui/joy/Sheet';
import { VariantProp } from '@mui/joy/styles';
import Typography from '@mui/joy/Typography';
import * as React from 'react';

export default function AlertColors() {
const [variant, setVariant] = React.useState<VariantProp>('solid');
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: 3,
}}
>
<Box
sx={{
display: 'grid',
gridTemplateColumns: 'repeat(3, minmax(150px, 1fr))',
gap: 1,
}}
>
<Alert variant={variant} color="primary">
Primary
</Alert>
<Alert variant={variant} color="neutral">
Neutral
</Alert>
<Alert variant={variant} color="danger">
Danger
</Alert>
<Alert variant={variant} color="info">
Info
</Alert>
<Alert variant={variant} color="success">
Success
</Alert>
<Alert variant={variant} color="warning">
Warning
</Alert>
</Box>
<Sheet
sx={{
background: 'transparent',
pl: 4,
borderLeft: '1px solid',
borderColor: 'divider',
}}
>
<Typography
level="body2"
fontWeight="xl"
id="variant-label"
textColor="text.primary"
mb={1}
>
Variant:
</Typography>
<RadioGroup
size="sm"
aria-labelledby="variant-label"
name="variant"
value={variant}
onChange={(event) => setVariant(event.target.value as VariantProp)}
>
<Radio label="Solid" value="solid" />
<Radio label="Soft" value="soft" />
<Radio label="Outlined" value="outlined" />
<Radio label="Plain" value="plain" />
</RadioGroup>
</Sheet>
</Box>
);
}
13 changes: 13 additions & 0 deletions docs/data/joy/components/alert/AlertSizes.js
@@ -0,0 +1,13 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';

export default function AlertSizes() {
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
<Alert size="sm">This is an alert in the small size.</Alert>
<Alert size="md">This is an alert in the medium size.</Alert>
<Alert size="lg">This is an alert in the large size.</Alert>
</Box>
);
}
13 changes: 13 additions & 0 deletions docs/data/joy/components/alert/AlertSizes.tsx
@@ -0,0 +1,13 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';

export default function AlertSizes() {
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
<Alert size="sm">This is an alert in the small size.</Alert>
<Alert size="md">This is an alert in the medium size.</Alert>
<Alert size="lg">This is an alert in the large size.</Alert>
</Box>
);
}
3 changes: 3 additions & 0 deletions docs/data/joy/components/alert/AlertSizes.tsx.preview
@@ -0,0 +1,3 @@
<Alert size="sm">This is an alert in the small size.</Alert>
<Alert size="md">This is an alert in the medium size.</Alert>
<Alert size="lg">This is an alert in the large size.</Alert>
33 changes: 33 additions & 0 deletions docs/data/joy/components/alert/AlertUsage.js
@@ -0,0 +1,33 @@
import * as React from 'react';
import Alert from '@mui/joy/Alert';
import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo';

export default function AlertUsage() {
return (
<JoyUsageDemo
componentName="Alert"
data={[
{
propName: 'variant',
knob: 'select',
defaultValue: 'soft',
options: ['plain', 'outlined', 'soft', 'solid'],
},
{
propName: 'color',
knob: 'color',
defaultValue: 'primary',
},
{
propName: 'size',
knob: 'radio',
options: ['sm', 'md', 'lg'],
defaultValue: 'md',
},
]}
renderDemo={(props) => (
<Alert {...props}>This is a Joy UI alert — check it out!</Alert>
)}
/>
);
}
14 changes: 14 additions & 0 deletions docs/data/joy/components/alert/AlertVariants.js
@@ -0,0 +1,14 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';

export default function AlertVariants() {
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
<Alert variant="solid">This is an alert using the solid variant.</Alert>
<Alert variant="soft">This is an alert using the soft variant.</Alert>
<Alert variant="outlined">This is an alert using the outlined variant.</Alert>
<Alert variant="plain">This is an alert using the plain variant.</Alert>
</Box>
);
}
14 changes: 14 additions & 0 deletions docs/data/joy/components/alert/AlertVariants.tsx
@@ -0,0 +1,14 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';

export default function AlertVariants() {
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
<Alert variant="solid">This is an alert using the solid variant.</Alert>
<Alert variant="soft">This is an alert using the soft variant.</Alert>
<Alert variant="outlined">This is an alert using the outlined variant.</Alert>
<Alert variant="plain">This is an alert using the plain variant.</Alert>
</Box>
);
}
4 changes: 4 additions & 0 deletions docs/data/joy/components/alert/AlertVariants.tsx.preview
@@ -0,0 +1,4 @@
<Alert variant="solid">This is an alert using the solid variant.</Alert>
<Alert variant="soft">This is an alert using the soft variant.</Alert>
<Alert variant="outlined">This is an alert using the outlined variant.</Alert>
<Alert variant="plain">This is an alert using the plain variant.</Alert>
50 changes: 50 additions & 0 deletions docs/data/joy/components/alert/AlertVariousStates.js
@@ -0,0 +1,50 @@
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' }}
startDecorator={React.cloneElement(icon, {
sx: { mt: '2px', mx: '4px' },
fontSize: 'xl2',
})}
variant="soft"
color={color}
endDecorator={
<IconButton variant="soft" size="sm" color={color}>
<CloseRoundedIcon />
</IconButton>
}
>
<div>
<Typography fontWeight="lg" mt={0.25}>
{title}
</Typography>
<Typography fontSize="sm" sx={{ opacity: 0.8 }}>
This is a {title} message.
</Typography>
</div>
</Alert>
))}
</Box>
);
}
54 changes: 54 additions & 0 deletions docs/data/joy/components/alert/AlertVariousStates.tsx
@@ -0,0 +1,54 @@
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' }}
startDecorator={React.cloneElement(icon, {
sx: { mt: '2px', mx: '4px' },
fontSize: 'xl2',
})}
variant="soft"
color={color}
endDecorator={
<IconButton variant="soft" size="sm" color={color}>
<CloseRoundedIcon />
</IconButton>
}
>
<div>
<Typography fontWeight="lg" mt={0.25}>
{title}
</Typography>
<Typography fontSize="sm" sx={{ opacity: 0.8 }}>
This is a {title} message.
</Typography>
</div>
</Alert>
))}
</Box>
);
}