@tdm-design/ui 0.0.14 → 0.0.16

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.
Files changed (47) hide show
  1. package/dist/@tdm-design/ui.js +113056 -0
  2. package/dist/@tdm-design/ui.js.map +1 -0
  3. package/dist/@tdm-design/ui.min.js +369 -0
  4. package/dist/@tdm-design/ui.min.js.LICENSE.txt +129 -0
  5. package/dist/@tdm-design/ui.min.js.map +1 -0
  6. package/dist/reset.css +246 -0
  7. package/dist/tdm-with-locales.js +369 -0
  8. package/dist/tdm-with-locales.js.LICENSE.txt +129 -0
  9. package/dist/tdm-with-locales.js.map +1 -0
  10. package/dist/tdm.css +1 -0
  11. package/es/config-provider/context.d.ts +1 -1
  12. package/es/drawer/style/index.js +5 -1
  13. package/es/index.d.ts +2 -2
  14. package/es/index.js +1 -1
  15. package/es/modal/style/confirm.js +6 -2
  16. package/es/modal/style/index.js +7 -2
  17. package/es/select/Select.d.ts +130 -0
  18. package/es/select/Select.js +333 -0
  19. package/es/select/SingleDisplaySelect.d.ts +5 -0
  20. package/es/select/SingleDisplaySelect.js +153 -0
  21. package/es/select/SortableSelect.d.ts +5 -0
  22. package/es/select/SortableSelect.js +173 -0
  23. package/es/select/index.d.ts +7 -124
  24. package/es/select/index.js +7 -274
  25. package/es/select/style/select-input-multiple.js +4 -1
  26. package/es/version/token.json +1 -1
  27. package/es/version/version.d.ts +1 -1
  28. package/es/version/version.js +1 -1
  29. package/lib/config-provider/context.d.ts +1 -1
  30. package/lib/drawer/style/index.js +5 -1
  31. package/lib/index.d.ts +2 -2
  32. package/lib/index.js +14 -1
  33. package/lib/modal/style/confirm.js +6 -2
  34. package/lib/modal/style/index.js +7 -2
  35. package/lib/select/Select.d.ts +130 -0
  36. package/lib/select/Select.js +340 -0
  37. package/lib/select/SingleDisplaySelect.d.ts +5 -0
  38. package/lib/select/SingleDisplaySelect.js +160 -0
  39. package/lib/select/SortableSelect.d.ts +5 -0
  40. package/lib/select/SortableSelect.js +180 -0
  41. package/lib/select/index.d.ts +7 -124
  42. package/lib/select/index.js +32 -274
  43. package/lib/select/style/select-input-multiple.js +4 -1
  44. package/lib/version/token.json +1 -1
  45. package/lib/version/version.d.ts +1 -1
  46. package/lib/version/version.js +1 -1
  47. package/package.json +11 -4
