Skip to content

Commit a3db488

Browse files
authored
Merge pull request #116 from HelixDesignSystem/Toast
Toast
2 parents fd265ff + de927b9 commit a3db488

4 files changed

Lines changed: 60 additions & 3 deletions

File tree

src/Alert/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import useEventListener from '../hooks/useEventListener';
55
const Alert = ({ onOpen, onClose, className, children, onDismiss, onSubmit, ...rest }) => {
66
const hxRef = useEventListener({ onDismiss, onSubmit });
77
return (
8-
<>
8+
<div>
99
{/* Wrappping element needed: Otherwise when alert removes itself from DOM on close, it will cause error */}
1010
<hx-alert class={className} ref={hxRef} {...rest}>
1111
{children}
1212
</hx-alert>
13-
</>
13+
</div>
1414
);
1515
};
1616

src/Toast/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import useEventListener from '../hooks/useEventListener';
4+
5+
const Toast = ({ onOpen, onClose, className, children, onDismiss, onSubmit, ...rest }) => {
6+
const hxRef = useEventListener({ onDismiss, onSubmit });
7+
return (
8+
<div>
9+
{/* Wrapping element needed: Otherwise when alert removes itself from DOM on close, it will cause error */}
10+
<hx-toast class={className} ref={hxRef} {...rest}>
11+
{children}
12+
</hx-toast>
13+
</div>
14+
);
15+
};
16+
17+
Toast.propTypes = {
18+
className: PropTypes.string,
19+
children: PropTypes.node.isRequired,
20+
type: PropTypes.oneOf(['info', 'error', 'success']),
21+
cta: PropTypes.string,
22+
onDismiss: PropTypes.func,
23+
onSubmit: PropTypes.func,
24+
};
25+
26+
export default Toast;

src/Toast/stories.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import { storiesOf } from '@storybook/react';
3+
import { select, text } from '@storybook/addon-knobs/react';
4+
import Toast from './index';
5+
import { action } from '@storybook/addon-actions';
6+
7+
const TYPES = {
8+
info: 'info',
9+
error: 'error',
10+
success: 'success',
11+
};
12+
13+
storiesOf('Toast', module).add('All Knobs', () => {
14+
let content = text('content', 'The password has been reset for foo@bar.com.');
15+
let cta = text('cta', 'Try Again');
16+
let type = select('type', TYPES, '');
17+
18+
return (
19+
<Toast
20+
{...(cta && { cta })}
21+
{...(status && { status })}
22+
{...(type && { type })}
23+
onDismiss={action('onDismiss')}
24+
onSubmit={action('onSubmit')}
25+
>
26+
{content}
27+
</Toast>
28+
);
29+
});

src/index.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Select from './Select';
2121
import Switch from './Switch';
2222
import Text from './Text';
2323
import TextArea from './TextArea';
24+
import Toast from './Toast';
2425
import Tooltip from './Tooltip';
2526

2627
export {
@@ -46,5 +47,6 @@ export {
4647
Switch,
4748
Text,
4849
TextArea,
49-
Tooltip
50+
Toast,
51+
Tooltip,
5052
};

0 commit comments

Comments
 (0)