Skip to content

Commit 35c35f4

Browse files
authored
feat(ui): radio - add text support
1 parent 42dbbe6 commit 35c35f4

File tree

5 files changed

+676
-380
lines changed

5 files changed

+676
-380
lines changed
Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
import React from 'react';
22
import {
3-
TouchableOpacity,
43
View,
5-
StyleSheet,
4+
TouchableOpacity,
65
TouchableOpacityProps,
76
GestureResponderEvent,
7+
StyleSheet,
88
} from 'react-native';
99
import {
10+
styled,
1011
StyledComponentProps,
1112
StyleType,
1213
Interaction,
1314
} from '@kitten/theme';
15+
import {
16+
Text as TextComponent,
17+
Props as TextProps,
18+
} from '../text/text.component';
1419

1520
interface RadioProps {
21+
text?: string;
1622
checked?: boolean;
1723
status?: string;
1824
size?: string;
1925
onChange?: (selected: boolean) => void;
2026
}
2127

28+
const Text = styled<TextComponent, TextProps>(TextComponent);
29+
2230
export type Props = RadioProps & StyledComponentProps & TouchableOpacityProps;
2331

2432
export class Radio extends React.Component<Props> {
@@ -46,54 +54,73 @@ export class Radio extends React.Component<Props> {
4654
};
4755

4856
private getComponentStyle = (style: StyleType): StyleType => {
49-
const { select, highlight, ...container } = style;
57+
const { text, select, highlight, ...container } = style;
5058

5159
return {
52-
container: {
53-
...container,
54-
...styles.container,
55-
},
56-
select: {
57-
...select,
58-
...styles.select,
59-
},
60-
highlight: {
61-
...highlight,
62-
...styles.highlight,
63-
},
60+
selectContainer: container,
61+
select: select,
62+
highlight: highlight,
63+
text: text,
6464
};
6565
};
6666

67+
private renderTextElement = (style: StyleType): React.ReactElement<TextProps> => {
68+
const { text } = this.props;
69+
70+
return (
71+
<Text style={[style, styles.text]} key={0}>{text}</Text>
72+
);
73+
};
74+
75+
private renderComponentChildren = (style: StyleType): React.ReactNode => {
76+
const { text } = this.props;
77+
78+
return [
79+
text ? this.renderTextElement(style.text) : undefined,
80+
];
81+
};
82+
6783
public render(): React.ReactElement<TouchableOpacityProps> {
68-
const { themedStyle, ...derivedProps } = this.props;
69-
const { container, select, highlight } = this.getComponentStyle(themedStyle);
84+
const { style, themedStyle, ...derivedProps } = this.props;
85+
const { selectContainer, select, highlight, ...componentStyles } = this.getComponentStyle(themedStyle);
86+
const componentChildren: React.ReactNode = this.renderComponentChildren(componentStyles);
7087

7188
return (
72-
<TouchableOpacity
73-
{...derivedProps}
74-
activeOpacity={1.0}
75-
onPress={this.onPress}
76-
onPressIn={this.onPressIn}
77-
onPressOut={this.onPressOut}>
78-
<View style={styles.container}>
79-
<View style={highlight}/>
80-
<View style={container}>
81-
<View style={select}/>
82-
</View>
89+
<View style={[style, styles.container]}>
90+
<View style={styles.highlightContainer}>
91+
<View style={[highlight, styles.highlight]}/>
92+
<TouchableOpacity
93+
{...derivedProps}
94+
style={[selectContainer, styles.selectContainer]}
95+
activeOpacity={1.0}
96+
onPress={this.onPress}
97+
onPressIn={this.onPressIn}
98+
onPressOut={this.onPressOut}>
99+
<View style={[select, styles.select]}/>
100+
</TouchableOpacity>
83101
</View>
84-
</TouchableOpacity>
102+
{componentChildren}
103+
</View>
85104
);
86105
}
87106
}
88107

89108
const styles = StyleSheet.create({
90109
container: {
110+
flexDirection: 'row',
111+
alignItems: 'center',
112+
},
113+
highlightContainer: {
114+
justifyContent: 'center',
115+
alignItems: 'center',
116+
},
117+
selectContainer: {
91118
justifyContent: 'center',
92119
alignItems: 'center',
93120
},
94121
select: {},
95122
highlight: {
96123
position: 'absolute',
97-
alignSelf: 'center',
98124
},
125+
text: {},
99126
});

src/framework/ui/radio/radio.spec.config.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ export const mapping: ThemeMappingType = {
6868
'mapping': {
6969
'borderWidth': 2,
7070
'borderColor': 'gray-primary',
71+
'text': {
72+
'color': 'text-primary',
73+
'fontWeight': '500',
74+
},
7175
'select': {
7276
'backgroundColor': 'transparent',
7377
},
@@ -89,6 +93,9 @@ export const mapping: ThemeMappingType = {
8993
},
9094
'disabled': {
9195
'borderColor': 'gray-light',
96+
'text': {
97+
'color': 'gray-300',
98+
},
9299
},
93100
'checked.active': {
94101
'borderColor': 'blue-dark',
@@ -132,6 +139,10 @@ export const mapping: ThemeMappingType = {
132139
'height': 50,
133140
'borderRadius': 25,
134141
},
142+
'text': {
143+
'marginLeft': 10,
144+
'fontSize': 14,
145+
},
135146
},
136147
'medium': {
137148
'width': 36,
@@ -147,6 +158,10 @@ export const mapping: ThemeMappingType = {
147158
'height': 60,
148159
'borderRadius': 30,
149160
},
161+
'text': {
162+
'marginLeft': 12,
163+
'fontSize': 16,
164+
},
150165
},
151166
'large': {
152167
'width': 42,
@@ -162,6 +177,10 @@ export const mapping: ThemeMappingType = {
162177
'height': 70,
163178
'borderRadius': 35,
164179
},
180+
'text': {
181+
'marginLeft': 14,
182+
'fontSize': 18,
183+
},
165184
},
166185
},
167186
},
@@ -178,4 +197,11 @@ export const theme: ThemeType = {
178197
'gray-dark': '#8992A3',
179198
'gray-highlight': '#EDF0F5',
180199
'pink-primary': '#FF3D71',
200+
'text-primary': '#000000',
201+
'text-primary-inverse': '#ffffff',
202+
203+
'gray-100': '#f7f8fa',
204+
'gray-200': '#edf0f5',
205+
'gray-300': '#c8cedb',
206+
'gray-400': '#a6aebd',
181207
};

0 commit comments

Comments
 (0)