Skip to content

Commit 9e701a9

Browse files
committed
added radio group
1 parent a6393c6 commit 9e701a9

File tree

4 files changed

+78
-23
lines changed

4 files changed

+78
-23
lines changed

src/checkboxGroup/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ class CheckboxGroup extends React.Component {
5757
CheckboxGroup.propTypes = {
5858
options: PropTypes.array.isRequired,
5959
inline: PropTypes.bool,
60+
theme: PropTypes.string,
6061
};
6162

6263
CheckboxGroup.defaultProps = {
6364
inline: false,
65+
theme: '',
6466
};
6567

6668
export default CheckboxGroup;

src/index.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
import Button from './button';
2-
import Card from './card';
3-
import Checkbox from './checkbox';
4-
import CheckboxGroup from './checkboxGroup';
5-
import Toggle from './toggle';
6-
7-
export default {
8-
Button,
9-
Card,
10-
Checkbox,
11-
CheckboxGroup,
12-
Toggle,
13-
};
1+
// import Button from './button';
2+
// import Card from './card';
3+
// import Checkbox from './checkbox';
4+
// import CheckboxGroup from './checkboxGroup';
5+
// import Toggle from './toggle';
146

7+
// export default {
8+
// Button,
9+
// Card,
10+
// Checkbox,
11+
// CheckboxGroup,
12+
// Toggle,
13+
// };
14+
15+
import React from 'react';
16+
import ReactDOM from 'react-dom';
17+
18+
import RadioButtonGroup from './radioButtonGroup';
19+
20+
const options = [{ label: 'Alpha' }, { label: 'Beta' }, { label: 'Zheta' }]
21+
const RadioDisplay = () => (
22+
<div>
23+
<RadioButtonGroup
24+
options={options}
25+
/>
26+
</div>
27+
);
28+
29+
ReactDOM.render(<RadioDisplay />, document.getElementById('index'));

src/radioButtonGroup/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@ class CheckboxGroup extends React.Component {
1010
super(props);
1111

1212
this.state = {
13-
isChecked: props.options.reduce((accumulator, { label, value }) => {
14-
accumulator[label] = false;
15-
return accumulator;
16-
}, {}),
13+
currentlyActive: '',
1714
}
1815
}
1916

20-
handleCheckListChange = (label) => {
21-
const isChecked = this.state.isChecked;
22-
isChecked[label] = !isChecked[label];
17+
handleCheckListChange = (currentlyActive) => {
18+
console.log(currentlyActive);
2319
this.setState({
24-
isChecked,
20+
currentlyActive,
2521
});
2622
}
2723

@@ -36,8 +32,12 @@ class CheckboxGroup extends React.Component {
3632
return options.map(option => (
3733
<React.Fragment key={option.label}>
3834
<div className={classNames}>
39-
<div className={cx(styles['each-check'], { inline })}>
40-
<input type="radio" />
35+
<div className={cx(styles['each-check'], { inline })} onClick={() => { this.handleCheckListChange(option.label)}}>
36+
<label className={cx(styles['customized-radio'], theme['customized-radio'])}>
37+
<label className={cx('inner', { active: (option.label === this.state.currentlyActive) ? 'active' : '' })}>
38+
<input type="radio" />
39+
</label>
40+
</label>
4141
<label className={styles['each-label']}>
4242
{option.label}
4343
</label>
@@ -52,10 +52,12 @@ class CheckboxGroup extends React.Component {
5252
CheckboxGroup.propTypes = {
5353
options: PropTypes.array.isRequired,
5454
inline: PropTypes.bool,
55+
theme: PropTypes.string,
5556
};
5657

5758
CheckboxGroup.defaultProps = {
5859
inline: false,
60+
theme: '',
5961
};
6062

6163
export default CheckboxGroup;

src/radioButtonGroup/theme.scss

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@import '../globals/theme';
2+
3+
:local(.radio-group) {
4+
input {
5+
position: relative;
6+
opacity: 0;
7+
cursor: pointer;
8+
}
9+
.clearfix {
10+
clear: both;
11+
}
12+
}
13+
14+
:local(.each-check) {
15+
&.inline {
16+
float: left;
17+
margin-right: 25px;
18+
}
19+
margin-bottom: 15px;
20+
}
21+
22+
:local(.each-label) {
23+
margin-left: 10px;
24+
}
25+
26+
:local(.customized-radio) {
27+
border: 1px solid $secondary-grey;
28+
border-radius: 50%;
29+
padding: 3px;
30+
.inner {
31+
border-radius: 50%;
32+
&.active {
33+
background: $secondary-blue;
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)