Skip to content

Commit f19067e

Browse files
author
Dave Ferris
committed
2 parents e2598ea + 129db71 commit f19067e

File tree

5 files changed

+90
-21
lines changed

5 files changed

+90
-21
lines changed

.eslintrc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"files": [
66
"stories/*.{js,jsx}"
77
],
8-
rules: {
9-
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
10-
},
8+
"rules": {
9+
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }]
10+
}
1111
},
1212
{
1313
"files": [
14-
"src/**/*.{js,jsx}",
14+
"src/**/*.{js,jsx}"
1515
],
1616
"env": {
1717
"browser": true
@@ -103,9 +103,16 @@
103103
"react-hooks/exhaustive-deps": "warn",
104104
"react-hooks/rules-of-hooks": "error",
105105
"semi": 0
106-
},
106+
}
107107
}
108108
],
109+
"settings": {
110+
"import/resolver": {
111+
"node": {
112+
"paths": ["./"]
113+
}
114+
}
115+
},
109116
"rules": {
110117
"class-methods-use-this": 0,
111118
"function-paren-newline": ["error", "consistent"],

.storybook/webpack.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@ module.exports = function({ config }) {
77
include: path.resolve(__dirname, '../')
88
});
99

10+
config.resolve.modules = [
11+
...(config.resolve.modules || []),
12+
path.resolve('./'),
13+
];
14+
1015
return config;
1116
};

src/RadioButton/RadioButton.jsx

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,51 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import classnames from 'classnames';
4+
5+
import './RadioButton.scss';
36

47
export default function RadioButton(props) {
8+
const classNames = classnames('RadioButton', {
9+
'RadioButton--bordered': props.bordered,
10+
});
11+
512
return (
6-
<input
7-
className="RadioButton"
8-
disabled={props.disabled}
9-
id={props.id}
10-
name={props.name}
11-
type="radio"
12-
{...props.radioButtonProps}
13-
/>
13+
<label className={classNames}>
14+
<input
15+
className="RadioButton__input"
16+
disabled={props.disabled}
17+
id={props.id}
18+
name={props.name}
19+
type="radio"
20+
{...props.radioButtonProps}
21+
/>
22+
23+
{props.label && (
24+
<span className="RadioButton__label">{props.label}</span>
25+
)}
26+
27+
{props.children && (
28+
<div className="RadioButton__children">
29+
{props.children}
30+
</div>
31+
)}
32+
</label>
1433
);
1534
}
1635

1736
RadioButton.propTypes = {
37+
bordered: PropTypes.bool,
38+
children: PropTypes.node,
1839
disabled: PropTypes.bool,
1940
id: PropTypes.string.isRequired,
41+
label: PropTypes.string.isRequired,
2042
name: PropTypes.string,
2143
radioButtonProps: PropTypes.object,
2244
};
2345

2446
RadioButton.defaultProps = {
47+
bordered: false,
48+
children: null,
2549
disabled: false,
2650
name: '',
2751
radioButtonProps: {},

src/RadioButton/RadioButton.scss

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@import 'scss/theme';
2+
@import 'scss/borders';
3+
4+
.RadioButton {
5+
display: flex;
6+
align-items: center;
7+
padding: 0.5rem;
8+
border: 1px solid transparent;
9+
flex-wrap: wrap;
10+
11+
&--bordered {
12+
border: 1px solid $ux-gray-400;
13+
border-radius: $ux-border-radius;
14+
}
15+
16+
&__label {
17+
flex-grow: 1;
18+
margin-left: 0.5rem;
19+
}
20+
21+
&__children {
22+
margin-top: 0.5rem;
23+
width: 100%;
24+
}
25+
}

stories/RadioButton.stories.jsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
import React from 'react';
22
import { withA11y } from '@storybook/addon-a11y';
3+
import { withKnobs, text, boolean } from '@storybook/addon-knobs';
34

4-
import RadioButton from '../src/RadioButton/RadioButton';
5+
import RadioButton from 'src/RadioButton/RadioButton';
56

6-
import { withPadding } from './decorators';
7+
import { withPadding } from 'stories/decorators';
8+
import { palette } from 'src/Styles';
79

810
export default {
9-
title: 'Design System/Buttons/Radio Button',
11+
title: 'Design System/Form Elements/Radio Button',
1012
component: RadioButton,
11-
decorators: [withA11y, withPadding],
13+
decorators: [withA11y, withPadding, withKnobs],
1214
};
1315

1416
export const Default = () => (
1517
<RadioButton
18+
bordered={boolean('Border', false)}
19+
disabled={boolean('Disabled', false)}
1620
id="default"
21+
label={text('Label', 'label')}
1722
/>
1823
);
1924

20-
export const Disabled = () => (
25+
export const WithChildren = () => (
2126
<RadioButton
22-
disabled
23-
id="disabled"
24-
/>
27+
label="Option with child"
28+
bordered
29+
id="default"
30+
>
31+
<span style={{ color: palette.uxGray500 }}>Some descriptive text for the option above</span>
32+
</RadioButton>
2533
);

0 commit comments

Comments
 (0)