Skip to content

Commit aba29e6

Browse files
authoredOct 24, 2024
Merge branch 'master' into master
2 parents ddc2e23 + 2e86046 commit aba29e6

File tree

15 files changed

+1008
-816
lines changed

15 files changed

+1008
-816
lines changed
 

‎next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/basic-features/typescript for more information.
5+
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.

‎pnpm-lock.yaml

Lines changed: 718 additions & 704 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎public/images/twicsy.png

818 Bytes
Loading

‎src/components/Footer.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
padding: 40px 0;
33
font-size: 0.8rem;
44
font-weight: 400;
5-
margin-bottom: 60px;
65
text-align: center;
76
}
87

‎src/components/Menu/Menu.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ function Menu({ pages = [] }: { pages: Pages }) {
7070
)
7171
})}
7272
</ul>
73+
74+
<div id="carbon-cover" />
7375
</div>
7476
</aside>
7577
)

‎src/components/Menu/MenuLinks.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,14 @@ export const getStartedLinks: Pages = [
277277
name: "Integrating with global state",
278278
pathname: "#Integratingwithglobalstate",
279279
},
280-
{
281-
name: "Integrating with services",
282-
pathname: "#Integratingwithservices",
283-
},
284280
{
285281
name: "Handle errors",
286282
pathname: "#Handleerrors",
287283
},
284+
{
285+
name: "Integrating with services",
286+
pathname: "#Integratingwithservices",
287+
},
288288
{
289289
name: "Schema Validation",
290290
pathname: "#SchemaValidation",

‎src/components/layout.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ table {
335335
border: 1px solid var(--color-light-grey);
336336
}
337337

338+
.scrollToTop,
339+
.editPage {
340+
display: none;
341+
}
342+
338343
.editPage:hover,
339344
.scrollToTop:hover {
340345
border-color: var(--color-secondary);
@@ -388,6 +393,11 @@ a.active {
388393
padding-left: 0;
389394
padding-right: 0;
390395
}
396+
397+
.scrollToTop,
398+
.editPage {
399+
display: block;
400+
}
391401
}
392402

393403
.editPage {
@@ -923,3 +933,11 @@ pre[class*="language-"] {
923933
height: auto;
924934
}
925935
}
936+
937+
#carbon-responsive {
938+
margin: 0 auto 50px;
939+
}
940+
941+
#carbon-cover {
942+
margin: 0 auto 50px;
943+
}

‎src/components/sponsorsList.module.css

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
.logoGroup {
3030
display: grid;
31-
grid-template-columns: repeat(3, 1fr);
32-
gap: 0.5rem;
31+
grid-template-columns: repeat(2, 1fr);
32+
gap: 1rem;
3333
margin: 0 1rem;
3434
}
3535

@@ -44,12 +44,16 @@
4444
padding: 0.5rem;
4545
}
4646

47+
.twicsy {
48+
border-radius: 50px;
49+
}
50+
4751
@media (min-width: 768px) {
4852
.logoGroup {
4953
display: grid;
50-
max-width: 500px;
54+
max-width: 600px;
5155
margin: 0 auto;
52-
grid-template-columns: repeat(3, 1fr);
53-
gap: 0.5rem;
56+
grid-template-columns: repeat(4, 1fr);
57+
gap: 1.5rem;
5458
}
5559
}

‎src/components/sponsorsList.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ export function SponsorsList() {
3333
alt="route4me"
3434
/>
3535
</a>
36+
<a
37+
href="https://twicsy.com/"
38+
target="_blank"
39+
rel="noopener noreferrer"
40+
>
41+
<img
42+
className={styles.twicsy}
43+
src="/images/twicsy.png"
44+
alt="twicsy"
45+
/>
46+
</a>
3647
</div>
3748
</div>
3849
)

