Skip to content

Commit

Permalink
Removed ts-ignore from various components (react-native-elements#2905)
Browse files Browse the repository at this point in the history
* Fixed ts-ignore issue resulted from theme prop

* Changed import/export and a small fix

* Added theme prop to index.ts
  • Loading branch information
hetanthakkar authored Mar 24, 2021
1 parent 6eaaf79 commit 661a3c8
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 55 deletions.
7 changes: 4 additions & 3 deletions src/badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ViewStyle,
} from 'react-native';
import { withTheme } from '../config';
import { Theme } from '../config/theme';
import { ThemeProps } from '../config';
import { renderNode } from '../helpers';

export type BadgeProps = {
Expand All @@ -20,11 +20,12 @@ export type BadgeProps = {
value?: React.ReactNode;
onPress?: (...args: any[]) => any;
Component?: typeof React.Component;
theme?: Theme;
status?: 'primary' | 'success' | 'warning' | 'error';
};

const Badge: React.FunctionComponent<BadgeProps> = (props) => {
const Badge: React.FunctionComponent<BadgeProps & ThemeProps<BadgeProps>> = (
props
) => {
const {
containerStyle,
textStyle,
Expand Down
6 changes: 4 additions & 2 deletions src/buttons/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { renderNode, color } from '../helpers';
import Icon, { IconNode } from '../icons/Icon';
import { Theme } from '../config/theme';
import { TextProps } from '../text/Text';
import { ThemeProps } from '../config';

const defaultLoadingProps = (
type: 'solid' | 'clear' | 'outline',
Expand Down Expand Up @@ -50,10 +51,11 @@ export type ButtonProps = TouchableOpacityProps &
disabledStyle?: StyleProp<ViewStyle>;
disabledTitleStyle?: StyleProp<TextStyle>;
raised?: boolean;
theme?: Theme;
};

const Button: React.FunctionComponent<ButtonProps> = (props: ButtonProps) => {
const Button: React.FunctionComponent<ButtonProps & ThemeProps<ButtonProps>> = (
props: ButtonProps & ThemeProps<ButtonProps>
) => {
useEffect(() => {
if (props.linearGradientProps && !props.ViewComponent) {
console.error(
Expand Down
7 changes: 4 additions & 3 deletions src/buttons/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TextStyle,
} from 'react-native';
import { withTheme } from '../config';
import { Theme } from '../config/theme';
import { ThemeProps } from '../config';
import { normalizeText, color } from '../helpers';
import Text from '../text/Text';

Expand All @@ -37,7 +37,6 @@ export type ButtonGroupProps = {
buttonStyle?: StyleProp<ViewStyle>;
buttonContainerStyle?: StyleProp<ViewStyle>;
selectMultiple?: boolean;
theme?: Theme;
disabled?: boolean | number[];
disabledStyle?: StyleProp<ViewStyle>;
disabledTextStyle?: StyleProp<TextStyle>;
Expand All @@ -46,7 +45,9 @@ export type ButtonGroupProps = {
vertical?: boolean;
};

const ButtonGroup: React.FunctionComponent<ButtonGroupProps> = (props) => {
const ButtonGroup: React.FunctionComponent<
ButtonGroupProps & ThemeProps<ButtonGroupProps>
> = (props) => {
const { theme, ...rest } = props;
const {
Component = Platform.select<typeof React.Component>({
Expand Down
6 changes: 3 additions & 3 deletions src/card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import CardDivider from './CardDivider';
import CardImage from './CardImage';
import CardFeaturedTitle from './CardFeaturedTitle';
import CardFeaturedSubtitle from './CardFeaturedSubtitle';
import { Theme } from '../config/theme';
import { ThemeProps } from '../config';

export type CardProps = {
containerStyle?: StyleProp<ViewStyle>;
wrapperStyle?: StyleProp<ViewStyle>;
theme?: Theme;
};

interface Card extends React.FunctionComponent<CardProps> {}
interface Card
extends React.FunctionComponent<CardProps & ThemeProps<CardProps>> {}

const Card: Card = (props) => {
const {
Expand Down
7 changes: 4 additions & 3 deletions src/checkbox/CheckBoxIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Theme } from '../config/theme';
import { ThemeProps } from '../config';
import getIconType from '../helpers/getIconType';
import { IconType } from '../icons/Icon';

Expand All @@ -13,10 +13,11 @@ export type CheckBoxIconProps = {
iconType?: IconType;
checkedColor?: string;
uncheckedColor?: string;
theme?: Theme;
};

const CheckBoxIcon: React.FunctionComponent<CheckBoxIconProps> = ({
const CheckBoxIcon: React.FunctionComponent<
CheckBoxIconProps & ThemeProps<CheckBoxIconProps>
> = ({
checked,
onIconPress,
onLongIconPress,
Expand Down
8 changes: 6 additions & 2 deletions src/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import BackgroundImage from './BackgroundImage';
import colors from './colors';
import colorsDark from './colorsDark';
import fonts from './fonts';
import ThemeProvider, { ThemeConsumer, ThemeContext } from './ThemeProvider';
import ThemeProvider, {
ThemeConsumer,
ThemeContext,
ThemeProps,
} from './ThemeProvider';
import withTheme from './withTheme';
import { makeStyles, useTheme } from './makeStyles';
import { Theme, FullTheme, UpdateTheme, ReplaceTheme } from './theme';
Expand All @@ -20,4 +24,4 @@ export {
makeStyles,
};

export type { Theme, FullTheme, UpdateTheme, ReplaceTheme };
export type { Theme, FullTheme, UpdateTheme, ReplaceTheme, ThemeProps };
11 changes: 4 additions & 7 deletions src/divider/Divider.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import React from 'react';
import { View, StyleSheet, ViewProps } from 'react-native';
import { withTheme } from '../config';
import { Theme } from '../config/theme';
import { ThemeProps } from '../config';

export type DividerProps = ViewProps & {
style?: object | any[];
theme?: Theme;
};

const Divider: React.FunctionComponent<DividerProps> = ({
style,
theme,
...rest
}) => (
const Divider: React.FunctionComponent<
DividerProps & ThemeProps<DividerProps>
> = ({ style, theme, ...rest }) => (
<View
style={StyleSheet.flatten([
{
Expand Down
7 changes: 4 additions & 3 deletions src/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { renderNode } from '../helpers';

import Text from '../text/Text';
import Icon, { IconObject } from '../icons/Icon';
import { Theme } from '../config/theme';
import { ThemeProps } from '../config';

type Placement = 'left' | 'center' | 'right';

Expand Down Expand Up @@ -84,12 +84,13 @@ export type HeaderProps = ViewProps & {
centerContainerStyle?: StyleProp<ViewStyle>;
leftContainerStyle?: StyleProp<ViewStyle>;
rightContainerStyle?: StyleProp<ViewStyle>;
theme?: Theme;
children?: JSX.Element[];
elevated: boolean;
};

const Header: React.FunctionComponent<HeaderProps> = (props: HeaderProps) => {
const Header: React.FunctionComponent<HeaderProps & ThemeProps<HeaderProps>> = (
props: HeaderProps & ThemeProps<HeaderProps>
) => {
React.useEffect(() => {
const { linearGradientProps, ViewComponent } = props;
if (linearGradientProps && !ViewComponent) {
Expand Down
7 changes: 4 additions & 3 deletions src/icons/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Color from 'color';
import getIconType from '../helpers/getIconType';
import getIconStyle from '../helpers/getIconStyle';
import { withTheme } from '../config';
import { Theme } from '../config/theme';
import { ThemeProps } from '../config';

export type IconType =
| 'material'
Expand Down Expand Up @@ -57,10 +57,11 @@ export type IconProps = IconButtonProps & {
disabledStyle?: StyleProp<ViewStyle>;
solid?: boolean;
brand?: boolean;
theme?: Theme;
};

const Icon: React.FunctionComponent<IconProps> = (props) => {
const Icon: React.FunctionComponent<IconProps & ThemeProps<IconProps>> = (
props
) => {
const {
type = 'material',
name,
Expand Down
7 changes: 5 additions & 2 deletions src/image/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
StyleProp,
} from 'react-native';
import { withTheme } from '../config';
import { ThemeProps } from '../config';

export type ImageProps = RNImageProps & {
Component?: typeof React.Component;
Expand All @@ -27,7 +28,10 @@ type ImageState = {
placeholderOpacity: Animated.Value;
};

class Image extends React.Component<ImageProps, ImageState> {
class Image extends React.Component<
ImageProps & ThemeProps<ImageProps>,
ImageState
> {
static getSize = ImageNative.getSize;
static getSizeWithHeaders = ImageNative.getSizeWithHeaders;
static prefetch = ImageNative.prefetch;
Expand Down Expand Up @@ -143,5 +147,4 @@ const styles = StyleSheet.create({
});

export { Image };
//@ts-ignore
export default withTheme(Image, 'Image');
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ import {
ReplaceTheme,
FullTheme,
Theme,
ThemeProps,
} from './config';
import getIconType, { registerCustomIconType } from './helpers/getIconType';
import normalize from './helpers/normalizeText';

//@ts-ignore
const AirbnbRating = withTheme(BaseAirbnbRating, 'AirbnbRating');
//@ts-ignore
const Rating = withTheme(BaseRating, 'Rating');

export {
Expand Down Expand Up @@ -138,4 +137,5 @@ export type {
Theme,
LinearProgressProps,
FABProps,
ThemeProps,
};
7 changes: 2 additions & 5 deletions src/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {
import { renderNode, patchWebProps } from '../helpers';
import { fonts, withTheme } from '../config';
import Icon from '../icons/Icon';
import { Theme } from '../config/theme';

import { ThemeProps } from '../config';
const renderText = (content, defaultProps, style) =>
renderNode(Text, content, {
...defaultProps,
Expand All @@ -40,11 +39,10 @@ export type InputProps = TextInputProps & {
label?: React.ReactNode;
labelStyle?: object | any[];
labelProps?: object;
theme?: Theme;
renderErrorMessage?: boolean;
};

class Input extends React.Component<InputProps> {
class Input extends React.Component<InputProps & ThemeProps<InputProps>> {
input: any;
shakeAnimationValue = new Animated.Value(0);

Expand Down Expand Up @@ -231,5 +229,4 @@ const styles = StyleSheet.create({
});

export { Input };
//@ts-ignore
export default withTheme(Input, 'Input');
6 changes: 3 additions & 3 deletions src/list/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ListItemCheckBox from './ListItemCheckBox';
import ListItemButtonGroup from './ListItemButtonGroup';
import ListItemTitle from './ListItemTitle';
import ListItemSubtitle from './ListItemSubtitle';
import { Theme } from '../config/theme';
import { ThemeProps } from '../config';

export type ListItemProps = TouchableHighlightProps & {
containerStyle?: StyleProp<ViewStyle>;
Expand All @@ -29,11 +29,11 @@ export type ListItemProps = TouchableHighlightProps & {
Component?: typeof React.Component;
ViewComponent?: typeof React.Component;
linearGradientProps?: any;
theme?: Theme;
children?: any;
};

interface ListItem extends React.FunctionComponent<ListItemProps> {
interface ListItem
extends React.FunctionComponent<ListItemProps & ThemeProps<ListItemProps>> {
Chevron: typeof ListItemChevron;
Content: typeof ListItemContent;
Input: typeof ListItemInput;
Expand Down
7 changes: 4 additions & 3 deletions src/pricing/PricingCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { fonts, withTheme } from '../config';
import Text from '../text/Text';
import Button from '../buttons/Button';
import Icon from '../icons/Icon';
import { Theme } from '../config/theme';
import { ThemeProps } from '../config';

type ButtonInformation = {
title: string;
Expand All @@ -33,10 +33,11 @@ export type PricingCardProps = {
titleStyle?: StyleProp<TextStyle>;
pricingStyle?: StyleProp<TextStyle>;
infoStyle?: StyleProp<TextStyle>;
theme?: Theme;
};

const PricingCard: React.FunctionComponent<PricingCardProps> = (props) => {
const PricingCard: React.FunctionComponent<
PricingCardProps & ThemeProps<PricingCardProps>
> = (props) => {
const { theme, ...rest } = props;
const {
containerStyle,
Expand Down
10 changes: 5 additions & 5 deletions src/searchbar/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ViewStyle,
} from 'react-native';
import { IconNode } from '../icons/Icon';
import { Theme } from '../config/theme';
import { ThemeProps } from '../config';

const SEARCHBAR_COMPONENTS = {
ios: IOSSearchBar,
Expand All @@ -34,18 +34,19 @@ export type SearchBarBaseProps = {
onBlur?(): void;
onChangeText?(text: string): void;
onCancel?(): void;
theme?: Theme;
};

export type SearchBarProps = SearchBarBaseProps &
SearchBarDefaultProps &
SearchBarAndroidProps &
SearchBarIosProps;

class SearchBar extends React.Component<SearchBarBaseProps> {
class SearchBar extends React.Component<
SearchBarBaseProps & ThemeProps<SearchBarBaseProps>
> {
searchbar!: IOSSearchBar;
static defaultProps = {
platform: 'default',
platform: 'default' as const,
};

focus = () => {
Expand Down Expand Up @@ -81,5 +82,4 @@ class SearchBar extends React.Component<SearchBarBaseProps> {
}

export { SearchBar };
//@ts-ignore
export default withTheme(SearchBar, 'SearchBar');
7 changes: 4 additions & 3 deletions src/text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
StyleProp,
} from 'react-native';
import { fonts, withTheme } from '../config';
import { Theme } from '../config/theme';
import { patchWebProps } from '../helpers';
import normalize from '../helpers/normalizeText';
import { ThemeProps } from '../config';

export type TextProps = TextProperties & {
style?: StyleProp<TextStyle>;
Expand All @@ -22,10 +22,11 @@ export type TextProps = TextProperties & {
h2Style?: StyleProp<TextStyle>;
h3Style?: StyleProp<TextStyle>;
h4Style?: StyleProp<TextStyle>;
theme?: Theme;
};

const TextElement: React.FunctionComponent<TextProps> = (props) => {
const TextElement: React.FunctionComponent<
TextProps & ThemeProps<TextProps & ThemeProps<TextProps>>
> = (props) => {
const {
style,
theme,
Expand Down
Loading

0 comments on commit 661a3c8

Please sign in to comment.