x-ui-design 0.6.51 → 0.6.52

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,10 +1,8 @@
1
- import React, { ReactElement } from 'react';
1
+ import { ReactElement } from 'react';
2
2
  import { SelectProps } from '../../types/select';
3
3
  import './style.css';
4
- declare const _default: React.MemoExoticComponent<{
4
+ declare const Select: {
5
5
  ({ prefixCls, id, searchValue, autoClearSearchValue, filterOption, optionFilterProp, children, options, listHeight, menuItemSelectedIcon, mode, value, defaultValue, maxCount, disabled, loading, placeholder, allowClear, filterable, defaultOpen, size, error, dropdownClassName, className, suffixIcon, searchIcon, style, showSearch, open, closeFromParent, showArrow, notFoundContent, noStyle, feedbackIcons, placement, removeIcon, maxTagCount, onSearch, onSelect, onDeselect, onClear, onChange, onClose, tagRender, getPopupContainer, dropdownRender, onDropdownVisibleChange, ref }: SelectProps): ReactElement;
6
6
  displayName: string;
7
- } & {
8
- Option: React.FC<import("../../types/select").OptionProps>;
9
- }>;
10
- export default _default;
7
+ };
8
+ export default Select;
@@ -14,56 +14,7 @@ declare const Textarea: import("react").ComponentType<import("@/types/input").Te
14
14
  declare const Radio: import("react").ComponentType<import("@/types/radio").RadioProps>;
15
15
  declare const RadioButton: import("react").ComponentType<import("@/types/radio").RadioButtonProps>;
16
16
  declare const RadioGroup: import("react").ComponentType<import("@/types/radio").RadioGroupProps>;
17
- declare const Select: import("react").ComponentType<import("@/types").DefaultProps & {
18
- id?: string;
19
- searchValue?: string;
20
- onSearch?: (value: string) => void;
21
- autoClearSearchValue?: boolean;
22
- onSelect?: (value: import("@/types").RuleTypes, option?: import("@/types/select").OptionType) => void;
23
- onDeselect?: (value: string, option?: import("@/types/select").OptionType) => void;
24
- filterOption?: boolean | ((input: string, option: import("@/types/select").OptionType) => boolean);
25
- optionFilterProp?: string;
26
- options?: import("@/types/select").OptionType[];
27
- children?: import("react").ReactNode;
28
- defaultActiveFirstOption?: boolean;
29
- listHeight?: number;
30
- menuItemSelectedIcon?: import("react").ReactNode;
31
- mode?: "default" | "multiple" | "tags";
32
- value?: import("@/types").RuleTypes;
33
- defaultValue?: import("@/types").RuleTypes;
34
- maxCount?: number;
35
- onChange?: (e: import("@/types").RuleTypes, option?: import("@/types/select").OptionType) => void;
36
- onClose?: () => void;
37
- disabled?: boolean;
38
- loading?: boolean;
39
- placeholder?: string;
40
- allowClear?: boolean;
41
- filterable?: boolean;
42
- defaultOpen?: boolean;
43
- size?: "small" | "middle" | "large";
44
- onClear?: () => void;
45
- error?: boolean;
46
- showSearch?: boolean;
47
- tagRender?: ((props: import("@/types/select").CustomTagProps) => import("react").ReactElement) | undefined;
48
- maxTagPlaceholder?: import("react").ReactNode | ((omittedValues: import("@/types/select").DisplayValueType[]) => import("react").ReactNode);
49
- dropdownClassName?: string;
50
- showArrow?: boolean;
51
- onBlur?: import("react").FocusEventHandler<HTMLElement> | undefined;
52
- onDropdownVisibleChange?: ((open: boolean, selected: import("@/types").RuleType) => void) | undefined;
53
- showAction?: ("click" | "focus")[] | undefined;
54
- suffixIcon?: import("react").ReactNode;
55
- searchIcon?: import("react").ReactNode;
56
- open?: boolean;
57
- notFoundContent?: import("react").ReactNode;
58
- getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
59
- dropdownRender?: (menu: import("react").ReactNode) => import("react").ReactNode;
60
- feedbackIcons?: boolean;
61
- placement?: "bottomLeft" | "bottomRight" | "topLeft" | "topRight";
62
- removeIcon?: import("react").ReactNode;
63
- maxTagCount?: number | "responsive";
64
- ref?: import("react").ForwardedRef<HTMLDivElement>;
65
- closeFromParent?: boolean;
66
- }>;
17
+ declare const Select: import("react").ComponentType<import("@/types/select").SelectProps>;
67
18
  declare const Option: import("react").ComponentType<import("@/types/select").OptionProps>;
