x-ui-design 0.5.25 → 0.5.27

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.
@@ -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: string;
64
- onClose: (e: MouseEvent<HTMLSpanElement> & TargetProps) => void;
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(),
@@ -3439,8 +3443,8 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
3439
3443
  return;
3440
3444
  }
3441
3445
  const updatedSelected = [...selected, newOptionValue];
3442
- onSelect?.(updatedSelected);
3443
3446
  onChange?.(updatedSelected);
3447
+ onSelect?.(updatedSelected);
3444
3448
  const input = selectRef.current?.querySelector('input');
3445
3449
  if (input) {
3446
3450
  input.value = '';
@@ -3464,16 +3468,16 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
3464
3468
  } else {
3465
3469
  setIsOpen(defaultOpen);
3466
3470
  setSelected(optionValue);
3467
- onSelect?.(optionValue, option);
3468
3471
  onChange?.(optionValue, option);
3472
+ onSelect?.(optionValue, option);
3469
3473
  }
3470
3474
  handleClearInputValue();
3471
3475
  };
3472
3476
  const handleClear = () => {
3473
3477
  const value = hasMode ? [] : '';
3474
3478
  setSelected(value);
3475
- onSelect?.('');
3476
3479
  onChange?.('');
3480
+ onSelect?.('');
3477
3481
  onClear?.();
3478
3482
  handleClearInputValue();
3479
3483
  };
@@ -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('.select-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 + 4; // 4px is the margin-right
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, selected.length ? selected.map((tag, index) => tagRender ? /*#__PURE__*/React.createElement("div", {
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,8 @@ 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 // Ref to the search input
3753
+ ,
3710
3754
  onClick: e => {
3711
3755
  if (disabled) {
3712
3756
  e.preventDefault();