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

51 lines
1.7 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';
2021-12-14 15:50:22 +00:00
import type { FocusEventHandler, MouseEventHandler } from '../_util/EventInterface';
2023-01-27 08:00:17 +00:00
import useConfigInject from '../config-provider/hooks/useConfigInject';
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',
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 },
2021-12-14 15:50:22 +00:00
onMouseenter: { type: Function as PropType<MouseEventHandler> },
onMouseleave: { type: Function as PropType<MouseEventHandler> },
onFocus: { type: Function as PropType<FocusEventHandler> },
onBlur: { type: Function as PropType<FocusEventHandler> },
2017-12-06 10:54:20 +00:00
},
2021-12-14 15:50:22 +00:00
setup(props, { slots }) {
const { prefixCls, direction } = useConfigInject('input-group', props);
2022-05-18 14:51:45 +00:00
const formItemInputContext = FormItemInputContext.useInject();
FormItemInputContext.useProvide(formItemInputContext, {
isFormItemInput: false,
});
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,
[`${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 (
<span
class={cls.value}
2022-09-02 08:16:03 +00:00
onMouseenter={props.onMouseenter}
onMouseleave={props.onMouseleave}
2021-12-14 15:50:22 +00:00
onFocus={props.onFocus}
onBlur={props.onBlur}
>
{slots.default?.()}
</span>
);
};
2018-03-19 01:43:31 +00:00
},
2020-10-16 06:24:14 +00:00
});