68
19
  declare const Tag: import("react").ComponentType<import("@/types/select").CustomTagProps>;
69
20
  declare const Skeleton: import("react").ComponentType<import("./types/skeleton").SkeletonProps>;
package/dist/index.d.ts CHANGED
@@ -2,8 +2,6 @@ import * as react from 'react';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
3
  import * as __types_select from '@/types/select';
4
4
  export { CustomTagProps, DisplayValueType, OptionProps, OptionType, SelectProps, TagProps } from '@/types/select';
5
- import * as __types from '@/types';
6
- export { DefaultProps, MouseEventHandlerSelect, RuleType, RuleTypes, SyntheticBaseEvent, TargetProps } from '@/types';
7
5
  import * as __types_radio from '@/types/radio';
8
6
  export { RadioButtonProps, RadioGroupProps, RadioProps } from '@/types/radio';
9
7
  import * as __types_input from '@/types/input';
@@ -21,6 +19,7 @@ export { BaseButtonProps, ButtonProps, ButtonType } from '@/types/button';
21
19
  export { ArrowIcon, CalendarIcon, CheckIcon, ClearIcon, DateDistanceIcon, ErrorIcon, LoadingIcon, SearchIcon, SpinerIcon, StampleIcon, SuccessIcon, TimeIcon, TrashIcon } from '@/components/Icons';
22
20
  export { useForm } from '@/hooks/useForm';
23
21
  export { useWatch } from '@/hooks/useWatch';
22
+ export { DefaultProps, MouseEventHandlerSelect, RuleType, RuleTypes, SyntheticBaseEvent, TargetProps } from '@/types';
24
23
  export { FormContext } from '@/components/Form/Form';
25
24
  export { clsx, createArray, parseValue } from '@/helpers';
26
25
  export { flattenChildren } from '@/helpers/flatten';
@@ -118,56 +117,7 @@ declare const Textarea: react.ComponentType<__types_input.TextareaProps>;
118
117
  declare const Radio: react.ComponentType<__types_radio.RadioProps>;
119
118
  declare const RadioButton: react.ComponentType<__types_radio.RadioButtonProps>;
120
119
  declare const RadioGroup: react.ComponentType<__types_radio.RadioGroupProps>;
