2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2015-11-24 20:03:57 +08:00
|
|
|
import classNames from 'classnames';
|
2020-01-03 13:38:16 +08:00
|
|
|
import { SizeType } from '../config-provider/SizeContext';
|
2018-12-05 19:12:18 +08:00
|
|
|
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
2016-07-14 13:29:50 +08:00
|
|
|
|
2016-09-13 15:31:29 +08:00
|
|
|
export interface ButtonGroupProps {
|
2020-01-03 13:38:16 +08:00
|
|
|
size?: SizeType;
|
2016-07-14 13:29:50 +08:00
|
|
|
style?: React.CSSProperties;
|
|
|
|
className?: string;
|
2016-09-14 16:18:33 +08:00
|
|
|
prefixCls?: string;
|
2016-07-14 13:29:50 +08:00
|
|
|
}
|
|
|
|
|
2018-12-05 19:12:18 +08:00
|
|
|
const ButtonGroup: React.SFC<ButtonGroupProps> = props => (
|
|
|
|
<ConfigConsumer>
|
2020-01-02 19:10:16 +08:00
|
|
|
{({ getPrefixCls, direction }: ConfigConsumerProps) => {
|
2018-12-05 19:12:18 +08:00
|
|
|
const { prefixCls: customizePrefixCls, size, className, ...others } = props;
|
|
|
|
const prefixCls = getPrefixCls('btn-group', customizePrefixCls);
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2018-12-05 19:12:18 +08:00
|
|
|
// large => lg
|
|
|
|
// small => sm
|
|
|
|
let sizeCls = '';
|
|
|
|
switch (size) {
|
|
|
|
case 'large':
|
|
|
|
sizeCls = 'lg';
|
|
|
|
break;
|
|
|
|
case 'small':
|
|
|
|
sizeCls = 'sm';
|
2019-08-05 18:38:10 +08:00
|
|
|
break;
|
2018-12-05 19:12:18 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-10-22 21:01:52 +08:00
|
|
|
|
2018-12-07 20:02:01 +08:00
|
|
|
const classes = classNames(
|
|
|
|
prefixCls,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-${sizeCls}`]: sizeCls,
|
2020-01-02 19:10:16 +08:00
|
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
2018-12-07 20:02:01 +08:00
|
|
|
},
|
|
|
|
className,
|
|
|
|
);
|
2015-10-22 21:01:52 +08:00
|
|
|
|
2018-12-05 19:12:18 +08:00
|
|
|
return <div {...others} className={classes} />;
|
|
|
|
}}
|
|
|
|
</ConfigConsumer>
|
|
|
|
);
|
2017-07-18 16:46:19 +08:00
|
|
|
|
|
|
|
export default ButtonGroup;
|