Skip to content

Commit e11e843

Browse files
committed
[FEAT] Add new props to radio button
1 parent 9c2c848 commit e11e843

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

src/RadioButton/RadioButton.jsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
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+
</label>
1427
);
1528
}
1629

1730
RadioButton.propTypes = {
31+
bordered: PropTypes.bool,
1832
disabled: PropTypes.bool,
1933
id: PropTypes.string.isRequired,
34+
label: PropTypes.string.isRequired,
2035
name: PropTypes.string,
2136
radioButtonProps: PropTypes.object,
2237
};
2338

2439
RadioButton.defaultProps = {
40+
bordered: false,
2541
disabled: false,
2642
name: '',
2743
radioButtonProps: {},

src/RadioButton/RadioButton.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
10+
&--bordered {
11+
border: 1px solid $ux-gray-400;
12+
border-radius: $ux-border-radius;
13+
}
14+
15+
&__label {
16+
flex-grow: 1;
17+
margin-left: 0.5rem;
18+
}
19+
}

stories/RadioButton.stories.jsx

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

45
import RadioButton from '../src/RadioButton/RadioButton';
56

67
import { withPadding } from './decorators';
78

89
export default {
9-
title: 'Design System/Buttons/Radio Button',
10+
title: 'Design System/Form Elements/Radio Button',
1011
component: RadioButton,
11-
decorators: [withA11y, withPadding],
12+
decorators: [withA11y, withPadding, withKnobs],
1213
};
1314

1415
export const Default = () => (
1516
<RadioButton
17+
bordered={boolean('Border', false)}
18+
disabled={boolean('Disabled', false)}
1619
id="default"
17-
/>
18-
);
19-
20-
export const Disabled = () => (
21-
<RadioButton
22-
disabled
23-
id="disabled"
20+
label={text('Label', 'label')}
2421
/>
2522
);

0 commit comments

Comments
 (0)