|
|
@ -1,4 +1,5 @@ |
|
|
|
import React from 'react'; |
|
|
|
import rcUtil from 'rc-util'; |
|
|
|
|
|
|
|
const rxTwoCNChar = /^[\u4e00-\u9fa5]{2,2}$/; |
|
|
|
const isTwoCNChar = rxTwoCNChar.test.bind(rxTwoCNChar); |
|
|
@ -7,11 +8,6 @@ function isString(str) { |
|
|
|
} |
|
|
|
|
|
|
|
const prefix = 'ant-btn-'; |
|
|
|
function updateClassWithProp(classSet, prop) { |
|
|
|
if (prop) { |
|
|
|
classSet.push(prefix + prop); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Insert one space between two chinese characters automatically. |
|
|
|
function insertSpace(child) { |
|
|
@ -32,20 +28,18 @@ export default class Button extends React.Component { |
|
|
|
const props = this.props; |
|
|
|
const {type, shape, size, onClick, className, children, ...others} = props; |
|
|
|
|
|
|
|
let classSet = ['ant-btn']; |
|
|
|
updateClassWithProp(classSet, type); |
|
|
|
updateClassWithProp(classSet, shape); |
|
|
|
updateClassWithProp(classSet, size); |
|
|
|
if ('loading' in props && props.loading !== false) { |
|
|
|
classSet.push(prefix + 'loading'); |
|
|
|
} |
|
|
|
if (className) { |
|
|
|
classSet.push(className); |
|
|
|
} |
|
|
|
const classes = rcUtil.classSet({ |
|
|
|
'ant-btn': true, |
|
|
|
[prefix + type]: type, |
|
|
|
[prefix + shape]: shape, |
|
|
|
[prefix + size]: size, |
|
|
|
[prefix + 'loading']: ('loading' in props && props.loading !== false), |
|
|
|
[className]: className |
|
|
|
}); |
|
|
|
|
|
|
|
const kids = React.Children.map(children, insertSpace); |
|
|
|
|
|
|
|
return <button {...others} type="button" className={classSet.join(' ')} onClick={onClick}> |
|
|
|
return <button {...others} type="button" className={classes} onClick={onClick}> |
|
|
|
{kids} |
|
|
|
</button>; |
|
|
|
} |
|
|
|