Skip to content

Commit

Permalink
fix: type definitions #2398 (#2407)
Browse files Browse the repository at this point in the history
* revert(button): rest props (#2404)

* fix: type definitions #2398

* chore: revert button

* fix: type definitions

* fix: miss

* refactor: revert button
  • Loading branch information
BANG88 authored and warmhug committed May 11, 2018
1 parent cc35ff5 commit 5a2d0d5
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 95 deletions.
16 changes: 0 additions & 16 deletions components/button/index.native.tsx
Expand Up @@ -84,25 +84,9 @@ export default class Button extends React.Component<ButtonProps, any> {
loading,
...restProps,
} = this.props;
// can not understand this line.
// tslint:disable-next-line:variable-name
const _styles: any = styles!;

// unnecessary see line: 134
// [
// 'activeOpacity',
// 'underlayColor',
// 'onPress',
// 'onPressIn',
// 'onPressOut',
// 'onShowUnderlay',
// 'onHideUnderlay',
// ].forEach(prop => {
// if (restProps.hasOwnProperty(prop)) {
// delete restProps[prop];
// }
// });

const textStyle = [
_styles[`${size}RawText`],
_styles[`${type}RawText`],
Expand Down
8 changes: 4 additions & 4 deletions components/card/PropsType.tsx
Expand Up @@ -5,13 +5,13 @@ export interface CardPropsType {
}

export interface CardHeaderPropsType {
title?: JSX.Element;
title?: React.ReactNode;
/** need url of img, if this is string. */
thumb?: React.ReactNode;
extra?: JSX.Element;
extra?: React.ReactNode;
}

export interface CardFooterPropsType {
content?: JSX.Element;
extra?: JSX.Element;
content?: React.ReactNode;
extra?: React.ReactNode;
}
6 changes: 3 additions & 3 deletions components/date-picker/PropsType.tsx
Expand Up @@ -29,8 +29,8 @@ export interface DatePickerPropsType {
extra?: string;
children?: React.ReactNode;
/** React.ReactElement only for web */
dismissText?: JSX.Element;
dismissText?: React.ReactNode;
/** React.ReactElement only for web */
okText?: JSX.Element;
title?: JSX.Element;
okText?: React.ReactNode;
title?: React.ReactNode;
}
2 changes: 1 addition & 1 deletion components/input-item/PropsType.tsx
Expand Up @@ -31,7 +31,7 @@ export interface InputItemPropsType {
updatePlaceholder?: boolean;
styles?: any;
locale?: object;
onChange?: InputEventHandler;
onChange?: (value: string) => void;
onFocus?: InputEventHandler;
onBlur?: InputEventHandler;
}
4 changes: 2 additions & 2 deletions components/list/PropsType.tsx
@@ -1,8 +1,8 @@
import React, { ReactNode } from 'react';
// export type ListType = JSX.Element
export interface ListPropsType {
renderHeader?: () => React.ReactType | JSX.Element;
renderFooter?: () => React.ReactType | JSX.Element;
renderHeader?: (() => React.ReactType) | string | JSX.Element;
renderFooter?: (() => React.ReactType) | string | JSX.Element;
children?: false | JSX.Element | JSX.Element[];
}

Expand Down
15 changes: 5 additions & 10 deletions components/modal/AlertContainer.native.tsx
@@ -1,18 +1,13 @@
/* tslint:disable:jsx-no-multiline-js */
import React from 'react';
import { ScrollView, StyleProp, Text, TextStyle } from 'react-native';
import { ScrollView, Text, TextStyle } from 'react-native';
import Modal from './Modal.native';

export interface AlertButtonType {
text: string;
onPress?: () => void | Promise<any>;
style?: StyleProp<TextStyle>;
}
import { Action } from './PropsType';

export interface AlertContainerProps {
title: JSX.Element;
content: JSX.Element;
actions: AlertButtonType[];
title: React.ReactNode;
content: React.ReactNode;
actions: Action<TextStyle>[];
onAnimationEnd?: (visible: boolean) => void;
}

Expand Down
3 changes: 2 additions & 1 deletion components/modal/Modal.native.tsx
Expand Up @@ -10,6 +10,7 @@ import {
TouchableWithoutFeedback,
View,
ViewStyle,
TextStyle,
} from 'react-native';
import RCModal from 'rmc-dialog/lib/Modal';
import { ModalPropsType } from './PropsType';
Expand All @@ -21,7 +22,7 @@ const maxHeight = StyleSheet.create({
},
}).maxHeight;

export interface IModalNativeProps extends ModalPropsType {
export interface IModalNativeProps extends ModalPropsType<TextStyle> {
styles?: IModalStyle;
style?: StyleProp<ViewStyle>;
bodyStyle?: StyleProp<ViewStyle>;
Expand Down
29 changes: 26 additions & 3 deletions components/modal/Modal.tsx
Expand Up @@ -2,9 +2,32 @@ import classnames from 'classnames';
import React from 'react';
import Dialog from 'rmc-dialog';
import TouchFeedback from 'rmc-feedback';
import { Action, ModalComponent, ModalPropsType } from './PropsType';
import { Action, ModalPropsType, CallbackOrActions } from './PropsType';
export abstract class ModalComponent<P, S> extends React.Component<P, S> {
static alert: (
title: React.ReactNode,
message: React.ReactNode,
actions?: Action<React.CSSProperties>[],
platform?: string,
) => { close: () => void };

export interface ModalProps extends ModalPropsType {
static prompt: (
title: React.ReactNode,
message: React.ReactNode,
callbackOrActions: CallbackOrActions<React.CSSProperties>,
type?: 'default' | 'secure-text' | 'login-password',
defaultValue?: string,
placeholders?: string[],
platform?: string,
) => { close: () => void };

static operation: (
actions?: Action<React.CSSProperties>[],
platform?: string,
) => { close: () => void };
}

export interface ModalProps extends ModalPropsType<React.CSSProperties> {
prefixCls?: string;
transitionName?: string;
maskTransitionName?: string;
Expand All @@ -31,7 +54,7 @@ export default class Modal extends ModalComponent<ModalProps, any> {
platform: 'ios',
};

renderFooterButton(button: Action, prefixCls: string | undefined, i: number) {
renderFooterButton(button: Action<React.CSSProperties>, prefixCls: string | undefined, i: number) {
let buttonStyle = {};
if (button.style) {
buttonStyle = button.style;
Expand Down
13 changes: 4 additions & 9 deletions components/modal/OperationContainer.native.tsx
@@ -1,16 +1,11 @@
import React from 'react';
import { StyleProp, TextStyle } from 'react-native';
import Modal from './Modal';
import { TextStyle } from 'react-native';
import Modal from './Modal.native';
import modalStyle from './style/index.native';

export interface OperationButtonType {
text: string;
onPress?: () => void;
style?: StyleProp<TextStyle>;
}
import { Action } from './PropsType';

export interface OperationContainerProps {
actions: OperationButtonType[];
actions: Action<TextStyle>[];
onAnimationEnd?: (visible: boolean) => void;
}

Expand Down
7 changes: 4 additions & 3 deletions components/modal/PromptContainer.native.tsx
Expand Up @@ -6,17 +6,18 @@ import {
Text,
TextInput,
View,
TextStyle,
} from 'react-native';
import Modal from './Modal';
import { CallbackOrActions } from './PropsType';
import promptStyle, { IPromptStyle } from './style/prompt.native';

export interface PropmptContainerProps {
title: JSX.Element;
message?: JSX.Element;
title: React.ReactNode;
message?: React.ReactNode;
type?: 'default' | 'login-password' | 'secure-text';
defaultValue?: string;
actions: CallbackOrActions;
actions: CallbackOrActions<TextStyle>;
onAnimationEnd?: (visible: boolean) => void;
styles?: IPromptStyle;
placeholders?: string[];
Expand Down
37 changes: 6 additions & 31 deletions components/modal/PropsType.tsx
@@ -1,12 +1,10 @@
import React from 'react';
import { StyleProp, TextStyle } from 'react-native';

export interface ModalPropsType {
title?: JSX.Element;
export interface ModalPropsType<T> {
title?: React.ReactNode;
visible: boolean;
maskClosable?: boolean;
closable?: boolean;
footer?: Action[];
footer?: Action<T>[];
onClose?: () => void;
transparent?: boolean;
popup?: boolean;
Expand All @@ -17,34 +15,11 @@ export interface ModalPropsType {
operation?: boolean;
}

export interface Action {
export interface Action<T> {
text: string;
onPress?: () => void | Promise<any>;
style?: React.CSSProperties | StyleProp<TextStyle> | string;
style?: T | string;
}

export type Callback = (valueOrLogin: string, password?: string) => void;
export type CallbackOrActions = Callback | Action[];
export abstract class ModalComponent<P, S> extends React.Component<P, S> {
static alert: (
title: JSX.Element,
message: JSX.Element,
actions?: Action[],
platform?: string,
) => { close: () => void };

static prompt: (
title: JSX.Element,
message: JSX.Element,
callbackOrActions: CallbackOrActions,
type?: 'default' | 'secure-text' | 'login-password',
defaultValue?: string,
placeholders?: string[],
platform?: string,
) => { close: () => void };

static operation: (
actions?: Action[],
platform?: string,
) => { close: () => void };
}
export type CallbackOrActions<T> = Callback | Action<T>[];
4 changes: 2 additions & 2 deletions components/modal/alert.native.tsx
Expand Up @@ -3,8 +3,8 @@ import topView from 'rn-topview';
import AlertContainer from './AlertContainer.native';

export default function a(
title: JSX.Element,
content: JSX.Element,
title: React.ReactNode,
content: React.ReactNode,
actions = [{ text: '确定' }],
) {
const onAnimationEnd = (visible: boolean) => {
Expand Down
6 changes: 3 additions & 3 deletions components/modal/alert.tsx
Expand Up @@ -5,8 +5,8 @@ import Modal from './Modal';
import { Action } from './PropsType';

export default function alert(
title: JSX.Element,
message: JSX.Element,
title: React.ReactNode,
message: React.ReactNode,
actions = [{ text: '确定' }],
platform = 'ios',
) {
Expand All @@ -29,7 +29,7 @@ export default function alert(
}
}

const footer = actions.map((button: Action) => {
const footer = actions.map((button: Action<React.CSSProperties>) => {
// tslint:disable-next-line:only-arrow-functions
const orginPress = button.onPress || function() {};
button.onPress = () => {
Expand Down
2 changes: 1 addition & 1 deletion components/modal/operation.tsx
Expand Up @@ -21,7 +21,7 @@ export default function operation(
}
}

const footer = actions.map((button: Action) => {
const footer = actions.map((button: Action<React.CSSProperties>) => {
// tslint:disable-next-line:only-arrow-functions
const orginPress = button.onPress || function() {};
button.onPress = () => {
Expand Down
7 changes: 4 additions & 3 deletions components/modal/prompt.native.tsx
Expand Up @@ -2,11 +2,12 @@ import React from 'react';
import topView from 'rn-topview';
import PromptContainer from './PromptContainer.native';
import { CallbackOrActions } from './PropsType';
import { TextStyle } from 'react-native';

export default function prompt(
title: JSX.Element,
message: JSX.Element,
callbackOrActions: CallbackOrActions,
title: React.ReactNode,
message: React.ReactNode,
callbackOrActions: CallbackOrActions<TextStyle>,
type = 'default',
defaultValue = '',
placeholders = ['', ''],
Expand Down
6 changes: 3 additions & 3 deletions components/modal/prompt.tsx
Expand Up @@ -5,9 +5,9 @@ import Modal from './Modal';
import { CallbackOrActions } from './PropsType';

export default function prompt(
title: JSX.Element,
message: JSX.Element,
callbackOrActions: CallbackOrActions,
title: React.ReactNode,
message: React.ReactNode,
callbackOrActions: CallbackOrActions<React.CSSProperties>,
type = 'default',
defaultValue = '',
placeholders = ['', ''],
Expand Down

0 comments on commit 5a2d0d5

Please sign in to comment.