Skip to content
Merged
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
48 changes: 48 additions & 0 deletions src/Alert/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { useRef, useEffect} from 'react';
import PropTypes from 'prop-types';

const Alert = (props) => {
const hxRef = useRef(null);

useEffect(() => {
hxRef.current.addEventListener('open', props.onOpen);
hxRef.current.addEventListener('close', props.onClose);
return () => {
hxRef.current.removeEventListener('open', props.onOpen);
hxRef.current.removeEventListener('close', props.onClose);
};
}, []);

return (
<>
{/*
Wrappping element needed: Otherwise when alert removes itself from DOM on close it confusing React
about where highest level parent element went, and will throw an error.
*/}
<hx-alert
type={props.type}
status={props.status}
persist={props.persist}
cta={props.cta}
className={props.className}
id={props.id}
ref={hxRef}
>
{props.children}
</hx-alert>
</>
);
};

Alert.propTypes = {
className: PropTypes.string,
children: PropTypes.node.isRequired,
type: PropTypes.string,
status: PropTypes.string,
cta: PropTypes.string,
persist: PropTypes.bool,
onOpen: PropTypes.func,
onClose: PropTypes.func
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes sense to specify which props should be marked with isRequired.

Copy link
Contributor Author

@nicko-winner nicko-winner Apr 13, 2020

Choose a reason for hiding this comment

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

I think just children may be the only required item do you see others?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are correct. Also, I noticed that the persist prop is missing from the propTypes.

Do we want to default the persist and type props?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch. i'm tempted to not use default propTypes and just let helix-ui pick the defaults. That way our wrapper defaults wont get in the way of what Helix may set as defaults in the future. (makes the wrapper slightly more light weight). @100stacks you have an any opinion on if we should be setting defaults props/attributes before passing them on to helix?

Copy link
Member

Choose a reason for hiding this comment

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

@HelixDesignSystem/helix-react-core I think we left this open during our sync today. Balancing explicit defaults vs. implied HelixUI defaults.

We can address again as needed.

};

export default Alert;
29 changes: 29 additions & 0 deletions src/Alert/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 { boolean, select, text } from '@storybook/addon-knobs/react';
import Alert from './index';

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

storiesOf('Alert', module)
.add('All Knobs', () => {
let content = text('content', 'Nope! Nope! Nope! Nope! Nope!');
let cta = text('cta', 'burn it');
let status = text('status', 'spider');
let persist = boolean('persist', false);
let type = select('type', TYPES, '');

return (
<Alert
{ ...( cta && { cta }) }
{ ...( status && { status }) }
{ ...( persist && { persist }) }
{ ...( type && { type }) }
>{content}</Alert>
);
});
2 changes: 2 additions & 0 deletions src/index.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* Export helix-react definition */
import Button from './Button';
import Alert from './Alert';
import Icon from './Icon';

export default {
Button,
Icon,
Alert
};