-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from hivemq/feature/alert-types
Feature / Add alerts to theme
- Loading branch information
Showing
7 changed files
with
246 additions
and
29 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
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,43 @@ | ||
import { | ||
Alert, | ||
AlertDescription, | ||
AlertIcon, | ||
AlertTitle, | ||
Box, | ||
HStack, | ||
Heading, | ||
} from '@chakra-ui/react' | ||
|
||
export function Alerts() { | ||
const variants: Array<'success' | 'error' | 'warning' | 'info'> = [ | ||
'success', | ||
'error', | ||
'warning', | ||
'info', | ||
] | ||
|
||
return ( | ||
<> | ||
<HStack width="100%" gap={8} alignItems="start"> | ||
{variants.map((variant) => { | ||
return ( | ||
<Box key={variant} p={2}> | ||
<Heading variant="h2" mb={2}> | ||
{variant.charAt(0).toUpperCase() + variant.slice(1)} | ||
</Heading> | ||
<Alert variant={variant} status={variant}> | ||
<AlertIcon /> | ||
<Box flex="1"> | ||
<AlertTitle> | ||
{variant.charAt(0).toUpperCase() + variant.slice(1)} Alert | ||
</AlertTitle> | ||
<AlertDescription>This is a {variant} alert.</AlertDescription> | ||
</Box> | ||
</Alert> | ||
</Box> | ||
) | ||
})} | ||
</HStack> | ||
</> | ||
) | ||
} |
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
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
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,156 @@ | ||
import { alertAnatomy } from '@chakra-ui/anatomy' | ||
import { createMultiStyleConfigHelpers } from '@chakra-ui/react' | ||
|
||
const { definePartsStyle, defineMultiStyleConfig } = createMultiStyleConfigHelpers( | ||
alertAnatomy.keys, | ||
) | ||
|
||
const success = definePartsStyle({ | ||
container: { | ||
background: 'background.bg-success.light', | ||
borderColor: 'border.border-success-strong.light', | ||
color: 'text.text-success.light', | ||
_dark: { | ||
background: 'background.bg-success.dark', | ||
borderColor: 'border.border-success-strong.dark', | ||
color: 'text.text-success.dark', | ||
}, | ||
}, | ||
icon: { | ||
color: 'icon.icon-success.light', | ||
_dark: { | ||
color: 'icon.icon-success.dark', | ||
}, | ||
}, | ||
title: { | ||
fontWeight: 'bold', | ||
}, | ||
description: { | ||
color: 'text.text-success.light', | ||
_dark: { | ||
color: 'text.text-success.dark', | ||
}, | ||
}, | ||
}) | ||
|
||
const error = definePartsStyle({ | ||
container: { | ||
background: 'background.bg-error.light', | ||
borderColor: 'border.border-error-strong.light', | ||
color: 'text.text-error.light', | ||
_dark: { | ||
background: 'background.bg-error.dark', | ||
borderColor: 'border.border-error-strong.dark', | ||
color: 'text.text-error.dark', | ||
}, | ||
}, | ||
icon: { | ||
color: 'icon.icon-error.light', | ||
_dark: { | ||
color: 'icon.icon-error.dark', | ||
}, | ||
}, | ||
title: { | ||
fontWeight: 'bold', | ||
}, | ||
description: { | ||
color: 'text.text-error.light', | ||
_dark: { | ||
color: 'text.text-error.dark', | ||
}, | ||
}, | ||
}) | ||
|
||
const warning = definePartsStyle({ | ||
container: { | ||
background: 'background.bg-warning.light', | ||
borderColor: 'border.border-warning-strong.light', | ||
color: 'text.text-warning.light', | ||
_dark: { | ||
background: 'background.bg-warning.dark', | ||
borderColor: 'border.border-warning-strong.dark', | ||
color: 'text.text-warning.dark', | ||
}, | ||
}, | ||
icon: { | ||
color: 'icon.icon-warning.light', | ||
_dark: { | ||
color: 'icon.icon-warning.dark', | ||
}, | ||
}, | ||
title: { | ||
fontWeight: 'bold', | ||
}, | ||
description: { | ||
color: 'text.text-warning.light', | ||
_dark: { | ||
color: 'text.text-warning.dark', | ||
}, | ||
}, | ||
}) | ||
|
||
const info = definePartsStyle({ | ||
container: { | ||
background: 'background.bg-info.light', | ||
borderColor: 'border.border-info-strong.light', | ||
color: 'text.text-info.light', | ||
_dark: { | ||
background: 'background.bg-info.dark', | ||
borderColor: 'border.border-info-strong.dark', | ||
color: 'text.text-info.dark', | ||
}, | ||
}, | ||
icon: { | ||
color: 'icon.icon-info.light', | ||
_dark: { | ||
color: 'icon.icon-info.dark', | ||
}, | ||
}, | ||
title: { | ||
fontWeight: 'bold', | ||
}, | ||
description: { | ||
color: 'text.text-info.light', | ||
_dark: { | ||
color: 'text.text-info.dark', | ||
}, | ||
}, | ||
}) | ||
|
||
const variants = { | ||
success, | ||
error, | ||
warning, | ||
info, | ||
} | ||
|
||
const baseStyle = definePartsStyle({ | ||
container: { | ||
borderRadius: 'md', | ||
borderWidth: '1px', | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: '0.5rem', | ||
padding: '1rem', | ||
}, | ||
icon: { | ||
marginRight: '0.5rem', | ||
width: '24px', | ||
}, | ||
title: { | ||
marginRight: '0.5rem', | ||
fontWeight: 'bold', | ||
}, | ||
description: { | ||
flex: 1, | ||
}, | ||
}) | ||
|
||
export const alertTheme = defineMultiStyleConfig({ | ||
baseStyle, | ||
variants, | ||
defaultProps: { | ||
variant: 'info', | ||
size: 'md', | ||
}, | ||
}) |
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
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