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
32 changes: 32 additions & 0 deletions src/Checkbox/index.js
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;
Copy link
Contributor Author

@nicko-winner nicko-winner Jul 20, 2020

Choose a reason for hiding this comment

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

2020-07-18_20-50-50
the docs say el.intermediate but sine there are many elements that exist to make this checkbox work it might be more clear if the docs said inputEl. indeterminate = true instead to be more explicit.

Copy link
Member

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)?

Copy link
Contributor Author

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 indeterminate prop on a few wrong elements before I got it working on the input. If the docs are explicit about what element to place indeterminate on 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.

Copy link
Contributor Author

@nicko-winner nicko-winner Jul 21, 2020

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.

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 for the feedback. Yes, I agree we need to make this more explicit in the HelixUI documentation.

}, [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;
25 changes: 25 additions & 0 deletions src/Checkbox/stories.js
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')}
/>
);
});
16 changes: 16 additions & 0 deletions src/Radio/RadioSet.js
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;
26 changes: 26 additions & 0 deletions src/Radio/index.js
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;
53 changes: 53 additions & 0 deletions src/Radio/stories.js
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>
);
});
13 changes: 10 additions & 3 deletions src/index.mjs
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,
};