-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Alert][joy] Add
Alert
component (#33859)
- Loading branch information
Showing
27 changed files
with
1,152 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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> | ||
); | ||
} |
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 |
---|---|---|
@@ -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> | ||
); | ||
} |
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 |
---|---|---|
@@ -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> | ||
); | ||
} |
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 |
---|---|---|
@@ -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> | ||
); | ||
} |
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 |
---|---|---|
@@ -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> |
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 |
---|---|---|
@@ -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> | ||
)} | ||
/> | ||
); | ||
} |
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 |
---|---|---|
@@ -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> | ||
); | ||
} |
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 |
---|---|---|
@@ -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> | ||
); | ||
} |
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 |
---|---|---|
@@ -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> |
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 |
---|---|---|
@@ -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> | ||
); | ||
} |
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 |
---|---|---|
@@ -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> | ||
); | ||
} |
Oops, something went wrong.