@kanda-libs/ks-component-ts 0.2.266 → 0.2.267

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/app/src/App.tsx CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  ValidationItems,
12
12
  } from "@kanda-libs/ks-component-ts";
13
13
  import { StringIndexedObject } from "~/types";
14
- import { useState } from "react";
14
+ import { useEffect, useState } from "react";
15
15
  import { Button } from "@kanda-libs/ks-design-library";
16
16
 
17
17
  if (!(Window.prototype as StringIndexedObject).setImmediate) {
@@ -26,9 +26,14 @@ function App() {
26
26
  const form = useForm({
27
27
  mode: "onBlur",
28
28
  defaultValues: {
29
- range: "100000",
29
+ range1: "100000",
30
+ range2: "100000",
30
31
  },
31
32
  });
33
+
34
+ const { watch, setValue } = form;
35
+ const { range1, range2 } = watch();
36
+
32
37
  const onSubmit = (data: StringIndexedObject) => console.log({ data });
33
38
  const [query, setQuery] = useState("");
34
39
 
@@ -59,6 +64,11 @@ function App() {
59
64
 
60
65
  const [isLoading, setIsLoading] = useState<boolean>(false);
61
66
 
67
+ useEffect(() => {
68
+ const n = 200000 - parseInt(range1, 10);
69
+ setValue("range2", String(n));
70
+ }, [range1]);
71
+
62
72
  return (
63
73
  <div style={{ maxWidth: 500 }}>
64
74
  <SearchInput query={query} onSearch={setQuery} />
@@ -78,15 +88,20 @@ function App() {
78
88
  onSubmit={onSubmit}
79
89
  className="flex flex-col"
80
90
  >
81
- <Field.Validator validation={validation}>
82
- <Field.RangeInput
83
- name="range"
84
- isLoading={isLoading}
85
- min="0"
86
- max="1000000"
87
- formatter={formatter}
88
- />
89
- </Field.Validator>
91
+ <Field.RangeInput
92
+ name="range1"
93
+ isLoading={isLoading}
94
+ min="0"
95
+ max="200000"
96
+ formatter={formatter}
97
+ />
98
+ <Field.RangeInput
99
+ name="range2"
100
+ isLoading={isLoading}
101
+ min="0"
102
+ max="200000"
103
+ formatter={formatter}
104
+ />
90
105
  <Button.Text submit label="submit" id="ksts-test-form-submit" />
91
106
  </Form>
92
107
  </div>