Skip to content

refactor:input #6237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/input/ClearableLabeledInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default defineComponent({
triggerFocus: { type: Function as PropType<() => void> },
hidden: Boolean,
status: String as PropType<InputStatus>,
hashId: String,
},
setup(props, { slots, attrs }) {
const statusContext = FormItemInputContext.useInject();
Expand Down Expand Up @@ -73,6 +74,7 @@ export default defineComponent({
status: customStatus,
addonAfter = slots.addonAfter,
addonBefore = slots.addonBefore,
hashId,
} = props;

const { status: contextStatus, hasFeedback } = statusContext;
Expand All @@ -96,6 +98,7 @@ export default defineComponent({
// className will go to addon wrapper
[`${attrs.class}`]: !hasAddon({ addonAfter, addonBefore }) && attrs.class,
},
hashId,
);
return (
<span class={affixWrapperCls} style={attrs.style as CSSProperties} hidden={hidden}>
Expand Down
13 changes: 11 additions & 2 deletions components/input/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { FormItemInputContext } from '../form/FormItemContext';
import type { FocusEventHandler, MouseEventHandler } from '../_util/EventInterface';
import useConfigInject from '../config-provider/hooks/useConfigInject';

// CSSINJS
import useStyle from './style';

export default defineComponent({
compatConfig: { MODE: 3 },
name: 'AInputGroup',
Expand All @@ -23,18 +26,24 @@ export default defineComponent({
FormItemInputContext.useProvide(formItemInputContext, {
isFormItemInput: false,
});

// style
const { prefixCls: inputPrefixCls } = useConfigInject('input', props);
const [wrapSSR, hashId] = useStyle(inputPrefixCls);

const cls = computed(() => {
const pre = prefixCls.value;
return {
[`${pre}`]: true,
[hashId.value]: true,
[`${pre}-lg`]: props.size === 'large',
[`${pre}-sm`]: props.size === 'small',
[`${pre}-compact`]: props.compact,
[`${pre}-rtl`]: direction.value === 'rtl',
};
});
return () => {
return (
return wrapSSR(
<span
class={cls.value}
onMouseenter={props.onMouseenter}
Expand All @@ -43,7 +52,7 @@ export default defineComponent({
onBlur={props.onBlur}
>
{slots.default?.()}
</span>
</span>,
);
};
},
Expand Down
18 changes: 15 additions & 3 deletions components/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import inputProps from './inputProps';
import omit from '../_util/omit';
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';

// CSSINJS
import useStyle from './style';

export default defineComponent({
compatConfig: { MODE: 3 },
name: 'AInput',
Expand All @@ -26,6 +29,9 @@ export default defineComponent({
const mergedStatus = computed(() => getMergedStatus(formItemInputContext.status, props.status));
const { direction, prefixCls, size, autocomplete } = useConfigInject('input', props);

// Style
const [wrapSSR, hashId] = useStyle(prefixCls);

const focus = (option?: InputFocusOptions) => {
inputRef.value?.focus(option);
};
Expand Down Expand Up @@ -140,6 +146,7 @@ export default defineComponent({
[`${prefixClsValue}-borderless`]: !bordered,
},
!inputHasPrefixSuffix && getStatusClassNames(prefixClsValue, mergedStatus.value),
hashId.value,
)}
affixWrapperClassName={classNames(
{
Expand All @@ -149,17 +156,22 @@ export default defineComponent({
[`${prefixClsValue}-affix-wrapper-borderless`]: !bordered,
},
getStatusClassNames(`${prefixClsValue}-affix-wrapper`, mergedStatus.value, hasFeedback),
hashId.value,
)}
wrapperClassName={classNames(
{
[`${prefixClsValue}-group-rtl`]: direction.value === 'rtl',
},
hashId.value,
)}
wrapperClassName={classNames({
[`${prefixClsValue}-group-rtl`]: direction.value === 'rtl',
})}
groupClassName={classNames(
{
[`${prefixClsValue}-group-wrapper-sm`]: size.value === 'small',
[`${prefixClsValue}-group-wrapper-lg`]: size.value === 'large',
[`${prefixClsValue}-group-wrapper-rtl`]: direction.value === 'rtl',
},
getStatusClassNames(`${prefixClsValue}-group-wrapper`, mergedStatus.value, hasFeedback),
hashId.value,
)}
v-slots={{ ...slots, clearIcon }}
></VcInput>
Expand Down
10 changes: 10 additions & 0 deletions components/input/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import omit from '../_util/omit';
import type { VueNode } from '../_util/type';
import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils';

// CSSINJS
import useStyle from './style';

function fixEmojiLength(value: string, maxLength: number) {
return [...(value || '')].slice(0, maxLength).join('');
}
Expand Down Expand Up @@ -58,6 +61,10 @@ export default defineComponent({
const resizableTextArea = ref();
const mergedValue = ref('');
const { prefixCls, size, direction } = useConfigInject('input', props);

// Style
const [wrapSSR, hashId] = useStyle(prefixCls);

const showCount = computed(() => {
return (props.showCount as any) === '' || props.showCount || false;
});
Expand Down Expand Up @@ -198,6 +205,7 @@ export default defineComponent({
[`${prefixCls.value}-lg`]: size.value === 'large',
},
getStatusClassNames(prefixCls.value, mergedStatus.value),
hashId.value,
],
showCount: null,
prefixCls: prefixCls.value,
Expand Down Expand Up @@ -252,6 +260,7 @@ export default defineComponent({
direction: direction.value,
bordered,
style: showCount.value ? undefined : style,
hashId: hashId.value,
};

let textareaNode = (
Expand Down Expand Up @@ -283,6 +292,7 @@ export default defineComponent({
},
`${prefixCls.value}-textarea-show-count`,
customClass,
hashId.value,
)}
style={style as CSSProperties}
data-count={typeof dataCount !== 'object' ? dataCount : undefined}
Expand Down
Loading