2023-01-25 19:39:49 +01:00
import React from 'react' ;
import { useState } from '@storybook/addons' ;
import {
DISPLAY ,
FLEX _DIRECTION ,
SEVERITIES ,
2023-02-02 21:15:26 +01:00
Size ,
2023-01-25 19:39:49 +01:00
} from '../../../helpers/constants/design-system' ;
import Box from '../../ui/box/box' ;
2023-04-05 18:11:10 +02:00
import { ButtonLink , ButtonPrimary , IconName } from '..' ;
2023-01-25 19:39:49 +01:00
import README from './README.mdx' ;
2023-02-07 18:32:35 +01:00
import { BannerAlert , BANNER _ALERT _SEVERITIES } from '.' ;
2023-01-25 19:39:49 +01:00
const marginSizeControlOptions = [
undefined ,
0 ,
1 ,
2 ,
3 ,
4 ,
5 ,
6 ,
7 ,
8 ,
9 ,
10 ,
11 ,
12 ,
'auto' ,
] ;
export default {
2023-02-07 18:32:35 +01:00
title : 'Components/ComponentLibrary/BannerAlert' ,
component : BannerAlert ,
2023-01-25 19:39:49 +01:00
parameters : {
docs : {
page : README ,
} ,
backgrounds : { default : 'alternative' } ,
} ,
argTypes : {
severity : {
2023-02-07 18:32:35 +01:00
options : Object . values ( BANNER _ALERT _SEVERITIES ) ,
2023-01-25 19:39:49 +01:00
control : 'select' ,
} ,
className : {
control : 'text' ,
} ,
title : {
control : 'text' ,
} ,
2023-02-07 18:32:35 +01:00
description : {
control : 'text' ,
} ,
2023-01-25 19:39:49 +01:00
children : {
control : 'text' ,
} ,
action : {
control : 'func' ,
} ,
actionButtonLabel : {
control : 'text' ,
} ,
actionButtonOnClick : {
control : 'func' ,
} ,
actionButtonProps : {
control : 'object' ,
} ,
onClose : {
action : 'onClose' ,
} ,
marginTop : {
options : marginSizeControlOptions ,
control : 'select' ,
table : { category : 'box props' } ,
} ,
marginRight : {
options : marginSizeControlOptions ,
control : 'select' ,
table : { category : 'box props' } ,
} ,
marginBottom : {
options : marginSizeControlOptions ,
control : 'select' ,
table : { category : 'box props' } ,
} ,
marginLeft : {
options : marginSizeControlOptions ,
control : 'select' ,
table : { category : 'box props' } ,
} ,
} ,
} ;
export const DefaultStory = ( args ) => {
2023-02-07 18:32:35 +01:00
const onClose = ( ) => console . log ( 'BannerAlert onClose trigger' ) ;
return < BannerAlert { ... args } onClose = { onClose } / > ;
2023-01-25 19:39:49 +01:00
} ;
DefaultStory . args = {
title : 'Title is sentence case no period' ,
children : "Description shouldn't repeat title. 1-3 lines." ,
actionButtonLabel : 'Action' ,
} ;
DefaultStory . storyName = 'Default' ;
export const Severity = ( args ) => {
return (
< Box display = { DISPLAY . FLEX } flexDirection = { FLEX _DIRECTION . COLUMN } gap = { 3 } >
2023-02-07 18:32:35 +01:00
< BannerAlert { ... args } severity = { SEVERITIES . INFO } title = "Info" >
2023-01-25 19:39:49 +01:00
This is a demo of severity Info .
2023-02-07 18:32:35 +01:00
< / B a n n e r A l e r t >
< BannerAlert { ... args } severity = { SEVERITIES . WARNING } title = "Warning" >
2023-01-25 19:39:49 +01:00
This is a demo of severity Warning .
2023-02-07 18:32:35 +01:00
< / B a n n e r A l e r t >
< BannerAlert { ... args } severity = { SEVERITIES . DANGER } title = "Danger" >
2023-01-25 19:39:49 +01:00
This is a demo of severity Danger .
2023-02-07 18:32:35 +01:00
< / B a n n e r A l e r t >
< BannerAlert { ... args } severity = { SEVERITIES . SUCCESS } title = "Success" >
2023-01-25 19:39:49 +01:00
This is a demo of severity Success .
2023-02-07 18:32:35 +01:00
< / B a n n e r A l e r t >
2023-01-25 19:39:49 +01:00
< / B o x >
) ;
} ;
export const Title = ( args ) => {
2023-02-07 18:32:35 +01:00
return < BannerAlert { ... args } / > ;
2023-01-25 19:39:49 +01:00
} ;
Title . args = {
title : 'Title is sentence case no period' ,
children : 'Pass only a string through the title prop' ,
} ;
2023-02-07 18:32:35 +01:00
export const Description = ( args ) => {
return < BannerAlert { ... args } / > ;
} ;
Description . args = {
title : 'Description vs children' ,
description :
'Pass only a string through the description prop or you can use children if the contents require more' ,
} ;
2023-01-25 19:39:49 +01:00
export const Children = ( args ) => {
return (
2023-02-07 18:32:35 +01:00
< BannerAlert { ... args } >
2023-01-25 19:39:49 +01:00
{ ` Description shouldn't repeat title. 1-3 lines. Can contain a ` }
2023-02-02 21:15:26 +01:00
< ButtonLink size = { Size . auto } href = "https://metamask.io/" target = "_blank" >
2023-01-25 19:39:49 +01:00
hyperlink .
< / B u t t o n L i n k >
2023-02-07 18:32:35 +01:00
< / B a n n e r A l e r t >
2023-01-25 19:39:49 +01:00
) ;
} ;
export const ActionButton = ( args ) => {
2023-02-07 18:32:35 +01:00
return < BannerAlert { ... args } / > ;
2023-01-25 19:39:49 +01:00
} ;
ActionButton . args = {
title : 'Action prop demo' ,
actionButtonLabel : 'Action' ,
actionButtonOnClick : ( ) => console . log ( 'ButtonLink actionButtonOnClick demo' ) ,
actionButtonProps : {
2023-04-05 18:11:10 +02:00
endIconName : IconName . Arrow2Right ,
2023-01-25 19:39:49 +01:00
} ,
children :
'Use actionButtonLabel for action text, actionButtonOnClick for the onClick handler, and actionButtonProps to pass any ButtonLink prop types such as iconName' ,
} ;
export const OnClose = ( args ) => {
const [ isShown , setShown ] = useState ( true ) ;
2023-02-07 18:32:35 +01:00
const bannerAlertToggle = ( ) => {
2023-01-25 19:39:49 +01:00
if ( isShown ) {
console . log ( 'close button clicked' ) ;
}
setShown ( ! isShown ) ;
} ;
return (
< >
{ isShown ? (
2023-02-07 18:32:35 +01:00
< BannerAlert { ... args } onClose = { bannerAlertToggle } / >
2023-01-25 19:39:49 +01:00
) : (
2023-02-07 18:32:35 +01:00
< ButtonPrimary onClick = { bannerAlertToggle } >
View BannerAlert
< / B u t t o n P r i m a r y >
2023-01-25 19:39:49 +01:00
) }
< / >
) ;
} ;
OnClose . args = {
title : 'onClose demo' ,
children : 'Click the close button icon to hide this notifcation' ,
} ;