Skip to content

Fix button static values and other small type fixes #834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generatedTypes/commons/asBaseComponent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export interface BaseComponentInjectedProps {
*/
modifiers: ReturnType<typeof Modifiers.generateModifiersStyle>;
}
declare function asBaseComponent<PROPS, STATICS = {}>(WrappedComponent: React.ComponentType<any>): React.ComponentType<PROPS> & STATICS;
declare function asBaseComponent<PROPS, STATICS = {}>(WrappedComponent: React.ComponentType<any>): React.ComponentClass<PROPS> & STATICS;
export default asBaseComponent;
41 changes: 22 additions & 19 deletions generatedTypes/components/button/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import React, { PureComponent } from 'react';
import { LayoutChangeEvent, ImageStyle, TextStyle } from 'react-native';
import { LayoutChangeEvent, ImageStyle, TextStyle, StyleProp } from 'react-native';
import { BaseComponentInjectedProps, ForwardRefInjectedProps, TypographyModifiers, ColorsModifiers, BackgroundColorModifier, MarginModifiers } from '../../commons/new';
import { TouchableOpacityProps } from '../touchableOpacity';
import { TextPropTypes } from '../text';
export declare type ButtonPropTypes = TextPropTypes & TypographyModifiers & ColorsModifiers & BackgroundColorModifier & MarginModifiers & {
declare enum ButtonSize {
xSmall = "xSmall",
small = "small",
medium = "medium",
large = "large"
}
declare enum AnimationDirection {
center = "center",
left = "left",
right = "right"
}
export declare type ButtonPropTypes = TouchableOpacityProps & TypographyModifiers & ColorsModifiers & BackgroundColorModifier & MarginModifiers & {
/**
* Text to show inside the button
*/
Expand All @@ -18,7 +30,7 @@ export declare type ButtonPropTypes = TextPropTypes & TypographyModifiers & Colo
/**
* Icon image style
*/
iconStyle?: ImageStyle;
iconStyle?: StyleProp<ImageStyle>;
/**
* Should the icon be right to the label
*/
Expand All @@ -30,7 +42,7 @@ export declare type ButtonPropTypes = TextPropTypes & TypographyModifiers & Colo
/**
* Size of the button [large, medium, small, xSmall]
*/
size?: 'xSmall' | 'small' | 'medium' | 'large';
size?: ButtonSize;
/**
* Custom border radius.
*/
Expand Down Expand Up @@ -70,7 +82,7 @@ export declare type ButtonPropTypes = TextPropTypes & TypographyModifiers & Colo
/**
* Props that will be passed to the button's Text label.
*/
labelProps?: object;
labelProps?: TextPropTypes;
/**
* should the button act as a coast to coast button (no border radius)
*/
Expand Down Expand Up @@ -104,7 +116,7 @@ export declare type ButtonPropTypes = TextPropTypes & TypographyModifiers & Colo
/**
* the direction of the animation ('left' and 'right' will effect the button's own alignment)
*/
animateTo?: 'center' | 'left' | 'right';
animateTo?: AnimationDirection;
};
export declare type ButtonState = {
size?: number;
Expand All @@ -125,17 +137,8 @@ declare class Button extends PureComponent<Props, ButtonState> {
static defaultProps: {
iconOnRight: boolean;
};
static sizes: {
xSmall: string;
small: string;
medium: string;
large: string;
};
static animationDirection: {
center: string;
left: string;
right: string;
};
static sizes: typeof ButtonSize;
static animationDirection: typeof AnimationDirection;
constructor(props: Props);
state: {
size: undefined;
Expand Down Expand Up @@ -316,7 +319,7 @@ declare class Button extends PureComponent<Props, ButtonState> {
} | {
shadowColor: any;
})[] | undefined;
getIconStyle(): (ImageStyle | undefined)[];
getIconStyle(): StyleProp<ImageStyle>[];
getAnimationDirectionStyle(): {
alignSelf: string;
} | undefined;
Expand All @@ -325,5 +328,5 @@ declare class Button extends PureComponent<Props, ButtonState> {
render(): JSX.Element;
}
export { Button };
declare const _default: React.ComponentClass<ButtonPropTypes, any> | React.FunctionComponent<ButtonPropTypes>;
declare const _default: React.ComponentClass<ButtonPropTypes, any> & typeof Button;
export default _default;
7 changes: 6 additions & 1 deletion generatedTypes/components/card/CardImage.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { ImageSourcePropType } from 'react-native';
import { ImageProps } from '../image';
export declare type CardImageProps = ImageProps & {
export declare type CardImageProps = Omit<ImageProps, 'source'> & {
/**
* Image source, either remote source or local. Note: for remote pass object {uri: <remote_uri_string>}
*/
Expand All @@ -24,6 +24,11 @@ export declare type CardImageProps = ImageProps & {
* border radius, basically for Android since overflow doesn't work well (deprecated)
*/
borderRadius?: number;
/**
* Image source, either remote source or local. Note: for remote pass object {uri: <remote_uri_string>}
* TODO: Remove after imageSource deprecation - should take it from Image props
*/
source?: ImageSourcePropType;
};
declare const _default: React.ComponentType<CardImageProps>;
export default _default;
2 changes: 1 addition & 1 deletion generatedTypes/components/card/CardSection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ export declare type CardSectionProps = ViewPropTypes & {
*/
imageProps?: ImageProps;
};
declare const _default: React.ComponentClass<CardSectionProps, any> | React.FunctionComponent<CardSectionProps>;
declare const _default: React.ComponentClass<CardSectionProps, any>;
export default _default;
9 changes: 3 additions & 6 deletions generatedTypes/components/card/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ export declare type CardPropTypes = ViewPropTypes & TouchableOpacityProps & {
hideIndicator?: boolean;
};
};
declare const _default: (React.ComponentClass<CardPropTypes, any> & {
declare const _default: React.ComponentClass<CardPropTypes, any> & {
Image: React.ComponentType<import("./CardImage").CardImageProps>;
Section: React.ComponentClass<CardSectionProps, any> | React.FunctionComponent<CardSectionProps>;
}) | (React.FunctionComponent<CardPropTypes> & {
Image: React.ComponentType<import("./CardImage").CardImageProps>;
Section: React.ComponentClass<CardSectionProps, any> | React.FunctionComponent<CardSectionProps>;
});
Section: React.ComponentClass<CardSectionProps, any>;
};
export default _default;
5 changes: 2 additions & 3 deletions generatedTypes/components/checkbox/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { StyleProp, TouchableOpacityProps, ViewStyle } from 'react-native';
interface CheckboxProps {
export interface CheckboxPropTypes extends TouchableOpacityProps {
/**
* The value of the Checkbox. If true the switch will be turned on. Default value is false.
*/
Expand Down Expand Up @@ -38,6 +38,5 @@ interface CheckboxProps {
*/
style?: StyleProp<ViewStyle>;
}
declare type Props = CheckboxProps & TouchableOpacityProps;
declare const _default: React.ComponentClass<Props, any> | React.FunctionComponent<Props>;
declare const _default: React.ComponentClass<CheckboxPropTypes, any>;
export default _default;
2 changes: 1 addition & 1 deletion generatedTypes/components/image/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ declare class Image extends PureComponent<Props> {
render(): JSX.Element;
}
export { Image };
declare const _default: React.ComponentClass<ImageProps, any> | React.FunctionComponent<ImageProps>;
declare const _default: React.ComponentClass<ImageProps, any>;
export default _default;
10 changes: 6 additions & 4 deletions generatedTypes/components/radioButton/RadioButton.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { TextStyle, ImageSourcePropType, ImageStyle } from 'react-native';
interface RadioButtonPropTypes {
import { TextStyle, ImageSourcePropType, ImageStyle, ViewProps } from 'react-native';
import { BaseComponentInjectedProps, ForwardRefInjectedProps } from '../../commons/new';
import { RadioGroupContextPropTypes } from './RadioGroupContext';
export declare type RadioButtonPropTypes = RadioGroupContextPropTypes & BaseComponentInjectedProps & ForwardRefInjectedProps & ViewProps & {
/**
* The identifier value of the radio button. must be different than other RadioButtons in the same group
*/
Expand Down Expand Up @@ -49,6 +51,6 @@ interface RadioButtonPropTypes {
* Should the icon be on the right side of the label
*/
iconOnRight?: boolean;
}
declare const _default: React.ComponentClass<RadioButtonPropTypes, any> | React.FunctionComponent<RadioButtonPropTypes>;
};
declare const _default: React.ComponentClass<RadioButtonPropTypes, any>;
export default _default;
7 changes: 4 additions & 3 deletions generatedTypes/components/radioButton/RadioGroup.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
interface RadioGroupPropTypes {
import { BaseComponentInjectedProps, ForwardRefInjectedProps } from '../../commons/new';
export declare type RadioGroupPropTypes = BaseComponentInjectedProps & ForwardRefInjectedProps & {
/**
* The initial value of the selected radio button
*/
Expand All @@ -8,6 +9,6 @@ interface RadioGroupPropTypes {
* Invoked once when value changes, by selecting one of the radio buttons in the group
*/
onValueChange?: (value: string | number | boolean) => void;
}
declare const _default: React.ComponentClass<RadioGroupPropTypes, any> | React.FunctionComponent<RadioGroupPropTypes>;
};
declare const _default: React.ComponentClass<RadioGroupPropTypes, any>;
export default _default;
2 changes: 1 addition & 1 deletion generatedTypes/components/text/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ declare class Text extends PureComponent<PropsTypes> {
render(): JSX.Element;
}
export { Text };
declare const _default: React.ComponentClass<TextPropTypes, any> | React.FunctionComponent<TextPropTypes>;
declare const _default: React.ComponentClass<TextPropTypes, any>;
export default _default;
2 changes: 1 addition & 1 deletion generatedTypes/components/touchableOpacity/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export declare type TouchableOpacityProps = RNTouchableOpacityProps & ContainerM
useNative?: boolean;
ref?: any;
};
declare const _default: React.ComponentClass<TouchableOpacityProps, any> | React.FunctionComponent<TouchableOpacityProps>;
declare const _default: React.ComponentClass<TouchableOpacityProps, any>;
export default _default;
2 changes: 1 addition & 1 deletion generatedTypes/components/view/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export interface ViewPropTypes extends ViewProps, ContainerModifiers {
*/
renderDelay?: number;
}
declare const _default: React.ComponentClass<ViewPropTypes, any> | React.FunctionComponent<ViewPropTypes>;
declare const _default: React.ComponentClass<ViewPropTypes, any>;
export default _default;
2 changes: 1 addition & 1 deletion generatedTypes/incubator/TouchableOpacity.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ declare type TouchableOpacityPropTypes = {
*/
style: ViewStyle;
};
declare const _default: React.ComponentClass<TouchableOpacityPropTypes, any> | React.FunctionComponent<TouchableOpacityPropTypes>;
declare const _default: React.ComponentClass<TouchableOpacityPropTypes, any>;
export default _default;
15 changes: 8 additions & 7 deletions generatedTypes/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ export * from './style';
export {withScrollEnabler} from './commons/new';
export {default as Card, CardPropTypes, CardSectionProps} from './components/card';
export {default as View, ViewPropTypes} from './components/view';
export {default as Text} from './components/text';
export {default as Text, TextPropTypes} from './components/text';
export {default as TouchableOpacity, TouchableOpacityProps} from './components/touchableOpacity';
export {default as Button} from './components/button';
export {default as Checkbox} from './components/checkbox';
export {default as Image} from './components/image';
export {default as Overlay} from './components/overlay';
export {default as RadioButton} from './components/radioButton/RadioButton';
export {default as RadioGroup} from './components/radioButton/RadioGroup';
export {default as Button, ButtonPropTypes} from './components/button';
export {default as Checkbox, CheckboxPropTypes} from './components/checkbox';
export {default as Image, ImageProps} from './components/image';
export {default as Overlay, OverlayTypes} from './components/overlay';
export {default as RadioButton, RadioButtonPropTypes} from './components/radioButton/RadioButton';
export {default as RadioGroup, RadioGroupPropTypes} from './components/radioButton/RadioGroup';

/* All components with manual typings */
export {
ActionBar,
ActionSheet,
Avatar,
AvatarProps,
Badge,
Card,
Carousel,
Expand Down
44 changes: 24 additions & 20 deletions src/components/button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {PureComponent} from 'react';
import {Platform, StyleSheet, LayoutAnimation, Image, LayoutChangeEvent, ImageStyle, TextStyle} from 'react-native';
import {Platform, StyleSheet, LayoutAnimation, Image, LayoutChangeEvent, ImageStyle, TextStyle, StyleProp} from 'react-native';
import _ from 'lodash';
import {
asBaseComponent,
Expand All @@ -15,10 +15,23 @@ import {
import {Constants} from '../../helpers';
import {Colors, Typography, ThemeManager, BorderRadiuses} from '../../style';
import {extractColorValue, extractTypographyValue} from '../../commons/modifiers';
import TouchableOpacity from '../touchableOpacity';
import TouchableOpacity, {TouchableOpacityProps} from '../touchableOpacity';
import Text, {TextPropTypes} from '../text';

export type ButtonPropTypes = TextPropTypes &
enum ButtonSize {
xSmall = 'xSmall',
small = 'small',
medium = 'medium',
large = 'large',
}

enum AnimationDirection {
center = 'center',
left = 'left',
right = 'right',
}

export type ButtonPropTypes = TouchableOpacityProps &
TypographyModifiers &
ColorsModifiers &
BackgroundColorModifier &
Expand All @@ -38,7 +51,7 @@ export type ButtonPropTypes = TextPropTypes &
/**
* Icon image style
*/
iconStyle?: ImageStyle;
iconStyle?: StyleProp<ImageStyle>;
/**
* Should the icon be right to the label
*/
Expand All @@ -50,7 +63,7 @@ export type ButtonPropTypes = TextPropTypes &
/**
* Size of the button [large, medium, small, xSmall]
*/
size?: 'xSmall' | 'small' | 'medium' | 'large';
size?: ButtonSize;
/**
* Custom border radius.
*/
Expand Down Expand Up @@ -90,7 +103,7 @@ export type ButtonPropTypes = TextPropTypes &
/**
* Props that will be passed to the button's Text label.
*/
labelProps?: object;
labelProps?: TextPropTypes;
/**
* should the button act as a coast to coast button (no border radius)
*/
Expand Down Expand Up @@ -124,7 +137,7 @@ export type ButtonPropTypes = TextPropTypes &
/**
* the direction of the animation ('left' and 'right' will effect the button's own alignment)
*/
animateTo?: 'center' | 'left' | 'right';
animateTo?: AnimationDirection;
};

export type ButtonState = {
Expand All @@ -151,7 +164,7 @@ const MIN_WIDTH = {
MEDIUM: 77,
LARGE: 90
};
const DEFAULT_SIZE = 'large';
const DEFAULT_SIZE = ButtonSize.large;

type Props = ButtonPropTypes & BaseComponentInjectedProps & ForwardRefInjectedProps;

Expand All @@ -170,18 +183,9 @@ class Button extends PureComponent<Props, ButtonState> {
iconOnRight: false
};

static sizes = {
xSmall: 'xSmall',
small: 'small',
medium: 'medium',
large: 'large'
};
static sizes = ButtonSize;

static animationDirection = {
center: 'center',
left: 'left',
right: 'right'
};
static animationDirection = AnimationDirection;

// This redundant constructor for some reason fix tests :/
// eslint-disable-next-line
Expand Down Expand Up @@ -553,4 +557,4 @@ function createStyles() {

export {Button}; // For tests

export default asBaseComponent<ButtonPropTypes>(forwardRef(Button));
export default asBaseComponent<ButtonPropTypes, typeof Button>(forwardRef(Button));
Loading