‎src/content/docs/useform.mdx

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ sidebar: apiLinks
9292
| [delayError](#delayError) | Delay error from appearing instantly. |
9393
| [shouldUseNativeValidation](#shouldUseNativeValidation) | Use browser built-in form constraint API. |
9494
| [shouldUnregister](#shouldUnregister) | Enable and disable input unregister after unmount. |
95+
| [disabled](#disabled) | Disable the entire form with all associated inputs. |
9596

9697
**Schema validation props:**
9798

@@ -322,7 +323,7 @@ This config will enable [browser native validation](https://developer.mozilla.or
322323

323324
- Only works with `onSubmit` and `onChange` modes, as the `reportValidity` execution will focus the error input.
324325
- Each registered field's validation message is required to be string to display them natively.
325-
- This feature only works with the `register` API and`useController/Controller` that are connected with actual DOM references.
326+
- This feature only works with the `register` API and `useController/Controller` that are connected with actual DOM references.
326327

327328
**Examples:**
328329

@@ -352,6 +353,54 @@ export default function App() {
352353
}
353354
```
354355

356+
#### disabled: <TypeText>boolean = false</TypeText> {#disabled}
357+
358+
---
359+
360+
This config allows you to disable the entire form and all associated inputs when set to `true`.<br />
361+
This can be useful for preventing user interaction during asynchronous tasks or other
362+
situations where inputs should be temporarily unresponsive.
363+
364+
**Examples:**
365+
366+
---
367+
368+
```javascript copy
369+
import { useForm, Controller } from "react-hook-form"
370+
371+
const App = () => {
372+
const [disabled, setDisabled] = useState(false)
373+
const { register, handleSubmit, control } = useForm({
374+
disabled,
375+
})
376+
377+
return (
378+
<form
379+
onSubmit={handleSubmit(async () => {
380+
setDisabled(true)
381+
await sleep(100)
382+
setDisabled(false)
383+
})}
384+
>
385+
<input
386+
type={"checkbox"}
387+
{...register("checkbox")}
388+
data-testid={"checkbox"}
389+
/>
390+
<select {...register("select")} data-testid={"select"} />
391+
392+
<Controller
393+
control={control}
394+
render={({ field }) => <input disabled={field.disabled} />}
395+
name="test"
396+
/>
397+
398+
<button type="submit">Submit</button>
399+
</form>
400+
)
401+
}
402+
```
403+
355404
#### resolver: [Resolver](/ts#Resolver) {#resolver}
356405

357406
---

‎src/content/docs/useform/seterror.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ const App = () => {
271271
minLength: "This is minLength",
272272
},
273273
})
274-
}, [setValue])
274+
}, [setError])
275275

276276
return (
277277
<form onSubmit={handleSubmit(onSubmit)}>

‎src/content/docs/useform/watch.mdx

Lines changed: 88 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,113 @@ description: Subscribe to input changes
44
sidebar: apiLinks
55
---
66

7-
## \</> `watch:` <TypeText>(names?: string | string[] | (data, options) => void) => unknown</TypeText>
7+
## \</> `watch:` _<TypeText>some overloads</TypeText>_
88

99
This method will watch specified inputs and return their values. It is useful to render input value and for determining what to render by condition.
1010

11-
### Props
11+
### Overloads
12+
13+
This function mainly serves **two purposes**:
14+
15+
1. Returns and keep sync with fields' values
16+
a. <TypeText>`watch(name: string, defaultValue?): unknown`</TypeText>
17+
b. <TypeText>`watch(names: string[], defaultValue?): {[key:string]: unknown}`</TypeText>
18+
c. <TypeText>`watch(): {[key:string]: unknown}`</TypeText>
19+
2. Start subscribing with given callback function (can be stopped by calling `unsubscribe` function)
20+
a. <TypeText>`watch(callback: (data, { name, type }) => void, defaultValues?): { unsubscribe: () => void }`</TypeText>
21+
22+
The explanation of each of these four overloads follows below.
23+
24+
#### 1-a. Watching single field <TypeText>`watch(name: string, defaultValue?: unknown): unknown`</TypeText>
25+
26+
---
27+
28+
Watch and subscribe to a single field used outside of render.
29+
30+
**Params**
31+
32+
| Name | Type | Description |
33+
| -------------- | ------------------------------ | ----------------------------------- |
34+
| `name` | <TypeText>`string`</TypeText> | the field name |
35+
| `defaultValue` | <TypeText>`unknown`</TypeText> | _optional_. default value for field |
36+
37+
**Returns** the single field value.
38+
39+
```tsx
40+
const name = watch("name")
41+
```
42+
43+
#### 1-b. Watching some fields <TypeText>`watch(names: string[], defaultValue?: {[key:string]: unknown}): unknown[]`</TypeText>
1244

1345
---
1446

15-
| Type | Description |
16-
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------- |
17-
| <TypeText>string</TypeText> | Watch input value by name (similar to lodash [get](https://lodash.com/docs/4.17.15#get) function) |
18-
| <TypeText>string[]</TypeText> | Watch multiple inputs |
19-
| <TypeText>undefined</TypeText> | Watch all inputs |
20-
| <TypeText>`(data: unknown, { name: string, type: string }) => void`</TypeText> | Watch all inputs and invoke a callback |
47+
Watch and subscribe to an array of fields used outside of render.
48+
49+
**Params**
50+
51+
| Name | Type | Description |
52+
| -------------- | ---------------------------------------------- | ------------------------------------- |
53+
| `names` | <TypeText>`string[]`</TypeText> | the field names |
54+
| `defaultValue` | <TypeText>`{[key:string]: unknown}`</TypeText> | _optional_. default values for fields |
55+
56+
**Returns** an array of field values.
57+
58+
```tsx
59+
const [name, name1] = watch(["name", "name1"])
60+
```
2161

22-
### Return
62+
#### 1-c. Watching the entire form <TypeText>`watch(): {[key:string]: unknown}`</TypeText>
2363

2464
---
2565

26-
| Example | Return |
27-
| ---------------------------------------------------------------- | -------------------------------------------------- |
28-
| `watch('inputName')` | <TypeText>unknown</TypeText> |
29-
| `watch(['inputName1'])` | <TypeText>unknown[]</TypeText> |
30-
| `watch()` | <TypeText>`{[key:string]: unknown}`</TypeText> |
31-
| `watch((data, { name, type }) => console.log(data, name, type))` | <TypeText>`{ unsubscribe: () => void }`</TypeText> |
66+
Watch and subscribe to the entire form update/change based on onChange and re-render at the useForm.
3267

33-
<Admonition type="important" title="Rules">
68+
**Params** None
69+
70+
**Returns** the entire form values.
71+
72+
```tsx
73+
const formValues = watch()
74+
```
75+
76+
#### 2. Start watching with callback fn <TypeText>`watch(callback: (data, { name, type }) => void, defaultValues?: {[key:string]: unknown}): { unsubscribe: () => void }`</TypeText>
77+
78+
---
79+
80+
Subscribe to field update/change without trigger re-render.
81+
82+
**Params**
83+
84+
| Name | Type | Description |
85+
| --------------- | ----------------------------------------------------- | ---------------------------------------------------- |
86+
| `callback` | <TypeText>`(data, { name, type }) => void`</TypeText> | callback function to subscribe to all fields changes |
87+
| `defaultValues` | <TypeText>`{[key:string]: unknown}`</TypeText> | _optional_. defaultValues for the entire form |
88+
89+
**Returns** object with `unsubscribe` function.
90+
91+
```tsx
92+
useEffect(() => {
93+
const { unsubscribe } = watch((value) => {
94+
console.log(value)
95+
})
96+
return () => unsubscribe()
97+
}, [watch])
98+
```
99+
100+
### Rules
101+
102+
---
34103

35104
- When `defaultValue` is not defined, the first render of `watch` will return `undefined` because it is called before `register`. It's **recommended** to provide `defaultValues` at `useForm` to avoid this behaviour, but you can set the inline `defaultValue` as the second argument.
36105
- When both `defaultValue` and `defaultValues` are supplied, `defaultValue` will be returned.
37106
- This API will trigger re-render at the root of your app or form, consider using a callback or the [useWatch](/docs/usewatch) api if you are experiencing performance issues.
38107
- `watch` result is optimised for render phase instead of `useEffect`'s deps, to detect value update you may want to use an external custom hook for value comparison.
39108

40-
</Admonition>
41-
42-
**Examples:**
109+
### Examples:
43110

44111
---
45112

46-
**Watch in a Form**
113+
#### Watch in a Form
47114

48115
<TabGroup buttonLabels={["TS", "JS"]}>
49116

@@ -138,7 +205,7 @@ function App() {
138205

139206
</TabGroup>
140207

141-
**Watch in Field Array**
208+
#### Watch in Field Array
142209

143210
<TabGroup buttonLabels={["TS", "JS"]}>
144211

0 commit comments

Comments
 (0)