mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 19:19:57 +08:00
refactor(button): enable noImplicitAny #5627
This commit is contained in:
parent
9ac0233ae8
commit
ae631c7190
@ -15,10 +15,16 @@ export default function ButtonGroup(props: ButtonGroupProps) {
|
||||
|
||||
// large => lg
|
||||
// small => sm
|
||||
const sizeCls = ({
|
||||
large: 'lg',
|
||||
small: 'sm',
|
||||
})[size] || '';
|
||||
let sizeCls = '';
|
||||
switch (size) {
|
||||
case 'large':
|
||||
sizeCls = 'lg';
|
||||
break;
|
||||
case 'small':
|
||||
sizeCls = 'sm';
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const classes = classNames(prefixCls, {
|
||||
[`${prefixCls}-${sizeCls}`]: sizeCls,
|
||||
|
@ -6,21 +6,23 @@ import omit from 'omit.js';
|
||||
|
||||
const rxTwoCNChar = /^[\u4e00-\u9fa5]{2}$/;
|
||||
const isTwoCNChar = rxTwoCNChar.test.bind(rxTwoCNChar);
|
||||
function isString(str) {
|
||||
function isString(str: any) {
|
||||
return typeof str === 'string';
|
||||
}
|
||||
|
||||
// Insert one space between two chinese characters automatically.
|
||||
function insertSpace(child) {
|
||||
function insertSpace(child: React.ReactChild) {
|
||||
// Check the child if is undefined or null.
|
||||
if (child == null) {
|
||||
return;
|
||||
}
|
||||
if (isString(child.type) && isTwoCNChar(child.props.children)) {
|
||||
// strictNullChecks oops.
|
||||
if (typeof child !== 'string' && typeof child !== 'number' &&
|
||||
isString(child.type) && isTwoCNChar(child.props.children)) {
|
||||
return React.cloneElement(child, {},
|
||||
child.props.children.split('').join(' '));
|
||||
child.props.children.split('').join(' '));
|
||||
}
|
||||
if (isString(child)) {
|
||||
if (typeof child === 'string') {
|
||||
if (isTwoCNChar(child)) {
|
||||
child = child.split('').join(' ');
|
||||
}
|
||||
@ -74,14 +76,14 @@ export default class Button extends React.Component<ButtonProps, any> {
|
||||
timeout: number;
|
||||
delayTimeout: number;
|
||||
|
||||
constructor(props) {
|
||||
constructor(props: ButtonProps) {
|
||||
super(props);
|
||||
this.state = {
|
||||
loading: props.loading,
|
||||
};
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
componentWillReceiveProps(nextProps: ButtonProps) {
|
||||
const currentLoading = this.props.loading;
|
||||
const loading = nextProps.loading;
|
||||
|
||||
@ -89,7 +91,7 @@ export default class Button extends React.Component<ButtonProps, any> {
|
||||
clearTimeout(this.delayTimeout);
|
||||
}
|
||||
|
||||
if (loading && loading.delay) {
|
||||
if (typeof loading !== 'boolean' && loading && loading.delay) {
|
||||
this.delayTimeout = setTimeout(() => this.setState({ loading }), loading.delay);
|
||||
} else {
|
||||
this.setState({ loading });
|
||||
@ -105,7 +107,7 @@ export default class Button extends React.Component<ButtonProps, any> {
|
||||
}
|
||||
}
|
||||
|
||||
handleClick = (e) => {
|
||||
handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||
// Add click effect
|
||||
this.setState({ clicked: true });
|
||||
clearTimeout(this.timeout);
|
||||
@ -118,7 +120,7 @@ export default class Button extends React.Component<ButtonProps, any> {
|
||||
}
|
||||
|
||||
// Handle auto focus when click button in Chrome
|
||||
handleMouseUp = (e) => {
|
||||
handleMouseUp = (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||
if (this.props.onMouseUp) {
|
||||
this.props.onMouseUp(e);
|
||||
}
|
||||
@ -130,12 +132,19 @@ export default class Button extends React.Component<ButtonProps, any> {
|
||||
} = this.props;
|
||||
|
||||
const { loading, clicked } = this.state;
|
||||
|
||||
// large => lg
|
||||
// small => sm
|
||||
const sizeCls = ({
|
||||
large: 'lg',
|
||||
small: 'sm',
|
||||
})[size] || '';
|
||||
let sizeCls = '';
|
||||
switch (size) {
|
||||
case 'large':
|
||||
sizeCls = 'lg';
|
||||
break;
|
||||
case 'small':
|
||||
sizeCls = 'sm';
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const classes = classNames(prefixCls, {
|
||||
[`${prefixCls}-${type}`]: type,
|
||||
|
Loading…
Reference in New Issue
Block a user