-
Notifications
You must be signed in to change notification settings - Fork 6
Checkbox, Radio, RadioSet #97
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,32 @@ | ||
| import PropTypes from 'prop-types'; | ||
| import React, { useRef, useEffect } from 'react'; | ||
|
|
||
| const Checkbox = ({ id, label, indeterminate, ...rest }) => { | ||
| const inputRef = useRef(); | ||
| useEffect(() => { | ||
| inputRef.current.indeterminate = indeterminate; | ||
| }, [indeterminate]); | ||
|
|
||
| return ( | ||
| <hx-checkbox-control> | ||
| <input ref={inputRef} {...rest} id={id} type="checkbox" /> | ||
| <label htmlFor={id}> | ||
| <hx-checkbox></hx-checkbox> | ||
| {label} | ||
| </label> | ||
| </hx-checkbox-control> | ||
| ); | ||
| }; | ||
|
|
||
| Checkbox.propTypes = { | ||
| checked: PropTypes.bool.isRequired, | ||
| id: PropTypes.string.isRequired, | ||
| disabled: PropTypes.bool, | ||
| indeterminate: PropTypes.bool, | ||
| required: PropTypes.bool, | ||
| label: PropTypes.bool, | ||
| name: PropTypes.string, | ||
| onChange: PropTypes.func, | ||
| }; | ||
|
|
||
| export default Checkbox; | ||
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,25 @@ | ||
| import React from 'react'; | ||
| import { action } from '@storybook/addon-actions'; | ||
| import { boolean, text } from '@storybook/addon-knobs/react'; | ||
| import { storiesOf } from '@storybook/react'; | ||
|
|
||
| import Checkbox from './index'; | ||
|
|
||
| storiesOf('Checkbox', module).add('All Knobs', () => { | ||
| let label = text('label', 'check me out'); | ||
| let checked = boolean('checked', false); | ||
| let disabled = boolean('disabled', false); | ||
| let indeterminate = boolean('indeterminate', false); | ||
| let required = boolean('required', false); | ||
| return ( | ||
| <Checkbox | ||
| id="chkDemo" | ||
| {...(checked && { checked })} | ||
| {...(disabled && { disabled })} | ||
| {...(indeterminate && { indeterminate })} | ||
| {...(required && { required })} | ||
| {...(label && { label })} | ||
| onChange={action('onChange')} | ||
| /> | ||
| ); | ||
| }); |
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,16 @@ | ||
| import PropTypes from 'prop-types'; | ||
| import React from 'react'; | ||
|
|
||
| const RadioSet = ({ className, children, ...rest }) => { | ||
| return ( | ||
| <hx-radio-set class={className} {...rest}> | ||
| {children} | ||
| </hx-radio-set> | ||
| ); | ||
| }; | ||
|
|
||
| RadioSet.propTypes = { | ||
| children: PropTypes.node, | ||
| }; | ||
|
|
||
| export default RadioSet; |
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,26 @@ | ||
| import PropTypes from 'prop-types'; | ||
| import React from 'react'; | ||
|
|
||
| const Radio = ({ id, label, className, ...rest }) => { | ||
| return ( | ||
| <hx-radio-control> | ||
| <input {...rest} id={id} type="radio" /> | ||
| <label htmlFor={id}> | ||
| <hx-radio></hx-radio> | ||
| {label} | ||
| </label> | ||
| </hx-radio-control> | ||
| ); | ||
| }; | ||
|
|
||
| Radio.propTypes = { | ||
| checked: PropTypes.bool.isRequired, | ||
| id: PropTypes.string.isRequired, | ||
| disabled: PropTypes.bool, | ||
| required: PropTypes.bool, | ||
| label: PropTypes.bool, | ||
| name: PropTypes.string, | ||
| onChange: PropTypes.func, | ||
| }; | ||
|
|
||
| export default Radio; |
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,53 @@ | ||
| import React from 'react'; | ||
| import { action } from '@storybook/addon-actions'; | ||
| import { boolean, text } from '@storybook/addon-knobs/react'; | ||
| import { storiesOf } from '@storybook/react'; | ||
|
|
||
| import Radio from './index'; | ||
| import RadioSet from './RadioSet'; | ||
|
|
||
| storiesOf('Radio', module) | ||
| .add('All Knobs', () => { | ||
| let label = text('label', 'Radio Label'); | ||
| let checked = boolean('checked', false); | ||
| let disabled = boolean('disabled', false); | ||
| let required = boolean('required', false); | ||
| return ( | ||
| <Radio | ||
| id="radioDemo" | ||
| {...(checked && { checked })} | ||
| {...(disabled && { disabled })} | ||
| {...(required && { required })} | ||
| {...(label && { label })} | ||
| onChange={action('onChange')} | ||
| /> | ||
| ); | ||
| }) | ||
| .add('Radio Set', () => { | ||
| let checked = boolean('default checked', false); | ||
| let disabled = boolean('disabled', false); | ||
| let required = boolean('required', false); | ||
| return ( | ||
| <RadioSet> | ||
| <Radio | ||
| id="radioDemo1" | ||
| name="myRadios" | ||
| value="option1" | ||
| label="option 1" | ||
| {...(checked && { checked })} | ||
| {...(disabled && { disabled })} | ||
| {...(required && { required })} | ||
| onChange={action('onChange')} | ||
| /> | ||
| <Radio | ||
| id="radioDemo2" | ||
| name="myRadios" | ||
| value="option2" | ||
| label="option 2" | ||
| {...(disabled && { disabled })} | ||
| {...(required && { required })} | ||
| onChange={action('onChange')} | ||
| /> | ||
| </RadioSet> | ||
| ); | ||
| }); |
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 |
|---|---|---|
| @@ -1,26 +1,33 @@ | ||
| /* Export helix-react definition */ | ||
| import Alert from './Alert'; | ||
| import Button from './Button'; | ||
| import Checkbox from './Checkbox'; | ||
| import ChoiceTile from './ChoiceTile'; | ||
| import Drawer from './Drawer'; | ||
| import Icon from './Icon'; | ||
| import Modal from './Modal'; | ||
| import Popover from './Popover'; | ||
| import Tooltip from './Tooltip'; | ||
| import Select from './Select'; | ||
| import Radio from './Radio'; | ||
| import RadioSet from './Radio/RadioSet'; | ||
| import Search from './Search'; | ||
| import SearchAssist from './Search/SearchAssist'; | ||
| import Select from './Select'; | ||
|
|
||
|
|
||
| export default { | ||
| Alert, | ||
| Button, | ||
| Checkbox, | ||
| ChoiceTile, | ||
| Drawer, | ||
| Icon, | ||
| Modal, | ||
| Popover, | ||
| Select, | ||
| Tooltip, | ||
| Radio, | ||
| RadioSet, | ||
| Search, | ||
| SearchAssist | ||
| SearchAssist, | ||
| Select, | ||
| }; |
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.
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.
the docs say
el.intermediatebut sine there are many elements that exist to make this checkbox work it might be more clear if the docs saidinputEl. indeterminate = trueinstead to be more explicit.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.
@nicko-winner, is this feedback for the HelixUI docs or something we should document here (or both)?
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.
It's a nit for the helix UI docs. I might have just have been trying silly things late in the day, but I tried to set the
indeterminateprop on a few wrong elements before I got it working on the input. If the docs are explicit about what element to placeindeterminateon it might take some ambiguity out of it. Not many people will likely need to use that state, but for those that do maybe someone will try the same foolishness I did.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.
In Helix React we hide this implementations detail from users, so they won't have to deal with it, just Helix UI users.
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.
Ok thanks for the feedback. Yes, I agree we need to make this more explicit in the HelixUI documentation.