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
30 changes: 30 additions & 0 deletions src/Drawer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import PropTypes from 'prop-types';
import React from 'react';

import { SIZES } from '../constants';
import useEventListener from '../hooks/useEventListener';
import { wcBool } from '../utils';

const Drawer = ({ children, className, id, onClose, onOpen, open, size, ...rest }) => {
const hxRef = useEventListener({ onOpen, onClose });
return (
<hx-drawer class={(className, SIZES[size])} id={id} open={wcBool(open)} ref={hxRef} {...rest}>
{children}
</hx-drawer>
);
};

Drawer.propTypes = {
className: PropTypes.string,
id: PropTypes.string.isRequired,
onClose: PropTypes.func,
onOpen: PropTypes.func,
open: PropTypes.bool,
size: PropTypes.oneOf(SIZES),
};

Drawer.defaultProps = {
open: null,
};

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

import Drawer from './index';
import Button from '../Button';
import HxDiv from '../HxDiv';
import { getLongText } from '../storyUtils';

const SIZES = {
small: 'small',
medium: 'medium',
large: 'large',
};

storiesOf('Drawer', module).add('All Knobs', () => {
let header = text('header', '');
let body = text('body', '');
let footer = text('footer', '');
let open = boolean('open', true);
let size = select('size', SIZES, 'medium');

const defaultBody = <p>{getLongText()}</p>;
const defaultHeader = 'Drawer Header';
const defaultFooter = (
<div class="hxButtonSet">
<Button variant="primary">Confirm</Button>
<Button variant="tertiary">Cancel</Button>
</div>
);

return (
<Drawer
{...(open && { open })}
{...(size && { size })}
onOpen={action('onOpen')}
onClose={action('onClose')}
>
{<header>{header || defaultHeader}</header>}
{<HxDiv className="hxMd">{body || defaultBody}</HxDiv>}
{<footer>{footer || defaultFooter}</footer>}
</Drawer>
);
});
7 changes: 1 addition & 6 deletions src/Modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import { wcBool } from '../utils';
const Modal = ({ onOpen, onClose, className, open, size, children, ...rest }) => {
const hxRef = useEventListener({ onOpen, onClose });
return (
<hx-modal
class={classNames(className, SIZES[size])}
ref={hxRef}
open={wcBool(open)}
{...rest}
>
<hx-modal class={classNames(className, SIZES[size])} ref={hxRef} open={wcBool(open)} {...rest}>
Copy link
Member

Choose a reason for hiding this comment

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

Is this prettier formatting? For me it's not as readable, though I defer to you @HelixDesignSystem/helix-react-core

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is based on the length of the line. It breaks when it exceeds 100 characters: https://github.com/HelixDesignSystem/helix-react/blob/master/prettier.config.js#L4

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 @michaelmang. 👍

I wonder if we can change that config...though that's very minor.

{children}
</hx-modal>
);
Expand Down
18 changes: 2 additions & 16 deletions src/Modal/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { boolean, select, text } from '@storybook/addon-knobs/react';
import Modal from './index';
import HxDiv from '../HxDiv';
import Button from '../Button';
import { getLongText } from '../storyUtils';

const SIZES = {
small: 'small',
Expand All @@ -21,22 +22,7 @@ storiesOf('Modal', module).add('All Knobs', () => {

const smallText =
'This is the body of a demo modal. Interaction with content behind this modal cannot take place until this modal is closed.\n';
const lorumIpsum = (
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Gravida rutrum quisque non tellus. Sagittis vitae et leo duis
ut diam quam nulla. Diam vel quam elementum pulvinar etiam non. Pulvinar sapien et ligula
ullamcorper malesuada proin libero nunc. Ultricies integer quis auctor elit sed vulputate mi
sit amet. Egestas dui id ornare arcu odio ut. In iaculis nunc sed augue. Pellentesque
adipiscing commodo elit at imperdiet dui accumsan sit amet. Erat velit scelerisque in dictum
non. Auctor augue mauris augue neque gravida in fermentum et. Posuere sollicitudin aliquam
ultrices sagittis orci a scelerisque purus. Ullamcorper dignissim cras tincidunt lobortis
feugiat vivamus at augue. Tincidunt vitae semper quis lectus nulla. Purus ut faucibus pulvinar
elementum integer enim neque volutpat. Etiam sit amet nisl purus in mollis nunc. Diam sit amet
nisl suscipit. Nulla pharetra diam sit amet nisl. Arcu odio ut sem nulla.
</p>
);
const longText = [1, 2, 3, 4, 5].map(() => lorumIpsum);
const longText = [1, 2, 3, 4, 5].map(() => <p>{getLongText()}</p>);
const defaultFooter = (
<>
<Button variant="primary">Confirm</Button>
Expand Down
2 changes: 2 additions & 0 deletions src/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Export helix-react definition */
import Button from './Button';
import Alert from './Alert';
import Drawer from './Drawer';
import Icon from './Icon';
import Tooltip from './Tooltip';
import Modal from './Modal';
Expand All @@ -9,6 +10,7 @@ import Select from './Select';
export default {
Button,
Alert,
Drawer,
Icon,
Modal,
Select,
Expand Down
13 changes: 13 additions & 0 deletions src/storyUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const getLongText = () => `
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Gravida rutrum quisque non tellus. Sagittis vitae et leo duis
ut diam quam nulla. Diam vel quam elementum pulvinar etiam non. Pulvinar sapien et ligula
ullamcorper malesuada proin libero nunc. Ultricies integer quis auctor elit sed vulputate mi
sit amet. Egestas dui id ornare arcu odio ut. In iaculis nunc sed augue. Pellentesque
adipiscing commodo elit at imperdiet dui accumsan sit amet. Erat velit scelerisque in dictum
non. Auctor augue mauris augue neque gravida in fermentum et. Posuere sollicitudin aliquam
ultrices sagittis orci a scelerisque purus. Ullamcorper dignissim cras tincidunt lobortis
feugiat vivamus at augue. Tincidunt vitae semper quis lectus nulla. Purus ut faucibus pulvinar
elementum integer enim neque volutpat. Etiam sit amet nisl purus in mollis nunc. Diam sit amet
nisl suscipit. Nulla pharetra diam sit amet nisl. Arcu odio ut sem nulla.
`;
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* @param {boolean} bool
* @return {*}
*/
export const wcBool = (bool) => bool ? true : null;
export const wcBool = (bool) => (bool ? true : null);