Skip to content

Commit c032978

Browse files
committed
feat: Add RadioButton support custom style
1 parent 2af2102 commit c032978

File tree

4 files changed

+74
-11
lines changed

4 files changed

+74
-11
lines changed

DEV.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
`npm run publish:docs`
99

1010
# Publish NPM Package
11-
`npm run publish:npm`
11+
`npm run publish:npm`

docs/src/routes/Components/RadioButton/SimpleExample.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default class SimpleExample extends React.Component {
1111
context: { theme: ReactUWP.ThemeType };
1212

1313
render() {
14+
const { theme } = this.context;
1415
return (
1516
<div>
1617
<RadioButton defaultChecked style={baseStyle} label="Checked" />
@@ -20,6 +21,16 @@ export default class SimpleExample extends React.Component {
2021
<RadioButton style={baseStyle} label="Disabled" disabled />
2122

2223
<RadioButton defaultChecked size={40} style={baseStyle} label="Custom Size" />
24+
25+
<RadioButton
26+
defaultChecked={false}
27+
size={40}
28+
style={baseStyle}
29+
radioStyle={{ background: "none", border: `12px solid ${theme.accent}` }}
30+
radioCheckedStyle={{ background: theme.accent, border: "12px solid #fff" }}
31+
radioDotStyle={{ display: "none" }}
32+
label="Custom Style"
33+
/>
2334
</div>
2435
);
2536
}

src/RadioButton/index.doc.json

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,30 @@
5252
"documentation": "Set RadioButton `label`.",
5353
"isRequired": false,
5454
"type": "string"
55+
},
56+
{
57+
"name": "radioStyle",
58+
"documentation": "Set RadioButton outside shape style.",
59+
"isRequired": false,
60+
"type": "CSSProperties"
61+
},
62+
{
63+
"name": "radioCheckedStyle",
64+
"documentation": "Set RadioButton outside shape checked style.",
65+
"isRequired": false,
66+
"type": "CSSProperties"
67+
},
68+
{
69+
"name": "radioDotStyle",
70+
"documentation": "Set RadioButton inside dot style.",
71+
"isRequired": false,
72+
"type": "CSSProperties"
73+
},
74+
{
75+
"name": "radioDotCheckedStyle",
76+
"documentation": "Set RadioButton inside dot checked style.",
77+
"isRequired": false,
78+
"type": "CSSProperties"
5579
}
5680
]
5781
},
@@ -100,7 +124,7 @@
100124
"exports": [
101125
{
102126
"name": "prototype",
103-
"type": "prototype"
127+
"type": "any"
104128
},
105129
{
106130
"name": "defaultProps",
@@ -157,8 +181,8 @@
157181
},
158182
{
159183
"name": "getStyles",
160-
"type": "(radioButton: RadioButton) => { root: any; wrapper: any; content: any; label: any; labelText: { f..."
184+
"type": "(radioButton: RadioButton) => { root: any; radioShape: any; radioDot: any; label: any; labelText:..."
161185
}
162186
],
163-
"type": "typeof \"D:/react-uwp/src/RadioButton/index\""
187+
"type": "typeof \"C:/[Work]/react-uwp/src/RadioButton/index\""
164188
}

src/RadioButton/index.tsx

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ export interface DataProps {
2424
* Set RadioButton `label`.
2525
*/
2626
label?: string;
27+
/**
28+
* Set RadioButton outside shape style.
29+
*/
30+
radioStyle?: React.CSSProperties;
31+
/**
32+
* Set RadioButton outside shape checked style.
33+
*/
34+
radioCheckedStyle?: React.CSSProperties;
35+
/**
36+
* Set RadioButton inside dot style.
37+
*/
38+
radioDotStyle?: React.CSSProperties;
39+
/**
40+
* Set RadioButton inside dot checked style.
41+
*/
42+
radioDotCheckedStyle?: React.CSSProperties;
2743
}
2844

2945
export interface RadioButtonProps extends DataProps, React.HTMLAttributes<HTMLSpanElement> {}
@@ -83,6 +99,10 @@ export class RadioButton extends React.Component<RadioButtonProps, RadioButtonSt
8399
disabled,
84100
label,
85101
className,
102+
radioStyle,
103+
radioCheckedStyle,
104+
radioDotStyle,
105+
radioDotCheckedStyle,
86106
...attributes
87107
} = this.props;
88108
const { currChecked, hovered } = this.state;
@@ -98,9 +118,9 @@ export class RadioButton extends React.Component<RadioButtonProps, RadioButtonSt
98118
onClick={disabled ? void 0 : this.handleClick}
99119
onMouseEnter={disabled ? void 0 : this.handleMouseEnter}
100120
onMouseLeave={disabled ? void 0 : this.handleMouseLeave}
101-
{...styles.wrapper}
121+
{...styles.radioShape}
102122
>
103-
<div {...styles.content} />
123+
<div {...styles.radioDot} />
104124
</div>
105125
);
106126

@@ -129,7 +149,11 @@ function getStyles(radioButton: RadioButton) {
129149
props: {
130150
style,
131151
size,
132-
disabled
152+
disabled,
153+
radioStyle,
154+
radioCheckedStyle,
155+
radioDotStyle,
156+
radioDotCheckedStyle
133157
},
134158
state: {
135159
currChecked,
@@ -144,7 +168,7 @@ function getStyles(radioButton: RadioButton) {
144168
...rootStyle,
145169
...style
146170
}) : rootStyle,
147-
wrapper: theme.prefixStyle({
171+
radioShape: theme.prefixStyle({
148172
position: "relative",
149173
flex: "0 0 auto",
150174
display: "inline-block",
@@ -156,9 +180,11 @@ function getStyles(radioButton: RadioButton) {
156180
width: size,
157181
height: size,
158182
overflow: "hidden",
159-
transition: "all .25s ease-in-out"
183+
transition: "all .25s ease-in-out",
184+
...radioStyle,
185+
...(currChecked ? radioCheckedStyle : void 0)
160186
}),
161-
content: theme.prefixStyle({
187+
radioDot: theme.prefixStyle({
162188
position: "absolute",
163189
top: 0,
164190
left: 0,
@@ -172,7 +198,9 @@ function getStyles(radioButton: RadioButton) {
172198
borderRadius: dotSize,
173199
width: dotSize,
174200
height: dotSize,
175-
transform: `scale(${currChecked ? 1 : 0})`
201+
transform: `scale(${currChecked ? 1 : 0})`,
202+
...radioDotStyle,
203+
...(currChecked ? radioDotCheckedStyle : void 0)
176204
}),
177205
label: theme.prefixStyle({
178206
display: "flex",

0 commit comments

Comments
 (0)