mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-12 04:13:13 +08:00
Fix implicit any error for Modal and Message
This commit is contained in:
parent
446977b916
commit
d8f6c3bd8c
@ -3,13 +3,13 @@ import Notification from 'rc-notification';
|
|||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
|
|
||||||
let defaultDuration = 3;
|
let defaultDuration = 3;
|
||||||
let defaultTop;
|
let defaultTop: number;
|
||||||
let messageInstance;
|
let messageInstance: any;
|
||||||
let key = 1;
|
let key = 1;
|
||||||
let prefixCls = 'ant-message';
|
let prefixCls = 'ant-message';
|
||||||
let getContainer;
|
let getContainer: () => HTMLElement;
|
||||||
|
|
||||||
function getMessageInstance(callback) {
|
function getMessageInstance(callback: (i: any) => void) {
|
||||||
if (messageInstance) {
|
if (messageInstance) {
|
||||||
callback(messageInstance);
|
callback(messageInstance);
|
||||||
return;
|
return;
|
||||||
@ -19,7 +19,7 @@ function getMessageInstance(callback) {
|
|||||||
transitionName: 'move-up',
|
transitionName: 'move-up',
|
||||||
style: { top: defaultTop }, // 覆盖原来的样式
|
style: { top: defaultTop }, // 覆盖原来的样式
|
||||||
getContainer,
|
getContainer,
|
||||||
}, (instance) => {
|
}, (instance: any) => {
|
||||||
messageInstance = instance;
|
messageInstance = instance;
|
||||||
callback(instance);
|
callback(instance);
|
||||||
});
|
});
|
||||||
|
@ -5,13 +5,19 @@ import { ButtonType } from '../button/button';
|
|||||||
|
|
||||||
export interface ActionButtonProps {
|
export interface ActionButtonProps {
|
||||||
type?: ButtonType;
|
type?: ButtonType;
|
||||||
actionFn: Function;
|
actionFn?: (...args: any[]) => any | PromiseLike<any>;
|
||||||
closeModal: Function;
|
closeModal: Function;
|
||||||
autoFocus?: Boolean;
|
autoFocus?: boolean;
|
||||||
}
|
}
|
||||||
export default class ActionButton extends React.Component<ActionButtonProps, any> {
|
|
||||||
|
export interface ActionButtonState {
|
||||||
|
loading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class ActionButton extends React.Component<ActionButtonProps, ActionButtonState> {
|
||||||
timeoutId: number;
|
timeoutId: number;
|
||||||
constructor(props) {
|
|
||||||
|
constructor(props: ActionButtonProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
loading: false,
|
loading: false,
|
||||||
@ -40,7 +46,7 @@ export default class ActionButton extends React.Component<ActionButtonProps, any
|
|||||||
}
|
}
|
||||||
if (ret && ret.then) {
|
if (ret && ret.then) {
|
||||||
this.setState({ loading: true });
|
this.setState({ loading: true });
|
||||||
ret.then((...args) => {
|
ret.then((...args: any[]) => {
|
||||||
// It's unnecessary to set loading=false, for the Modal will be unmounted after close.
|
// It's unnecessary to set loading=false, for the Modal will be unmounted after close.
|
||||||
// this.setState({ loading: false });
|
// this.setState({ loading: false });
|
||||||
closeModal(...args);
|
closeModal(...args);
|
||||||
|
@ -7,8 +7,8 @@ import { ButtonType } from '../button/button';
|
|||||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||||
import { getConfirmLocale } from './locale';
|
import { getConfirmLocale } from './locale';
|
||||||
|
|
||||||
let mousePosition;
|
let mousePosition: { x: number, y: number } | null;
|
||||||
let mousePositionEventBinded;
|
let mousePositionEventBinded: boolean;
|
||||||
|
|
||||||
export interface ModalProps {
|
export interface ModalProps {
|
||||||
/** 对话框是否可见*/
|
/** 对话框是否可见*/
|
||||||
@ -46,11 +46,13 @@ export interface ModalProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ModalFuncProps {
|
export interface ModalFuncProps {
|
||||||
|
prefixCls?: string;
|
||||||
|
className?: string;
|
||||||
visible?: boolean;
|
visible?: boolean;
|
||||||
title?: React.ReactNode | string;
|
title?: React.ReactNode;
|
||||||
content?: React.ReactNode | string;
|
content?: React.ReactNode;
|
||||||
onOk?: (func: Function) => any;
|
onOk?: (...args: any[]) => any | PromiseLike<any>;
|
||||||
onCancel?: (func: Function) => any;
|
onCancel?: (...args: any[]) => any | PromiseLike<any>;
|
||||||
width?: string | number;
|
width?: string | number;
|
||||||
iconClassName?: string;
|
iconClassName?: string;
|
||||||
okText?: string;
|
okText?: string;
|
||||||
@ -59,12 +61,22 @@ export interface ModalFuncProps {
|
|||||||
iconType?: string;
|
iconType?: string;
|
||||||
maskClosable?: boolean;
|
maskClosable?: boolean;
|
||||||
zIndex?: number;
|
zIndex?: number;
|
||||||
|
okCancel?: boolean;
|
||||||
|
style?: React.CSSProperties;
|
||||||
|
type?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ModalFunc = (props: ModalFuncProps) => {
|
export type ModalFunc = (props: ModalFuncProps) => {
|
||||||
destroy: () => void,
|
destroy: () => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class Modal extends React.Component<ModalProps, any> {
|
export interface ModalLocale {
|
||||||
|
okText: string;
|
||||||
|
cancelText: string;
|
||||||
|
justOkText: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Modal extends React.Component<ModalProps, {}> {
|
||||||
static info: ModalFunc;
|
static info: ModalFunc;
|
||||||
static success: ModalFunc;
|
static success: ModalFunc;
|
||||||
static error: ModalFunc;
|
static error: ModalFunc;
|
||||||
@ -97,14 +109,14 @@ export default class Modal extends React.Component<ModalProps, any> {
|
|||||||
closable: PropTypes.bool,
|
closable: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
handleCancel = (e) => {
|
handleCancel = (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
const onCancel = this.props.onCancel;
|
const onCancel = this.props.onCancel;
|
||||||
if (onCancel) {
|
if (onCancel) {
|
||||||
onCancel(e);
|
onCancel(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleOk = (e) => {
|
handleOk = (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
const onOk = this.props.onOk;
|
const onOk = this.props.onOk;
|
||||||
if (onOk) {
|
if (onOk) {
|
||||||
onOk(e);
|
onOk(e);
|
||||||
@ -129,7 +141,7 @@ export default class Modal extends React.Component<ModalProps, any> {
|
|||||||
mousePositionEventBinded = true;
|
mousePositionEventBinded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderFooter = (locale) => {
|
renderFooter = (locale: ModalLocale) => {
|
||||||
const { okText, okType, cancelText, confirmLoading } = this.props;
|
const { okText, okType, cancelText, confirmLoading } = this.props;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -2,12 +2,12 @@ import * as React from 'react';
|
|||||||
import * as ReactDOM from 'react-dom';
|
import * as ReactDOM from 'react-dom';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
import Dialog from './Modal';
|
import Dialog, { ModalFuncProps } from './Modal';
|
||||||
import ActionButton from './ActionButton';
|
import ActionButton from './ActionButton';
|
||||||
import { getConfirmLocale } from './locale';
|
import { getConfirmLocale } from './locale';
|
||||||
|
|
||||||
export default function confirm(config) {
|
export default function confirm(config: ModalFuncProps) {
|
||||||
const props = {
|
const props: ModalFuncProps = {
|
||||||
iconType: 'question-circle',
|
iconType: 'question-circle',
|
||||||
okType: 'primary',
|
okType: 'primary',
|
||||||
...config,
|
...config,
|
||||||
@ -33,7 +33,7 @@ export default function confirm(config) {
|
|||||||
(props.okCancel ? runtimeLocale.okText : runtimeLocale.justOkText);
|
(props.okCancel ? runtimeLocale.okText : runtimeLocale.justOkText);
|
||||||
props.cancelText = props.cancelText || runtimeLocale.cancelText;
|
props.cancelText = props.cancelText || runtimeLocale.cancelText;
|
||||||
|
|
||||||
function close(...args) {
|
function close(...args: any[]) {
|
||||||
const unmountResult = ReactDOM.unmountComponentAtNode(div);
|
const unmountResult = ReactDOM.unmountComponentAtNode(div);
|
||||||
if (unmountResult && div.parentNode) {
|
if (unmountResult && div.parentNode) {
|
||||||
div.parentNode.removeChild(div);
|
div.parentNode.removeChild(div);
|
||||||
@ -47,7 +47,7 @@ export default function confirm(config) {
|
|||||||
|
|
||||||
let body = (
|
let body = (
|
||||||
<div className={`${prefixCls}-body`}>
|
<div className={`${prefixCls}-body`}>
|
||||||
<Icon type={props.iconType} />
|
<Icon type={props.iconType!} />
|
||||||
<span className={`${prefixCls}-title`}>{props.title}</span>
|
<span className={`${prefixCls}-title`}>{props.title}</span>
|
||||||
<div className={`${prefixCls}-content`}>{props.content}</div>
|
<div className={`${prefixCls}-content`}>{props.content}</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user