2021-06-30 13:48:02 +08:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2021-06-30 10:03:17 +08:00
|
|
|
import { flattenChildren } from '../_util/props-util';
|
2019-09-08 20:16:17 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2021-06-30 10:03:17 +08:00
|
|
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
2019-03-13 09:38:54 +08:00
|
|
|
|
2021-06-30 10:03:17 +08:00
|
|
|
import type { ExtractPropTypes, PropType } from 'vue';
|
|
|
|
import type { SizeType } from '../config-provider';
|
|
|
|
|
|
|
|
const buttonGroupProps = {
|
2019-09-08 20:16:17 +08:00
|
|
|
prefixCls: PropTypes.string,
|
2021-06-30 10:03:17 +08:00
|
|
|
size: {
|
|
|
|
type: String as PropType<SizeType>,
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2021-06-30 10:03:17 +08:00
|
|
|
export { buttonGroupProps };
|
|
|
|
|
|
|
|
export type ButtonGroupProps = Partial<ExtractPropTypes<typeof buttonGroupProps>>;
|
|
|
|
|
2020-10-13 18:04:02 +08:00
|
|
|
export default defineComponent({
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'AButtonGroup',
|
2021-06-30 10:03:17 +08:00
|
|
|
props: buttonGroupProps,
|
|
|
|
setup(props, { slots }) {
|
|
|
|
const { prefixCls, direction } = useConfigInject('btn-group', props);
|
2021-06-30 13:48:02 +08:00
|
|
|
const classes = computed(() => {
|
2021-06-30 10:03:17 +08:00
|
|
|
const { size } = props;
|
|
|
|
// large => lg
|
|
|
|
// small => sm
|
|
|
|
let sizeCls = '';
|
|
|
|
switch (size) {
|
|
|
|
case 'large':
|
|
|
|
sizeCls = 'lg';
|
|
|
|
break;
|
|
|
|
case 'small':
|
|
|
|
sizeCls = 'sm';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-06-30 13:48:02 +08:00
|
|
|
return {
|
2021-06-30 10:03:17 +08:00
|
|
|
[`${prefixCls.value}`]: true,
|
|
|
|
[`${prefixCls.value}-${sizeCls}`]: sizeCls,
|
|
|
|
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
|
|
|
|
};
|
2021-06-30 13:48:02 +08:00
|
|
|
});
|
|
|
|
return () => {
|
|
|
|
return <div class={classes.value}>{flattenChildren(slots.default?.())}</div>;
|
2019-03-13 09:38:54 +08:00
|
|
|
};
|
2018-01-24 15:39:21 +08:00
|
|
|
},
|
2020-10-13 18:04:02 +08:00
|
|
|
});
|