Skip to content

Commit 3b3b5a4

Browse files
authored
Merge pull request #127 from HelixDesignSystem/helix-upgrade
feat: migrate HelixUI to v2.0
2 parents babf87b + e142102 commit 3b3b5a4

File tree

29 files changed

+369
-292
lines changed

29 files changed

+369
-292
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@storybook/addons": "^5.3.17",
5555
"@storybook/react": "^5.3.17",
5656
"babel-loader": "^8.1.0",
57-
"helix-ui": "^0.24.0",
57+
"helix-ui": "^2.0.0",
5858
"husky": "^4.2.5",
5959
"microbundle": "^0.12.3",
6060
"prettier": "^2.0.4",
@@ -68,7 +68,7 @@
6868
"use-onclickoutside": "^0.3"
6969
},
7070
"peerDependencies": {
71-
"helix-ui": "^0.24.0",
71+
"helix-ui": "^2.0.0",
7272
"prop-types": "^15.7.2",
7373
"react": "^16.6.3"
7474
},

src/Alert/index.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
import React from 'react';
1+
import React, { useRef } from 'react';
22
import PropTypes from 'prop-types';
33
import useEventListener from '../hooks/useEventListener';
4+
import useCombinedRefs from '../hooks/useCombinedRefs';
45

5-
const Alert = ({ onOpen, onClose, className, children, onDismiss, onSubmit, ...rest }) => {
6-
const hxRef = useEventListener({ onDismiss, onSubmit });
7-
return (
8-
<div>
9-
{/* Wrappping element needed: Otherwise when alert removes itself from DOM on close, it will cause error */}
10-
<hx-alert class={className} ref={hxRef} {...rest}>
11-
{children}
12-
</hx-alert>
13-
</div>
14-
);
15-
};
6+
const Alert = React.forwardRef(
7+
({ onOpen, onClose, className, children, onDismiss, onSubmit, ...rest }, ref) => {
8+
const hxRef = useEventListener({ onDismiss, onSubmit }, ref);
9+
return (
10+
<div>
11+
{/* Wrappping element needed: Otherwise when alert removes itself from DOM on close, it will cause error */}
12+
<hx-alert class={className} ref={hxRef} {...rest}>
13+
{children}
14+
</hx-alert>
15+
</div>
16+
);
17+
}
18+
);
19+
20+
Alert.displayName = 'Alert';
1621

