Last active
January 17, 2021 07:13
-
-
Save itaditya/06f84618587b37e4c10edbe2fd82e727 to your computer and use it in GitHub Desktop.
Scalable Props API structure
This file contains hidden or 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
const toastProps = { | |
purpose: 'alert', | |
variant: 'success', | |
isClosable: false, | |
onClose: handleClose, | |
root: { | |
'data-testId': 'root-wrapper', | |
}, | |
content: { | |
id: 'main-toast', | |
}, | |
primaryAction: { | |
icon: 'chevron-up', | |
children: ( | |
<span> | |
Expand | |
</span> | |
) | |
}, | |
}; | |
<Toast {...toastProps}> | |
Your order has been placed | |
</Toast> | |
function Toast(props) { | |
const { | |
purpose = 'status', | |
variant = 'neutral', | |
isClosable = true, | |
onClose = noop, | |
children, | |
root = {}, | |
content = {}, | |
primaryAction = {}, | |
} = props; | |
const contentCn = cn(styles.toastContent, content.className); | |
return ( | |
<div {...root} className={styles.toastRoot} data-variant={variant}> | |
<div {...content} className={contentCn} role={purpose}> | |
{children} | |
</div> | |
<div> | |
<Button {...primaryAction} /> | |
{ | |
isClosable && ( | |
<Button onClick={onClose}> | |
Dismiss | |
</Button> | |
) | |
} | |
</div> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment