x-ui-design 0.2.91 → 0.2.93

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.
@@ -1,4 +1,4 @@
1
- import React, { ReactElement } from 'react';
1
+ import React, { ReactElement, ReactNode } from 'react';
2
2
  import { OptionType } from '../../types/select';
3
3
  import './style.css';
4
4
  declare const Select: React.ForwardRefExoticComponent<import("../../types").DefaultProps & {
@@ -11,10 +11,10 @@ declare const Select: React.ForwardRefExoticComponent<import("../../types").Defa
11
11
  filterOption?: boolean | ((input: string, option: OptionType) => boolean);
12
12
  optionFilterProp?: string;
13
13
  options?: OptionType[];
14
- children?: React.ReactNode;
14
+ children?: ReactNode;
15
15
  defaultActiveFirstOption?: boolean;
16
16
  listHeight?: number;
17
- menuItemSelectedIcon?: React.ReactNode;
17
+ menuItemSelectedIcon?: ReactNode;
18
18
  mode?: "default" | "multiple" | "tags";
19
19
  value?: import("../../types").RuleTypes;
20
20
  defaultValue?: import("../../types").RuleTypes;
@@ -31,20 +31,20 @@ declare const Select: React.ForwardRefExoticComponent<import("../../types").Defa
31
31
  error?: boolean;
32
32
  showSearch?: boolean;
33
33
  tagRender?: ((props: import("../../types/select").CustomTagProps) => ReactElement) | undefined;
34
- maxTagPlaceholder?: React.ReactNode | ((omittedValues: import("../../types/select").DisplayValueType[]) => React.ReactNode);
34
+ maxTagPlaceholder?: ReactNode | ((omittedValues: import("../../types/select").DisplayValueType[]) => ReactNode);
35
35
  dropdownClassName?: string;
36
36
  showArrow?: boolean;
37
37
  onBlur?: React.FocusEventHandler<HTMLElement> | undefined;
38
38
  onDropdownVisibleChange?: ((open: boolean) => void) | undefined;
39
39
  showAction?: ("click" | "focus")[] | undefined;
40
- suffixIcon?: React.ReactNode;
40
+ suffixIcon?: ReactNode;
41
41
  open?: boolean;
42
- notFoundContent?: React.ReactNode;
42
+ notFoundContent?: ReactNode;
43
43
  getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
44
- dropdownRender?: (menu: React.ReactNode) => React.ReactNode;
44
+ dropdownRender?: (menu: ReactNode) => ReactNode;
45
45
  feedbackIcons?: boolean;
46
46
  placement?: "bottomLeft" | "bottomRight" | "topLeft" | "topRight";
47
- removeIcon?: React.ReactNode;
47
+ removeIcon?: ReactNode;
48
48
  } & React.RefAttributes<HTMLDivElement>> & {
49
49
  Option: React.FC<import("../../types/select").OptionProps>;
50
50
  };
@@ -83,7 +83,7 @@ export interface FormItemChildComponentProps {
83
83
  export interface FormInstance {
84
84
  submit: () => Promise<Record<string, RuleTypes> | undefined>;
85
85
  setFields: (fields: FieldData[]) => void;
86
- resetFields: (nameList?: string[], showError?: boolean) => void;
86
+ resetFields: (nameList?: string[], showError?: boolean | null) => void;
87
87
  getFieldError: (name: string) => string[];
88
88
  registerField: (name: string, rules?: RuleObject[]) => void;
89
89
  setFieldValue: (name: string, value: RuleTypes) => void;
package/dist/index.esm.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import require$$1 from 'react/jsx-runtime';
2
2
  import React$1, { useRef, useState, useContext, useMemo, useEffect, Children, isValidElement, Fragment, createContext, forwardRef, useImperativeHandle, cloneElement, useCallback } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
+ import ReactDOMServer from 'react-dom/server';
4
5
 
5
6
  function getDefaultExportFromCjs (x) {
6
7
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -638,12 +639,18 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange) => {
638
639
  errors: err
639
640
  }));
640
641
  }
641
- function setFieldValue(name, value, errors, reset) {
642
- if (!reset && ([undefined, null].includes(value) || formRef.current[name] === value)) {
642
+ function setFieldValue(name, value, errors, reset = null) {
643
+ if (!reset && reset !== null && ([undefined, null].includes(value) || formRef.current[name] === value)) {
643
644
  return;
644
645
  }
645
646
  formRef.current[name] = value;
646
647
  touchedFieldsRef.current.add(name);
648
+ if (reset === null) {
649
+ setErrors({
650
+ [name]: []
651
+ });
652
+ return;
653
+ }
647
654
  if (!errors?.length) {
648
655
  validateField(name).then(() => {
649
656
  const allValues = getFieldsValue();
@@ -737,37 +744,23 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange) => {
737
744
  const results = await Promise.all(fieldsToValidate.map(name => validateField(name)));
738
745
  return results.every(valid => valid);
739
746
  }
740
- function resetFields(nameList, showError = false) {
747
+ function resetFields(nameList, showError = true) {
741
748
  if (nameList?.length) {
742
749
  nameList.forEach(name => {
743
750
  formRef.current[name] = initialValues[name];
744
751
  touchedFieldsRef.current.delete(name);
745
752
  delete warningsRef.current[name];
746
- if (showError) {
747
- setErrors(prev => ({
748
- ...prev,
749
- [name]: []
750
- }));
751
- setFieldValue(name, initialValues[name], undefined, true);
752
- } else {
753
- setFieldValue(name, initialValues[name], undefined, true);
754
- setErrors(prev => ({
755
- ...prev,
756
- [name]: []
757
- }));
758
- }
753
+ setErrors(prev => ({
754
+ ...prev,
755
+ [name]: []
756
+ }));
757
+ setFieldValue(name, initialValues[name], undefined, showError);
759
758
  });
760
759
  } else {
761
760
  touchedFieldsRef.current.clear();
762
761
  warningsRef.current = {};
763
762
  Object.keys(formRef.current).forEach(name => {
764
- setFieldValue(name, initialValues[name], undefined, true);
765
- if (!showError) {
766
- setErrors(prev => ({
767
- ...prev,
768
- [name]: []
769
- }));
770
- }
763
+ setFieldValue(name, initialValues[name], undefined, showError);
771
764
  });
772
765
  }
773
766
  formSubscribers.current.forEach(callback => callback(getFieldsValue()));
@@ -2929,6 +2922,16 @@ styleInject(css_248z$5);
2929
2922
  const LIST_HEIGHT = 200;
2930
2923
  const PADDING_PLACEMENT = 18;
2931
2924
  const PADDING_TAG_INPUT = 4;
2925
+ function getTextFromNode(node) {
2926
+ if (typeof node === 'string' || typeof node === 'number') {
2927
+ return node.toString();
2928
+ }
2929
+ if (/*#__PURE__*/React$1.isValidElement(node)) {
2930
+ const html = ReactDOMServer.renderToStaticMarkup(node);
2931
+ return html.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
2932
+ }
2933
+ return '';
2934
+ }
2932
2935
  const SelectComponent = /*#__PURE__*/forwardRef(({
2933
2936
  prefixCls = prefixClsSelect,
2934
2937
  id,
@@ -3146,10 +3149,10 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
3146
3149
  if (filterOption === false) {
3147
3150
  return true;
3148
3151
  }
3149
- const valueToCheck = `${['string', 'number'].includes(typeof option.children) ? option.children :
3150
3152
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3151
3153
  // @ts-expect-error
3152
- option[optionFilterProp] || option.value}`;
3154
+ const optionFilterPropValue = option[optionFilterProp];
3155
+ const valueToCheck = optionFilterProp && typeof optionFilterPropValue === 'string' ? String(optionFilterPropValue) : getTextFromNode(option.children) || String(option.value);
3153
3156
  return valueToCheck.toLowerCase().includes(searchQuery.toLowerCase());
3154
3157
  });
3155
3158
  const handleTriggerClick = () => {
@@ -3173,10 +3176,10 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
3173
3176
  children,
3174
3177
  className = '',
3175
3178
  ...props
3176
- }) => {
3179
+ }, index) => {
3177
3180
  const isSelected = hasMode ? selected.includes(props.value) : props.value === selected;
3178
3181
  return /*#__PURE__*/React$1.createElement(Option, _extends({
3179
- key: `${props.value}`
3182
+ key: `${props.value}_${index}`
3180
3183
  }, props, {
3181
3184
  selected: isSelected,
3182
3185
  className: clsx([className, {