x-ui-design 0.6.99 → 0.7.21

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.
@@ -83,7 +83,7 @@ const FormItem = ({
83
83
  if (initialValue && getFieldValue(name) === undefined) {
84
84
  setFieldValue(name, initialValue);
85
85
  }
86
- }, []);
86
+ }, [name]);
87
87
 
88
88
  useEffect(() => {
89
89
  if (name && dependencies.length > 0) {
@@ -107,7 +107,8 @@ const Select = ({
107
107
  dropdownRender,
108
108
  onDropdownVisibleChange,
109
109
  iconClick,
110
- ref
110
+ ref,
111
+ controlled
111
112
  }: SelectProps
112
113
  ): ReactElement => {
113
114
  const asTag = mode === 'tags';
@@ -396,19 +397,19 @@ const Select = ({
396
397
  ? (selected as string[]).filter(item => item !== optionValue)
397
398
  : [...selected, optionValue];
398
399
 
399
- setSelected(newSelection);
400
+ !controlled && setSelected(newSelection);
400
401
  onChange?.(newSelection, option);
401
402
 
402
403
  if (selected.includes(optionValue)) {
403
- onDeselect?.(optionValue, option);
404
+ !controlled && onDeselect?.(optionValue, option);
404
405
  } else {
405
- onSelect?.(optionValue, option);
406
+ !controlled && onSelect?.(optionValue, option);
406
407
  }
407
408
  } else {
408
409
  setIsOpen(defaultOpen);
409
- setSelected(optionValue);
410
+ !controlled && setSelected(optionValue);
410
411
  onChange?.(optionValue, option);
411
- onSelect?.(optionValue, option);
412
+ !controlled && onSelect?.(optionValue, option);
412
413
  }
413
414
 
414
415
  handleClearInputValue();
@@ -417,9 +418,9 @@ const Select = ({
417
418
  const handleClear = () => {
418
419
  const value = hasMode ? [] : '';
419
420
 
420
- setSelected(value);
421
+ !controlled && setSelected(value);
421
422
  onChange?.('');
422
- onSelect?.('');
423
+ !controlled && onSelect?.('');
423
424
  onClear?.();
424
425
 
425
426
  handleClearInputValue();
@@ -21,9 +21,9 @@ const useForm = (
21
21
  scrollToFirstError?: boolean,
22
22
  onFinish?: ((values: Record<string, RuleTypes>) => void) | undefined,
23
23
  onFinishFailed?: (errorInfo: {
24
- values: Record<string, RuleTypes>;
25
- errorFields: Pick<FieldError, 'errors' | 'name'>[];
26
- }) => void
24
+ values: Record<string, RuleTypes>;
25
+ errorFields: Pick<FieldError, 'errors' | 'name'>[];
26
+ }) => void
27
27
  ): FormInstance => {
28
28
  const touchedFieldsRef = useRef(new Set<string>());
29
29
  const rulesRef = useRef<Record<string, RuleObject[] | RuleRender>>({});
@@ -53,7 +53,7 @@ const useForm = (
53
53
  const fieldInstancesRef = useRef<Record<string, FieldInstancesRef | null>>({});
54
54
 
55
55
  const [isReseting, setIsReseting] = useState(false);
56
-
56
+
57
57
  const errorsRef = useRef<Record<string, string[]>>({});
58
58
  const errorSubscribers = useRef<
59
59
  Record<string, ((errors: string[]) => void)[]>
@@ -83,7 +83,7 @@ const useForm = (
83
83
 
84
84
  function getFieldsValue(nameList?: string[]) {
85
85
  const formData = getFormFields();
86
-
86
+
87
87
  if (!nameList) {
88
88
  return formData;
89
89
  }
@@ -111,7 +111,7 @@ const useForm = (
111
111
  name: string,
112
112
  value: RuleTypes,
113
113
  errors?: string[],
114
- reset: boolean | null | undefined = undefined,
114
+ reset: boolean | null | -1 | undefined = undefined,
115
115
  touch?: boolean
116
116
  ) {
117
117
  if (
@@ -132,7 +132,7 @@ const useForm = (
132
132
  return;
133
133
  }
134
134
  })
135
-
135
+
136
136
  if (!isFieldExist) {
137
137
  formRef.current[stepRef.current][name] = value;
138
138
  }
@@ -163,7 +163,15 @@ const useForm = (
163
163
  }
164
164
  });
165
165
  } else {
166
- errorsRef.current[name] = errors;
166
+ if (reset === -1) {
167
+ setTimeout(() => {
168
+ errorsRef.current[name] = errors;
169
+ notifyErrorSubscribers(name);
170
+ }, 0);
171
+ } else {
172
+ errorsRef.current[name] = errors;
173
+ notifyErrorSubscribers(name);
174
+ }
167
175
  }
168
176
  }
169
177
 
@@ -175,7 +183,12 @@ const useForm = (
175
183
 
176
184
  function setFields(fields: FieldData[]) {
177
185
  fields.forEach(({ name, value, errors }) =>
178
- setFieldValue(Array.isArray(name) ? name[0] : name, value, errors)
186
+ setFieldValue(
187
+ Array.isArray(name) ? name[0] : name,
188
+ value ?? getFieldValue(Array.isArray(name) ? name[0] : name),
189
+ errors,
190
+ -1
191
+ )
179
192
  );
180
193
  }
181
194
 
@@ -224,7 +237,7 @@ const useForm = (
224
237
  delete formRef.current[step][name];
225
238
  }
226
239
  })
227
-
240
+
228
241
  formRef.current[stepRef.current][name] = initialValues?.[name];
229
242
 
230
243
  if (Object.keys(existFields).length) {
@@ -307,7 +320,7 @@ const useForm = (
307
320
  }
308
321
  })
309
322
  );
310
-
323
+
311
324
  errorsRef.current[name] = fieldErrors
312
325
  warningsRef.current[name] = fieldWarnings;
313
326
 
@@ -65,7 +65,8 @@ export type SelectProps = DefaultProps & {
65
65
  removeIcon?: ReactNode;
66
66
  maxTagCount?: number | 'responsive',
67
67
  ref?: ForwardedRef<HTMLDivElement>,
68
- closeFromParent?: boolean
68
+ closeFromParent?: boolean;
69
+ controlled?: boolean
69
70
  };
70
71
 
71
72
  export interface OptionType {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-ui-design",
3
- "version": "0.6.99",
3
+ "version": "0.7.21",
4
4
  "license": "ISC",
5
5
  "author": "Gabriel Boyajyan",
6
6
  "main": "dist/index.js",
package/src/app/page.tsx CHANGED
@@ -1904,7 +1904,7 @@ export default function Home() {
1904
1904
  // }, []);
1905
1905
 
1906
1906
  const [aa, bb] = useState([new Date(), new Date()])
1907
- const [c, d] = useState(false)
1907
+ const [selected, setSelected] = useState('Armenia')
1908
1908
 
1909
1909
  useEffect(() => {
1910
1910
  setTimeout(() => {
@@ -1912,13 +1912,30 @@ export default function Home() {
1912
1912
  }, 3000);
1913
1913
  }, [])
1914
1914
 
1915
+ const disableDate = useCallback(
1916
+ (date: any) => {
1917
+ const startDate = aa[0];
1918
+ const endDate = aa[1];
1919
+ const dateToCheck = date;
1920
+
1921
+ console.log({
1922
+ endDate,
1923
+ startDate,
1924
+ dateToCheck
1925
+ });
1926
+
1927
+ if (dateToCheck >= startDate && dateToCheck <= endDate) {
1928
+ return false
1929
+ }
1930
+
1931
+ return true
1932
+ },
1933
+ [aa]
1934
+ );
1935
+
1915
1936
  return (
1916
1937
  <>
1917
- <button onClick={() => { d(!c) }}>aaaa</button>
1918
- <RangePicker size="middle" format={'YYYY-MM-DD'} value={aa} defaultValue={aa} />
1919
- <Switch checked={c} onChange={(ccc) => {
1920
- d(!c)
1921
- }} />
1938
+ <RangePicker size="middle" format={'YYYY-MM-DD'} value={aa} defaultValue={aa} disabledDate={disableDate} />
1922
1939
 
1923
1940
  <Form
1924
1941
  form={form}
@@ -1949,10 +1966,12 @@ export default function Home() {
1949
1966
  </RadioGroup>
1950
1967
  </Item>}
1951
1968
 
1952
- <Item rules={[{ required: true }]} initialValue={'Philippines'} name="country" label="Country">
1969
+ <Item rules={[{ required: true }]} name="country" label="Country">
1953
1970
  <Select
1954
1971
  showSearch
1955
1972
  iconClickClear
1973
+ value={selected}
1974
+ controlled
1956
1975
  // suffixIcon={<>clear</>}
1957
1976
  // style={{ width: 400 }}
1958
1977
  placeholder="Select..."