1722
Alert.propTypes = {
1823
className: PropTypes.string,

src/Breadcrumb/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const Breadcrumb = ({ children, icon = 'angle-right', addDelimiter = true, ...re
88
? children.map((child, index) => [
99
child,
1010
addDelimiter && index + 1 < children.length && (
11-
<hx-icon class="delimiter" type={icon}></hx-icon>
11+
<hx-icon key={index} class="delimiter" type={icon} />
1212
),
1313
])
1414
: children;
@@ -22,7 +22,7 @@ const Breadcrumb = ({ children, icon = 'angle-right', addDelimiter = true, ...re
2222

2323
Breadcrumb.propTypes = {
2424
icon: PropTypes.string,
25-
children: PropTypes.func,
25+
children: PropTypes.node,
2626
};
2727

2828
export default Breadcrumb;

src/Breadcrumb/stories.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { addParameters, storiesOf } from '@storybook/react';
3+
import { text } from '@storybook/addon-knobs/react';
34
import Breadcrumb from './index';
45

56
addParameters({
@@ -8,18 +9,22 @@ addParameters({
89

910
storiesOf('Breadcrumb', module)
1011
.add('Multiple Breadcrumbs', () => {
12+
let item1 = text('item1', 'Home');
13+
let item2 = text('item2', 'Library');
14+
let item3 = text('item3', 'Current');
1115
return (
1216
<Breadcrumb>
13-
<a href="#">Home</a>
14-
<a href="#">Library</a>
15-
<a href="#">Current</a>
17+
<a href="#">{item1}</a>
18+
<a href="#">{item2}</a>
19+
<a href="#">{item3}</a>
1620
</Breadcrumb>
1721
);
1822
})
1923
.add('Single Breadcrumb', () => {
24+
let item1 = text('item1', 'Home');
2025
return (
2126
<Breadcrumb>
22-
<a href="#">Home</a>
27+
<a href="#">{item1}</a>
2328
</Breadcrumb>
2429
);
2530
});

src/Busy/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33

44
// Storybook story lives in /Progress folder
55
const Busy = ({ className, children, ...rest }) => {
6-
return <hx-busy class={className} {...rest}></hx-busy>;
6+
return <hx-busy class={className} {...rest} />;
77
};
88

99
Busy.propTypes = {

src/Button/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import Icon from '../Icon';
4+
import Busy from '../Busy';
45

56
function cssFor(modifier) {
67
return {
@@ -34,7 +35,7 @@ class Button extends React.Component {
3435
<button className={classNames(this.props)} type={type || 'button'} {...props}>
3536
{headIcon && <Icon type={headIcon} />}
3637
{children && <span>{children}</span>}
37-
{busy ? <hx-busy></hx-busy> : tailIcon && <Icon type={tailIcon} />}
38+
{busy ? <Busy /> : tailIcon && <Icon type={tailIcon} />}
3839
</button>
3940
);
4041
}

src/Button/stories.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@ addParameters({
1010
});
1111

1212
const SIZES = {
13-
small: 'Small',
14-
'': 'Medium',
15-
large: 'Large',
13+
small: 'small',
14+
medium: 'medium',
15+
large: 'large',
1616
};
17+
1718
const VARIANTS = {
18-
primary: 'Primary',
19-
'': 'Secondary',
20-
tertiary: 'Tertiary',
19+
primary: 'primary',
20+
secondary: 'secondary',
21+
tertiary: 'tertiary',
2122
};
2223

2324
storiesOf('Button', module)
2425
.addDecorator(centered)
2526
.add('Sizes', () => {
26-
const size = select('size', SIZES, '');
27+
const size = select('size', SIZES, 'medium');
2728
return <Button {...(size && { size })}>{SIZES[size]} Button</Button>;
2829
})
2930
.add('Variants', () => {
30-
const variant = select('variant', VARIANTS, '');
31+
const variant = select('variant', VARIANTS, 'primary');
3132
return <Button {...(variant && { variant })}>{VARIANTS[variant]} Button</Button>;
3233
})
3334
.add('Icon Only', () => {

src/Checkbox/index.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
import PropTypes from 'prop-types';
22
import React, { useRef, useEffect } from 'react';
3+
import useCombinedRefs from '../hooks/useCombinedRefs';
34

4-
const Checkbox = ({ id, label, indeterminate, className, style, ...rest }) => {
5-
const inputRef = useRef();
6-
useEffect(() => {
7-
inputRef.current.indeterminate = indeterminate;
8-
}, [indeterminate]);
5+
const Checkbox = React.forwardRef(
6+
({ id, label, indeterminate, className, style, ...rest }, ref) => {
7+
const hxRef = useCombinedRefs(ref, useRef());
8+
useEffect(() => {
9+
hxRef.current.indeterminate = indeterminate;
10+
}, [indeterminate]);
911

10-
return (
11-
<hx-checkbox-control class={className}>
12-
<input ref={inputRef} {...rest} id={id} type="checkbox" />
13-
<label htmlFor={id}>
14-
<hx-checkbox></hx-checkbox>
15-
{label}
16-
</label>
17-
</hx-checkbox-control>
18-
);
19-
};
12+
return (
13+
<hx-checkbox-control class={className}>
14+
<input ref={hxRef} {...rest} id={id} type="checkbox" />
15+
<label htmlFor={id}>
16+
<hx-checkbox />
17+
{label}
18+
</label>
19+
</hx-checkbox-control>
20+
);
21+
}
22+
);
23+
24+
Checkbox.displayName = 'Checkbox';
2025

2126
Checkbox.propTypes = {
2227
className: PropTypes.string,

src/ChoiceTile/index.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,24 @@ const ChoiceTile = ({
1818
subdued,
1919
title,
2020
style,
21+
radioInput,
2122
...rest
2223
}) => {
2324
return (
2425
<label className={classNames({ hxChoice: true }, className)} style={style}>
25-
<input
26-
checked={wcBool(checked)}
27-
disabled={disabled}
28-
invalid={invalid?.toString()}
29-
name={name}
30-
onChange={onChange}
31-
type="radio"
32-
{...rest}
33-
/>
26+
{radioInput ? (
27+
radioInput
28+
) : (
29+
<input
30+
checked={wcBool(checked)}
31+
disabled={disabled}
32+
invalid={invalid?.toString()}
33+
name={name}
34+
onChange={onChange}
35+
type="radio"
36+
{...rest}
37+
/>
38+
)}
3439
<hx-tile class={classNames({ hxSubdued: subdued, [SIZES[size]]: true })}>
3540
<hx-icon type="checkmark"></hx-icon>
3641
{icon && (
@@ -53,15 +58,17 @@ ChoiceTile.propTypes = {
5358
disabled: PropTypes.bool,
5459
icon: PropTypes.string,
5560
invalid: PropTypes.bool,
56-
name: PropTypes.string.isRequired,
61+
name: PropTypes.string,
5762
onChange: PropTypes.func,
5863
size: PropTypes.oneOf(Object.keys(SIZES)),
5964
subdued: PropTypes.bool,
6065
title: PropTypes.string.isRequired,
66+
radioInput: PropTypes.node,
6167
};
6268

6369
ChoiceTile.defaultProps = {
6470
checked: false,
71+
size: 'medium',
6572
};
6673

6774
export default ChoiceTile;

src/ChoiceTile/stories.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const SIZES = {
1717
};
1818

1919
storiesOf('Choice Tile', module).add('All Knobs', () => {
20-
let description = text('description', '');
2120
let title = text('title', '');
2221
let checked = boolean('checked', false);
2322
let disabled = boolean('disabled', false);
@@ -52,16 +51,18 @@ storiesOf('Choice Tile', module).add('All Knobs', () => {
5251
style={{ width: 200, float: 'left' }}
5352
title={title || defaultTitle}
5453
>
55-
{<p>{description || defaultDescription}</p>}
54+
{<p>{'standard choice tile' || defaultDescription}</p>}
5655
</ChoiceTile>
5756

5857
<ChoiceTile
5958
icon="bell"
60-
name="choiceTileDemo"
59+
radioInput={
60+
<input type="radio" name="choiceTileDemo" onChange={callback(action('onChange'))} />
61+
}
6162
style={{ marginLeft: 25, width: 200, float: 'left' }}
6263
title="Other Choice"
6364
>
64-
{<p>{defaultDescription}</p>}
65+
{<p>custom radio (see JSX)</p>}
6566
</ChoiceTile>
6667
</React.Fragment>
6768
);

0 commit comments

Comments
 (0)