Skip to content

Commit b2e3b78

Browse files
committed
Merge branch 'radio-group' into 'master'
Radio group See merge request code.brahma/react-lite-ui!4
2 parents ac73c5a + 49f23c5 commit b2e3b78

File tree

9 files changed

+159
-8
lines changed

9 files changed

+159
-8
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export const defaultCode = `
2+
class Demo extends React.Component {
3+
render() {
4+
const options = [
5+
{ label: 'Alpha' },
6+
{ label: 'Beta'},
7+
{ label: 'Zheta' }
8+
];
9+
return (
10+
<div>
11+
{/* Preview Block 1 */}
12+
<PreviewBlock header="Default RadioButton group">
13+
<RadioButtonGroup
14+
options={options}
15+
/>
16+
</PreviewBlock>
17+
{/* Preview Block 2 */}
18+
<PreviewBlock header="Inline RadioButton group">
19+
<RadioButtonGroup
20+
inline
21+
options={options}
22+
/>
23+
</PreviewBlock>
24+
</div>
25+
)
26+
}
27+
}
28+
`;

docs/client/components/common/DefaultCode/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export { defaultCode as CardDefaultCode } from './Card';
22
export { defaultCode as ButtonDefaultCode } from './Button';
33
export { defaultCode as CheckboxDefaultCode } from './Checkbox';
44
export { defaultCode as CheckboxGroupDefaultCode } from './CheckboxGroup';
5-
export { defaultCode as ToggleDefaultCode } from './Toggle';
5+
export { defaultCode as ToggleDefaultCode } from './Toggle';
6+
export { defaultCode as RadioButtonGroupDefaultCode } from './RadioButtonGroup';

docs/client/components/common/componentList.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import CheckboxGroup from '../../../../src/checkbox';
88
import CheckboxGroupReadme from '../../../../src/checkbox/readMe.md';
99
import Toggle from '../../../../src/toggle';
1010
import ToggleReadme from '../../../../src/toggle/readMe.md';
11+
import RadioButtonGroup from '../../../../src/radioButtonGroup';
1112

1213
import {
1314
CardDefaultCode,
1415
ButtonDefaultCode,
1516
CheckboxDefaultCode,
1617
CheckboxGroupDefaultCode,
1718
ToggleDefaultCode,
19+
RadioButtonGroupDefaultCode
1820
} from './DefaultCode';
1921

2022
export const componentList = [
@@ -48,4 +50,10 @@ export const componentList = [
4850
component: Toggle,
4951
defaultCode: ToggleDefaultCode,
5052
},
53+
{
54+
name: 'RadioButtonGroup',
55+
docs: CheckboxGroupReadme,
56+
component: RadioButtonGroup,
57+
defaultCode: RadioButtonGroupDefaultCode,
58+
},
5159
];

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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,32 @@ import Card from './card';
33
import Checkbox from './checkbox';
44
import CheckboxGroup from './checkboxGroup';
55
import Toggle from './toggle';
6+
import RadioButtonGroup from './radioButtonGroup';
67

78
export default {
89
Button,
910
Card,
1011
Checkbox,
1112
CheckboxGroup,
13+
RadioButtonGroup,
1214
Toggle,
1315
};
1416

17+
// import React from 'react';
18+
// import ReactDOM from 'react-dom';
19+
20+
// import RadioButtonGroup from './radioButtonGroup';
21+
// import theme from './theme.scss';
22+
23+
// const options = [{ label: 'Alpha' }, { label: 'Beta' }, { label: 'Zheta' }]
24+
// const RadioDisplay = () => (
25+
// <div>
26+
// <RadioButtonGroup
27+
// theme={theme}
28+
// options={options}
29+
// inline
30+
// />
31+
// </div>
32+
// );
33+
34+
// ReactDOM.render(<RadioDisplay />, document.getElementById('index'));

src/radioButtonGroup/index.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import cx from 'classnames';
4+
import Checkbox from '../checkbox';
5+
6+
import styles from './theme.scss';
7+
8+
class RadioButtonGroup extends React.Component {
9+
constructor(props) {
10+
super(props);
11+
12+
this.state = {
13+
currentlyActive: '',
14+
};
15+
}
16+
17+
handleCheckListChange = (currentlyActive) => {
18+
console.log(currentlyActive);
19+
this.setState({
20+
currentlyActive,
21+
});
22+
}
23+
24+
render() {
25+
const {
26+
options,
27+
inline,
28+
theme,
29+
} = this.props;
30+
31+
const classNames = cx(styles['radio-group']);
32+
return options.map(option => (
33+
<React.Fragment key={option.label}>
34+
<div className={classNames}>
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', { checked: (option.label === this.state.currentlyActive) ? 'active' : '' })}>
38+
<input type="radio" />
39+
</label>
40+
</label>
41+
<label className={styles['each-label']}>
42+
{option.label}
43+
</label>
44+
</div>
45+
</div>
46+
<div className="clearfix" />
47+
</React.Fragment>
48+
));
49+
}
50+
}
51+
52+
RadioButtonGroup.propTypes = {
53+
options: PropTypes.array.isRequired,
54+
inline: PropTypes.bool,
55+
theme: PropTypes.string,
56+
};
57+
58+
RadioButtonGroup.defaultProps = {
59+
inline: false,
60+
theme: '',
61+
};
62+
63+
export default RadioButtonGroup;

src/radioButtonGroup/readMe.md

Whitespace-only changes.

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+
&.checked {
33+
background: $secondary-blue;
34+
}
35+
}
36+
}

src/theme.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +0,0 @@
1-
$secondary-grey: #d2d2d2;
2-
$secondary-blue: blue;
3-
$original-white: #ffffff;
4-
5-
6-
@import './toggle/theme.scss';
7-

0 commit comments

Comments
 (0)