2023-01-11 18:42:18 +01:00
import React from 'react' ;
import { useState } from '@storybook/addons' ;
2023-02-02 21:15:26 +01:00
import { Size } from '../../../helpers/constants/design-system' ;
2023-01-11 18:42:18 +01:00
import { Icon , ICON _NAMES , ButtonLink , ButtonPrimary } from '..' ;
import { BannerBase } from './banner-base' ;
import README from './README.mdx' ;
const marginSizeControlOptions = [
undefined ,
0 ,
1 ,
2 ,
3 ,
4 ,
5 ,
6 ,
7 ,
8 ,
9 ,
10 ,
11 ,
12 ,
'auto' ,
] ;
export default {
title : 'Components/ComponentLibrary/BannerBase' ,
component : BannerBase ,
parameters : {
docs : {
page : README ,
} ,
backgrounds : { default : 'alternative' } ,
} ,
argTypes : {
className : {
control : 'text' ,
} ,
title : {
control : 'text' ,
} ,
2023-02-03 09:12:53 +01:00
description : {
control : 'text' ,
} ,
2023-01-11 18:42:18 +01:00
children : {
control : 'text' ,
} ,
action : {
control : 'func' ,
} ,
actionButtonLabel : {
control : 'text' ,
} ,
actionButtonOnClick : {
control : 'func' ,
} ,
actionButtonProps : {
control : 'object' ,
} ,
startAccessory : {
control : 'text' ,
} ,
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 ) => {
const onClose = ( ) => console . log ( 'BannerBase onClose trigger' ) ;
return < BannerBase { ... args } onClose = { onClose } / > ;
} ;
DefaultStory . args = {
title : 'Title is sentence case no period' ,
children : "Description shouldn't repeat title. 1-3 lines." ,
actionButtonLabel : 'Action' ,
2023-02-02 21:15:26 +01:00
startAccessory : < Icon name = { ICON _NAMES . INFO } size = { Size . LG } / > ,
2023-01-11 18:42:18 +01:00
} ;
DefaultStory . storyName = 'Default' ;
export const Title = ( args ) => {
return < BannerBase { ... args } / > ;
} ;
Title . args = {
title : 'Title is sentence case no period' ,
children : 'Pass only a string through the title prop' ,
} ;
2023-02-03 09:12:53 +01:00
export const Description = ( args ) => {
return < BannerBase { ... 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-11 18:42:18 +01:00
export const Children = ( args ) => {
return (
< BannerBase { ... args } >
{ ` Description shouldn't repeat title. 1-3 lines. Can contain a ` }
2023-02-03 09:12:53 +01:00
< ButtonLink
size = { Size . inherit }
href = "https://metamask.io/"
target = "_blank"
>
2023-01-11 18:42:18 +01:00
hyperlink .
< / B u t t o n L i n k >
< / B a n n e r B a s e >
) ;
} ;
export const ActionButton = ( args ) => {
return < BannerBase { ... args } / > ;
} ;
ActionButton . args = {
title : 'Action prop demo' ,
actionButtonLabel : 'Action' ,
actionButtonOnClick : ( ) => console . log ( 'ButtonLink actionButtonOnClick demo' ) ,
actionButtonProps : {
2023-02-22 18:42:06 +01:00
endIconName : ICON _NAMES . ARROW _2 _RIGHT ,
2023-01-11 18:42:18 +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 ) ;
const bannerToggle = ( ) => {
if ( isShown ) {
console . log ( 'close button clicked' ) ;
}
setShown ( ! isShown ) ;
} ;
return (
< >
{ isShown ? (
< BannerBase { ... args } onClose = { bannerToggle } / >
) : (
< ButtonPrimary onClick = { bannerToggle } > View BannerBase < / B u t t o n P r i m a r y >
) }
< / >
) ;
} ;
OnClose . args = {
title : 'onClose demo' ,
children : 'Click the close button icon to hide this notifcation' ,
} ;
export const StartAccessory = ( args ) => {
return < BannerBase { ... args } / > ;
} ;
StartAccessory . args = {
title : 'Start accessory demo' ,
children :
'The info icon on the left is passed through the startAccessory prop' ,
2023-02-02 21:15:26 +01:00
startAccessory : < Icon name = { ICON _NAMES . INFO } size = { Size . LG } / > ,
2023-01-11 18:42:18 +01:00
} ;