Skip to content

Commit

Permalink
fix(ui): mapping find issues
Browse files Browse the repository at this point in the history
  • Loading branch information
artyorsh authored Apr 23, 2019
1 parent e71ca2c commit a08f8f2
Show file tree
Hide file tree
Showing 25 changed files with 69 additions and 7 deletions.
14 changes: 13 additions & 1 deletion src/framework/theme/component/style/style.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface TestComponentProps extends StyledComponentProps, ViewProps {
}

class Test extends React.Component<TestComponentProps> {
static displayName: string = 'Radio';
static styledComponentName: string = 'Radio';

static defaultProps: Partial<TestComponentProps> = {
testID: styleConsumerTestId,
Expand All @@ -78,8 +78,20 @@ class Test extends React.Component<TestComponentProps> {
}
}

class NonStyledComponent extends React.Component<TestComponentProps> {
public render(): React.ReactElement<ViewProps> {
return undefined;
}
}

describe('@style: ui component checks', () => {

it('* returns null if has no static `styledComponentName` property', () => {
const styledComponent = styled(NonStyledComponent);

expect(styledComponent).toBeNull();
});

it('* static methods are copied over', async () => {
// @ts-ignore: test-case
Test.staticMethod = function () {
Expand Down
10 changes: 8 additions & 2 deletions src/framework/theme/component/style/styleConsumer.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export interface Context {

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

// @ts-ignore
if (!Component.styledComponentName) {
console.warn('Styled components should specify corresponding style name.');
return null;
}

type WrappingProps = PrivateProps<WrappedElementInstance> & WrappedProps;
type WrappedProps = P & Props;
type WrappingElement = React.ReactElement<WrappingProps>;
Expand All @@ -51,9 +57,9 @@ export const styled = <P extends object>(Component: React.ComponentClass<P>) =>
private service: StyleConsumerService;

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

this.service = new StyleConsumerService(displayName, context);
// @ts-ignore
this.service = new StyleConsumerService(Component.styledComponentName, context);
this.defaultProps = this.service.createDefaultProps();

this.init = true;
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/avatar/avatar.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export type Props = AvatarProps & StyledComponentProps & ImageProps;

export class Avatar extends React.Component<Props> {

static styledComponentName: string = 'Avatar';

private getComponentStyle = (source: StyleType): StyleType => {
const { roundCoefficient, ...componentStyle } = source;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export type Props = TabNavigatorProps & StyledComponentProps & ViewProps;

export class BottomNavigation extends React.Component<Props> {

static styledComponentName: string = 'BottomNavigation';

static defaultProps: Partial<Props> = {
selectedIndex: 0,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export type Props = BottomNavigatorTabProps & StyledComponentProps & TouchableOp

export class BottomNavigationTab extends React.Component<Props> {

static styledComponentName: string = 'BottomNavigationTab';

private onPress = () => {
if (this.props.onSelect) {
this.props.onSelect(!this.props.selected);
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/button/button.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const ALIGNMENT_DEFAULT: ButtonIconAlignment = ButtonIconAlignments.LEFT;

export class Button extends React.Component<Props> {

static styledComponentName: string = 'Button';

static defaultProps: Partial<Props> = {
iconAlignment: 'left',
};
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/buttonGroup/buttonGroup.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export type Props = ButtonGroupProps & StyledComponentProps & ViewProps;

export class ButtonGroup extends React.Component<Props> {

static styledComponentName: string = 'ButtonGroup';

private styleProvider: ButtonStyleProvider = ButtonStyleProviders.DEFAULT;

private getComponentStyle = (style: StyleType): StyleType => {
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/checkbox/checkbox.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export type Props = CheckBoxProps & StyledComponentProps & TouchableOpacityProps

export class CheckBox extends React.Component<Props> {

static styledComponentName: string = 'CheckBox';

private onPress = () => {
this.props.dispatch([]);

Expand Down
4 changes: 2 additions & 2 deletions src/framework/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ const Input = styled<InputProps>(InputComponent);
const Layout = styled<LayoutProps>(LayoutComponent);
const List = styled<ListProps>(ListComponent);
const ListItem = styled<ListItemProps>(ListItemComponent);
const OverflowMenu = styled<OverflowMenuProps>(OverflowMenuComponent);
const OverflowMenuItem = styled<OverflowMenuItemProps>(OverflowMenuItemComponent);
const Popover = styled<PopoverProps>(PopoverComponent);
const Radio = styled<RadioProps>(RadioComponent);
const RadioGroup = styled<RadioGroupProps>(RadioGroupComponent);
Expand All @@ -133,8 +135,6 @@ const Toggle = styled<ToggleProps>(ToggleComponent);
const Tooltip = styled<TooltipProps>(TooltipComponent);
const TopNavigation = styled<TopNavigationBarProps>(TopNavigationComponent);
const TopNavigationAction = styled<TopNavigationBarActionProps>(TopNavigationActionComponent);
const OverflowMenuItem = styled<OverflowMenuItemProps>(OverflowMenuItemComponent);
const OverflowMenu = styled<OverflowMenuProps>(OverflowMenuComponent);

export {
Avatar,
Expand Down
6 changes: 4 additions & 2 deletions src/framework/ui/input/input.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import {
FlexStyleProps,
} from '../common/props';

const Text = styled<TextProps>(TextComponent);

type IconElement = React.ReactElement<ImageProps>;
type TextElement = React.ReactElement<TextProps>;
type IconProp = (style: StyleType) => React.ReactElement<ImageProps>;
Expand All @@ -44,8 +42,12 @@ interface InputProps {

export type Props = InputProps & StyledComponentProps & TextInputProps;

const Text = styled<TextProps>(TextComponent);

export class Input extends React.Component<Props> {

static styledComponentName: string = 'Input';

private onFocus = (event: InputFocusEvent) => {
this.props.dispatch([Interaction.FOCUSED]);

Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/layout/layout.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type Props = LayoutProps & StyledComponentProps & ViewProps;

export class Layout extends React.Component<Props> {

static styledComponentName: string = 'Layout';

private getComponentStyle = (style: StyleType): StyleType => {
return {
container: style,
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/list/list.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export type Props = ListProps<ItemType> & StyledComponentProps & FlatListProps<I

export class List extends React.Component<Props> {

static styledComponentName: string = 'List';

private listRef: React.RefObject<FlatList<ItemType>> = React.createRef();

public scrollToEnd = (params?: { animated?: boolean }) => {
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/list/listItem.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export type Props = ListItemProps & StyledComponentProps & TouchableOpacityIndex

export class ListItem extends React.Component<Props> {

static styledComponentName: string = 'ListItem';

private onPress = (event: GestureResponderEvent) => {
if (this.props.onPress) {
this.props.onPress(this.props.index, event);
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/overflowMenu/overflowMenu.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export type Props = & StyledComponentProps & OverflowMenuProps & Omit<PopoverPro

export class OverflowMenu extends React.Component<Props> {

static styledComponentName: string = 'OverflowMenu';

static defaultProps: Partial<Props> = {
indicatorOffset: 12,
};
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/overflowMenu/overflowMenuItem.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export type Props = OverflowMenuItemType & StyledComponentProps & TouchableOpaci

export class OverflowMenuItem extends React.Component<Props> {

static styledComponentName: string = 'OverflowMenuItem';

private onPress = (event: GestureResponderEvent) => {
if (this.props.onPress) {
this.props.onPress(this.props.index, event);
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/popover/popover.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const PLACEMENT_DEFAULT: Placement = Placements.BOTTOM;

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

static styledComponentName: string = 'Popover';

static defaultProps: Partial<Props> = {
placement: PLACEMENT_DEFAULT.rawValue,
visible: false,
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/radio/radio.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export type Props = RadioProps & StyledComponentProps & TouchableOpacityProps;

export class Radio extends React.Component<Props> {

static styledComponentName: string = 'Radio';

private onPress = () => {
if (this.props.onChange) {
this.props.onChange(!this.props.checked);
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/radioGroup/radioGroup.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export type Props = RadioGroupProps & StyledComponentProps & ViewProps;

export class RadioGroup extends React.Component<Props> {

static styledComponentName: string = 'RadioGroup';

static defaultProps: Partial<Props> = {
selectedIndex: -1,
};
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/tab/tab.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export type Props = TabProps & StyledComponentProps & TouchableOpacityProps;

export class Tab extends React.Component<Props> {

static styledComponentName: string = 'Tab';

static defaultProps: Partial<Props> = {
selected: false,
};
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/tab/tabBar.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export type Props = TabBarProps & StyledComponentProps & ViewProps;

export class TabBar extends React.Component<Props> {

static styledComponentName: string = 'TabBar';

static defaultProps: Partial<Props> = {
selectedIndex: 0,
};
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/text/text.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export type Props = TextProps & StyledComponentProps & TextComponentProps;

export class Text extends React.Component<Props> {

static styledComponentName: string = 'Text';

private getComponentStyle = (source: StyleType): StyleType => {
return {
color: source.color,
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/toggle/toggle.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export type Props = ToggleComponentProps & StyledComponentProps & ViewProps;

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

static styledComponentName: string = 'Toggle';

private panResponder: PanResponderInstance;
private thumbWidthAnimation: Animated.Value;
private thumbTranslateAnimation: Animated.Value;
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/tooltip/tooltip.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export type Props = TooltipProps & StyledComponentProps & Omit<PopoverProps, 'co

export class Tooltip extends React.Component<Props> {

static styledComponentName: string = 'Tooltip';

static defaultProps: Partial<Props> = {
indicatorOffset: 8,
};
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/topNavigation/topNavigation.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export type Props = TopNavigationProps & StyledComponentProps & ViewProps;

export class TopNavigation extends React.Component<Props> {

static styledComponentName: string = 'TopNavigation';

private getComponentStyle = (style: StyleType): StyleType => {
const { alignment: alignmentValue, leftControl, rightControls } = this.props;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export type Props = StyledComponentProps & TouchableOpacityProps & TopNavigation

export class TopNavigationAction extends React.Component<Props> {

static styledComponentName: string = 'TopNavigationAction';

private onPress = (event: GestureResponderEvent) => {
if (this.props.onPress) {
this.props.onPress(event);
Expand Down

0 comments on commit a08f8f2

Please sign in to comment.