-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathuse-textarea-render.ts
More file actions
27 lines (23 loc) · 1.23 KB
/
use-textarea-render.ts
File metadata and controls
27 lines (23 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { computed, toRefs, ref, inject } from 'vue';
import { FORM_TOKEN, FormContext, FORM_ITEM_TOKEN, FormItemContext, STYLE_TOKEN } from '../../../form';
import { TextareaProps, UseTextareaRender } from '../textarea-types';
import { useNamespace } from '@devui/shared/utils';
export function useTextareaRender(props: TextareaProps): UseTextareaRender {
const formContext = inject(FORM_TOKEN, undefined) as FormContext;
const formItemContext = inject(FORM_ITEM_TOKEN, undefined) as FormItemContext;
const ns = useNamespace('textarea');
const isValidateError = computed(() => formItemContext?.validateState === 'error');
const isFocus = ref(false);
const { error, disabled } = toRefs(props);
const textareaDisabled = computed(() => disabled.value || formContext?.disabled);
const styleType = inject(STYLE_TOKEN, undefined);
const wrapClasses = computed(() => ({
[ns.b()]: true,
[ns.m('focus')]: isFocus.value,
[ns.m('disabled')]: textareaDisabled.value,
[ns.m('error')]: error.value || isValidateError.value,
[ns.m('feedback')]: Boolean(formItemContext?.validateState) && formItemContext?.showFeedback,
[ns.m('gary-style')]: styleType === 'gray',
}));
return { isFocus, textareaDisabled, wrapClasses };
}