|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useState } from 'react'; |
| 4 | +import { BiCaretDown } from 'react-icons/bi'; |
| 5 | +import { type CodeData } from '~/components/code-demo'; |
| 6 | +import { Button, Popover, Label, TextInput } from '~/src'; |
| 7 | + |
| 8 | +const code = ` |
| 9 | +'use client'; |
| 10 | +
|
| 11 | +import { useState } from 'react'; |
| 12 | +import { BiCaretDown } from 'react-icons/bi'; |
| 13 | +import { Button, Popover, Label, TextInput } from 'flowbite-react'; |
| 14 | +
|
| 15 | +function Component() { |
| 16 | + const [open, setOpen] = useState(false); |
| 17 | +
|
| 18 | + return ( |
| 19 | + <Popover |
| 20 | + aria-labelledby="area-popover" |
| 21 | + open={open} |
| 22 | + onOpenChange={setOpen} |
| 23 | + content={ |
| 24 | + <div className="flex w-64 flex-col gap-4 p-4 text-sm text-gray-500 dark:text-gray-400"> |
| 25 | + <div> |
| 26 | + <h2 id="area-popover" className="text-base text-gray-500">Area (sqft)</h2> |
| 27 | + <div className="mb-2 block"> |
| 28 | + <Label htmlFor="minsqft" value="Minimum sqft" /> |
| 29 | + </div> |
| 30 | + <TextInput id="minsqft" type="number" /> |
| 31 | + </div> |
| 32 | + <div> |
| 33 | + <div className="mb-2 block"> |
| 34 | + <Label htmlFor="maxsqft" value="Maximum sqft" /> |
| 35 | + </div> |
| 36 | + <TextInput id="maxsqft" type="number" /> |
| 37 | + </div> |
| 38 | + <div className="flex gap-2"> |
| 39 | + <Button color="gray">Reset</Button> |
| 40 | + <Button color="success" onClick={() => setOpen(false)}> |
| 41 | + Save |
| 42 | + </Button> |
| 43 | + </div> |
| 44 | + </div> |
| 45 | + } |
| 46 | + > |
| 47 | + <Button> |
| 48 | + Area <BiCaretDown className="ml-2" /> |
| 49 | + </Button> |
| 50 | + </Popover> |
| 51 | + ); |
| 52 | +} |
| 53 | +`; |
| 54 | + |
| 55 | +function Component() { |
| 56 | + const [open, setOpen] = useState(false); |
| 57 | + |
| 58 | + return ( |
| 59 | + <Popover |
| 60 | + open={open} |
| 61 | + onOpenChange={setOpen} |
| 62 | + content={ |
| 63 | + <div className="flex w-64 flex-col gap-4 p-4 text-sm text-gray-500 dark:text-gray-400"> |
| 64 | + <div> |
| 65 | + <h2 className="text-base text-gray-500">Area (sqft)</h2> |
| 66 | + <div className="mb-2 block"> |
| 67 | + <Label htmlFor="minsqft" value="Minimum sqft" /> |
| 68 | + </div> |
| 69 | + <TextInput id="minsqft" type="number" /> |
| 70 | + </div> |
| 71 | + <div> |
| 72 | + <div className="mb-2 block"> |
| 73 | + <Label htmlFor="maxsqft" value="Maximum sqft" /> |
| 74 | + </div> |
| 75 | + <TextInput id="maxsqft" type="number" /> |
| 76 | + </div> |
| 77 | + <div className="flex gap-2"> |
| 78 | + <Button color="gray">Reset</Button> |
| 79 | + <Button color="success" onClick={() => setOpen(false)}> |
| 80 | + Save |
| 81 | + </Button> |
| 82 | + </div> |
| 83 | + </div> |
| 84 | + } |
| 85 | + > |
| 86 | + <Button> |
| 87 | + Area <BiCaretDown className="ml-2" /> |
| 88 | + </Button> |
| 89 | + </Popover> |
| 90 | + ); |
| 91 | +} |
| 92 | + |
| 93 | +export const controlled: CodeData = { |
| 94 | + type: 'single', |
| 95 | + code: [ |
| 96 | + { |
| 97 | + fileName: 'client', |
| 98 | + language: 'tsx', |
| 99 | + code, |
| 100 | + }, |
| 101 | + ], |
| 102 | + githubSlug: 'popover/popover.controlled.tsx', |
| 103 | + component: <Component />, |
| 104 | +}; |
0 commit comments