-
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.
This PR cleans up the flash message implementation and adds documentation
- Loading branch information
1 parent
0dbb4cb
commit 93ecefa
Showing
5 changed files
with
145 additions
and
7 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,46 @@ | ||
import { createFlash } from './Flash/Flash.js'; | ||
import FlashDocs from './Flash/Flash.mdx'; | ||
|
||
export default { | ||
title: 'Components/Flash', | ||
argTypes: { | ||
label: { control: 'text' }, | ||
style: { | ||
control: { type: 'select' }, | ||
options: ['notice', 'info', 'alert', 'warning'], | ||
}, | ||
}, | ||
parameters: { | ||
docs: { | ||
page: FlashDocs | ||
}, | ||
}, | ||
}; | ||
|
||
const Template = ({ label, ...args }) => { | ||
return createFlash({ label, ...args }); | ||
}; | ||
|
||
export const Notice = Template.bind({}); | ||
Notice.args = { | ||
label: 'Success Message', | ||
style: 'notice', | ||
}; | ||
|
||
export const Info = Template.bind({}); | ||
Info.args = { | ||
label: 'Info Message', | ||
style: 'info', | ||
}; | ||
|
||
export const Alert = Template.bind({}); | ||
Alert.args = { | ||
label: 'Alert Message', | ||
style: 'alert', | ||
}; | ||
|
||
export const Warning = Template.bind({}); | ||
Warning.args = { | ||
label: 'Warning Message', | ||
style: 'warning', | ||
}; |
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,36 @@ | ||
import { createIcon } from '../Icon/Icon.js' | ||
|
||
const capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1) | ||
|
||
export const createFlash = ({ | ||
label, | ||
style = 'notice', | ||
}) => { | ||
const flash = document.createElement('div'); | ||
|
||
flash.className = [ | ||
'flash', | ||
'flash--demo', | ||
`flash--${style}`, | ||
].filter(Boolean).join(' ') | ||
|
||
const iconMapping = { | ||
'notice': 'check_circle', | ||
'info': 'info', | ||
'alert': 'cancel', | ||
'warning': 'warning', | ||
} | ||
|
||
flash.innerHTML += "\n " | ||
|
||
flash.appendChild(createIcon({ name: iconMapping[style], size: 'large' })) | ||
|
||
flash.innerHTML += ` | ||
<div> | ||
<div class='flash__message-type'>${capitalize(style)}</div> | ||
<div class='flash__message'>${label}</div> | ||
</div> | ||
` | ||
|
||
return flash | ||
} |
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 { Primary, ArgsTable, Canvas, Story } from "@storybook/addon-docs"; | ||
|
||
import imageFile from './flash.gif'; | ||
|
||
# Flash | ||
|
||
<img src={imageFile} alt='Flash' /> | ||
|
||
Flash classes provide notification style alert messages that "Flash" onto the screen (top right corner) with application information. | ||
|
||
**Note:** The `flash--demo` class that each example here uses is not intended to be used in a real application. It is only used here to allow for showing the flash messages in a static way. | ||
|
||
## Notice | ||
|
||
`.flash--notice` Provides a success styled message using the alert green color with a circle checkmark icon. | ||
|
||
<Canvas withToolbar> | ||
<Story id='components-flash--notice' /> | ||
</Canvas> | ||
|
||
## Info | ||
|
||
`.flash--info` Provides an info styled message using the alert blue color with a circle info icon. | ||
|
||
<Canvas withToolbar> | ||
<Story id='components-flash--info' /> | ||
</Canvas> | ||
|
||
## Alert | ||
|
||
`.flash--alert` Provides an alert styled message using the alert danger color with a circle cross icon. | ||
|
||
<Canvas withToolbar> | ||
<Story id='components-flash--alert' /> | ||
</Canvas> | ||
|
||
## Warning | ||
|
||
`.flash--warning` Provides an warning styled message using the alert warning color with a triangle exclamation icon. | ||
|
||
<Canvas withToolbar> | ||
<Story id='components-flash--warning' /> | ||
</Canvas> | ||
|
||
## Playground | ||
|
||
<Primary/> | ||
<ArgsTable of='.' story='^'/> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.