-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(organizations): add wrapped mantine alert component TASK-1380 (#…
…5422) ### 📣 Summary Adds a wrapped mantine Alert component together with theming and storybook entry. ### 👀 Preview steps Compare the "demo" stories for `common/Alert` and `commonDeprecated/InlineMessage` in storybook.
- Loading branch information
1 parent
c933d13
commit e1a2910
Showing
6 changed files
with
136 additions
and
1 deletion.
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,28 @@ | ||
import Alert from './alert'; | ||
|
||
export default {title: 'common/Alert'}; | ||
|
||
export function Demo() { | ||
const message = | ||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam'; | ||
return ( | ||
<div> | ||
<Alert type='default'>{message}</Alert> | ||
<Alert iconName='alert' type='default'> | ||
{message} | ||
</Alert> | ||
<Alert iconName='alert' type='error'> | ||
{message} | ||
</Alert> | ||
<Alert iconName='alert' type='info'> | ||
{message} | ||
</Alert> | ||
<Alert iconName='alert' type='success'> | ||
{message} | ||
</Alert> | ||
<Alert iconName='alert' type='warning'> | ||
{message} | ||
</Alert> | ||
</div> | ||
); | ||
} |
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,24 @@ | ||
import {Alert as AlertMantine} from '@mantine/core'; | ||
import type {AlertProps as AlertPropsMantine} from '@mantine/core/lib/components'; | ||
import Icon from './icon'; | ||
import type {IconName} from 'jsapp/fonts/k-icons'; | ||
import {forwardRef} from 'react'; | ||
|
||
export type AlertType = 'default' | 'error' | 'success' | 'warning' | 'info'; | ||
|
||
// We only use the Mantine variant 'light', so we omit the prop here. | ||
// We also remove the color prop in favor of a custom 'type' prop, since we are setting | ||
// the component colors by hand instead of using Mantine's color handling | ||
export interface AlertProps extends Omit<AlertPropsMantine, 'icon' | 'variant' | 'color'> { | ||
iconName?: IconName; | ||
type: AlertType; | ||
} | ||
|
||
const Alert = forwardRef<HTMLDivElement, AlertProps>( | ||
({iconName, ...props}, ref) => { | ||
const icon = iconName ? <Icon name={iconName} size='m' /> : null; | ||
return <AlertMantine {...props} icon={icon} ref={ref} />; | ||
} | ||
); | ||
|
||
export default 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
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,16 @@ | ||
.root { | ||
padding: 12px 24px; | ||
|
||
&:not(:last-child) { | ||
margin-bottom: 24px; | ||
} | ||
|
||
&:not(:first-child) { | ||
margin-top: 24px; | ||
} | ||
} | ||
|
||
.message { | ||
font-size: var(--mantine-font-size-md); | ||
color: var(--mantine-color-gray-1); | ||
} |
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,39 @@ | ||
import {Alert} from '@mantine/core'; | ||
import classes from './Alert.module.css'; | ||
import {AlertType} from 'jsapp/js/components/common/alert'; | ||
|
||
declare module '@mantine/core' { | ||
export interface AlertProps { | ||
type: AlertType; | ||
} | ||
} | ||
|
||
export const AlertThemeKobo = Alert.extend({ | ||
classNames: classes, | ||
vars: (theme, props) => { | ||
return { | ||
root: { | ||
...(props.type === 'default' && { | ||
'--alert-bg': theme.colors.gray[7], | ||
'--alert-color': theme.colors.gray[4], | ||
}), | ||
...(props.type === 'error' && { | ||
'--alert-bg': theme.colors.red[9], | ||
'--alert-color': theme.colors.red[7], | ||
}), | ||
...(props.type === 'info' && { | ||
'--alert-bg': theme.colors.blue[9], | ||
'--alert-color': theme.colors.blue[6], | ||
}), | ||
...(props.type === 'success' && { | ||
'--alert-bg': theme.colors.teal[6], | ||
'--alert-color': theme.colors.teal[4], | ||
}), | ||
...(props.type === 'warning' && { | ||
'--alert-bg': theme.colors.amber[7], | ||
'--alert-color': theme.colors.amber[6], | ||
}), | ||
}, | ||
}; | ||
}, | ||
}); |
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