@tdm-design/ui 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@tdm-design/ui.js +113060 -0
- package/dist/@tdm-design/ui.js.map +1 -0
- package/dist/@tdm-design/ui.min.js +373 -0
- package/dist/@tdm-design/ui.min.js.LICENSE.txt +129 -0
- package/dist/@tdm-design/ui.min.js.map +1 -0
- package/dist/reset.css +246 -0
- package/dist/tdm-with-locales.js +373 -0
- package/dist/tdm-with-locales.js.LICENSE.txt +129 -0
- package/dist/tdm-with-locales.js.map +1 -0
- package/dist/tdm.css +1 -0
- package/es/config-provider/context.d.ts +1 -1
- package/es/index.d.ts +2 -2
- package/es/index.js +1 -1
- package/es/select/Select.d.ts +130 -0
- package/es/select/Select.js +333 -0
- package/es/select/SingleDisplaySelect.d.ts +5 -0
- package/es/select/SingleDisplaySelect.js +157 -0
- package/es/select/SortableSelect.d.ts +5 -0
- package/es/select/SortableSelect.js +173 -0
- package/es/select/index.d.ts +7 -124
- package/es/select/index.js +7 -274
- package/es/select/style/select-input-multiple.js +4 -1
- package/es/version/token.json +1 -1
- package/es/version/version.d.ts +1 -1
- package/es/version/version.js +1 -1
- package/lib/config-provider/context.d.ts +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +14 -1
- package/lib/select/Select.d.ts +130 -0
- package/lib/select/Select.js +340 -0
- package/lib/select/SingleDisplaySelect.d.ts +5 -0
- package/lib/select/SingleDisplaySelect.js +164 -0
- package/lib/select/SortableSelect.d.ts +5 -0
- package/lib/select/SortableSelect.js +180 -0
- package/lib/select/index.d.ts +7 -124
- package/lib/select/index.js +32 -274
- package/lib/select/style/select-input-multiple.js +4 -1
- package/lib/version/token.json +1 -1
- package/lib/version/version.d.ts +1 -1
- package/lib/version/version.js +1 -1
- package/package.json +10 -3
|
@@ -175,7 +175,7 @@ export type FloatButtonConfig = ComponentStyleConfig & Pick<FloatButtonProps, 'c
|
|
|
175
175
|
export type FloatButtonGroupConfig = ComponentStyleConfig & Pick<FloatButtonGroupProps, 'closeIcon' | 'classNames' | 'styles'>;
|
|
176
176
|
export type PaginationConfig = ComponentStyleConfig & Pick<PaginationProps, 'showSizeChanger' | 'totalBoundaryShowSizeChanger' | 'classNames' | 'styles'>;
|
|
177
177
|
export type ProgressConfig = ComponentStyleConfig & Pick<ProgressProps, 'classNames' | 'styles'>;
|
|
178
|
-
export type SelectConfig = ComponentStyleConfig & Pick<SelectProps, 'showSearch' | 'variant' | 'classNames' | 'styles' | 'optionFilterProp'>;
|
|
178
|
+
export type SelectConfig = ComponentStyleConfig & Pick<SelectProps, 'showSearch' | 'variant' | 'classNames' | 'styles' | 'optionFilterProp' | 'maxLines'>;
|
|
179
179
|
export type SpaceConfig = ComponentStyleConfig & Pick<SpaceProps, 'size' | 'classNames' | 'styles'>;
|
|
180
180
|
export type TooltipConfig = Pick<TooltipProps, 'className' | 'style' | 'styles' | 'classNames' | 'arrow' | 'trigger'> & {
|
|
181
181
|
/**
|
package/es/index.d.ts
CHANGED
|
@@ -68,8 +68,8 @@ export { default as Row } from './row';
|
|
|
68
68
|
export type { RowProps } from './row';
|
|
69
69
|
export { default as Segmented } from './segmented';
|
|
70
70
|
export type { SegmentedProps } from './segmented';
|
|
71
|
-
export { default as Select } from './select';
|
|
72
|
-
export type { RefSelectProps, SelectProps } from './select';
|
|
71
|
+
export { default as Select, SortableSelect, SingleDisplaySelect } from './select';
|
|
72
|
+
export type { RefSelectProps, SelectProps, SortableSelectProps, SingleDisplaySelectProps } from './select';
|
|
73
73
|
export { default as Skeleton } from './skeleton';
|
|
74
74
|
export type { SkeletonProps } from './skeleton';
|
|
75
75
|
export { default as Slider } from './slider';
|
package/es/index.js
CHANGED
|
@@ -75,7 +75,7 @@ export { default as Radio } from './radio';
|
|
|
75
75
|
export { default as Result } from './result';
|
|
76
76
|
export { default as Row } from './row';
|
|
77
77
|
export { default as Segmented } from './segmented';
|
|
78
|
-
export { default as Select } from './select';
|
|
78
|
+
export { default as Select, SortableSelect, SingleDisplaySelect } from './select';
|
|
79
79
|
export { default as Skeleton } from './skeleton';
|
|
80
80
|
export { default as Slider } from './slider';
|
|
81
81
|
export { default as Space } from './space';
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { BaseSelectRef, SelectProps as RcSelectProps } from '@rc-component/select';
|
|
3
|
+
import { OptGroup, Option } from '@rc-component/select';
|
|
4
|
+
import type { OptionProps } from '@rc-component/select/lib/Option';
|
|
5
|
+
import type { BaseOptionType, DefaultOptionType } from '@rc-component/select/lib/Select';
|
|
6
|
+
import type { SemanticClassNamesType, SemanticStylesType } from '../_util/hooks';
|
|
7
|
+
import type { SelectCommonPlacement } from '../_util/motion';
|
|
8
|
+
import type { InputStatus } from '../_util/statusUtils';
|
|
9
|
+
import type { Variant } from '../config-provider';
|
|
10
|
+
import type { SizeType } from '../config-provider/SizeContext';
|
|
11
|
+
type RawValue = string | number;
|
|
12
|
+
export type { BaseOptionType, DefaultOptionType, OptionProps, BaseSelectRef as RefSelectProps };
|
|
13
|
+
export interface LabeledValue {
|
|
14
|
+
key?: string;
|
|
15
|
+
value: RawValue;
|
|
16
|
+
label: React.ReactNode;
|
|
17
|
+
}
|
|
18
|
+
export type SelectValue = RawValue | RawValue[] | LabeledValue | LabeledValue[] | undefined;
|
|
19
|
+
export interface InternalSelectProps<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType> extends Omit<RcSelectProps<ValueType, OptionType>, 'mode'> {
|
|
20
|
+
rootClassName?: string;
|
|
21
|
+
prefix?: React.ReactNode;
|
|
22
|
+
suffixIcon?: React.ReactNode;
|
|
23
|
+
size?: SizeType;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
mode?: 'multiple' | 'tags' | 'SECRET_COMBOBOX_MODE_DO_NOT_USE' | 'combobox';
|
|
26
|
+
/** @deprecated Use `variant` instead. */
|
|
27
|
+
bordered?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated `showArrow` is deprecated which will be removed in next major version. It will be a
|
|
30
|
+
* default behavior, you can hide it by setting `suffixIcon` to null.
|
|
31
|
+
*/
|
|
32
|
+
showArrow?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* @since 5.13.0
|
|
35
|
+
* @default "outlined"
|
|
36
|
+
*/
|
|
37
|
+
variant?: Variant;
|
|
38
|
+
classNames?: SelectSemanticClassNames & {
|
|
39
|
+
popup?: SelectPopupSemanticClassNames;
|
|
40
|
+
};
|
|
41
|
+
styles?: SelectSemanticStyles & {
|
|
42
|
+
popup?: SelectPopupSemanticStyles;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @description Whether the option is a filter item
|
|
46
|
+
* @default false
|
|
47
|
+
* @type boolean
|
|
48
|
+
* TDM_CUSTOM: custom select filter (BEGIN)
|
|
49
|
+
*/
|
|
50
|
+
isFilterItem?: boolean;
|
|
51
|
+
}
|
|
52
|
+
export type SelectSemanticName = keyof SelectSemanticClassNames & keyof SelectSemanticStyles;
|
|
53
|
+
export type SelectSemanticClassNames = {
|
|
54
|
+
root?: string;
|
|
55
|
+
prefix?: string;
|
|
56
|
+
suffix?: string;
|
|
57
|
+
input?: string;
|
|
58
|
+
placeholder?: string;
|
|
59
|
+
content?: string;
|
|
60
|
+
item?: string;
|
|
61
|
+
itemContent?: string;
|
|
62
|
+
itemRemove?: string;
|
|
63
|
+
clear?: string;
|
|
64
|
+
};
|
|
65
|
+
export type SelectSemanticStyles = {
|
|
66
|
+
root?: React.CSSProperties;
|
|
67
|
+
prefix?: React.CSSProperties;
|
|
68
|
+
suffix?: React.CSSProperties;
|
|
69
|
+
input?: React.CSSProperties;
|
|
70
|
+
placeholder?: React.CSSProperties;
|
|
71
|
+
content?: React.CSSProperties;
|
|
72
|
+
item?: React.CSSProperties;
|
|
73
|
+
itemContent?: React.CSSProperties;
|
|
74
|
+
itemRemove?: React.CSSProperties;
|
|
75
|
+
clear?: React.CSSProperties;
|
|
76
|
+
};
|
|
77
|
+
export type SelectPopupSemanticName = keyof SelectPopupSemanticClassNames & keyof SelectPopupSemanticStyles;
|
|
78
|
+
export type SelectPopupSemanticClassNames = {
|
|
79
|
+
root?: string;
|
|
80
|
+
listItem?: string;
|
|
81
|
+
list?: string;
|
|
82
|
+
};
|
|
83
|
+
export type SelectPopupSemanticStyles = {
|
|
84
|
+
root?: React.CSSProperties;
|
|
85
|
+
listItem?: React.CSSProperties;
|
|
86
|
+
list?: React.CSSProperties;
|
|
87
|
+
};
|
|
88
|
+
export type SelectClassNamesType = SemanticClassNamesType<SelectProps, SelectSemanticClassNames, {
|
|
89
|
+
popup?: SelectPopupSemanticClassNames;
|
|
90
|
+
}>;
|
|
91
|
+
export type SelectStylesType = SemanticStylesType<SelectProps, SelectSemanticStyles, {
|
|
92
|
+
popup?: SelectPopupSemanticStyles;
|
|
93
|
+
}>;
|
|
94
|
+
export interface SelectProps<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType> extends Omit<InternalSelectProps<ValueType, OptionType>, 'mode' | 'getInputElement' | 'getRawInputElement' | 'backfill' | 'placement' | 'dropdownClassName' | 'dropdownStyle'> {
|
|
95
|
+
placement?: SelectCommonPlacement;
|
|
96
|
+
mode?: 'multiple' | 'tags';
|
|
97
|
+
status?: InputStatus;
|
|
98
|
+
/**
|
|
99
|
+
* @description Maximum number of lines to display tags before collapsing into `+N`
|
|
100
|
+
* @type number
|
|
101
|
+
*/
|
|
102
|
+
maxLines?: number;
|
|
103
|
+
/** @deprecated Please use `classNames.popup.root` instead */
|
|
104
|
+
popupClassName?: string;
|
|
105
|
+
/** @deprecated Please use `classNames.popup.root` instead */
|
|
106
|
+
dropdownClassName?: string;
|
|
107
|
+
/** @deprecated Please use `styles.popup` instead */
|
|
108
|
+
dropdownStyle?: React.CSSProperties;
|
|
109
|
+
/** @deprecated Please use `popupRender` instead */
|
|
110
|
+
dropdownRender?: SelectProps['popupRender'];
|
|
111
|
+
/** @deprecated Please use `onOpenChange` instead */
|
|
112
|
+
onDropdownVisibleChange?: SelectProps['onPopupVisibleChange'];
|
|
113
|
+
/** @deprecated Please use `popupMatchSelectWidth` instead */
|
|
114
|
+
dropdownMatchSelectWidth?: boolean | number;
|
|
115
|
+
popupMatchSelectWidth?: boolean | number;
|
|
116
|
+
styles?: SelectStylesType;
|
|
117
|
+
classNames?: SelectClassNamesType;
|
|
118
|
+
onOpenChange?: (visible: boolean) => void;
|
|
119
|
+
}
|
|
120
|
+
declare const Select: (<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType>(props: React.PropsWithChildren<SelectProps<ValueType, OptionType>> & React.RefAttributes<BaseSelectRef>) => React.ReactElement) & {
|
|
121
|
+
displayName?: string;
|
|
122
|
+
SECRET_COMBOBOX_MODE_DO_NOT_USE: string;
|
|
123
|
+
/** @deprecated Please use `options` instead. */
|
|
124
|
+
Option: typeof Option;
|
|
125
|
+
/** @deprecated Please use `options` instead. */
|
|
126
|
+
OptGroup: typeof OptGroup;
|
|
127
|
+
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
|
128
|
+
};
|
|
129
|
+
declare const PurePanel: (props: import("../_util/type").AnyObject) => React.JSX.Element;
|
|
130
|
+
export default Select;
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// TODO: 4.0 - codemod should help to change `filterOption` to support node props.
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import RcSelect, { OptGroup, Option } from '@rc-component/select';
|
|
6
|
+
import { omit } from '@rc-component/util';
|
|
7
|
+
import { clsx } from 'clsx';
|
|
8
|
+
import { useMergeSemantic, useZIndex } from '../_util/hooks';
|
|
9
|
+
import { getTransitionName } from '../_util/motion';
|
|
10
|
+
import genPurePanel from '../_util/PurePanel';
|
|
11
|
+
import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils';
|
|
12
|
+
import { devUseWarning } from '../_util/warning';
|
|
13
|
+
import { ConfigContext } from '../config-provider';
|
|
14
|
+
import { useComponentConfig } from '../config-provider/context';
|
|
15
|
+
import DefaultRenderEmpty from '../config-provider/defaultRenderEmpty';
|
|
16
|
+
import DisabledContext from '../config-provider/DisabledContext';
|
|
17
|
+
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
|
18
|
+
import useSize from '../config-provider/hooks/useSize';
|
|
19
|
+
import { FormItemInputContext } from '../form/context';
|
|
20
|
+
import useVariants from '../form/hooks/useVariants';
|
|
21
|
+
import { useCompactItemContext } from '../space/Compact';
|
|
22
|
+
import { useToken } from '../theme/internal';
|
|
23
|
+
import mergedBuiltinPlacements from './mergedBuiltinPlacements';
|
|
24
|
+
import useStyle from './style';
|
|
25
|
+
import useIcons from './useIcons';
|
|
26
|
+
import usePopupRender from './usePopupRender';
|
|
27
|
+
import useShowArrow from './useShowArrow';
|
|
28
|
+
const SECRET_COMBOBOX_MODE_DO_NOT_USE = 'SECRET_COMBOBOX_MODE_DO_NOT_USE';
|
|
29
|
+
const InternalSelect = (props, ref) => {
|
|
30
|
+
const {
|
|
31
|
+
prefixCls: customizePrefixCls,
|
|
32
|
+
bordered,
|
|
33
|
+
className,
|
|
34
|
+
rootClassName,
|
|
35
|
+
getPopupContainer,
|
|
36
|
+
popupClassName,
|
|
37
|
+
dropdownClassName,
|
|
38
|
+
listHeight = 256,
|
|
39
|
+
placement,
|
|
40
|
+
listItemHeight: customListItemHeight,
|
|
41
|
+
size: customizeSize,
|
|
42
|
+
disabled: customDisabled,
|
|
43
|
+
notFoundContent,
|
|
44
|
+
status: customStatus,
|
|
45
|
+
builtinPlacements,
|
|
46
|
+
dropdownMatchSelectWidth,
|
|
47
|
+
popupMatchSelectWidth,
|
|
48
|
+
direction: propDirection,
|
|
49
|
+
style,
|
|
50
|
+
allowClear,
|
|
51
|
+
variant: customizeVariant,
|
|
52
|
+
popupStyle,
|
|
53
|
+
dropdownStyle,
|
|
54
|
+
transitionName,
|
|
55
|
+
tagRender,
|
|
56
|
+
maxCount,
|
|
57
|
+
prefix,
|
|
58
|
+
dropdownRender,
|
|
59
|
+
/**
|
|
60
|
+
* @since 5.25.0
|
|
61
|
+
*/
|
|
62
|
+
popupRender,
|
|
63
|
+
onDropdownVisibleChange,
|
|
64
|
+
onOpenChange,
|
|
65
|
+
styles,
|
|
66
|
+
classNames,
|
|
67
|
+
isFilterItem,
|
|
68
|
+
// TDM_CUSTOM: custom select filter
|
|
69
|
+
optionFilterProp,
|
|
70
|
+
maxLines,
|
|
71
|
+
...rest
|
|
72
|
+
} = props;
|
|
73
|
+
const {
|
|
74
|
+
getPopupContainer: getContextPopupContainer,
|
|
75
|
+
getPrefixCls,
|
|
76
|
+
renderEmpty,
|
|
77
|
+
direction: contextDirection,
|
|
78
|
+
virtual,
|
|
79
|
+
popupMatchSelectWidth: contextPopupMatchSelectWidth,
|
|
80
|
+
popupOverflow
|
|
81
|
+
} = React.useContext(ConfigContext);
|
|
82
|
+
const {
|
|
83
|
+
showSearch,
|
|
84
|
+
optionFilterProp: contextOptionFilterProp,
|
|
85
|
+
maxLines: contextMaxLines,
|
|
86
|
+
style: contextStyle,
|
|
87
|
+
styles: contextStyles,
|
|
88
|
+
className: contextClassName,
|
|
89
|
+
classNames: contextClassNames
|
|
90
|
+
} = useComponentConfig('select');
|
|
91
|
+
const mergedMaxLines = maxLines ?? contextMaxLines;
|
|
92
|
+
const [, token] = useToken();
|
|
93
|
+
const listItemHeight = customListItemHeight ?? token?.controlHeight;
|
|
94
|
+
const prefixCls = getPrefixCls('select', customizePrefixCls);
|
|
95
|
+
const rootPrefixCls = getPrefixCls();
|
|
96
|
+
const direction = propDirection ?? contextDirection;
|
|
97
|
+
const {
|
|
98
|
+
compactSize,
|
|
99
|
+
compactItemClassnames
|
|
100
|
+
} = useCompactItemContext(prefixCls, direction);
|
|
101
|
+
const [variant, enableVariantCls] = useVariants('select', customizeVariant, bordered);
|
|
102
|
+
const rootCls = useCSSVarCls(prefixCls);
|
|
103
|
+
const [hashId, cssVarCls] = useStyle(prefixCls, rootCls);
|
|
104
|
+
const mode = React.useMemo(() => {
|
|
105
|
+
const {
|
|
106
|
+
mode: m
|
|
107
|
+
} = props;
|
|
108
|
+
if (m === 'combobox') {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
if (m === SECRET_COMBOBOX_MODE_DO_NOT_USE) {
|
|
112
|
+
return 'combobox';
|
|
113
|
+
}
|
|
114
|
+
return m;
|
|
115
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
116
|
+
}, [props.mode]);
|
|
117
|
+
const isMultiple = mode === 'multiple' || mode === 'tags';
|
|
118
|
+
const showSuffixIcon = useShowArrow(props.suffixIcon, props.showArrow);
|
|
119
|
+
const mergedPopupMatchSelectWidth = popupMatchSelectWidth ?? dropdownMatchSelectWidth ?? contextPopupMatchSelectWidth;
|
|
120
|
+
const mergedPopupRender = usePopupRender(popupRender || dropdownRender);
|
|
121
|
+
const mergedOnOpenChange = onOpenChange || onDropdownVisibleChange;
|
|
122
|
+
// ===================== Form Status =====================
|
|
123
|
+
const {
|
|
124
|
+
status: contextStatus,
|
|
125
|
+
hasFeedback,
|
|
126
|
+
isFormItemInput,
|
|
127
|
+
feedbackIcon
|
|
128
|
+
} = React.useContext(FormItemInputContext);
|
|
129
|
+
const mergedStatus = getMergedStatus(contextStatus, customStatus);
|
|
130
|
+
// ===================== Empty =====================
|
|
131
|
+
let mergedNotFound;
|
|
132
|
+
if (notFoundContent !== undefined) {
|
|
133
|
+
mergedNotFound = notFoundContent;
|
|
134
|
+
} else if (mode === 'combobox') {
|
|
135
|
+
mergedNotFound = null;
|
|
136
|
+
} else {
|
|
137
|
+
mergedNotFound = renderEmpty?.('Select') || /*#__PURE__*/React.createElement(DefaultRenderEmpty, {
|
|
138
|
+
componentName: "Select"
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
// ===================== Icons =====================
|
|
142
|
+
const {
|
|
143
|
+
suffixIcon,
|
|
144
|
+
itemIcon,
|
|
145
|
+
removeIcon,
|
|
146
|
+
clearIcon
|
|
147
|
+
} = useIcons({
|
|
148
|
+
...rest,
|
|
149
|
+
multiple: isMultiple,
|
|
150
|
+
hasFeedback,
|
|
151
|
+
feedbackIcon,
|
|
152
|
+
showSuffixIcon,
|
|
153
|
+
prefixCls,
|
|
154
|
+
componentName: 'Select'
|
|
155
|
+
});
|
|
156
|
+
const mergedAllowClear = allowClear === true ? {
|
|
157
|
+
clearIcon
|
|
158
|
+
} : allowClear;
|
|
159
|
+
const selectProps = omit(rest, ['suffixIcon', 'itemIcon']);
|
|
160
|
+
const mergedSize = useSize(ctx => customizeSize ?? compactSize ?? ctx);
|
|
161
|
+
// ===================== Disabled =====================
|
|
162
|
+
const disabled = React.useContext(DisabledContext);
|
|
163
|
+
const mergedDisabled = customDisabled ?? disabled;
|
|
164
|
+
// ========== Merged Props for Semantic ==================
|
|
165
|
+
const mergedProps = {
|
|
166
|
+
...props,
|
|
167
|
+
variant,
|
|
168
|
+
status: mergedStatus,
|
|
169
|
+
disabled: mergedDisabled,
|
|
170
|
+
size: mergedSize
|
|
171
|
+
};
|
|
172
|
+
const [mergedClassNames, mergedStyles] = useMergeSemantic([contextClassNames, classNames], [contextStyles, styles], {
|
|
173
|
+
props: mergedProps
|
|
174
|
+
}, {
|
|
175
|
+
popup: {
|
|
176
|
+
_default: 'root'
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
const mergedPopupClassName = clsx(mergedClassNames.popup?.root, popupClassName, dropdownClassName, {
|
|
180
|
+
[`${prefixCls}-dropdown-${direction}`]: direction === 'rtl'
|
|
181
|
+
}, rootClassName, cssVarCls, rootCls, hashId);
|
|
182
|
+
const mergedPopupStyle = {
|
|
183
|
+
...mergedStyles.popup?.root,
|
|
184
|
+
...(popupStyle ?? dropdownStyle)
|
|
185
|
+
};
|
|
186
|
+
const mergedClassName = clsx({
|
|
187
|
+
[`${prefixCls}-lg`]: mergedSize === 'large',
|
|
188
|
+
[`${prefixCls}-sm`]: mergedSize === 'small',
|
|
189
|
+
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
190
|
+
[`${prefixCls}-${variant}`]: enableVariantCls,
|
|
191
|
+
[`${prefixCls}-in-form-item`]: isFormItemInput,
|
|
192
|
+
// TDM_CUSTOM: custom select filter
|
|
193
|
+
[`${prefixCls}-filter`]: isFilterItem
|
|
194
|
+
}, getStatusClassNames(prefixCls, mergedStatus, hasFeedback), compactItemClassnames, contextClassName, className, mergedClassNames.root, rootClassName, cssVarCls, rootCls, hashId);
|
|
195
|
+
// ===================== Placement =====================
|
|
196
|
+
const memoPlacement = React.useMemo(() => {
|
|
197
|
+
if (placement !== undefined) {
|
|
198
|
+
return placement;
|
|
199
|
+
}
|
|
200
|
+
return direction === 'rtl' ? 'bottomRight' : 'bottomLeft';
|
|
201
|
+
}, [placement, direction]);
|
|
202
|
+
// ====================== Warning ======================
|
|
203
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
204
|
+
const warning = devUseWarning('Select');
|
|
205
|
+
const deprecatedProps = {
|
|
206
|
+
dropdownMatchSelectWidth: 'popupMatchSelectWidth',
|
|
207
|
+
dropdownStyle: 'styles.popup.root',
|
|
208
|
+
dropdownClassName: 'classNames.popup.root',
|
|
209
|
+
popupClassName: 'classNames.popup.root',
|
|
210
|
+
dropdownRender: 'popupRender',
|
|
211
|
+
onDropdownVisibleChange: 'onOpenChange',
|
|
212
|
+
bordered: 'variant'
|
|
213
|
+
};
|
|
214
|
+
Object.entries(deprecatedProps).forEach(([oldProp, newProp]) => {
|
|
215
|
+
warning.deprecated(!(oldProp in props), oldProp, newProp);
|
|
216
|
+
});
|
|
217
|
+
process.env.NODE_ENV !== "production" ? warning(!('showArrow' in props), 'deprecated', '`showArrow` is deprecated which will be removed in next major version. It will be a default behavior, you can hide it by setting `suffixIcon` to null.') : void 0;
|
|
218
|
+
process.env.NODE_ENV !== "production" ? warning(!(typeof maxCount !== 'undefined' && !isMultiple), 'usage', '`maxCount` only works with mode `multiple` or `tags`') : void 0;
|
|
219
|
+
}
|
|
220
|
+
// ====================== MaxLines ======================
|
|
221
|
+
const internalSelectRef = React.useRef(null);
|
|
222
|
+
React.useImperativeHandle(ref, () => internalSelectRef.current);
|
|
223
|
+
const [linesMaxTagCount, setLinesMaxTagCount] = React.useState(undefined);
|
|
224
|
+
const calculateMaxLinesTags = React.useCallback(() => {
|
|
225
|
+
if (!mergedMaxLines || !isMultiple) return;
|
|
226
|
+
const container = internalSelectRef.current?.nativeElement;
|
|
227
|
+
if (!container) return;
|
|
228
|
+
const tagElements = container.querySelectorAll(`.${prefixCls}-selection-item, .${prefixCls}-content-item`);
|
|
229
|
+
if (tagElements.length === 0) {
|
|
230
|
+
setLinesMaxTagCount(undefined);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const firstTagTop = tagElements[0].offsetTop;
|
|
234
|
+
const tagHeight = tagElements[0].offsetHeight || 24;
|
|
235
|
+
const rowHeightThreshold = tagHeight + 6;
|
|
236
|
+
const maxAllowedTop = firstTagTop + rowHeightThreshold * (mergedMaxLines - 1);
|
|
237
|
+
let fitCount = tagElements.length;
|
|
238
|
+
for (let i = 0; i < tagElements.length; i++) {
|
|
239
|
+
const el = tagElements[i];
|
|
240
|
+
if (el.offsetTop > maxAllowedTop) {
|
|
241
|
+
fitCount = Math.max(1, i - 1);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (fitCount < tagElements.length) {
|
|
246
|
+
setLinesMaxTagCount(fitCount);
|
|
247
|
+
} else {
|
|
248
|
+
setLinesMaxTagCount(undefined);
|
|
249
|
+
}
|
|
250
|
+
}, [mergedMaxLines, isMultiple, prefixCls]);
|
|
251
|
+
React.useLayoutEffect(() => {
|
|
252
|
+
if (!mergedMaxLines || !isMultiple) {
|
|
253
|
+
setLinesMaxTagCount(undefined);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
setLinesMaxTagCount(undefined);
|
|
257
|
+
const timer = requestAnimationFrame(() => {
|
|
258
|
+
calculateMaxLinesTags();
|
|
259
|
+
});
|
|
260
|
+
return () => cancelAnimationFrame(timer);
|
|
261
|
+
}, [props.value, mergedMaxLines, isMultiple, calculateMaxLinesTags]);
|
|
262
|
+
React.useLayoutEffect(() => {
|
|
263
|
+
if (!mergedMaxLines || !isMultiple) return;
|
|
264
|
+
const container = internalSelectRef.current?.nativeElement;
|
|
265
|
+
if (!container || typeof ResizeObserver === 'undefined') return;
|
|
266
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
267
|
+
calculateMaxLinesTags();
|
|
268
|
+
});
|
|
269
|
+
resizeObserver.observe(container);
|
|
270
|
+
return () => resizeObserver.disconnect();
|
|
271
|
+
}, [mergedMaxLines, isMultiple, calculateMaxLinesTags]);
|
|
272
|
+
// ====================== zIndex =========================
|
|
273
|
+
const [zIndex] = useZIndex('SelectLike', mergedStyles.popup?.root?.zIndex ?? mergedPopupStyle?.zIndex);
|
|
274
|
+
// ====================== Render =======================
|
|
275
|
+
return /*#__PURE__*/React.createElement(RcSelect, {
|
|
276
|
+
ref: internalSelectRef,
|
|
277
|
+
virtual: virtual,
|
|
278
|
+
classNames: mergedClassNames,
|
|
279
|
+
styles: mergedStyles,
|
|
280
|
+
showSearch: showSearch,
|
|
281
|
+
optionFilterProp: optionFilterProp ?? contextOptionFilterProp ?? 'label',
|
|
282
|
+
...selectProps,
|
|
283
|
+
maxTagCount: mergedMaxLines && isMultiple ? linesMaxTagCount : props.maxTagCount ?? (isMultiple ? maxCount : undefined),
|
|
284
|
+
style: {
|
|
285
|
+
...mergedStyles.root,
|
|
286
|
+
...contextStyle,
|
|
287
|
+
...style
|
|
288
|
+
},
|
|
289
|
+
popupMatchSelectWidth: mergedPopupMatchSelectWidth,
|
|
290
|
+
transitionName: getTransitionName(rootPrefixCls, 'slide-up', transitionName),
|
|
291
|
+
builtinPlacements: mergedBuiltinPlacements(builtinPlacements, popupOverflow),
|
|
292
|
+
listHeight: listHeight,
|
|
293
|
+
listItemHeight: listItemHeight,
|
|
294
|
+
mode: mode,
|
|
295
|
+
prefixCls: prefixCls,
|
|
296
|
+
placement: memoPlacement,
|
|
297
|
+
direction: direction,
|
|
298
|
+
prefix: prefix,
|
|
299
|
+
suffixIcon: suffixIcon,
|
|
300
|
+
menuItemSelectedIcon: itemIcon,
|
|
301
|
+
removeIcon: removeIcon,
|
|
302
|
+
allowClear: mergedAllowClear,
|
|
303
|
+
notFoundContent: mergedNotFound,
|
|
304
|
+
className: mergedClassName,
|
|
305
|
+
getPopupContainer: getPopupContainer || getContextPopupContainer,
|
|
306
|
+
popupClassName: mergedPopupClassName,
|
|
307
|
+
disabled: mergedDisabled,
|
|
308
|
+
popupStyle: {
|
|
309
|
+
...mergedStyles.popup?.root,
|
|
310
|
+
...mergedPopupStyle,
|
|
311
|
+
zIndex
|
|
312
|
+
},
|
|
313
|
+
maxCount: isMultiple ? maxCount : undefined,
|
|
314
|
+
tagRender: isMultiple ? tagRender : undefined,
|
|
315
|
+
popupRender: mergedPopupRender,
|
|
316
|
+
onPopupVisibleChange: mergedOnOpenChange
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
320
|
+
InternalSelect.displayName = 'Select';
|
|
321
|
+
}
|
|
322
|
+
const Select = /*#__PURE__*/React.forwardRef(InternalSelect);
|
|
323
|
+
// We don't care debug panel
|
|
324
|
+
/* istanbul ignore next */
|
|
325
|
+
const PurePanel = genPurePanel(Select, 'popupAlign');
|
|
326
|
+
Select.SECRET_COMBOBOX_MODE_DO_NOT_USE = SECRET_COMBOBOX_MODE_DO_NOT_USE;
|
|
327
|
+
Select.Option = Option;
|
|
328
|
+
Select.OptGroup = OptGroup;
|
|
329
|
+
Select._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
|
|
330
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
331
|
+
Select.displayName = 'Select';
|
|
332
|
+
}
|
|
333
|
+
export default Select;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SelectProps, BaseOptionType, DefaultOptionType } from './Select';
|
|
3
|
+
export type SingleDisplaySelectProps<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType> = SelectProps<ValueType, OptionType>;
|
|
4
|
+
declare const SingleDisplaySelect: <ValueType extends any[] = any[], OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType>(props: SingleDisplaySelectProps<ValueType, OptionType>) => React.JSX.Element;
|
|
5
|
+
export default SingleDisplaySelect;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { useState, useEffect, useCallback } from 'react';
|
|
4
|
+
import Select from './Select';
|
|
5
|
+
import Popover from '../popover';
|
|
6
|
+
import Tag from '../tag';
|
|
7
|
+
import { ConfigContext } from '../config-provider';
|
|
8
|
+
import CloseOutlinedIcon from '@tdm-design/icons/CloseOutlinedIcon';
|
|
9
|
+
function extractValueId(val) {
|
|
10
|
+
if (typeof val === 'object' && val !== null) {
|
|
11
|
+
if ('key' in val && val.key !== undefined) return val.key;
|
|
12
|
+
if ('value' in val && val.value !== undefined) return val.value;
|
|
13
|
+
}
|
|
14
|
+
return val;
|
|
15
|
+
}
|
|
16
|
+
const SingleDisplaySelect = props => {
|
|
17
|
+
const {
|
|
18
|
+
value,
|
|
19
|
+
defaultValue,
|
|
20
|
+
onChange,
|
|
21
|
+
disabled,
|
|
22
|
+
tagRender,
|
|
23
|
+
maxTagPlaceholder,
|
|
24
|
+
prefixCls: customizePrefixCls,
|
|
25
|
+
...restProps
|
|
26
|
+
} = props;
|
|
27
|
+
const {
|
|
28
|
+
getPrefixCls
|
|
29
|
+
} = React.useContext(ConfigContext);
|
|
30
|
+
const prefixCls = getPrefixCls('select', customizePrefixCls);
|
|
31
|
+
// Maintain internal state for uncontrolled usage
|
|
32
|
+
const [internalValue, setInternalValue] = useState(() => {
|
|
33
|
+
if (value !== undefined) return value;
|
|
34
|
+
if (defaultValue !== undefined) return defaultValue;
|
|
35
|
+
return [];
|
|
36
|
+
});
|
|
37
|
+
// Keep track of the options to properly call onChange
|
|
38
|
+
const [internalOptions, setInternalOptions] = useState([]);
|
|
39
|
+
// Sync with controlled value
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (value !== undefined) {
|
|
42
|
+
setInternalValue(value);
|
|
43
|
+
}
|
|
44
|
+
}, [value]);
|
|
45
|
+
// Sync internalOptions when value changes externally if possible
|
|
46
|
+
// In a real scenario we'd need to lookup options from the list if we don't have them
|
|
47
|
+
// For simplicity we just rely on onChange to provide them.
|
|
48
|
+
const handleChange = (val, opt) => {
|
|
49
|
+
if (value === undefined) {
|
|
50
|
+
setInternalValue(val);
|
|
51
|
+
}
|
|
52
|
+
setInternalOptions(opt);
|
|
53
|
+
onChange?.(val, opt);
|
|
54
|
+
};
|
|
55
|
+
const handleRemove = (itemValue, e) => {
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
e.stopPropagation();
|
|
58
|
+
const prevArray = Array.isArray(internalValue) ? internalValue : [];
|
|
59
|
+
const newValue = prevArray.filter(v => extractValueId(v) !== itemValue);
|
|
60
|
+
// We try to filter internalOptions, if it's not maintained correctly, we might pass []
|
|
61
|
+
// which is better than passing the wrong options.
|
|
62
|
+
const newOptions = Array.isArray(internalOptions) ? internalOptions.filter(opt => extractValueId(opt.value) !== itemValue) : [];
|
|
63
|
+
handleChange(newValue, newOptions);
|
|
64
|
+
};
|
|
65
|
+
const defaultTagRender = useCallback(tagProps => {
|
|
66
|
+
const {
|
|
67
|
+
label,
|
|
68
|
+
closable,
|
|
69
|
+
onClose,
|
|
70
|
+
disabled: itemDisabled
|
|
71
|
+
} = tagProps;
|
|
72
|
+
const onMouseDown = e => {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
e.stopPropagation();
|
|
75
|
+
};
|
|
76
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
77
|
+
className: `${prefixCls}-selection-item${itemDisabled ? ` ${prefixCls}-selection-item-disabled` : ''}`,
|
|
78
|
+
onMouseDown: onMouseDown
|
|
79
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
80
|
+
className: `${prefixCls}-selection-item-content`
|
|
81
|
+
}, label), closable && (/*#__PURE__*/React.createElement("span", {
|
|
82
|
+
className: `${prefixCls}-selection-item-remove`,
|
|
83
|
+
onClick: e => {
|
|
84
|
+
e.stopPropagation();
|
|
85
|
+
onClose?.(e);
|
|
86
|
+
},
|
|
87
|
+
onMouseDown: onMouseDown
|
|
88
|
+
}, /*#__PURE__*/React.createElement(CloseOutlinedIcon, null))));
|
|
89
|
+
}, [prefixCls]);
|
|
90
|
+
const mergedTagRender = tagRender || defaultTagRender;
|
|
91
|
+
const defaultMaxTagPlaceholder = useCallback(omittedValues => {
|
|
92
|
+
return /*#__PURE__*/React.createElement(Popover, {
|
|
93
|
+
content: /*#__PURE__*/React.createElement("div", {
|
|
94
|
+
style: {
|
|
95
|
+
display: 'flex',
|
|
96
|
+
flexWrap: 'wrap',
|
|
97
|
+
gap: 6,
|
|
98
|
+
maxWidth: 350,
|
|
99
|
+
padding: 8
|
|
100
|
+
}
|
|
101
|
+
}, omittedValues.map(v => (/*#__PURE__*/React.createElement(Tag, {
|
|
102
|
+
key: extractValueId(v.value),
|
|
103
|
+
closable: !disabled && !v.disabled,
|
|
104
|
+
closeIcon: /*#__PURE__*/React.createElement("span", {
|
|
105
|
+
style: {
|
|
106
|
+
fontSize: 10,
|
|
107
|
+
display: 'inline-flex',
|
|
108
|
+
alignItems: 'center',
|
|
109
|
+
marginLeft: 6
|
|
110
|
+
}
|
|
111
|
+
}, "\u2715"),
|
|
112
|
+
onClose: e => handleRemove(extractValueId(v.value), e),
|
|
113
|
+
style: {
|
|
114
|
+
margin: 0,
|
|
115
|
+
display: 'flex',
|
|
116
|
+
alignItems: 'center',
|
|
117
|
+
padding: '2px 6px',
|
|
118
|
+
borderRadius: 4
|
|
119
|
+
}
|
|
120
|
+
}, v.label)))),
|
|
121
|
+
placement: "top",
|
|
122
|
+
trigger: "hover"
|
|
123
|
+
}, /*#__PURE__*/React.createElement("span", null, "+", omittedValues.length, " ..."));
|
|
124
|
+
}, [disabled, internalValue, internalOptions]);
|
|
125
|
+
const mergedMaxTagPlaceholder = maxTagPlaceholder || defaultMaxTagPlaceholder;
|
|
126
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("style", null, `
|
|
127
|
+
.tdm-single-display-select .${prefixCls}-selector {
|
|
128
|
+
align-items: center !important;
|
|
129
|
+
}
|
|
130
|
+
.tdm-single-display-select .${prefixCls}-selection-item {
|
|
131
|
+
margin-top: 0 !important;
|
|
132
|
+
margin-bottom: 0 !important;
|
|
133
|
+
max-width: 100% !important;
|
|
134
|
+
}
|
|
135
|
+
.tdm-single-display-select .${prefixCls}-content-item {
|
|
136
|
+
max-width: 100% !important;
|
|
137
|
+
}
|
|
138
|
+
.tdm-single-display-select .${prefixCls}-selection-overflow {
|
|
139
|
+
flex-wrap: nowrap !important;
|
|
140
|
+
overflow: hidden;
|
|
141
|
+
}
|
|
142
|
+
.tdm-single-display-select .${prefixCls}-selection-overflow-item {
|
|
143
|
+
max-width: 100% !important;
|
|
144
|
+
}
|
|
145
|
+
`), /*#__PURE__*/React.createElement(Select, {
|
|
146
|
+
...restProps,
|
|
147
|
+
className: `tdm-single-display-select ${restProps.className || ''}`,
|
|
148
|
+
mode: restProps.mode || 'multiple',
|
|
149
|
+
value: internalValue,
|
|
150
|
+
onChange: handleChange,
|
|
151
|
+
disabled: disabled,
|
|
152
|
+
maxTagCount: restProps.maxTagCount !== undefined ? restProps.maxTagCount : 1,
|
|
153
|
+
tagRender: mergedTagRender,
|
|
154
|
+
maxTagPlaceholder: mergedMaxTagPlaceholder
|
|
155
|
+
}));
|
|
156
|
+
};
|
|
157
|
+
export default SingleDisplaySelect;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SelectProps, BaseOptionType, DefaultOptionType } from './Select';
|
|
3
|
+
export type SortableSelectProps<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType> = SelectProps<ValueType, OptionType>;
|
|
4
|
+
declare const SortableSelect: <ValueType extends any[] = any[], OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType>(props: SortableSelectProps<ValueType, OptionType>) => React.JSX.Element;
|
|
5
|
+
export default SortableSelect;
|