121
- declare const Select: react.ComponentType<__types.DefaultProps & {
122
- id?: string;
123
- searchValue?: string;
124
- onSearch?: (value: string) => void;
125
- autoClearSearchValue?: boolean;
126
- onSelect?: (value: __types.RuleTypes, option?: __types_select.OptionType) => void;
127
- onDeselect?: (value: string, option?: __types_select.OptionType) => void;
128
- filterOption?: boolean | ((input: string, option: __types_select.OptionType) => boolean);
129
- optionFilterProp?: string;
130
- options?: __types_select.OptionType[];
131
- children?: react.ReactNode;
132
- defaultActiveFirstOption?: boolean;
133
- listHeight?: number;
134
- menuItemSelectedIcon?: react.ReactNode;
135
- mode?: "default" | "multiple" | "tags";
136
- value?: __types.RuleTypes;
137
- defaultValue?: __types.RuleTypes;
138
- maxCount?: number;
139
- onChange?: (e: __types.RuleTypes, option?: __types_select.OptionType) => void;
140
- onClose?: () => void;
141
- disabled?: boolean;
142
- loading?: boolean;
143
- placeholder?: string;
144
- allowClear?: boolean;
145
- filterable?: boolean;
146
- defaultOpen?: boolean;
147
- size?: "small" | "middle" | "large";
148
- onClear?: () => void;
149
- error?: boolean;
150
- showSearch?: boolean;
151
- tagRender?: ((props: __types_select.CustomTagProps) => react.ReactElement) | undefined;
152
- maxTagPlaceholder?: react.ReactNode | ((omittedValues: __types_select.DisplayValueType[]) => react.ReactNode);
153
- dropdownClassName?: string;
154
- showArrow?: boolean;
155
- onBlur?: react.FocusEventHandler<HTMLElement> | undefined;
156
- onDropdownVisibleChange?: ((open: boolean, selected: __types.RuleType) => void) | undefined;
157
- showAction?: ("click" | "focus")[] | undefined;
158
- suffixIcon?: react.ReactNode;
159
- searchIcon?: react.ReactNode;
160
- open?: boolean;
161
- notFoundContent?: react.ReactNode;
162
- getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
163
- dropdownRender?: (menu: react.ReactNode) => react.ReactNode;
164
- feedbackIcons?: boolean;
165
- placement?: "bottomLeft" | "bottomRight" | "topLeft" | "topRight";
166
- removeIcon?: react.ReactNode;
167
- maxTagCount?: number | "responsive";
168
- ref?: react.ForwardedRef<HTMLDivElement>;
169
- closeFromParent?: boolean;
170
- }>;
120
+ declare const Select: react.ComponentType<__types_select.SelectProps>;
171
121
  declare const Option: react.ComponentType<__types_select.OptionProps>;
172
122
  declare const Tag: react.ComponentType<__types_select.CustomTagProps>;
173
123
  declare const Skeleton: react.ComponentType<SkeletonProps>;
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import require$$1 from 'react/jsx-runtime';
2
- import React, { useRef, useState, Children, isValidElement, Fragment, Suspense, useEffect, useContext, useMemo, createContext, useImperativeHandle, memo, useCallback, useLayoutEffect } from 'react';
2
+ import React, { useRef, useState, Children, isValidElement, Fragment, Suspense, useEffect, useContext, useMemo, useCallback, createContext, useImperativeHandle, useLayoutEffect } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
4
  import ReactDOMServer from 'react-dom/server';
5
5
 
@@ -877,6 +877,7 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
877
877
  formRef.current[stepRef.current] = {};
878
878
  }
879
879
  }
880
+ const formInstanceRef = useRef(null);
880
881
  const formInstance = {
881
882
  submit,
882
883
  setFields,
@@ -910,7 +911,12 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
910
911
  setOnValuesChange,
911
912
  changeStep
912
913
  };
913
- return formInstance;
914
+ if (formInstanceRef.current) {
915
+ return formInstanceRef.current;
916
+ } else {
917
+ formInstanceRef.current = formInstance;
918
+ return formInstanceRef.current;
919
+ }
914
920
  };
915
921
 
916
922
  function _extends() {
@@ -1069,6 +1075,7 @@ const FormItem$1 = ({
1069
1075
  }
1070
1076
  }, [dependencies, name]);
1071
1077
  const isRequired = useMemo(() => rules.some(rule => rule.required), [rules]);
