ant-design-vue/components/input/Group.tsx

51 lines
1.5 KiB
Vue
Raw Normal View History

2021-12-14 15:50:22 +00:00
import type { PropType } from 'vue';
import { computed, defineComponent } from 'vue';
import type { SizeType } from '../config-provider';
2022-05-18 14:51:45 +00:00
import { FormItemInputContext } from '../form/FormItemContext';
2023-01-27 08:00:17 +00:00
import useConfigInject from '../config-provider/hooks/useConfigInject';
import classNames from '../_util/classNames';
// CSSINJS
import useStyle from './style';
2019-04-07 09:19:18 +00:00
2020-10-16 06:24:14 +00:00
export default defineComponent({
compatConfig: { MODE: 3 },
2018-04-08 13:17:20 +00:00
name: 'AInputGroup',
inheritAttrs: false,
2017-12-06 10:54:20 +00:00
props: {
prefixCls: String,
2021-12-14 15:50:22 +00:00
size: { type: String as PropType<SizeType> },
compact: { type: Boolean, default: undefined },
2017-12-06 10:54:20 +00:00
},
setup(props, { slots, attrs }) {
2023-02-08 03:04:16 +00:00
const { prefixCls, direction, getPrefixCls } = useConfigInject('input-group', props);
2022-05-18 14:51:45 +00:00
const formItemInputContext = FormItemInputContext.useInject();
FormItemInputContext.useProvide(formItemInputContext, {
isFormItemInput: false,
});
// style
2023-02-08 03:04:16 +00:00
const inputPrefixCls = computed(() => getPrefixCls('input'));
const [wrapSSR, hashId] = useStyle(inputPrefixCls);
2021-12-14 15:50:22 +00:00
const cls = computed(() => {
const pre = prefixCls.value;
2017-12-06 10:54:20 +00:00
return {
2021-12-14 15:50:22 +00:00
[`${pre}`]: true,
[hashId.value]: true,
2021-12-14 15:50:22 +00:00
[`${pre}-lg`]: props.size === 'large',
[`${pre}-sm`]: props.size === 'small',
[`${pre}-compact`]: props.compact,
[`${pre}-rtl`]: direction.value === 'rtl',
2019-01-12 03:33:27 +00:00
};
2021-12-14 15:50:22 +00:00
});
return () => {
return wrapSSR(
2023-02-08 03:04:16 +00:00
<span {...attrs} class={classNames(cls.value, attrs.class)}>
2021-12-14 15:50:22 +00:00
{slots.default?.()}
</span>,
2021-12-14 15:50:22 +00:00
);
};
2018-03-19 01:43:31 +00:00
},
2020-10-16 06:24:14 +00:00
});