Skip to content

Commit 820ce8f

Browse files
refactor(select-input): component optimization (Tencent#5068)
* refactor(select-input): component optimization * refactor(select-input): expose * chore: fix build --------- Co-authored-by: Uyarn <[email protected]>
1 parent c87827e commit 820ce8f

File tree

12 files changed

+86
-101
lines changed

12 files changed

+86
-101
lines changed

packages/components/range-input/range-input-popup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Popup from '../popup';
33
import { usePrefixClass } from '../hooks/useConfig';
44
import RangeInput from './range-input';
55
import props from './range-input-popup-props';
6-
import useOverlayInnerStyle from '../select-input/useOverlayInnerStyle';
6+
import { useOverlayInnerStyle } from '../select-input/hooks/useOverlayInnerStyle';
77
import { TdRangeInputPopupProps } from './type';
88

99
export default defineComponent({
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './useMultiple';
2+
export * from './useOverlayInnerStyle';
3+
export * from './useSingle';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../../style/index.css';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../../style/index.js';

packages/components/select-input/useMultiple.tsx renamed to packages/components/select-input/hooks/useMultiple.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { SetupContext, computed, ref, toRefs, Ref } from 'vue';
22
import { isObject } from 'lodash-es';
3-
import { TdSelectInputProps, SelectInputChangeContext, SelectInputKeys } from './type';
4-
import { SelectInputCommonProperties } from './interface';
5-
import TagInput, { TagInputValue, TagInputProps } from '../tag-input';
6-
import Loading from '../loading';
7-
import useDefault from '../hooks/useDefaultValue';
8-
import { usePrefixClass } from '../hooks/useConfig';
9-
import { useDisabled } from '../hooks/useDisabled';
10-
import { useReadonly } from '../hooks/useReadonly';
11-
import { PopupInstanceFunctions } from '../popup';
3+
import { TdSelectInputProps, SelectInputChangeContext, SelectInputKeys } from '../type';
4+
import { SelectInputCommonProperties } from '../types';
5+
import TagInput, { TagInputValue, TagInputProps } from '../../tag-input';
6+
import Loading from '../../loading';
7+
import useDefault from '../../hooks/useDefaultValue';
8+
import { usePrefixClass } from '../../hooks/useConfig';
9+
import { useDisabled } from '../../hooks/useDisabled';
10+
import { useReadonly } from '../../hooks/useReadonly';
11+
import { PopupInstanceFunctions } from '../../popup';
1212

1313
export interface RenderSelectMultipleParams {
1414
commonInputProps: SelectInputCommonProperties;
@@ -23,11 +23,7 @@ const DEFAULT_KEYS = {
2323
children: 'children',
2424
};
2525

26-
export default function useMultiple(
27-
props: TdSelectInputProps,
28-
context: SetupContext,
29-
popupRef: Ref<PopupInstanceFunctions>,
30-
) {
26+
export function useMultiple(props: TdSelectInputProps, context: SetupContext, popupRef: Ref<PopupInstanceFunctions>) {
3127
const { inputValue } = toRefs(props);
3228
const classPrefix = usePrefixClass();
3329
const tagInputRef = ref();

packages/components/select-input/useOverlayInnerStyle.ts renamed to packages/components/select-input/hooks/useOverlayInnerStyle.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { ref, toRefs, computed, CSSProperties } from 'vue';
22
import { isObject } from 'lodash-es';
33
import { isFunction } from 'lodash-es';
4-
import { TdSelectInputProps } from './type';
5-
import { TdPopupProps, PopupVisibleChangeContext } from '../popup';
6-
import { useDisabled } from '../hooks/useDisabled';
7-
import { useReadonly } from '../hooks/useReadonly';
4+
import { TdSelectInputProps } from '../type';
5+
import { TdPopupProps, PopupVisibleChangeContext } from '../../popup';
6+
import { useDisabled } from '../../hooks/useDisabled';
7+
import { useReadonly } from '../../hooks/useReadonly';
88

99
export type overlayInnerStyleProps = Pick<
1010
TdSelectInputProps,
@@ -16,7 +16,7 @@ const MAX_POPUP_WIDTH = 1000;
1616
// 避免因滚动条出现文本省略,预留宽度 8
1717
const RESERVE_WIDTH = 0;
1818

19-
export default function useOverlayInnerStyle(props: overlayInnerStyleProps) {
19+
export function useOverlayInnerStyle(props: overlayInnerStyleProps) {
2020
const { popupProps, autoWidth } = toRefs(props);
2121
const innerPopupVisible = ref(false);
2222
const disable = useDisabled();

packages/components/select-input/useSingle.tsx renamed to packages/components/select-input/hooks/useSingle.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { SetupContext, ref, computed, toRefs, Ref } from 'vue';
22
import { isObject } from 'lodash-es';
33
import { pick } from 'lodash-es';
4-
import Input, { StrInputProps } from '../input';
5-
import Loading from '../loading';
6-
import { useTNodeJSX } from '../hooks/tnode';
7-
import { usePrefixClass } from '../hooks/useConfig';
8-
import useDefaultValue from '../hooks/useDefaultValue';
9-
import { useDisabled } from '../hooks/useDisabled';
10-
import { useReadonly } from '../hooks/useReadonly';
11-
import { PopupInstanceFunctions } from '../popup';
12-
import { TdSelectInputProps } from './type';
13-
import { SelectInputCommonProperties } from './interface';
4+
import Input, { StrInputProps } from '../../input';
5+
import Loading from '../../loading';
6+
import { useTNodeJSX } from '../../hooks/tnode';
7+
import { usePrefixClass } from '../../hooks/useConfig';
8+
import useDefaultValue from '../../hooks/useDefaultValue';
9+
import { useDisabled } from '../../hooks/useDisabled';
10+
import { useReadonly } from '../../hooks/useReadonly';
11+
import { PopupInstanceFunctions } from '../../popup';
12+
import { TdSelectInputProps } from '../type';
13+
import { SelectInputCommonProperties } from '../types';
1414

1515
// single 和 multiple 共有特性
1616
const COMMON_PROPERTIES = [
@@ -47,7 +47,7 @@ function getInputValue(value: TdSelectInputProps['value'], keys: TdSelectInputPr
4747
return isObject(value) ? (value as Record<string, any>)[iKeys.label] : value;
4848
}
4949

50-
export default function useSingle(
50+
export function useSingle(
5151
props: TdSelectInputProps & { valueDisplayOptions: SelectInputValueDisplayOptions },
5252
context: SetupContext,
5353
popupRef: Ref<PopupInstanceFunctions>,

packages/components/select-input/select-input.tsx

Lines changed: 52 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { computed, defineComponent, onBeforeUnmount, onMounted, PropType, ref, S
22
import Popup, { PopupInstanceFunctions, PopupProps, PopupVisibleChangeContext } from '../popup';
33
import props from './props';
44
import { TdSelectInputProps } from './type';
5-
import useSingle, { SelectInputValueDisplayOptions } from './useSingle';
6-
import useMultiple from './useMultiple';
7-
import useOverlayInnerStyle from './useOverlayInnerStyle';
5+
import { useMultiple, useSingle, useOverlayInnerStyle } from './hooks';
6+
import type { SelectInputValueDisplayOptions } from './hooks';
87
import { usePrefixClass } from '../hooks/useConfig';
98
import { useTNodeJSX } from '../hooks';
109

@@ -20,7 +19,6 @@ const useComponentClassName = () => {
2019

2120
export default defineComponent({
2221
name: 'TSelectInput',
23-
2422
props: {
2523
...props,
2624
/**
@@ -42,7 +40,7 @@ export default defineComponent({
4240

4341
const selectInputRef = ref();
4442
const popupRef = ref<PopupInstanceFunctions>();
45-
const { multiple, value, popupVisible, borderless } = toRefs(props);
43+
const { multiple, value, popupVisible, borderless, popupProps, panel, allowInput, status } = toRefs(props);
4644

4745
const { tOverlayInnerStyle, innerPopupVisible, onInnerPopupVisibleChange } = useOverlayInnerStyle(props);
4846

@@ -96,68 +94,56 @@ export default defineComponent({
9694
if (props.multiple) tagInputRef.value?.focus?.();
9795
};
9896

99-
return {
100-
classPrefix,
101-
NAME_CLASS,
102-
innerPopupVisible,
103-
commonInputProps,
104-
tOverlayInnerStyle,
105-
selectInputRef,
97+
context.expose({
10698
popupRef,
107-
classes,
108-
onInnerClear,
109-
renderTNodeJSX,
110-
renderSelectSingle,
111-
renderSelectMultiple,
112-
onOverlayClick,
113-
onInnerPopupVisibleChange,
114-
};
115-
},
99+
allowInput,
100+
});
116101

117-
render() {
118-
// 浮层显示的受控与非受控
119-
const visibleProps = { visible: this.popupVisible ?? this.innerPopupVisible };
120-
121-
const mainContent = (
122-
<Popup
123-
ref="popupRef"
124-
trigger={(this.popupProps as TdSelectInputProps['popupProps'])?.trigger || 'click'}
125-
placement="bottom-left"
126-
{...visibleProps}
127-
content={this.panel}
128-
v-slots={{ ...this.$slots, content: this.$slots.panel }}
129-
hideEmptyPopup={true}
130-
{...{
131-
onVisibleChange: this.onInnerPopupVisibleChange,
132-
onOverlayClick: this.onOverlayClick,
133-
...(this.popupProps as TdSelectInputProps['popupProps']),
134-
overlayInnerStyle: this.tOverlayInnerStyle,
135-
}}
136-
>
137-
{this.multiple
138-
? this.renderSelectMultiple({
139-
commonInputProps: this.commonInputProps,
140-
onInnerClear: this.onInnerClear,
141-
popupVisible: visibleProps.visible,
142-
allowInput: this.allowInput,
143-
})
144-
: this.renderSelectSingle(visibleProps.visible)}
145-
</Popup>
146-
);
147-
148-
const tipsNode = this.renderTNodeJSX('tips');
149-
150-
const tipsClasses = [
151-
`${this.classPrefix}-input__tips`,
152-
`${this.classPrefix}-tips`,
153-
`${this.classPrefix}-is-${this.status}`,
154-
];
155-
156-
return (
157-
<div ref="selectInputRef" class={this.classes}>
158-
{mainContent}
159-
{tipsNode && <div class={tipsClasses}>{tipsNode}</div>}
160-
</div>
161-
);
102+
return () => {
103+
// 浮层显示的受控与非受控
104+
const visibleProps = { visible: popupVisible.value ?? innerPopupVisible.value };
105+
106+
const mainContent = (
107+
<Popup
108+
ref={popupRef}
109+
trigger={popupProps.value?.trigger || 'click'}
110+
placement="bottom-left"
111+
{...visibleProps}
112+
content={panel.value}
113+
v-slots={{ ...context.slots, content: context.slots.panel }}
114+
hideEmptyPopup={true}
115+
{...{
116+
onVisibleChange: onInnerPopupVisibleChange,
117+
onOverlayClick: onOverlayClick,
118+
...popupProps.value,
119+
overlayInnerStyle: tOverlayInnerStyle.value,
120+
}}
121+
>
122+
{multiple.value
123+
? renderSelectMultiple({
124+
commonInputProps: commonInputProps.value,
125+
onInnerClear: onInnerClear,
126+
popupVisible: visibleProps.visible,
127+
allowInput: allowInput.value,
128+
})
129+
: renderSelectSingle(visibleProps.visible)}
130+
</Popup>
131+
);
132+
133+
const tipsNode = renderTNodeJSX('tips');
134+
135+
const tipsClasses = [
136+
`${classPrefix.value}-input__tips`,
137+
`${classPrefix.value}-tips`,
138+
`${classPrefix.value}-is-${status.value}`,
139+
];
140+
141+
return (
142+
<div ref={selectInputRef} class={classes.value}>
143+
{mainContent}
144+
{tipsNode && <div class={tipsClasses}>{tipsNode}</div>}
145+
</div>
146+
);
147+
};
162148
},
163149
});

packages/components/select/select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { useSelectOptions, useKeyboardControl } from './hooks';
2323
import type { PopupProps, PopupVisibleChangeContext } from '../popup';
2424
import type { SelectInputChangeContext, SelectInputValueChangeContext } from '../select-input';
2525
import type { TdSelectProps, SelectValue } from './type';
26-
import { SelectInputValueDisplayOptions } from '../select-input/useSingle';
26+
import { SelectInputValueDisplayOptions } from '../select-input/hooks/useSingle';
2727
import { TagInputTriggerSource } from '../tag-input';
2828

2929
export default defineComponent({

packages/components/skeleton/skeleton.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ const getColItemStyle = (obj: SkeletonRowColObj) => {
5656

5757
export default defineComponent({
5858
name: 'TSkeleton',
59-
6059
props,
61-
6260
setup(props, { slots }) {
6361
const isShow = ref(false);
6462
const COMPONENT_NAME = usePrefixClass('skeleton');

packages/components/table/type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ export interface PrimaryTableInstanceFunctions<T extends TableRowData = TableRow
641641
/**
642642
* 校验表格可编辑单元格数据,校验完成后,会触发事件 `onValidate`
643643
*/
644-
validateTableCellData: () => Promise<{ result: TableErrorListMap }>;
644+
validateTableCellData: () => Promise<{ result: TableErrorListMap }>;
645645
/**
646646
* 校验表格全部数据,校验完成后,会触发事件 `onValidate`
647647
*/

0 commit comments

Comments
 (0)