|
1
|
import { Button, FocusModal, Input, Label } from "@medusajs/ui" |
|
2
|
import { useState } from "react" |
|
3
|
|
|
4
|
export default function FocusModalForm() { |
|
5
|
const [open, setOpen] = useState(false) |
|
6
|
const [value, setValue] = useState("") |
|
7
|
|
|
8
|
function handleSubmit(e: React.FormEvent) { |
|
9
|
e.preventDefault() |
|
10
|
setOpen(false) |
|
11
|
} |
|
12
|
|
|
13
|
return ( |
|
14
|
<div className="flex flex-col gap-2 items-center"> |
|
15
|
<FocusModal open={open} onOpenChange={setOpen}> |
|
16
|
<FocusModal.Trigger asChild> |
|
17
|
<Button>Create Item</Button> |
|
18
|
</FocusModal.Trigger> |
|
19
|
<FocusModal.Content> |
|
20
|
<FocusModal.Header> |
|
21
|
<FocusModal.Title>Create Item</FocusModal.Title> |
|
22
|
</FocusModal.Header> |
|
23
|
<form onSubmit={handleSubmit} className="flex flex-col flex-1"> |
|
24
|
<FocusModal.Body> |
|
25
|
<div className="p-6"> |
|
26
|
<Label htmlFor="name">Name</Label> |
|
27
|
<Input |
|
28
|
id="name" |
|
29
|
value={value} |
|
30
|
onChange={(e) => setValue(e.target.value)} |
|
31
|
placeholder="Enter your name" |
|
32
|
/> |
|
33
|
</div> |
|
34
|
</FocusModal.Body> |
|
35
|
<FocusModal.Footer> |
|
36
|
<Button type="submit">Submit</Button> |
|
37
|
</FocusModal.Footer> |
|
38
|
</form> |
|
39
|
</FocusModal.Content> |
|
40
|
</FocusModal> |
|
41
|
{value && ( |
|
42
|
<div className="text-ui-fg-muted"> |
|
43
|
Form submitted with name: {value} |
|
44
|
</div> |
|
45
|
)} |
|
46
|
</div> |
|
47
|
) |
|
48
|
} |