Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 60b5f2d

Browse files
authored
Merge pull request #4744 from matrix-org/joriks/radio-buttons-isolated
Add styled radio buttons
2 parents 224a296 + 9787b4d commit 60b5f2d

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-0
lines changed

res/css/_components.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
@import "./views/elements/_Slider.scss";
119119
@import "./views/elements/_Spinner.scss";
120120
@import "./views/elements/_StyledCheckbox.scss";
121+
@import "./views/elements/_StyledRadioButton.scss";
121122
@import "./views/elements/_SyntaxHighlight.scss";
122123
@import "./views/elements/_TextWithTooltip.scss";
123124
@import "./views/elements/_ToggleSwitch.scss";
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
Copyright 2020 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/**
18+
* This component expects the parent to specify a positive padding and
19+
* width
20+
*/
21+
22+
.mx_RadioButton {
23+
24+
$radio-circle-color: $muted-fg-color;
25+
$active-radio-circle-color: $accent-color;
26+
position: relative;
27+
28+
display: flex;
29+
align-items: center;
30+
flex-grow: 1;
31+
32+
> span {
33+
flex-grow: 1;
34+
35+
display: flex;
36+
37+
margin-left: 8px;
38+
margin-right: 8px;
39+
}
40+
41+
.mx_RadioButton_spacer {
42+
flex-shrink: 0;
43+
flex-grow: 0;
44+
45+
height: $font-16px;
46+
width: $font-16px;
47+
}
48+
49+
> input[type=radio] {
50+
// Remove the OS's representation
51+
margin: 0;
52+
padding: 0;
53+
appearance: none;
54+
55+
+ div {
56+
flex-shrink: 0;
57+
flex-grow: 0;
58+
59+
display: flex;
60+
align-items: center;
61+
justify-content: center;
62+
63+
box-sizing: border-box;
64+
height: $font-16px;
65+
width: $font-16px;
66+
67+
border: $font-1-5px solid $radio-circle-color;
68+
border-radius: $font-16px;
69+
70+
> div {
71+
box-sizing: border-box;
72+
73+
height: $font-8px;
74+
width: $font-8px;
75+
76+
border-radius: $font-8px;
77+
}
78+
}
79+
}
80+
81+
> input[type=radio]:checked {
82+
+ div {
83+
border-color: $active-radio-circle-color;
84+
85+
> div {
86+
background: $active-radio-circle-color;
87+
}
88+
}
89+
}
90+
91+
> input[type=radio]:disabled {
92+
+ div {
93+
> div {
94+
display: none;
95+
}
96+
}
97+
}
98+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2020 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React from 'react';
18+
import classnames from 'classnames';
19+
20+
interface IProps extends React.InputHTMLAttributes<HTMLInputElement> {
21+
}
22+
23+
interface IState {
24+
}
25+
26+
export default class StyledRadioButton extends React.PureComponent<IProps, IState> {
27+
public static readonly defaultProps = {
28+
className: '',
29+
}
30+
31+
public render() {
32+
const { children, className, ...otherProps } = this.props;
33+
return <label className={classnames('mx_RadioButton', className)}>
34+
<input type='radio' {...otherProps} />
35+
{/* Used to render the radio button circle */}
36+
<div><div></div></div>
37+
<span>{children}</span>
38+
<div className="mx_RadioButton_spacer" />
39+
</label>
40+
}
41+
}

0 commit comments

Comments
 (0)