Skip to content

Commit

Permalink
Merge pull request ant-design#5920 from ant-design/refactor-enable-no…
Browse files Browse the repository at this point in the history
…ImplicitAny

refactor(button): enable noImplicitAny ant-design#5627
  • Loading branch information
afc163 authored Apr 27, 2017
2 parents 339e60b + ae631c7 commit 97762a9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
14 changes: 10 additions & 4 deletions components/button/button-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
37 changes: 23 additions & 14 deletions components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ');
}
Expand Down Expand Up @@ -74,22 +76,22 @@ 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;

if (currentLoading) {
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 });
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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,
Expand Down

0 comments on commit 97762a9

Please sign in to comment.