ant-design-vue/components/button/button-group.tsx

50 lines
1.3 KiB
Vue
Raw Normal View History

2021-06-30 13:48:02 +08:00
import { computed, defineComponent } from 'vue';
import { flattenChildren } from '../_util/props-util';
2019-09-08 20:16:17 +08:00
import PropTypes from '../_util/vue-types';
import useConfigInject from '../_util/hooks/useConfigInject';
2019-03-13 09:38:54 +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,
size: {
type: String as PropType<SizeType>,
},
2019-01-12 11:33:27 +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',
props: buttonGroupProps,
setup(props, { slots }) {
const { prefixCls, direction } = useConfigInject('btn-group', props);
2021-06-30 13:48:02 +08:00
const classes = computed(() => {
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 {
[`${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
});