File size: 1,230 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import React from 'react';
import cn from 'classnames';
import propTypes from 'prop-types';
import style from './index.less';
import { transform } from '../../../unit/const';
export default class Button extends React.Component {
shouldComponentUpdate(nextProps) {
return nextProps.active !== this.props.active;
}
render() {
const {
active, color, size, top, left, label, position, arrow,
} = this.props;
return (
<div
className={cn({ [style.button]: true, [style[color]]: true, [style[size]]: true })}
style={{ top, left }}
>
<i
className={cn({ [style.active]: active })}
ref={(c) => { this.dom = c; }}
/>
{ size === 's1' && <em
style={{
[transform]: `${arrow} scale(1,2)`,
}}
/> }
<span className={cn({ [style.position]: position })}>{label}</span>
</div>
);
}
}
Button.propTypes = {
color: propTypes.string.isRequired,
size: propTypes.string.isRequired,
top: propTypes.number.isRequired,
left: propTypes.number.isRequired,
label: propTypes.string.isRequired,
position: propTypes.bool,
arrow: propTypes.string,
active: propTypes.bool.isRequired,
};
|