Skip to content

Commit a08f8f2

Browse files
authored
fix(ui): mapping find issues
1 parent e71ca2c commit a08f8f2

25 files changed

+69
-7
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ interface TestComponentProps extends StyledComponentProps, ViewProps {
6565
}
6666

6767
class Test extends React.Component<TestComponentProps> {
68-
static displayName: string = 'Radio';
68+
static styledComponentName: string = 'Radio';
6969

7070
static defaultProps: Partial<TestComponentProps> = {
7171
testID: styleConsumerTestId,
@@ -78,8 +78,20 @@ class Test extends React.Component<TestComponentProps> {
7878
}
7979
}
8080

81+
class NonStyledComponent extends React.Component<TestComponentProps> {
82+
public render(): React.ReactElement<ViewProps> {
83+
return undefined;
84+
}
85+
}
86+
8187
describe('@style: ui component checks', () => {
8288

89+
it('* returns null if has no static `styledComponentName` property', () => {
90+
const styledComponent = styled(NonStyledComponent);
91+
92+
expect(styledComponent).toBeNull();
93+
});
94+
8395
it('* static methods are copied over', async () => {
8496
// @ts-ignore: test-case
8597
Test.staticMethod = function () {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export interface Context {
3232

3333
export const styled = <P extends object>(Component: React.ComponentClass<P>) => {
3434

35+
// @ts-ignore
36+
if (!Component.styledComponentName) {
37+
console.warn('Styled components should specify corresponding style name.');
38+
return null;
39+
}
40+
3541
type WrappingProps = PrivateProps<WrappedElementInstance> & WrappedProps;
3642
type WrappedProps = P & Props;
3743
type WrappingElement = React.ReactElement<WrappingProps>;
@@ -51,9 +57,9 @@ export const styled = <P extends object>(Component: React.ComponentClass<P>) =>
5157
private service: StyleConsumerService;
5258

5359
private onInit = (context: Context) => {
54-
const displayName: string = Component.displayName || Component.name;
5560

56-
this.service = new StyleConsumerService(displayName, context);
61+
// @ts-ignore
62+
this.service = new StyleConsumerService(Component.styledComponentName, context);
5763
this.defaultProps = this.service.createDefaultProps();
5864

5965
this.init = true;

src/framework/ui/avatar/avatar.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export type Props = AvatarProps & StyledComponentProps & ImageProps;
2020

2121
export class Avatar extends React.Component<Props> {
2222

23+
static styledComponentName: string = 'Avatar';
24+
2325
private getComponentStyle = (source: StyleType): StyleType => {
2426
const { roundCoefficient, ...componentStyle } = source;
2527

src/framework/ui/bottomNavigation/bottomNavigation.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export type Props = TabNavigatorProps & StyledComponentProps & ViewProps;
2727

2828
export class BottomNavigation extends React.Component<Props> {
2929

30+
static styledComponentName: string = 'BottomNavigation';
31+
3032
static defaultProps: Partial<Props> = {
3133
selectedIndex: 0,
3234
};

src/framework/ui/bottomNavigation/bottomNavigationTab.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export type Props = BottomNavigatorTabProps & StyledComponentProps & TouchableOp
2323

2424
export class BottomNavigationTab extends React.Component<Props> {
2525

26+
static styledComponentName: string = 'BottomNavigationTab';
27+
2628
private onPress = () => {
2729
if (this.props.onSelect) {
2830
this.props.onSelect(!this.props.selected);

src/framework/ui/button/button.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const ALIGNMENT_DEFAULT: ButtonIconAlignment = ButtonIconAlignments.LEFT;
4242

4343
export class Button extends React.Component<Props> {
4444

45+
static styledComponentName: string = 'Button';
46+
4547
static defaultProps: Partial<Props> = {
4648
iconAlignment: 'left',
4749
};

src/framework/ui/buttonGroup/buttonGroup.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export type Props = ButtonGroupProps & StyledComponentProps & ViewProps;
2525

2626
export class ButtonGroup extends React.Component<Props> {
2727

28+
static styledComponentName: string = 'ButtonGroup';
29+
2830
private styleProvider: ButtonStyleProvider = ButtonStyleProviders.DEFAULT;
2931

3032
private getComponentStyle = (style: StyleType): StyleType => {

src/framework/ui/checkbox/checkbox.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export type Props = CheckBoxProps & StyledComponentProps & TouchableOpacityProps
3939

4040
export class CheckBox extends React.Component<Props> {
4141

42+
static styledComponentName: string = 'CheckBox';
43+
4244
private onPress = () => {
4345
this.props.dispatch([]);
4446

src/framework/ui/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ const Input = styled<InputProps>(InputComponent);
123123
const Layout = styled<LayoutProps>(LayoutComponent);
124124
const List = styled<ListProps>(ListComponent);
125125
const ListItem = styled<ListItemProps>(ListItemComponent);
126+
const OverflowMenu = styled<OverflowMenuProps>(OverflowMenuComponent);
127+
const OverflowMenuItem = styled<OverflowMenuItemProps>(OverflowMenuItemComponent);
126128
const Popover = styled<PopoverProps>(PopoverComponent);
127129
const Radio = styled<RadioProps>(RadioComponent);
128130
const RadioGroup = styled<RadioGroupProps>(RadioGroupComponent);
@@ -133,8 +135,6 @@ const Toggle = styled<ToggleProps>(ToggleComponent);
133135
const Tooltip = styled<TooltipProps>(TooltipComponent);
134136
const TopNavigation = styled<TopNavigationBarProps>(TopNavigationComponent);
135137
const TopNavigationAction = styled<TopNavigationBarActionProps>(TopNavigationActionComponent);
136-
const OverflowMenuItem = styled<OverflowMenuItemProps>(OverflowMenuItemComponent);
137-
const OverflowMenu = styled<OverflowMenuProps>(OverflowMenuComponent);
138138

139139
export {
140140
Avatar,

src/framework/ui/input/input.component.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import {
2727
FlexStyleProps,
2828
} from '../common/props';
2929

30-
const Text = styled<TextProps>(TextComponent);
31-
3230
type IconElement = React.ReactElement<ImageProps>;
3331
type TextElement = React.ReactElement<TextProps>;
3432
type IconProp = (style: StyleType) => React.ReactElement<ImageProps>;
@@ -44,8 +42,12 @@ interface InputProps {
4442

4543
export type Props = InputProps & StyledComponentProps & TextInputProps;
4644

45+
const Text = styled<TextProps>(TextComponent);
46+
4747
export class Input extends React.Component<Props> {
4848

49+
static styledComponentName: string = 'Input';
50+
4951
private onFocus = (event: InputFocusEvent) => {
5052
this.props.dispatch([Interaction.FOCUSED]);
5153

src/framework/ui/layout/layout.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export type Props = LayoutProps & StyledComponentProps & ViewProps;
1616

1717
export class Layout extends React.Component<Props> {
1818

19+
static styledComponentName: string = 'Layout';
20+
1921
private getComponentStyle = (style: StyleType): StyleType => {
2022
return {
2123
container: style,

src/framework/ui/list/list.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export type Props = ListProps<ItemType> & StyledComponentProps & FlatListProps<I
2222

2323
export class List extends React.Component<Props> {
2424

25+
static styledComponentName: string = 'List';
26+
2527
private listRef: React.RefObject<FlatList<ItemType>> = React.createRef();
2628

2729
public scrollToEnd = (params?: { animated?: boolean }) => {

src/framework/ui/list/listItem.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export type Props = ListItemProps & StyledComponentProps & TouchableOpacityIndex
5252

5353
export class ListItem extends React.Component<Props> {
5454

55+
static styledComponentName: string = 'ListItem';
56+
5557
private onPress = (event: GestureResponderEvent) => {
5658
if (this.props.onPress) {
5759
this.props.onPress(this.props.index, event);

src/framework/ui/overflowMenu/overflowMenu.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export type Props = & StyledComponentProps & OverflowMenuProps & Omit<PopoverPro
3636

3737
export class OverflowMenu extends React.Component<Props> {
3838

39+
static styledComponentName: string = 'OverflowMenu';
40+
3941
static defaultProps: Partial<Props> = {
4042
indicatorOffset: 12,
4143
};

src/framework/ui/overflowMenu/overflowMenuItem.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export type Props = OverflowMenuItemType & StyledComponentProps & TouchableOpaci
3030

3131
export class OverflowMenuItem extends React.Component<Props> {
3232

33+
static styledComponentName: string = 'OverflowMenuItem';
34+
3335
private onPress = (event: GestureResponderEvent) => {
3436
if (this.props.onPress) {
3537
this.props.onPress(this.props.index, event);

src/framework/ui/popover/popover.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const PLACEMENT_DEFAULT: Placement = Placements.BOTTOM;
4747

4848
export class Popover extends React.Component<Props, State> {
4949

50+
static styledComponentName: string = 'Popover';
51+
5052
static defaultProps: Partial<Props> = {
5153
placement: PLACEMENT_DEFAULT.rawValue,
5254
visible: false,

src/framework/ui/radio/radio.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export type Props = RadioProps & StyledComponentProps & TouchableOpacityProps;
3636

3737
export class Radio extends React.Component<Props> {
3838

39+
static styledComponentName: string = 'Radio';
40+
3941
private onPress = () => {
4042
if (this.props.onChange) {
4143
this.props.onChange(!this.props.checked);

src/framework/ui/radioGroup/radioGroup.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export type Props = RadioGroupProps & StyledComponentProps & ViewProps;
2121

2222
export class RadioGroup extends React.Component<Props> {
2323

24+
static styledComponentName: string = 'RadioGroup';
25+
2426
static defaultProps: Partial<Props> = {
2527
selectedIndex: -1,
2628
};

src/framework/ui/tab/tab.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export type Props = TabProps & StyledComponentProps & TouchableOpacityProps;
3434

3535
export class Tab extends React.Component<Props> {
3636

37+
static styledComponentName: string = 'Tab';
38+
3739
static defaultProps: Partial<Props> = {
3840
selected: false,
3941
};

src/framework/ui/tab/tabBar.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export type Props = TabBarProps & StyledComponentProps & ViewProps;
2424

2525
export class TabBar extends React.Component<Props> {
2626

27+
static styledComponentName: string = 'TabBar';
28+
2729
static defaultProps: Partial<Props> = {
2830
selectedIndex: 0,
2931
};

src/framework/ui/text/text.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export type Props = TextProps & StyledComponentProps & TextComponentProps;
1717

1818
export class Text extends React.Component<Props> {
1919

20+
static styledComponentName: string = 'Text';
21+
2022
private getComponentStyle = (source: StyleType): StyleType => {
2123
return {
2224
color: source.color,

src/framework/ui/toggle/toggle.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export type Props = ToggleComponentProps & StyledComponentProps & ViewProps;
3131

3232
export class Toggle extends React.Component<Props> implements PanResponderCallbacks {
3333

34+
static styledComponentName: string = 'Toggle';
35+
3436
private panResponder: PanResponderInstance;
3537
private thumbWidthAnimation: Animated.Value;
3638
private thumbTranslateAnimation: Animated.Value;

src/framework/ui/tooltip/tooltip.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export type Props = TooltipProps & StyledComponentProps & Omit<PopoverProps, 'co
3333

3434
export class Tooltip extends React.Component<Props> {
3535

36+
static styledComponentName: string = 'Tooltip';
37+
3638
static defaultProps: Partial<Props> = {
3739
indicatorOffset: 8,
3840
};

src/framework/ui/topNavigation/topNavigation.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export type Props = TopNavigationProps & StyledComponentProps & ViewProps;
3030

3131
export class TopNavigation extends React.Component<Props> {
3232

33+
static styledComponentName: string = 'TopNavigation';
34+
3335
private getComponentStyle = (style: StyleType): StyleType => {
3436
const { alignment: alignmentValue, leftControl, rightControls } = this.props;
3537

src/framework/ui/topNavigation/topNavigationAction.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export type Props = StyledComponentProps & TouchableOpacityProps & TopNavigation
2020

2121
export class TopNavigationAction extends React.Component<Props> {
2222

23+
static styledComponentName: string = 'TopNavigationAction';
24+
2325
private onPress = (event: GestureResponderEvent) => {
2426
if (this.props.onPress) {
2527
this.props.onPress(event);

0 commit comments

Comments
 (0)