From b2d62f9cb819a2eb160e5d961800abcfff9ced84 Mon Sep 17 00:00:00 2001 From: Raphael Oliveira Date: Thu, 28 Mar 2019 14:24:03 -0300 Subject: [PATCH] feat(BTS-167): implements actionTrigger props and update SnackBarExample --- components/SnackBar/SnackBar.jsx | 42 +++++++++++++------ stories/SnackBar/examples/SnackBarExample.jsx | 13 +++++- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/components/SnackBar/SnackBar.jsx b/components/SnackBar/SnackBar.jsx index 2476c6a64..d12e2c876 100644 --- a/components/SnackBar/SnackBar.jsx +++ b/components/SnackBar/SnackBar.jsx @@ -47,6 +47,7 @@ const CloseIcon = styled(Button.Icon).attrs({ const ActionLink = styled.a` color: ${Colors.WHITE}; + cursor: pointer; font-weight: bold; padding: 13px 8px; text-decoration: underline; @@ -87,9 +88,14 @@ class SnackBar extends React.Component { } render() { - const _id = uniqId('snack-bar-dialog-'); - const { text, onClose, closeButtonAriaLabel, ...rest } = this.props; - + const _id = uniqId('snackbar-dialog-'); + const { + text, + onClose, + closeButtonAriaLabel, + actionTrigger, + ...rest + } = this.props; return ReactDOM.createPortal( @@ -101,15 +107,19 @@ class SnackBar extends React.Component { tabIndex="0" > {text} - - action - {onClose && ( - - )} - + {actionTrigger && ( + + + {actionTrigger.title} + + {onClose && ( + + )} + + )} @@ -122,6 +132,10 @@ class SnackBar extends React.Component { CloseIcon.displayName = 'CloseIcon'; SnackBar.propTypes = { + actionTrigger: PropTypes.shape({ + title: PropTypes.string, + callback: PropTypes.func, + }), closeButtonAriaLabel: PropTypes.string, onClose: PropTypes.func, secondsToClose: PropTypes.number, @@ -135,6 +149,10 @@ SnackBar.defaultProps = { secondsToClose: 6, skin: 'cobalt', text: 'Text of SnackBar component', + actionTrigger: { + title: 'ACTION', + callbackFn: () => {}, + }, }; export default SnackBar; diff --git a/stories/SnackBar/examples/SnackBarExample.jsx b/stories/SnackBar/examples/SnackBarExample.jsx index d512766ba..f3cbe5a44 100644 --- a/stories/SnackBar/examples/SnackBarExample.jsx +++ b/stories/SnackBar/examples/SnackBarExample.jsx @@ -15,14 +15,25 @@ class SnackBarExample extends React.Component { closeSnackBar = () => this.setState({ showSnackBar: false }); + actionCallback = () => this.closeSnackBar(); + render() { const { showSnackBar } = this.state; + const actions = { + title: 'HIDE', + callbackFn: this.actionCallback, + }; + return ( <> {showSnackBar && ( - + )} );