Skip to content

Commit 48c6cfe

Browse files
artyorshmalashkevich
authored andcommitted
feat(ui): Radio. Closes #201 (#212)
* feat(ui/radio): initial compomponent implementation * feat(ui/radio): state mapping support * feat(ui/radio): apply design styles * test(radio): add radio component tests * test(ui/radio): [temporary] radio tests * feat(theme): add appearances mapping config * refactor(theme): split theme service * refactor(theme): remove useless tests * refactor(theme): [temporary] mapping & style services * merge: style-consumer-appearance-support * refactor(theme): style-consumer methods refactor, move to service * refactor(theme): remove unused imports from style-consumer * refactor(theme): move method from hoc to service (style-consumer) * refactor(theme): framework ui-component imports refactor (style-component is decorator now). * test(theme): style-consumer-service spec add * refactor(theme): style-consumer-service functions refactor * refactor(theme): style-consumer-service as a class implement and integrate * build(tsconfig): allow using decorators switch-on * refactor(theme): styled decorator rename * feat(theme): createStyle function supporting appearances * refactor(theme): style consumer service * refactor(ui/radio): adopt component to new config * test(theme): adopt theme test to new config * refactor(playground): remove sample component * feat(playground): update radio screen examples * build(package): react-native-testing-library update * test(ui/radio): add radio component snapshot tests * refactor(playground): adopt radio screen to appearances config
1 parent 14f0cf9 commit 48c6cfe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2855
-1040
lines changed

package-lock.json

Lines changed: 80 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"react-addons-test-utils": "^15.6.2",
4646
"react-native": "^0.57.4",
4747
"react-native-mock": "^0.3.1",
48-
"react-native-testing-library": "^1.3.0",
48+
"react-native-testing-library": "^1.5.0",
4949
"react-native-typescript-transformer": "^1.2.10",
5050
"react-test-renderer": "^16.6.0",
5151
"rimraf": "^2.6.2",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { ThemeMappingType } from './type';
33

4-
const defaultValue: ThemeMappingType[] = [];
4+
const defaultValue: ThemeMappingType = {};
55
const MappingContext = React.createContext(defaultValue);
66

77
export default MappingContext;

src/framework/theme/component/mapping/mappingProvider.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import MappingContext from './mappingContext';
33
import { ThemeMappingType } from './type';
44

55
export interface Props {
6-
mapping: ThemeMappingType[];
6+
mapping: ThemeMappingType;
77
children: JSX.Element | React.ReactNode;
88
}
99

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
// TODO(mapping/type): declare Config/Token type
1+
export type ThemeMappingType = any;
22

3-
export type ThemeMappingConfigType = any;
3+
export interface ComponentMappingType {
4+
appearance: any;
5+
}
46

5-
export interface ThemeMappingType {
6-
parameters: string[];
7-
variants: any;
7+
export interface AppearanceType {
8+
mapping: MappingType;
9+
variant?: any;
810
}
911

12+
export type VariantGroupType = any;
13+
1014
export interface VariantType {
11-
state: any;
15+
mapping: MappingType;
16+
}
17+
18+
export interface MappingType {
19+
state?: StateType;
1220
}
1321

22+
export type StateType = any;
23+
24+
1425
export type TokenType = any;

src/framework/theme/component/style/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export {
44
} from './styleProvider.component';
55

66
export {
7-
StyledComponent,
7+
styled,
88
Props as StyledComponentProps,
99
} from './styleConsumer.component';

src/framework/theme/component/style/styleConsumer.component.tsx

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,68 @@ import {
44
ThemeType,
55
StyleType,
66
} from '../theme';
7-
import { ThemeMappingType } from '../mapping';
7+
import {
8+
ThemeMappingType,
9+
ComponentMappingType,
10+
} from '../mapping';
811
import ThemeContext from '../theme/themeContext';
912
import MappingContext from '../mapping/mappingContext';
1013
import {
1114
createStyle,
12-
getComponentThemeMapping,
15+
getComponentMapping,
16+
StyleConsumerService,
1317
} from '../../service';
1418

1519
interface PrivateProps<T> {
1620
forwardedRef: React.RefObject<T>;
1721
}
1822

1923
interface ConsumerProps {
20-
mapping: ThemeMappingType[];
24+
mapping: ThemeMappingType;
2125
theme: ThemeType;
2226
}
2327

2428
export interface Props {
25-
variant?: string;
29+
appearance?: string;
2630
theme?: ThemeType;
2731
themedStyle?: StyleType;
28-
requestStateStyle?: (state: string[] | string) => StyleType;
32+
requestStateStyle?: (state: string[]) => StyleType;
2933
}
3034

31-
export const StyledComponent = <T extends React.Component, P extends object>(Component: React.ComponentClass<P>) => {
35+
export const styled = <T extends React.Component, P extends object>(Component: React.ComponentClass<P>) => {
3236

3337
type ComponentProps = Props & P;
3438
type WrapperProps = PrivateProps<T> & ComponentProps;
3539

3640
class Wrapper extends React.Component<WrapperProps> {
3741

42+
service: StyleConsumerService = new StyleConsumerService();
43+
3844
getComponentName = (): string => Component.displayName || Component.name;
3945

40-
createStyle = (theme: ThemeType,
41-
mapping: ThemeMappingType,
42-
variant: string[] | string,
43-
state: string[] | string): StyleType => {
46+
createComponentStyle = (theme: ThemeType,
47+
mapping: ComponentMappingType,
48+
appearance: string,
49+
variant: string[],
50+
state: string[]): StyleType => {
4451

4552
if (state.length === 0) {
4653
console.warn('Redundant `requestStateStyle` call! Use `this.props.themedStyle` instead!');
4754
}
48-
return createStyle(theme, mapping, variant, state);
55+
return createStyle(theme, mapping, appearance, variant, state);
4956
};
5057

51-
createCustomProps = (props: ConsumerProps, variant: string): Props => {
52-
const mapping = getComponentThemeMapping(this.getComponentName(), props.mapping);
58+
createCustomProps = (props: ConsumerProps, componentProps: P & Props): Props => {
59+
const mapping = getComponentMapping(props.mapping, this.getComponentName());
60+
const variants = this.service.getVariantPropKeys<P & Props>(mapping, componentProps);
61+
5362
return {
54-
variant: variant,
63+
appearance: componentProps.appearance,
5564
theme: props.theme,
56-
themedStyle: createStyle(props.theme, mapping, variant),
57-
requestStateStyle: state => this.createStyle(props.theme, mapping, variant, state),
65+
themedStyle: createStyle(props.theme, mapping, componentProps.appearance, variants),
66+
requestStateStyle: state => {
67+
return this.createComponentStyle(props.theme, mapping, componentProps.appearance, variants, state);
68+
},
5869
};
5970
};
6071

@@ -65,15 +76,15 @@ export const StyledComponent = <T extends React.Component, P extends object>(Com
6576
return (
6677
<Component
6778
ref={forwardedRef}
68-
{...this.createCustomProps(props, componentProps.variant)}
79+
{...this.createCustomProps(props, componentProps)}
6980
{...componentProps}
7081
/>
7182
);
7283
};
7384

7485
render() {
7586
return (
76-
<MappingContext.Consumer>{(mapping: ThemeMappingType[]) => (
87+
<MappingContext.Consumer>{(mapping: ThemeMappingType) => (
7788
<ThemeContext.Consumer>{(theme: ThemeType) => {
7889
return this.renderWrappedComponent({ mapping: mapping, theme: theme });
7990
}}</ThemeContext.Consumer>

0 commit comments

Comments
 (0)