2019-01-12 03:33:27 +00:00
|
|
|
import { filterEmpty } from '../_util/props-util';
|
2019-09-08 12:16:17 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2019-03-13 01:38:54 +00:00
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
|
|
|
|
2018-01-29 10:57:20 +00:00
|
|
|
const ButtonGroupProps = {
|
2019-09-08 12:16:17 +00:00
|
|
|
prefixCls: PropTypes.string,
|
2018-01-29 10:57:20 +00:00
|
|
|
size: {
|
2019-01-12 03:33:27 +00:00
|
|
|
validator(value) {
|
|
|
|
return ['small', 'large', 'default'].includes(value);
|
2017-10-26 07:18:08 +00:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
|
|
|
export { ButtonGroupProps };
|
2018-01-29 10:57:20 +00:00
|
|
|
export default {
|
2018-04-08 13:17:20 +00:00
|
|
|
name: 'AButtonGroup',
|
2018-01-29 10:57:20 +00:00
|
|
|
props: ButtonGroupProps,
|
2019-03-13 01:38:54 +00:00
|
|
|
inject: {
|
2019-09-11 14:35:25 +00:00
|
|
|
configProvider: { default: () => ConfigConsumerProps },
|
2019-03-13 01:38:54 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
data() {
|
2017-10-26 07:18:08 +00:00
|
|
|
return {
|
|
|
|
sizeMap: {
|
|
|
|
large: 'lg',
|
|
|
|
small: 'sm',
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2017-10-26 07:18:08 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2020-03-18 06:52:02 +00:00
|
|
|
const { prefixCls: customizePrefixCls, size, $slots } = this;
|
2019-09-11 14:35:25 +00:00
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-03-13 01:38:54 +00:00
|
|
|
const prefixCls = getPrefixCls('btn-group', customizePrefixCls);
|
|
|
|
|
|
|
|
// large => lg
|
|
|
|
// small => sm
|
|
|
|
let sizeCls = '';
|
|
|
|
switch (size) {
|
|
|
|
case 'large':
|
|
|
|
sizeCls = 'lg';
|
|
|
|
break;
|
|
|
|
case 'small':
|
|
|
|
sizeCls = 'sm';
|
2020-03-07 11:45:13 +00:00
|
|
|
break;
|
2019-03-13 01:38:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const classes = {
|
|
|
|
[`${prefixCls}`]: true,
|
|
|
|
[`${prefixCls}-${sizeCls}`]: sizeCls,
|
|
|
|
};
|
2019-01-12 03:33:27 +00:00
|
|
|
return <div class={classes}>{filterEmpty($slots.default)}</div>;
|
2018-01-24 07:39:21 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|