Skip to content
Merged

Toast #116

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Alert/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import useEventListener from '../hooks/useEventListener';
const Alert = ({ onOpen, onClose, className, children, onDismiss, onSubmit, ...rest }) => {
const hxRef = useEventListener({ onDismiss, onSubmit });
return (
<>
<div>
Copy link
Contributor Author

@nicko-winner nicko-winner Oct 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noticed <> elements don't fix the disappearing react element error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicko-winner, sorry what's this error again? Does the <> cause the error on render?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error happens after helix removes the element from the DOM (by clicking dismiss), and you change pages in storybook. This is the error:
2020-10-16_16-48-23

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks for the explanation. This helps alot. 👍

{/* Wrappping element needed: Otherwise when alert removes itself from DOM on close, it will cause error */}
<hx-alert class={className} ref={hxRef} {...rest}>
{children}
</hx-alert>
</>
</div>
);
};

Expand Down
26 changes: 26 additions & 0 deletions src/Toast/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import PropTypes from 'prop-types';
import useEventListener from '../hooks/useEventListener';

const Toast = ({ onOpen, onClose, className, children, onDismiss, onSubmit, ...rest }) => {
const hxRef = useEventListener({ onDismiss, onSubmit });
return (
<div>
{/* Wrapping element needed: Otherwise when alert removes itself from DOM on close, it will cause error */}
<hx-toast class={className} ref={hxRef} {...rest}>
{children}
</hx-toast>
</div>
);
};

Toast.propTypes = {
className: PropTypes.string,
children: PropTypes.node.isRequired,
type: PropTypes.oneOf(['info', 'error', 'success']),
cta: PropTypes.string,
onDismiss: PropTypes.func,
onSubmit: PropTypes.func,
};

export default Toast;
29 changes: 29 additions & 0 deletions src/Toast/stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { select, text } from '@storybook/addon-knobs/react';
import Toast from './index';
import { action } from '@storybook/addon-actions';

const TYPES = {
info: 'info',
error: 'error',
success: 'success',
};

storiesOf('Toast', module).add('All Knobs', () => {
let content = text('content', 'The password has been reset for foo@bar.com.');
let cta = text('cta', 'Try Again');
let type = select('type', TYPES, '');

return (
<Toast
{...(cta && { cta })}
{...(status && { status })}
{...(type && { type })}
onDismiss={action('onDismiss')}
onSubmit={action('onSubmit')}
>
{content}
</Toast>
);
});
4 changes: 3 additions & 1 deletion src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Select from './Select';
import Switch from './Switch';
import Text from './Text';
import TextArea from './TextArea';
import Toast from './Toast';
import Tooltip from './Tooltip';

export {
Expand All @@ -42,5 +43,6 @@ export {
Switch,
Text,
TextArea,
Tooltip
Toast,
Tooltip,
};