Skip to content

Commit 36b554a

Browse files
committed
Toast + fixes for Alert
1 parent f441f85 commit 36b554a

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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> {/* Wrappping element needed: Otherwise when alert removes itself from DOM on close, it will cause error */}
9+
<hx-toast class={className} ref={hxRef} {...rest}>
10+
{children}
11+
</hx-toast>
12+
</div>
13+
);
14+
};
15+
16+
Toast.propTypes = {
17+
className: PropTypes.string,
18+
children: PropTypes.node.isRequired,
19+
type: PropTypes.oneOf(['info','error','success']),
20+
cta: PropTypes.string,
21+
onDismiss: PropTypes.func,
22+
onSubmit: PropTypes.func,
23+
};
24+
25+
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 [email protected].');
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+
});

0 commit comments

Comments
 (0)