Skip to content

Commit bf23e8a

Browse files
authored
Merge pull request #36 from next-dev-team/feat-utils
Update Docs
2 parents b86c3af + 3915939 commit bf23e8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3402
-2167
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ Thank you for your interest in contributing to `rnr-registry-template`! We welco
88

99
1. Fork the repository to your GitHub account.
1010
2. Clone the forked repository to your local machine:
11+
1112
```bash
1213
git clone https://github.com/your-username/rnr-registry-template.git
1314
cd rnr-registry-template
1415
```
16+
1517
3. Create a new branch:
1618

1719
```bash
@@ -41,18 +43,18 @@ Please follow the coding style and guidelines used in the project. If there are
4143
4244
## Issue Tracker
4345

44-
Check the [issue tracker](https://github.com/gabimoncha/rnr-registry-template/issues) for existing issues or open a new issue to discuss and coordinate your contribution with the maintainers.
46+
Check the [issue tracker](https://github.com/next-dev-team/next-dev/issues) for existing issues or open a new issue to discuss and coordinate your contribution with the maintainers.
4547

4648
## Code of Conduct
4749

48-
Please review and adhere to our [Code of Conduct](https://github.com/gabimoncha/rnr-registry-template/blob/main/CODE_OF_CONDUCT.md). Be respectful and considerate towards others.
50+
Please review and adhere to our [Code of Conduct](https://github.com/next-dev-team/next-dev/blob/main/CODE_OF_CONDUCT.md). Be respectful and considerate towards others.
4951

5052
## License
5153

52-
By contributing to this project, you agree that your contributions will be licensed under the [LICENSE](https://github.com/gabimoncha/rnr-registry-template/blob/main/LICENSE) file of this repository.
54+
By contributing to this project, you agree that your contributions will be licensed under the [LICENSE](https://github.com/next-dev-team/next-dev/blob/main/LICENSE) file of this repository.
5355

5456
## Contact
5557

56-
If you have any questions or need further assistance, feel free to contact us at hello@foundedlabs.com.
58+
If you have any questions or need further assistance, feel free to contact us at <hello@foundedlabs.com>.
5759

5860
**We appreciate your contributions and look forward to working with you!**

apps/docs/app/(home)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function Layout({ children }: { children: ReactNode }) {
1616
<>
1717
<SkipNavigationButton />
1818
<HomeLayout
19-
githubUrl="https://github.com/gabimoncha/rnr-registry-template"
19+
githubUrl="https://github.com/next-dev-team/next-dev"
2020
nav={{
2121
title: (
2222
<div className="hover:bg-fd-accent -ml-0.5 flex size-8 items-center justify-center rounded-md transition-colors duration-200">

apps/docs/app/docs/[[...slug]]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function Footer({ url }: { url: string }) {
123123
</a>{' '}
124124
to React Native. Source on{' '}
125125
<a
126-
href="https://github.com/gabimoncha/rnr-registry-template"
126+
href="https://github.com/next-dev-team/next-dev"
127127
target="_blank"
128128
rel="noreferrer"
129129
className="underline underline-offset-4">

apps/docs/app/docs/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ export default function Layout({ children }: { children: ReactNode }) {
1818
<div className="flex items-center justify-center">
1919
<RnrIcon />
2020
</div>
21-
<p className="text-base">Registry Template</p>
21+
<p className="text-base">Next Dev</p>
2222
</div>
2323
),
2424
}}
2525
sidebar={SIDEBAR_PROPS}
26-
githubUrl="https://github.com/gabimoncha/rnr-registry-template">
26+
githubUrl="https://github.com/next-dev-team/next-dev">
2727
{children}
2828
</DocsLayout>
2929
</>

apps/docs/components/utils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,4 @@ export function ObjectUtilityPlayground() {
442442
)}
443443
</BaseUtilityPlayground>
444444
);
445-
}
445+
}

apps/docs/content/docs/changelog.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ title: Changelog
33
description: Latest updates and announcements.
44
---
55

6-
## August 2025 - Initial Release
6+
## Nov 2025 - Initial Release
77

88
New React Native Reusables registry template.
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
---
2+
title: Advanced Form Patterns
3+
description: Advanced form patterns including dynamic fields, custom validation, and field dependencies using rc-field-form.
4+
---
5+
6+
import {
7+
FormFieldTypesPreview,
8+
FormCustomValidationPreview,
9+
FormDynamicFieldsPreview,
10+
FormFieldDependenciesPreview,
11+
FormAsyncValidationPreview
12+
} from '@docs/components/examples';
13+
14+
<ExternalLinks
15+
links={[
16+
{ title: 'rc-field-form Docs', url: 'https://github.com/react-component/field-form' },
17+
]}
18+
/>
19+
20+
<div className="h-5" />
21+
22+
## Field Types Example
23+
24+
Demonstrates various input field types including text, email, phone, password, and textarea fields.
25+
26+
<Tabs defaultValue="preview">
27+
<TabsList>
28+
<TabsTrigger value="preview">Preview</TabsTrigger>
29+
<TabsTrigger value="code">Code</TabsTrigger>
30+
</TabsList>
31+
<TabsContent value="preview">
32+
<PreviewCard preview={<FormFieldTypesPreview />} />
33+
</TabsContent>
34+
<TabsContent value="code">
35+
```json doc-gen:file
36+
{
37+
"file": "./node_modules/@rnr/rnr-ui/src/examples/form/form-field-types.tsx",
38+
"codeblock": {
39+
"lang": "tsx"
40+
}
41+
}
42+
```
43+
</TabsContent>
44+
</Tabs>
45+
46+
## Custom Validation Example
47+
48+
Shows how to implement custom validation rules with complex business logic and field dependencies.
49+
50+
<Tabs defaultValue="preview">
51+
<TabsList>
52+
<TabsTrigger value="preview">Preview</TabsTrigger>
53+
<TabsTrigger value="code">Code</TabsTrigger>
54+
</TabsList>
55+
<TabsContent value="preview">
56+
<PreviewCard preview={<FormCustomValidationPreview />} />
57+
</TabsContent>
58+
<TabsContent value="code">
59+
```json doc-gen:file
60+
{
61+
"file": "./node_modules/@rnr/rnr-ui/src/examples/form/form-custom-validation.tsx",
62+
"codeblock": {
63+
"lang": "tsx"
64+
}
65+
}
66+
```
67+
</TabsContent>
68+
</Tabs>
69+
70+
## Dynamic Fields Example
71+
72+
Demonstrates how to create forms with dynamically added and removed fields.
73+
74+
<Tabs defaultValue="preview">
75+
<TabsList>
76+
<TabsTrigger value="preview">Preview</TabsTrigger>
77+
<TabsTrigger value="code">Code</TabsTrigger>
78+
</TabsList>
79+
<TabsContent value="preview">
80+
<PreviewCard preview={<FormDynamicFieldsPreview />} />
81+
</TabsContent>
82+
<TabsContent value="code">
83+
```json doc-gen:file
84+
{
85+
"file": "./node_modules/@rnr/rnr-ui/src/examples/form/form-dynamic-fields.tsx",
86+
"codeblock": {
87+
"lang": "tsx"
88+
}
89+
}
90+
```
91+
</TabsContent>
92+
</Tabs>
93+
94+
## Field Dependencies Example
95+
96+
Shows how to create conditional fields and validation based on other field values.
97+
98+
<Tabs defaultValue="preview">
99+
<TabsList>
100+
<TabsTrigger value="preview">Preview</TabsTrigger>
101+
<TabsTrigger value="code">Code</TabsTrigger>
102+
</TabsList>
103+
<TabsContent value="preview">
104+
<PreviewCard preview={<FormFieldDependenciesPreview />} />
105+
</TabsContent>
106+
<TabsContent value="code">
107+
```json doc-gen:file
108+
{
109+
"file": "./node_modules/@rnr/rnr-ui/src/examples/form/form-field-dependencies.tsx",
110+
"codeblock": {
111+
"lang": "tsx"
112+
}
113+
}
114+
```
115+
</TabsContent>
116+
</Tabs>
117+
118+
## Async Validation Example
119+
120+
Demonstrates asynchronous validation with simulated API calls for username, email, and phone validation.
121+
122+
<Tabs defaultValue="preview">
123+
<TabsList>
124+
<TabsTrigger value="preview">Preview</TabsTrigger>
125+
<TabsTrigger value="code">Code</TabsTrigger>
126+
</TabsList>
127+
<TabsContent value="preview">
128+
<PreviewCard preview={<FormAsyncValidationPreview />} />
129+
</TabsContent>
130+
<TabsContent value="code">
131+
```json doc-gen:file
132+
{
133+
"file": "./node_modules/@rnr/rnr-ui/src/examples/form/form-async-validation.tsx",
134+
"codeblock": {
135+
"lang": "tsx"
136+
}
137+
}
138+
```
139+
</TabsContent>
140+
</Tabs>
141+
142+
## Key Concepts
143+
144+
### Custom Validators
145+
146+
Custom validators receive three parameters: `rule`, `value`, and `callback`. They should return a Promise that resolves when validation passes or rejects with an error message when validation fails.
147+
148+
```tsx
149+
const validateUsername = async (_: any, value: string) => {
150+
if (!value) {
151+
return Promise.reject(new Error('Username is required'));
152+
}
153+
// Additional validation logic
154+
return Promise.resolve();
155+
};
156+
157+
<Form.Item
158+
name="username"
159+
label="Username"
160+
rules={[{ validator: validateUsername }]}
161+
>
162+
<TextInput placeholder="Enter username" />
163+
</Form.Item>
164+
```
165+
166+
### Field Dependencies
167+
168+
Use `dependencies` to make one field depend on another. The dependent field will re-validate when the dependency changes.
169+
170+
```tsx
171+
<Form.Item
172+
name="confirmPassword"
173+
label="Confirm Password"
174+
dependencies={['password']}
175+
rules={[{ validator: validateConfirmPassword }]}
176+
>
177+
<TextInput placeholder="Confirm password" secureTextEntry />
178+
</Form.Item>
179+
```
180+
181+
### Dynamic Fields
182+
183+
Manage arrays of fields using React state and render them dynamically with proper field names.
184+
185+
```tsx
186+
{emails.map((_, index) => (
187+
<Form.Item
188+
key={index}
189+
name={['emails', index]}
190+
rules={[{ required: true, message: 'Email is required' }]}
191+
>
192+
<TextInput placeholder={`Email ${index + 1}`} />
193+
</Form.Item>
194+
))}
195+
```
196+
197+
### Async Validation
198+
199+
Async validators can perform API calls or other asynchronous operations. Use `validateTrigger="onBlur"` to validate on field blur instead of every change.
200+
201+
```tsx
202+
<Form.Item
203+
name="username"
204+
label="Username"
205+
rules={[{ validator: validateUsername }]}
206+
validateTrigger="onBlur"
207+
>
208+
<TextInput placeholder="Enter username" />
209+
</Form.Item>
210+
```
211+
212+
## Best Practices
213+
214+
1. **Use `validateTrigger="onBlur"`** for async validation to avoid excessive API calls
215+
2. **Provide clear error messages** that help users understand what they need to fix
216+
3. **Use field dependencies** to create conditional validation logic
217+
4. **Handle loading states** during async validation to improve user experience
218+
5. **Validate on the client first** before making async calls to reduce server load
219+
6. **Use proper TypeScript types** for better development experience and error catching

0 commit comments

Comments
 (0)