|
| 1 | +import { DialogChangeEvent, DialogContentInstance, DialogProps } from '@primereact/types/shared/dialog'; |
| 2 | +import { Button } from 'primereact/button'; |
| 3 | +import { Dialog } from 'primereact/dialog'; |
| 4 | +import { InputText } from 'primereact/inputtext'; |
| 5 | +import { Label } from 'primereact/label'; |
| 6 | +import * as React from 'react'; |
| 7 | + |
| 8 | +export default function PositionDemo() { |
| 9 | + const [open, setOpen] = React.useState<boolean>(false); |
| 10 | + const [position, setPosition] = React.useState<DialogProps['position']>('center'); |
| 11 | + |
| 12 | + const openPosition = (position: DialogProps['position']) => { |
| 13 | + setOpen(true); |
| 14 | + setPosition(position); |
| 15 | + }; |
| 16 | + |
| 17 | + return ( |
| 18 | + <div className="card"> |
| 19 | + <div className="flex flex-wrap justify-center gap-2 mb-2"> |
| 20 | + <Button onClick={() => openPosition('left')} severity="secondary" style={{ minWidth: '10rem' }}> |
| 21 | + Left |
| 22 | + <i className="pi pi-arrow-right" /> |
| 23 | + </Button> |
| 24 | + <Button onClick={() => openPosition('right')} severity="secondary" style={{ minWidth: '10rem' }}> |
| 25 | + Right |
| 26 | + <i className="pi pi-arrow-left" /> |
| 27 | + </Button> |
| 28 | + </div> |
| 29 | + <div className="flex flex-wrap justify-center gap-2 mb-2"> |
| 30 | + <Button onClick={() => openPosition('topleft')} severity="secondary" style={{ minWidth: '10rem' }}> |
| 31 | + TopLeft |
| 32 | + <i className="pi pi-arrow-down-right" /> |
| 33 | + </Button> |
| 34 | + <Button onClick={() => openPosition('top')} severity="secondary" style={{ minWidth: '10rem' }}> |
| 35 | + Top |
| 36 | + <i className="pi pi-arrow-down" /> |
| 37 | + </Button> |
| 38 | + <Button onClick={() => openPosition('topright')} severity="secondary" style={{ minWidth: '10rem' }}> |
| 39 | + TopRight |
| 40 | + <i className="pi pi-arrow-down-left" /> |
| 41 | + </Button> |
| 42 | + </div> |
| 43 | + <div className="flex flex-wrap justify-center gap-2"> |
| 44 | + <Button onClick={() => openPosition('bottomleft')} severity="secondary" style={{ minWidth: '10rem' }}> |
| 45 | + BottomLeft |
| 46 | + <i className="pi pi-arrow-up-right" /> |
| 47 | + </Button> |
| 48 | + <Button onClick={() => openPosition('bottom')} severity="secondary" style={{ minWidth: '10rem' }}> |
| 49 | + Bottom |
| 50 | + <i className="pi pi-arrow-up" /> |
| 51 | + </Button> |
| 52 | + <Button onClick={() => openPosition('bottomright')} severity="secondary" style={{ minWidth: '10rem' }}> |
| 53 | + BottomRight |
| 54 | + <i className="pi pi-arrow-up-left" /> |
| 55 | + </Button> |
| 56 | + </div> |
| 57 | + <Dialog open={open} onOpenChange={(e: DialogChangeEvent) => setOpen(e.value as boolean)} modal position={position} draggable={false}> |
| 58 | + <Dialog.Portal style={{ width: '25rem' }}> |
| 59 | + <Dialog.Header> |
| 60 | + <Dialog.Title>Edit Profile</Dialog.Title> |
| 61 | + <Dialog.HeaderActions> |
| 62 | + <Dialog.Close /> |
| 63 | + </Dialog.HeaderActions> |
| 64 | + </Dialog.Header> |
| 65 | + <Dialog.Content> |
| 66 | + {(instance: DialogContentInstance) => { |
| 67 | + const { dialog } = instance; |
| 68 | + |
| 69 | + return ( |
| 70 | + <> |
| 71 | + <span className="text-surface-500 dark:text-surface-400 block mb-8">Update your information.</span> |
| 72 | + <div className="flex items-center gap-4 mb-4"> |
| 73 | + <Label htmlFor="username" className="font-semibold w-24"> |
| 74 | + Username |
| 75 | + </Label> |
| 76 | + <InputText id="username" className="flex-auto" autoComplete="off" /> |
| 77 | + </div> |
| 78 | + <div className="flex items-center gap-4 mb-8"> |
| 79 | + <Label htmlFor="email" className="font-semibold w-24"> |
| 80 | + Email |
| 81 | + </Label> |
| 82 | + <InputText id="email" className="flex-auto" autoComplete="off" /> |
| 83 | + </div> |
| 84 | + <div className="flex justify-end gap-2"> |
| 85 | + <Button type="button" severity="secondary" onClick={dialog?.close}> |
| 86 | + Cancel |
| 87 | + </Button> |
| 88 | + <Button type="button" onClick={dialog?.close}> |
| 89 | + Save |
| 90 | + </Button> |
| 91 | + </div> |
| 92 | + </> |
| 93 | + ); |
| 94 | + }} |
| 95 | + </Dialog.Content> |
| 96 | + </Dialog.Portal> |
| 97 | + </Dialog> |
| 98 | + </div> |
| 99 | + ); |
| 100 | +} |
0 commit comments