Skip to content

Instantly share code, notes, and snippets.

@itaditya
Last active January 17, 2021 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itaditya/06f84618587b37e4c10edbe2fd82e727 to your computer and use it in GitHub Desktop.
Save itaditya/06f84618587b37e4c10edbe2fd82e727 to your computer and use it in GitHub Desktop.
Scalable Props API structure
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