x-ui-design 0.5.26 → 0.5.28
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/esm/types/components/Select/Select.d.ts +1 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/types/select.d.ts +3 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +45 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +45 -2
- package/dist/index.js.map +1 -1
- package/lib/components/Select/Select.tsx +101 -37
- package/lib/components/Select/Tag/Tag.tsx +1 -1
- package/lib/types/select.ts +3 -2
- package/package.json +1 -1
- package/src/app/page.tsx +36 -33
|
@@ -47,6 +47,7 @@ declare const Select: React.ForwardRefExoticComponent<import("../../types").Defa
|
|
|
47
47
|
feedbackIcons?: boolean;
|
|
48
48
|
placement?: "bottomLeft" | "bottomRight" | "topLeft" | "topRight";
|
|
49
49
|
removeIcon?: ReactNode;
|
|
50
|
+
maxTagCount?: number | "responsive";
|
|
50
51
|
} & React.RefAttributes<HTMLDivElement>> & {
|
|
51
52
|
Option: React.FC<import("../../types/select").OptionProps>;
|
|
52
53
|
};
|
|
@@ -150,6 +150,7 @@ declare const Select: import("react").ComponentType<import("@/types").DefaultPro
|
|
|
150
150
|
feedbackIcons?: boolean;
|
|
151
151
|
placement?: "bottomLeft" | "bottomRight" | "topLeft" | "topRight";
|
|
152
152
|
removeIcon?: import("react").ReactNode;
|
|
153
|
+
maxTagCount?: number | "responsive";
|
|
153
154
|
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
154
155
|
declare const Option: import("react").ComponentType<import("@/types/select").OptionProps>;
|
|
155
156
|
declare const Tag: import("react").ComponentType<import("@/types/select").CustomTagProps>;
|
|
@@ -46,6 +46,7 @@ export type SelectProps = DefaultProps & {
|
|
|
46
46
|
feedbackIcons?: boolean;
|
|
47
47
|
placement?: 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight';
|
|
48
48
|
removeIcon?: ReactNode;
|
|
49
|
+
maxTagCount?: number | 'responsive';
|
|
49
50
|
};
|
|
50
51
|
export interface OptionType {
|
|
51
52
|
value: RuleType;
|
|
@@ -60,8 +61,8 @@ export interface OptionType {
|
|
|
60
61
|
}
|
|
61
62
|
export type CustomTagProps = DefaultProps & {
|
|
62
63
|
label?: ReactNode;
|
|
63
|
-
value
|
|
64
|
-
onClose
|
|
64
|
+
value?: string;
|
|
65
|
+
onClose?: (e: MouseEvent<HTMLSpanElement> & TargetProps) => void;
|
|
65
66
|
onMouseDown?: MouseEventHandler | undefined;
|
|
66
67
|
onLoadCapture?: ReactEventHandler | undefined;
|
|
67
68
|
closable?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -252,6 +252,7 @@ declare const Select: react.ComponentType<__types.DefaultProps & {
|
|
|
252
252
|
feedbackIcons?: boolean;
|
|
253
253
|
placement?: "bottomLeft" | "bottomRight" | "topLeft" | "topRight";
|
|
254
254
|
removeIcon?: react.ReactNode;
|
|
255
|
+
maxTagCount?: number | "responsive";
|
|
255
256
|
} & react.RefAttributes<HTMLDivElement>>;
|
|
256
257
|
declare const Option: react.ComponentType<__types_select.OptionProps>;
|
|
257
258
|
declare const Tag: react.ComponentType<__types_select.CustomTagProps>;
|
package/dist/index.esm.js
CHANGED
|
@@ -3194,7 +3194,7 @@ const Tag = ({
|
|
|
3194
3194
|
e.preventDefault();
|
|
3195
3195
|
e.stopPropagation();
|
|
3196
3196
|
e.target.value = value;
|
|
3197
|
-
onClose(e);
|
|
3197
|
+
onClose?.(e);
|
|
3198
3198
|
};
|
|
3199
3199
|
return /*#__PURE__*/React.createElement("div", {
|
|
3200
3200
|
style: {
|
|
@@ -3272,6 +3272,7 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3272
3272
|
feedbackIcons,
|
|
3273
3273
|
placement = 'bottomLeft',
|
|
3274
3274
|
removeIcon,
|
|
3275
|
+
maxTagCount,
|
|
3275
3276
|
onSearch,
|
|
3276
3277
|
onSelect,
|
|
3277
3278
|
onDeselect,
|
|
@@ -3296,6 +3297,9 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3296
3297
|
const [isOpenChecker, setIsOpenChecker] = useState(isOpen);
|
|
3297
3298
|
const [searchQuery, setSearchQuery] = useState(searchValue || '');
|
|
3298
3299
|
const [dropdownPosition, setDropdownPosition] = useState({});
|
|
3300
|
+
const tagContainerRef = useRef(null);
|
|
3301
|
+
const searchInputRef = useRef(null);
|
|
3302
|
+
const [responsiveTagCount, setResponsiveTagCount] = useState(null);
|
|
3299
3303
|
const [selected, setSelected] = useState(hasMode ? checkModeInitialValue : initialValue);
|
|
3300
3304
|
useImperativeHandle(ref, () => ({
|
|
3301
3305
|
focus: () => selectRef.current?.focus(),
|
|
@@ -3653,6 +3657,40 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3653
3657
|
const option = extractedOptions.find(e => e.value === selected || e.label === selected || e.children === selected) || selected;
|
|
3654
3658
|
return option?.children || option?.label || option?.value || null;
|
|
3655
3659
|
})() || selected || null;
|
|
3660
|
+
const hasMaxTagCount = hasMode && (typeof maxTagCount === 'number' || maxTagCount === 'responsive');
|
|
3661
|
+
const displayTagCount = maxTagCount === 'responsive' ? responsiveTagCount : maxTagCount;
|
|
3662
|
+
const selectedTags = hasMode ? selected : [];
|
|
3663
|
+
const tagsToDisplay = hasMaxTagCount ? selectedTags.slice(0, displayTagCount || selectedTags.length) : selectedTags;
|
|
3664
|
+
const overflowCount = hasMaxTagCount ? selectedTags.length - (displayTagCount || selectedTags.length) : 0;
|
|
3665
|
+
useEffect(() => {
|
|
3666
|
+
if (maxTagCount === 'responsive' && tagContainerRef.current) {
|
|
3667
|
+
const calculateTagsToDisplay = () => {
|
|
3668
|
+
const container = tagContainerRef.current;
|
|
3669
|
+
const tags = Array.from(container?.querySelectorAll(`.${prefixCls}-tag`) || []);
|
|
3670
|
+
const containerWidth = container?.clientWidth || 0;
|
|
3671
|
+
let currentWidth = 0;
|
|
3672
|
+
let count = 0;
|
|
3673
|
+
for (let i = 0; i < tags.length; i++) {
|
|
3674
|
+
const tag = tags[i];
|
|
3675
|
+
currentWidth += tag.offsetWidth + 32;
|
|
3676
|
+
if (currentWidth < containerWidth) {
|
|
3677
|
+
count++;
|
|
3678
|
+
} else {
|
|
3679
|
+
break;
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
setResponsiveTagCount(count);
|
|
3683
|
+
};
|
|
3684
|
+
const observer = new ResizeObserver(() => {
|
|
3685
|
+
calculateTagsToDisplay();
|
|
3686
|
+
});
|
|
3687
|
+
observer.observe(tagContainerRef.current);
|
|
3688
|
+
calculateTagsToDisplay();
|
|
3689
|
+
return () => {
|
|
3690
|
+
observer.disconnect();
|
|
3691
|
+
};
|
|
3692
|
+
}
|
|
3693
|
+
}, [maxTagCount, selected, tagContainerRef]);
|
|
3656
3694
|
return /*#__PURE__*/React.createElement("div", {
|
|
3657
3695
|
id: id,
|
|
3658
3696
|
ref: selectRef,
|
|
@@ -3672,6 +3710,7 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3672
3710
|
onMouseLeave: handleMouseLeave,
|
|
3673
3711
|
className: `${prefixCls}-trigger`
|
|
3674
3712
|
}, showSearch || hasMode ? /*#__PURE__*/React.createElement("div", {
|
|
3713
|
+
ref: tagContainerRef,
|
|
3675
3714
|
style: {
|
|
3676
3715
|
...style,
|
|
3677
3716
|
...(isOpen ? {
|
|
@@ -3681,7 +3720,7 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3681
3720
|
minWidth: `${searchInputWidth}px`
|
|
3682
3721
|
},
|
|
3683
3722
|
className: `${prefixCls}-tag-container`
|
|
3684
|
-
}, hasMode ? /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
3723
|
+
}, hasMode ? /*#__PURE__*/React.createElement(React.Fragment, null, selectedTags.length ? /*#__PURE__*/React.createElement(React.Fragment, null, tagsToDisplay.map((tag, index) => tagRender ? /*#__PURE__*/React.createElement("div", {
|
|
3685
3724
|
key: `${index}_${tag}`
|
|
3686
3725
|
}, tagRender?.({
|
|
3687
3726
|
label: (() => {
|
|
@@ -3700,6 +3739,9 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3700
3739
|
})() || tag || null,
|
|
3701
3740
|
onClose: handleRemoveTag,
|
|
3702
3741
|
key: `${index}_${tag}`
|
|
3742
|
+
})), overflowCount > 0 && /*#__PURE__*/React.createElement(Tag, {
|
|
3743
|
+
label: `+${overflowCount}`,
|
|
3744
|
+
className: `${prefixCls}-tag-overflow`
|
|
3703
3745
|
})) : /*#__PURE__*/React.createElement("span", {
|
|
3704
3746
|
style: {
|
|
3705
3747
|
opacity: 0.5
|
|
@@ -3707,6 +3749,7 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3707
3749
|
}, searchFocused ? '' : placeholder)) : null, isOpen ? /*#__PURE__*/React.createElement("div", {
|
|
3708
3750
|
className: `${prefixCls}-tag`
|
|
3709
3751
|
}, /*#__PURE__*/React.createElement("div", _extends({
|
|
3752
|
+
ref: searchInputRef,
|
|
3710
3753
|
onClick: e => {
|
|
3711
3754
|
if (disabled) {
|
|
3712
3755
|
e.preventDefault();
|