-
Notifications
You must be signed in to change notification settings - Fork 6
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 #580 from open-formulieren/feature/467-alert-refactor
[#467] Alert refactor
- Loading branch information
Showing
39 changed files
with
303 additions
and
147 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
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
Submodule design-tokens
updated
4 files
+2 −2 | package-lock.json | |
+1 −1 | package.json | |
+56 −0 | src/community/utrecht/alert.tokens.json | |
+0 −18 | src/components/alert.tokens.json |
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
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 was deleted.
Oops, something went wrong.
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,32 @@ | ||
import {Alert} from '@utrecht/component-library-react'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
import useScrollIntoView from 'hooks/useScrollIntoView'; | ||
|
||
const ICONS = { | ||
error: <i className="fa fas fa-exclamation-circle" />, | ||
info: <i className="fa fas fa-info-circle" />, | ||
warning: <i className="fa fas fa-exclamation-triangle" />, | ||
ok: <i className="fa fas fa-check-circle" />, | ||
}; | ||
|
||
const ALERT_MODIFIERS = ['info', 'warning', 'error', 'ok']; | ||
|
||
const ErrorMessage = ({children, modifier = 'error'}) => { | ||
const errorRef = useScrollIntoView(); | ||
if (!children) return null; | ||
return ( | ||
<Alert type={modifier} icon={ICONS[modifier]} ref={errorRef}> | ||
{children} | ||
</Alert> | ||
); | ||
}; | ||
|
||
ErrorMessage.propTypes = { | ||
children: PropTypes.node, | ||
modifier: PropTypes.oneOf(ALERT_MODIFIERS), | ||
}; | ||
|
||
export {ALERT_MODIFIERS}; | ||
export default ErrorMessage; |
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,21 @@ | ||
import {ArgTypes, Canvas, Meta, Story} from '@storybook/blocks'; | ||
|
||
import * as ErrorsStories from './Errors.stories'; | ||
|
||
<Meta of={ErrorsStories} /> | ||
|
||
# Error Message | ||
|
||
The error message component uses the | ||
[Utrecht Alert component](https://nl-design-system.github.io/utrecht/storybook/?path=/docs/react_react-alert--docs). | ||
|
||
<Canvas> | ||
<Story of={ErrorsStories.ErrorMessageOkStory} /> | ||
<Story of={ErrorsStories.ErrorMessageInfoStory} /> | ||
<Story of={ErrorsStories.ErrorMessageErrorStory} /> | ||
<Story of={ErrorsStories.ErrorMessageWarningStory} /> | ||
</Canvas> | ||
|
||
## Props | ||
|
||
<ArgTypes of={ErrorsStories} /> |
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,48 @@ | ||
import ErrorMessage from './ErrorMessage'; | ||
import {ALERT_MODIFIERS} from './ErrorMessage'; | ||
|
||
export default { | ||
title: 'Private API / Error Message', | ||
render: ({message, modifier}) => <ErrorMessage modifier={modifier}>{message}</ErrorMessage>, | ||
argTypes: { | ||
modifier: { | ||
options: ALERT_MODIFIERS, | ||
control: { | ||
type: 'radio', | ||
}, | ||
}, | ||
children: {control: false}, | ||
}, | ||
}; | ||
|
||
export const ErrorMessageErrorStory = { | ||
name: 'Error Message', | ||
args: { | ||
modifier: 'error', | ||
message: 'Sadness, something went wrong.', | ||
}, | ||
}; | ||
|
||
export const ErrorMessageOkStory = { | ||
name: 'Ok Message', | ||
args: { | ||
modifier: 'ok', | ||
message: 'Something went OK.', | ||
}, | ||
}; | ||
|
||
export const ErrorMessageInfoStory = { | ||
name: 'Info Message', | ||
args: { | ||
modifier: 'info', | ||
message: 'This is an info!', | ||
}, | ||
}; | ||
|
||
export const ErrorMessageWarningStory = { | ||
name: 'Warning Message', | ||
args: { | ||
modifier: 'warning', | ||
message: 'You are being warned.', | ||
}, | ||
}; |
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
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
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
Oops, something went wrong.