Skip to content

Commit 15e5678

Browse files
committed
feat: add "cleardestroy" demonstration
1 parent c1e3d04 commit 15e5678

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use client';
2+
3+
import React, { useState } from 'react';
4+
import { Button, Card, Form, FormField, Input, useForm } from 'soybean-react-ui';
5+
6+
type FormValues = {
7+
password: string;
8+
username: string;
9+
};
10+
11+
const ClearDestroy = () => {
12+
const [form] = useForm<FormValues>();
13+
14+
const [show, setShow] = useState(true);
15+
16+
function toggle() {
17+
setShow(!show);
18+
}
19+
20+
return (
21+
<Card title="Clear Destroy">
22+
{show && (
23+
<Form
24+
clearOnDestroy
25+
className="w-[480px] max-sm:w-full space-y-4"
26+
form={form}
27+
initialValues={{ password: '123456' }}
28+
>
29+
<FormField
30+
label="Username"
31+
name="username"
32+
>
33+
<Input placeholder="Username" />
34+
</FormField>
35+
36+
<FormField
37+
label="Password"
38+
name="password"
39+
>
40+
<Input placeholder="Password" />
41+
</FormField>
42+
</Form>
43+
)}
44+
45+
<Button
46+
className="mt-2"
47+
onClick={toggle}
48+
>
49+
Toggle
50+
</Button>
51+
</Card>
52+
);
53+
};
54+
55+
export default ClearDestroy;

playground/src/app/(demo)/form/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ClearDestroy from './modules/ClearDestroy';
12
import Default from './modules/Default';
23
import FieldChange from './modules/FieldChange';
34
import Preserve from './modules/Preserve';
@@ -22,6 +23,8 @@ const FormPage = () => {
2223
<Reset />
2324

2425
<Preserve />
26+
27+
<ClearDestroy />
2528
</div>
2629
);
2730
};

0 commit comments

Comments
 (0)