-
Notifications
You must be signed in to change notification settings - Fork 6
Drawer #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drawer #90
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| 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> | ||
100stacks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </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> | ||
| ); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
| ); | ||
|
|
||
| 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. | ||
| `; |
Uh oh!
There was an error while loading. Please reload this page.