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';
|
2017-09-25 22:14:49 +08:00
|
|
|
import { ButtonSize } from './button';
|
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 {
|
2016-07-14 13:29:50 +08:00
|
|
|
size?: ButtonSize;
|
|
|
|
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>
|
|
|
|
{({ getPrefixCls }: ConfigConsumerProps) => {
|
|
|
|
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';
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-10-22 21:01:52 +08:00
|
|
|
|
2018-12-05 19:12:18 +08:00
|
|
|
const classes = classNames(prefixCls, {
|
|
|
|
[`${prefixCls}-${sizeCls}`]: sizeCls,
|
|
|
|
}, 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;
|