2021-06-30 05:48:02 +00:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2021-06-30 02:03:17 +00:00
|
|
|
import { flattenChildren } from '../_util/props-util';
|
|
|
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
2019-03-13 01:38:54 +00:00
|
|
|
|
2021-06-30 02:03:17 +00:00
|
|
|
import type { ExtractPropTypes, PropType } from 'vue';
|
|
|
|
import type { SizeType } from '../config-provider';
|
2022-03-12 01:56:32 +00:00
|
|
|
import UnreachableException from '../_util/unreachableException';
|
2021-06-30 02:03:17 +00:00
|
|
|
|
2022-03-26 14:52:54 +00:00
|
|
|
export const buttonGroupProps = () => ({
|
|
|
|
prefixCls: String,
|
2021-06-30 02:03:17 +00:00
|
|
|
size: {
|
|
|
|
type: String as PropType<SizeType>,
|
|
|
|
},
|
2022-03-26 14:52:54 +00:00
|
|
|
});
|
2021-06-30 02:03:17 +00:00
|
|
|
|
2022-03-26 14:52:54 +00:00
|
|
|
export type ButtonGroupProps = Partial<ExtractPropTypes<ReturnType<typeof buttonGroupProps>>>;
|
2021-06-30 02:03:17 +00:00
|
|
|
|
2020-10-13 10:04:02 +00:00
|
|
|
export default defineComponent({
|
2018-04-08 13:17:20 +00:00
|
|
|
name: 'AButtonGroup',
|
2022-03-26 14:52:54 +00:00
|
|
|
props: buttonGroupProps(),
|
2021-06-30 02:03:17 +00:00
|
|
|
setup(props, { slots }) {
|
|
|
|
const { prefixCls, direction } = useConfigInject('btn-group', props);
|
2021-06-30 05:48:02 +00:00
|
|
|
const classes = computed(() => {
|
2021-06-30 02:03:17 +00:00
|
|
|
const { size } = props;
|
|
|
|
// large => lg
|
|
|
|
// small => sm
|
|
|
|
let sizeCls = '';
|
|
|
|
switch (size) {
|
|
|
|
case 'large':
|
|
|
|
sizeCls = 'lg';
|
|
|
|
break;
|
|
|
|
case 'small':
|
|
|
|
sizeCls = 'sm';
|
|
|
|
break;
|
2022-03-12 01:56:32 +00:00
|
|
|
case 'middle':
|
|
|
|
case undefined:
|
2021-06-30 02:03:17 +00:00
|
|
|
break;
|
2022-03-12 01:56:32 +00:00
|
|
|
default:
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.warn(new UnreachableException(size).error);
|
2021-06-30 02:03:17 +00:00
|
|
|
}
|
2021-06-30 05:48:02 +00:00
|
|
|
return {
|
2021-06-30 02:03:17 +00:00
|
|
|
[`${prefixCls.value}`]: true,
|
|
|
|
[`${prefixCls.value}-${sizeCls}`]: sizeCls,
|
|
|
|
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
|
|
|
|
};
|
2021-06-30 05:48:02 +00:00
|
|
|
});
|
|
|
|
return () => {
|
|
|
|
return <div class={classes.value}>{flattenChildren(slots.default?.())}</div>;
|
2019-03-13 01:38:54 +00:00
|
|
|
};
|
2018-01-24 07:39:21 +00:00
|
|
|
},
|
2020-10-13 10:04:02 +00:00
|
|
|
});
|