-
Notifications
You must be signed in to change notification settings - Fork 6
Implement Choice Tile #91
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
95f5b45
Create get short text util
a879187
Implement choice tile
a3e5dd7
Create demo
a3ea1de
Move class name to top level
f2d95b5
Remove unneeded wcBool uses
6bc8bad
Prettier
34600cc
id --> name
2c5553d
Expose onChange
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import classNames from 'classnames'; | ||
| import PropTypes from 'prop-types'; | ||
| import React from 'react'; | ||
|
|
||
| import { SIZES } from '../constants'; | ||
| import { wcBool } from '../utils'; | ||
|
|
||
| const ChoiceTile = ({ | ||
| checked, | ||
| children, | ||
| className, | ||
| disabled, | ||
| icon, | ||
| invalid, | ||
| name, | ||
| onChange, | ||
| size, | ||
| subdued, | ||
| title, | ||
| ...rest | ||
| }) => { | ||
| return ( | ||
| <label className={classNames({ hxChoice: true, className })}> | ||
| <input | ||
| checked={wcBool(checked)} | ||
| disabled={disabled} | ||
| invalid={invalid?.toString()} | ||
| name={name} | ||
| onChange={onChange} | ||
| type="radio" | ||
michaelmang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /> | ||
| <hx-tile class={classNames({ hxSubdued: subdued, [SIZES[size]]: true })} {...rest}> | ||
| <hx-icon type="checkmark"></hx-icon> | ||
| {icon && ( | ||
| <div className="hx-tile-icon"> | ||
| <hx-icon type={icon}></hx-icon> | ||
| </div> | ||
| )} | ||
| <header>{title}</header> | ||
| {children} | ||
| </hx-tile> | ||
| </label> | ||
| ); | ||
| }; | ||
|
|
||
| ChoiceTile.propTypes = { | ||
| checked: PropTypes.bool.isRequired, | ||
| children: PropTypes.node, | ||
| className: PropTypes.string, | ||
| disabled: PropTypes.bool, | ||
| icon: PropTypes.string, | ||
| invalid: PropTypes.bool, | ||
| name: PropTypes.string.isRequired, | ||
| onChange: PropTypes.func, | ||
| size: PropTypes.oneOf(SIZES), | ||
| subdued: PropTypes.bool, | ||
| title: PropTypes.string.isRequired, | ||
| }; | ||
|
|
||
| ChoiceTile.defaultProps = { | ||
| checked: false, | ||
| }; | ||
|
|
||
| export default ChoiceTile; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import React from 'react'; | ||
| import { action } from '@storybook/addon-actions'; | ||
| import { optionsKnob as options } from '@storybook/addon-knobs'; | ||
| import { boolean, select, text } from '@storybook/addon-knobs/react'; | ||
| import { storiesOf } from '@storybook/react'; | ||
|
|
||
| import ChoiceTile from './index'; | ||
| import { getShortText } from '../storyUtils'; | ||
|
|
||
| const SIZES = { | ||
| small: 'small', | ||
| medium: 'medium', | ||
| large: 'large', | ||
| }; | ||
|
|
||
| storiesOf('Choice Tile', module).add('All Knobs', () => { | ||
| let description = text('description', ''); | ||
| let title = text('title', ''); | ||
| let checked = boolean('checked', false); | ||
| let disabled = boolean('disabled', false); | ||
| let invalid = boolean('invalid', false); | ||
| let subdued = boolean('subdued', false); | ||
| let size = select('size', SIZES, 'medium'); | ||
| let icon = options( | ||
| 'icon', | ||
| { | ||
| account: 'account', | ||
| bell: 'bell', | ||
| key: 'key', | ||
| }, | ||
| 'key', | ||
| { display: 'inline-radio' } | ||
| ); | ||
|
|
||
| const defaultDescription = getShortText(); | ||
| const defaultTitle = 'Title Here'; | ||
|
|
||
| return ( | ||
| <React.Fragment> | ||
| <ChoiceTile | ||
| {...(checked && { checked })} | ||
| {...(disabled && { disabled })} | ||
| {...(invalid && { invalid })} | ||
| {...(subdued && { subdued })} | ||
| {...(size && { size })} | ||
| icon={icon} | ||
| name="choiceTileDemo" | ||
| onChange={action('onChange')} | ||
| style={{ width: 200 }} | ||
| title={title || defaultTitle} | ||
| > | ||
| {<p>{description || defaultDescription}</p>} | ||
| </ChoiceTile> | ||
|
|
||
| <ChoiceTile | ||
| icon="bell" | ||
| name="choiceTileDemo" | ||
| style={{ marginLeft: 25, width: 200 }} | ||
| title="Other Choice" | ||
| > | ||
| {<p>{defaultDescription}</p>} | ||
| </ChoiceTile> | ||
| </React.Fragment> | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non blocking: a potential shorter way to say the same thing:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this alternative would add a class name of undefined when there is no
className, right?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only if it was written like this:
classNames={`hxChoice ${className}`}butclassName()does not include undefined values.from the docs: https://github.com/JedWatson/classnames#readme