@@ -0,0 +1,153 @@
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-item {
139
+ max-width: 100% !important;
140
+ }
141
+ `), /*#__PURE__*/React.createElement(Select, {
142
+ ...restProps,
143
+ className: `tdm-single-display-select ${restProps.className || ''}`,
144
+ mode: restProps.mode || 'multiple',
145
+ value: internalValue,
146
+ onChange: handleChange,
147
+ disabled: disabled,
148
+ maxTagCount: restProps.maxTagCount !== undefined ? restProps.maxTagCount : 1,
149
+ tagRender: mergedTagRender,
150
+ maxTagPlaceholder: mergedMaxTagPlaceholder
151
+ }));
152
+ };
153
+ 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;
@@ -0,0 +1,173 @@
1
+ "use client";
2
+
3
+ import React, { useCallback, useEffect, useState } from 'react';
4
+ import Select from './Select';
5
+ import { DndContext, closestCenter, KeyboardSensor, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
6
+ import { arrayMove, SortableContext, sortableKeyboardCoordinates, useSortable, horizontalListSortingStrategy } from '@dnd-kit/sortable';
7
+ import { CSS } from '@dnd-kit/utilities';
8
+ import { ConfigContext } from '../config-provider';
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
+ import CloseOutlinedIcon from '@tdm-design/icons/CloseOutlinedIcon';
17
+ const DraggableTag = props => {
18
+ const {
19
+ value,
20
+ closable,
21
+ onClose,
22
+ label,
23
+ disabled,
24
+ prefixCls,
25
+ customTagRender
26
+ } = props;
27
+ const id = extractValueId(value);
28
+ const {
29
+ attributes,
30
+ listeners,
31
+ setNodeRef,
32
+ transform,
33
+ transition,
34
+ isDragging
35
+ } = useSortable({
36
+ id,
37
+ disabled: disabled || !id
38
+ });
39
+ const mergedStyle = {
40
+ transform: CSS.Transform.toString(transform),
41
+ transition,
42
+ opacity: isDragging ? 0.4 : undefined,
43
+ zIndex: isDragging ? 1 : undefined,
44
+ cursor: disabled || !id ? 'default' : 'move'
45
+ };
46
+ const onMouseDown = e => {
47
+ e.preventDefault();
48
+ e.stopPropagation();
49
+ };
50
+ if (customTagRender) {
51
+ return /*#__PURE__*/React.createElement("span", {
52
+ ref: setNodeRef,
53
+ style: {
54
+ ...mergedStyle,
55
+ display: 'inline-flex'
56
+ },
57
+ ...attributes,
58
+ ...listeners,
59
+ onMouseDown: onMouseDown
60
+ }, customTagRender(props));
61
+ }
62
+ return /*#__PURE__*/React.createElement("span", {
63
+ ref: setNodeRef,
64
+ style: mergedStyle,
65
+ className: `${prefixCls}-selection-item${disabled ? ` ${prefixCls}-selection-item-disabled` : ''}`,
66
+ ...attributes,
67
+ ...listeners,
68
+ onMouseDown: onMouseDown
69
+ }, /*#__PURE__*/React.createElement("span", {
70
+ className: `${prefixCls}-selection-item-content`
71
+ }, label), closable && (/*#__PURE__*/React.createElement("span", {
72
+ className: `${prefixCls}-selection-item-remove`,
73
+ onClick: e => {
74
+ e.stopPropagation();
75
+ onClose?.(e);
76
+ },
77
+ onMouseDown: e => {
78
+ e.preventDefault();
79
+ e.stopPropagation();
80
+ }
81
+ }, /*#__PURE__*/React.createElement(CloseOutlinedIcon, null))));
82
+ };
83
+ const SortableSelect = props => {
84
+ const {
85
+ value,
86
+ defaultValue,
87
+ onChange,
88
+ disabled,
89
+ prefixCls: customizePrefixCls,
90
+ tagRender: customTagRender,
91
+ ...restProps
92
+ } = props;
93
+ const {
94
+ getPrefixCls
95
+ } = React.useContext(ConfigContext);
96
+ const prefixCls = getPrefixCls('select', customizePrefixCls);
97
+ // Maintain internal state for uncontrolled usage
98
+ const [internalValue, setInternalValue] = useState(() => {
99
+ if (value !== undefined) return value;
100
+ if (defaultValue !== undefined) return defaultValue;
101
+ return [];
102
+ });
103
+ // Sync with controlled value
104
+ useEffect(() => {
105
+ if (value !== undefined) {
106
+ setInternalValue(value);
107
+ }
108
+ }, [value]);
109
+ const sensors = useSensors(useSensor(PointerSensor, {
110
+ activationConstraint: {
111
+ distance: 5
112
+ }
113
+ }), useSensor(KeyboardSensor, {
114
+ coordinateGetter: sortableKeyboardCoordinates
115
+ }));
116
+ const handleDragEnd = useCallback(event => {
117
+ const {
118
+ active,
119
+ over
120
+ } = event;
121
+ if (!over || active.id === over.id) {
122
+ return;
123
+ }
124
+ setInternalValue(prev => {
125
+ const prevArray = Array.isArray(prev) ? prev : [];
126
+ const oldIndex = prevArray.findIndex(item => extractValueId(item) === active.id);
127
+ const newIndex = prevArray.findIndex(item => extractValueId(item) === over.id);
128
+ if (oldIndex !== -1 && newIndex !== -1) {
129
+ const newArray = arrayMove(prevArray, oldIndex, newIndex);
130
+ // Only call onChange if the new array is actually different
131
+ onChange?.(newArray, []); // We skip options parameter for simplicity here
132
+ return newArray;
133
+ }
134
+ return prev;
135
+ });
136
+ }, [onChange]);
137
+ const handleChange = (val, opt) => {
138
+ if (value === undefined) {
139
+ setInternalValue(val);
140
+ }
141
+ onChange?.(val, opt);
142
+ };
143
+ const tagRender = useCallback(tagProps => {
144
+ return /*#__PURE__*/React.createElement(DraggableTag, {
145
+ ...tagProps,
146
+ disabled: !!disabled,
147
+ prefixCls: prefixCls,
148
+ customTagRender: customTagRender
149
+ });
150
+ }, [disabled, prefixCls, customTagRender]);
151
+ // Extract sortable items
152
+ const items = Array.isArray(internalValue) ? internalValue.map(extractValueId) : [];
153
+ return /*#__PURE__*/React.createElement(DndContext, {
154
+ sensors: sensors,
155
+ collisionDetection: closestCenter,
156
+ onDragEnd: handleDragEnd
157
+ }, /*#__PURE__*/React.createElement(SortableContext, {
158
+ items: items,
159
+ strategy: horizontalListSortingStrategy
160
+ }, /*#__PURE__*/React.createElement(Select, {
161
+ ...restProps,
162
+ mode: restProps.mode || 'multiple',
163
+ value: internalValue,
164
+ onChange: handleChange,
165
+ disabled: disabled,
166
+ prefixCls: customizePrefixCls,
167
+ tagRender: tagRender,
168
+ // Force disable maxTagCount & maxLines so all tags are rendered
169
+ maxTagCount: undefined,
170
+ maxLines: undefined
171
+ })));
172
+ };
173
+ export default SortableSelect;
@@ -1,125 +1,8 @@
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
- /** @deprecated Please use `classNames.popup.root` instead */
99
- popupClassName?: string;
100
- /** @deprecated Please use `classNames.popup.root` instead */
101
- dropdownClassName?: string;
102
- /** @deprecated Please use `styles.popup` instead */
103
- dropdownStyle?: React.CSSProperties;
104
- /** @deprecated Please use `popupRender` instead */
105
- dropdownRender?: SelectProps['popupRender'];
106
- /** @deprecated Please use `onOpenChange` instead */
107
- onDropdownVisibleChange?: SelectProps['onPopupVisibleChange'];
108
- /** @deprecated Please use `popupMatchSelectWidth` instead */
109
- dropdownMatchSelectWidth?: boolean | number;
110
- popupMatchSelectWidth?: boolean | number;
111
- styles?: SelectStylesType;
112
- classNames?: SelectClassNamesType;
113
- onOpenChange?: (visible: boolean) => void;
114
- }
115
- declare const Select: (<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType>(props: React.PropsWithChildren<SelectProps<ValueType, OptionType>> & React.RefAttributes<BaseSelectRef>) => React.ReactElement) & {
116
- displayName?: string;
117
- SECRET_COMBOBOX_MODE_DO_NOT_USE: string;
118
- /** @deprecated Please use `options` instead. */
119
- Option: typeof Option;
120
- /** @deprecated Please use `options` instead. */
121
- OptGroup: typeof OptGroup;
122
- _InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
123
- };
124
- declare const PurePanel: (props: import("../_util/type").AnyObject) => React.JSX.Element;
1
+ import Select from './Select';
2
+ import SortableSelect from './SortableSelect';
3
+ import SingleDisplaySelect from './SingleDisplaySelect';
4
+ export type { SortableSelectProps } from './SortableSelect';
5
+ export type { SingleDisplaySelectProps } from './SingleDisplaySelect';
6
+ export * from './Select';
7
+ export { SortableSelect, SingleDisplaySelect };
125
8
  export default Select;