1078
+ console.log(name);
1072
1079
  return /*#__PURE__*/React.createElement("div", {
1073
1080
  style: style,
1074
1081
  "data-instance": name,
@@ -1177,6 +1184,10 @@ const FormItemChildComponent = ({
1177
1184
  if (isWrapper) {
1178
1185
  return /*#__PURE__*/React.createElement(child.type, childProps, Children.map(flattenChildren(childProps.children), injectPropsIntoFinalLeaf));
1179
1186
  }
1187
+ const _onChange = useCallback((e, option) => {
1188
+ handleChange(e);
1189
+ childProps?.onChange?.(e, option);
1190
+ }, [handleChange, childProps?.onChange]);
1180
1191
  if (childProps?.__injected) {
1181
1192
  return child;
1182
1193
  }
@@ -1187,10 +1198,7 @@ const FormItemChildComponent = ({
1187
1198
  }, child.props, {
1188
1199
  name: name,
1189
1200
  child: child,
1190
- onChange: (e, option) => {
1191
- handleChange(e);
1192
- childProps?.onChange?.(e, option);
1193
- },
1201
+ onChange: _onChange,
1194
1202
  key: `${name}_${wasNormalize}`,
1195
1203
  value: fieldValue ?? props.value
1196
1204
  }, 'dangerouslySetInnerHTML' in childProps ? {} : {
@@ -1233,12 +1241,12 @@ const Form$1 = ({
1233
1241
  });
1234
1242
  const formRef = useRef(null);
1235
1243
  const formInstance = useMemo(() => form || internalForm, [form, internalForm]);
1236
- const handleSubmit = async e => {
1244
+ const childrenList = useMemo(() => flattenChildren(children), [children]);
1245
+ const handleSubmit = useCallback(async e => {
1237
1246
  e.preventDefault();
1238
1247
  e.stopPropagation();
1239
1248
  await formInstance.submit();
1240
- };
1241
- const childrenList = useMemo(() => flattenChildren(children), [children]);
1249
+ }, []);
1242
1250
  useEffect(() => {
1243
1251
  if (onFinish) {
1244
1252
  formInstance.setOnFinish?.(onFinish);
@@ -1256,7 +1264,7 @@ const Form$1 = ({
1256
1264
  formInstance.setScrollToFirstError(scrollToFirstError);
1257
1265
  }
1258
1266
  }, [formInstance, onFieldsChange, onValuesChange, onFinishFailed, onFinish, scrollToFirstError]);
1259
- const injectPropsIntoFinalLeaf = child => {
1267
+ const injectPropsIntoFinalLeaf = useCallback(child => {
1260
1268
  if (! /*#__PURE__*/isValidElement(child)) {
1261
1269
  return child;
1262
1270
  }
@@ -1273,7 +1281,7 @@ const Form$1 = ({
1273
1281
  size: childProps.size || rest.size,
1274
1282
  layout: childProps.layout || layout
1275
1283
  }));
1276
- };
1284
+ }, [rest.size, layout]);
1277
1285
  return /*#__PURE__*/React.createElement(FormContext.Provider, {
1278
1286
  value: formInstance
1279
1287
  }, /*#__PURE__*/React.createElement("form", {
@@ -1281,7 +1289,7 @@ const Form$1 = ({
1281
1289
  ref: formRef,
1282
1290
  onSubmit: handleSubmit,
1283
1291
  className: `${prefixCls} ${className}`
1284
- }, Children.map(childrenList, child => injectPropsIntoFinalLeaf(child))));
1292
+ }, Children.map(childrenList, injectPropsIntoFinalLeaf)));
1285
1293
  };
1286
1294
  Form$1.Item = FormItem$1;
1287
1295
 
@@ -1361,7 +1369,7 @@ const RadioButton$1 = dynamic$1(() => Promise.resolve().then(function () { retur
1361
1369
  const RadioGroup$1 = dynamic$1(() => Promise.resolve().then(function () { return Group; }), {
1362
1370
  ssr: false
1363
1371
  });
1364
- const Select$3 = dynamic$1(() => Promise.resolve().then(function () { return Select$2; }), {
1372
+ const Select$2 = dynamic$1(() => Promise.resolve().then(function () { return Select$1; }), {
1365
1373
  ssr: false
1366
1374
  });
1367
1375
  const Option$2 = dynamic$1(() => Promise.resolve().then(function () { return Option$1; }), {
@@ -3364,7 +3372,7 @@ function getTextFromNode(node) {
3364
3372
  }
3365
3373
  return '';
3366
3374
  }
3367
- const SelectComponent = ({
3375
+ const Select = ({
3368
3376
  prefixCls = prefixClsSelect,
3369
3377
  id,
3370
3378
  searchValue = '',
@@ -3443,8 +3451,8 @@ const SelectComponent = ({
3443
3451
  selectRef.current?.scrollTo(...args),
3444
3452
  nativeElement: selectRef.current
3445
3453
  }), []);
3446
- const handleMouseEnter = () => !disabled && selected?.length && setIsHover(true);
3447
- const handleMouseLeave = () => !disabled && setIsHover(false);
3454
+ const handleMouseEnter = useCallback(() => !disabled && selected?.length && setIsHover(true), [disabled, selected?.length]);
3455
+ const handleMouseLeave = useCallback(() => !disabled && setIsHover(false), [disabled]);
3448
3456
  const handleClearInputValue = useCallback(() => {
3449
3457
  if (!autoClearSearchValue) {
3450
3458
  return;
@@ -3461,7 +3469,7 @@ const SelectComponent = ({
3461
3469
  useEffect(() => {
3462
3470
  setSelected(hasMode ? checkModeInitialValue : initialValue);
3463
3471
  }, [checkModeInitialValue, hasMode, initialValue]);
3464
- const handleClickOutside = event => {
3472
+ const handleClickOutside = useCallback(event => {
3465
3473
  if (!selectRef.current) return;
3466
3474
  const dropdown = document.querySelector(`.${prefixCls}-dropdown`);
3467
3475
  const clickedInside = selectRef.current.contains(event?.target) || dropdown && dropdown.contains(event?.target);
@@ -3472,7 +3480,7 @@ const SelectComponent = ({
3472
3480
  onClose?.();
3473
3481
  onDropdownVisibleChange?.(false, selected);
3474
3482
  }
3475
- };
3483
+ }, [selectRef.current, prefixCls, selected]);
3476
3484
  useEffect(() => {
3477
3485
  document.addEventListener('mousedown', handleClickOutside);
3478
3486
  return () => {
@@ -3556,7 +3564,7 @@ const SelectComponent = ({
3556
3564
  useEffect(() => {
3557
3565
  updateDropdownPosition(true);
3558
3566
  }, [searchQuery.length]);
3559
- const getScrollParents = element => {
3567
+ const getScrollParents = useCallback(element => {
3560
3568
  const parents = [];
3561
3569
  let current = element.parentElement;
3562
3570
  while (current) {
@@ -3566,7 +3574,7 @@ const SelectComponent = ({
3566
3574
  current = current.parentElement;
3567
3575
  }
3568
3576
  return parents;
3569
- };
3577
+ }, []);
3570
3578
  const handleSearch = e => {
3571
3579
  setSearchQuery(e.target.value);
3572
3580
  onSearch?.(e.target.value);
@@ -3695,7 +3703,7 @@ const SelectComponent = ({
3695
3703
  }, []);
3696
3704
  const extractedOptions = useMemo(() => {
3697
3705
  return children ? extractOptions(children) : Array.isArray(options) ? options : [];
3698
- }, [children, children]);
3706
+ }, [children, options]);
3699
3707
  const triggerNode = useMemo(() => {
3700
3708
  return selectRef.current?.querySelector(`.${prefixCls}-trigger`);
3701
3709
  }, [prefixCls]);
@@ -3934,15 +3942,11 @@ const SelectComponent = ({
3934
3942
  }, menuItemSelectedIcon === true ? /*#__PURE__*/React.createElement(CheckIcon, null) : menuItemSelectedIcon));
3935
3943
  }) : !asTag ? notFoundContent || /*#__PURE__*/React.createElement(EmptyContent, null) : null)))));
3936
3944
  };
3937
- SelectComponent.displayName = 'Select';
3938
- const Select = Object.assign(SelectComponent, {
3939
- Option
3940
- });
3941
- var Select$1 = /*#__PURE__*/memo(Select);
3945
+ Select.displayName = 'Select';
3942
3946
 
3943
- var Select$2 = /*#__PURE__*/Object.freeze({
3947
+ var Select$1 = /*#__PURE__*/Object.freeze({
3944
3948
  __proto__: null,
3945
- default: Select$1
3949
+ default: Select
3946
3950
  });
3947
3951
 
3948
3952
  var css_248z$4 = "@keyframes xUi-skeleton-loading{0%{background-position:100% 50%}to{background-position:0 50%}}.xUi-skeleton-element{display:inline-block!important;width:auto!important}.xUi-skeleton-button{background:hsla(0,0%,75%,.2);border-radius:4px;display:inline-block;height:32px;line-height:32px;min-width:64px;vertical-align:top;width:64px}.xUi-skeleton-button-sm{height:24px;line-height:24px;min-width:48px;width:48px}.xUi-skeleton-button-lg{height:44px;line-height:44px;min-width:80px;width:80px}.xUi-skeleton-active .xUi-skeleton-button{animation:xUi-skeleton-loading 1.4s ease infinite;background:linear-gradient(90deg,hsla(0,0%,75%,.2) 25%,hsla(0,0%,51%,.24) 37%,hsla(0,0%,75%,.2) 63%);background-size:400% 100%}";
@@ -4166,5 +4170,5 @@ var Skeleton$1 = /*#__PURE__*/Object.freeze({
4166
4170
  default: Skeleton
4167
4171
  });
4168
4172
 
4169
- export { ArrowIcon, Button$3 as Button, CalendarIcon, CheckIcon, Checkbox$2 as Checkbox, ClearIcon, DateDistanceIcon, DatePicker$2 as DatePicker, Empty$1 as Empty, ErrorIcon, Form, FormContext, FormItem, Input$3 as Input, LoadingIcon, Option$2 as Option, Radio$2 as Radio, RadioButton$1 as RadioButton, RadioGroup$1 as RadioGroup, RangePicker$2 as RangePicker, SearchIcon, Select$3 as Select, Skeleton$2 as Skeleton, SkeletonAvatar$1 as SkeletonAvatar, SkeletonButton$1 as SkeletonButton, SkeletonImage$1 as SkeletonImage, SkeletonInput$1 as SkeletonInput, SpinerIcon, StampleIcon, SuccessIcon, Switch$2 as Switch, Tag$2 as Tag, Textarea$2 as Textarea, TimeIcon, TimePicker$2 as TimePicker, TrashIcon, Upload$2 as Upload, clsx, createArray, flattenChildren, parseValue, useForm, useWatch };
4173
+ export { ArrowIcon, Button$3 as Button, CalendarIcon, CheckIcon, Checkbox$2 as Checkbox, ClearIcon, DateDistanceIcon, DatePicker$2 as DatePicker, Empty$1 as Empty, ErrorIcon, Form, FormContext, FormItem, Input$3 as Input, LoadingIcon, Option$2 as Option, Radio$2 as Radio, RadioButton$1 as RadioButton, RadioGroup$1 as RadioGroup, RangePicker$2 as RangePicker, SearchIcon, Select$2 as Select, Skeleton$2 as Skeleton, SkeletonAvatar$1 as SkeletonAvatar, SkeletonButton$1 as SkeletonButton, SkeletonImage$1 as SkeletonImage, SkeletonInput$1 as SkeletonInput, SpinerIcon, StampleIcon, SuccessIcon, Switch$2 as Switch, Tag$2 as Tag, Textarea$2 as Textarea, TimeIcon, TimePicker$2 as TimePicker, TrashIcon, Upload$2 as Upload, clsx, createArray, flattenChildren, parseValue, useForm, useWatch };
4170
4174
  //# sourceMappingURL=index.esm.js.map