From 35c35f457720bda481a76c479a3209069c04f64d Mon Sep 17 00:00:00 2001 From: Artur Yorsh <10753921+artyorsh@users.noreply.github.com> Date: Wed, 13 Mar 2019 14:45:53 +0300 Subject: [PATCH] feat(ui): radio - add text support --- src/framework/ui/radio/radio.component.tsx | 87 +- src/framework/ui/radio/radio.spec.config.ts | 26 + src/framework/ui/radio/radio.spec.tsx.snap | 868 +++++++++++------- .../ui/radioGroup/radioGroup.spec.config.ts | 26 + .../src/ui/screen/radio.component.tsx | 49 +- 5 files changed, 676 insertions(+), 380 deletions(-) diff --git a/src/framework/ui/radio/radio.component.tsx b/src/framework/ui/radio/radio.component.tsx index 337dd019b..c01562831 100644 --- a/src/framework/ui/radio/radio.component.tsx +++ b/src/framework/ui/radio/radio.component.tsx @@ -1,24 +1,32 @@ import React from 'react'; import { - TouchableOpacity, View, - StyleSheet, + TouchableOpacity, TouchableOpacityProps, GestureResponderEvent, + StyleSheet, } from 'react-native'; import { + styled, StyledComponentProps, StyleType, Interaction, } from '@kitten/theme'; +import { + Text as TextComponent, + Props as TextProps, +} from '../text/text.component'; interface RadioProps { + text?: string; checked?: boolean; status?: string; size?: string; onChange?: (selected: boolean) => void; } +const Text = styled(TextComponent); + export type Props = RadioProps & StyledComponentProps & TouchableOpacityProps; export class Radio extends React.Component { @@ -46,54 +54,73 @@ export class Radio extends React.Component { }; private getComponentStyle = (style: StyleType): StyleType => { - const { select, highlight, ...container } = style; + const { text, select, highlight, ...container } = style; return { - container: { - ...container, - ...styles.container, - }, - select: { - ...select, - ...styles.select, - }, - highlight: { - ...highlight, - ...styles.highlight, - }, + selectContainer: container, + select: select, + highlight: highlight, + text: text, }; }; + private renderTextElement = (style: StyleType): React.ReactElement => { + const { text } = this.props; + + return ( + {text} + ); + }; + + private renderComponentChildren = (style: StyleType): React.ReactNode => { + const { text } = this.props; + + return [ + text ? this.renderTextElement(style.text) : undefined, + ]; + }; + public render(): React.ReactElement { - const { themedStyle, ...derivedProps } = this.props; - const { container, select, highlight } = this.getComponentStyle(themedStyle); + const { style, themedStyle, ...derivedProps } = this.props; + const { selectContainer, select, highlight, ...componentStyles } = this.getComponentStyle(themedStyle); + const componentChildren: React.ReactNode = this.renderComponentChildren(componentStyles); return ( - - - - - - + + + + + + - + {componentChildren} + ); } } const styles = StyleSheet.create({ container: { + flexDirection: 'row', + alignItems: 'center', + }, + highlightContainer: { + justifyContent: 'center', + alignItems: 'center', + }, + selectContainer: { justifyContent: 'center', alignItems: 'center', }, select: {}, highlight: { position: 'absolute', - alignSelf: 'center', }, + text: {}, }); diff --git a/src/framework/ui/radio/radio.spec.config.ts b/src/framework/ui/radio/radio.spec.config.ts index cb7281d2c..2e6cd7296 100644 --- a/src/framework/ui/radio/radio.spec.config.ts +++ b/src/framework/ui/radio/radio.spec.config.ts @@ -68,6 +68,10 @@ export const mapping: ThemeMappingType = { 'mapping': { 'borderWidth': 2, 'borderColor': 'gray-primary', + 'text': { + 'color': 'text-primary', + 'fontWeight': '500', + }, 'select': { 'backgroundColor': 'transparent', }, @@ -89,6 +93,9 @@ export const mapping: ThemeMappingType = { }, 'disabled': { 'borderColor': 'gray-light', + 'text': { + 'color': 'gray-300', + }, }, 'checked.active': { 'borderColor': 'blue-dark', @@ -132,6 +139,10 @@ export const mapping: ThemeMappingType = { 'height': 50, 'borderRadius': 25, }, + 'text': { + 'marginLeft': 10, + 'fontSize': 14, + }, }, 'medium': { 'width': 36, @@ -147,6 +158,10 @@ export const mapping: ThemeMappingType = { 'height': 60, 'borderRadius': 30, }, + 'text': { + 'marginLeft': 12, + 'fontSize': 16, + }, }, 'large': { 'width': 42, @@ -162,6 +177,10 @@ export const mapping: ThemeMappingType = { 'height': 70, 'borderRadius': 35, }, + 'text': { + 'marginLeft': 14, + 'fontSize': 18, + }, }, }, }, @@ -178,4 +197,11 @@ export const theme: ThemeType = { 'gray-dark': '#8992A3', 'gray-highlight': '#EDF0F5', 'pink-primary': '#FF3D71', + 'text-primary': '#000000', + 'text-primary-inverse': '#ffffff', + + 'gray-100': '#f7f8fa', + 'gray-200': '#edf0f5', + 'gray-300': '#c8cedb', + 'gray-400': '#a6aebd', }; diff --git a/src/framework/ui/radio/radio.spec.tsx.snap b/src/framework/ui/radio/radio.spec.tsx.snap index 3d507afbe..f30ae1833 100644 --- a/src/framework/ui/radio/radio.spec.tsx.snap +++ b/src/framework/ui/radio/radio.spec.tsx.snap @@ -1,23 +1,15 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`@radio: matches snapshot active 1`] = ` - - - + - + `; exports[`@radio: matches snapshot active checked 1`] = ` - - - + - + `; exports[`@radio: matches snapshot active checked: checked 1`] = ` - - - + - + `; exports[`@radio: matches snapshot active: default 1`] = ` - - - + - + `; exports[`@radio: matches snapshot checked 1`] = ` - - - + - + `; exports[`@radio: matches snapshot checked disabled 1`] = ` - - - + - + `; exports[`@radio: matches snapshot default 1`] = ` - - - + - + `; exports[`@radio: matches snapshot disabled 1`] = ` - - - + - + `; diff --git a/src/framework/ui/radioGroup/radioGroup.spec.config.ts b/src/framework/ui/radioGroup/radioGroup.spec.config.ts index 9f9791967..24e62870e 100644 --- a/src/framework/ui/radioGroup/radioGroup.spec.config.ts +++ b/src/framework/ui/radioGroup/radioGroup.spec.config.ts @@ -68,6 +68,10 @@ export const mapping: ThemeMappingType = { 'mapping': { 'borderWidth': 2, 'borderColor': 'gray-primary', + 'text': { + 'color': 'text-primary', + 'fontWeight': '500', + }, 'select': { 'backgroundColor': 'transparent', }, @@ -89,6 +93,9 @@ export const mapping: ThemeMappingType = { }, 'disabled': { 'borderColor': 'gray-light', + 'text': { + 'color': 'gray-300', + }, }, 'checked.active': { 'borderColor': 'blue-dark', @@ -132,6 +139,10 @@ export const mapping: ThemeMappingType = { 'height': 50, 'borderRadius': 25, }, + 'text': { + 'marginLeft': 10, + 'fontSize': 14, + }, }, 'medium': { 'width': 36, @@ -147,6 +158,10 @@ export const mapping: ThemeMappingType = { 'height': 60, 'borderRadius': 30, }, + 'text': { + 'marginLeft': 12, + 'fontSize': 16, + }, }, 'large': { 'width': 42, @@ -162,6 +177,10 @@ export const mapping: ThemeMappingType = { 'height': 70, 'borderRadius': 35, }, + 'text': { + 'marginLeft': 14, + 'fontSize': 18, + }, }, }, }, @@ -202,4 +221,11 @@ export const theme: ThemeType = { 'gray-dark': '#8992A3', 'gray-highlight': '#EDF0F5', 'pink-primary': '#FF3D71', + 'text-primary': '#000000', + 'text-primary-inverse': '#ffffff', + + 'gray-100': '#f7f8fa', + 'gray-200': '#edf0f5', + 'gray-300': '#c8cedb', + 'gray-400': '#a6aebd', }; diff --git a/src/playground/src/ui/screen/radio.component.tsx b/src/playground/src/ui/screen/radio.component.tsx index f4bb7a235..82cdbbc62 100644 --- a/src/playground/src/ui/screen/radio.component.tsx +++ b/src/playground/src/ui/screen/radio.component.tsx @@ -20,6 +20,8 @@ interface State { isRadio4Checked: boolean; } +const STATUS: string = ''; + class Radio extends React.Component { static navigationOptions = { @@ -58,68 +60,80 @@ class Radio extends React.Component { - Error + Size - - Size - + Text + + @@ -141,10 +155,13 @@ export const RadioScreen = withStyles(Radio, (theme: ThemeType) => ({ alignItems: 'center', marginTop: 4, }, + containerPreviewColumn: { + marginTop: 4, + }, textDescription: { fontSize: 18, }, component: { - marginHorizontal: 4, + margin: 4, }, }));