|
| 1 | +'use client'; |
| 2 | + |
| 3 | +export const getCode = (props: { title?: string; description?: string }) => { |
| 4 | + const { title, description } = props; |
| 5 | + return ` |
| 6 | + <AlertDialog> |
| 7 | + <AlertDialog.Trigger render={<Button color="danger" />}> |
| 8 | + Discard draft |
| 9 | + </AlertDialog.Trigger> |
| 10 | + <AlertDialog.Content width={400} showCloseButton={false}> |
| 11 | + <AlertDialog.Body> |
| 12 | + <AlertDialog.Title>${title}</AlertDialog.Title> |
| 13 | + <AlertDialog.Description> |
| 14 | + ${description} |
| 15 | + </AlertDialog.Description> |
| 16 | + </AlertDialog.Body> |
| 17 | + <AlertDialog.Footer> |
| 18 | + <AlertDialog.Close render={<Button variant="outline" color="neutral">Cancel</Button>} /> |
| 19 | + <AlertDialog.Close render={<Button color="danger">Discard</Button>} /> |
| 20 | + </AlertDialog.Footer> |
| 21 | + </AlertDialog.Content> |
| 22 | + </AlertDialog>`; |
| 23 | +}; |
| 24 | + |
| 25 | +export const playground = { |
| 26 | + type: 'playground', |
| 27 | + controls: { |
| 28 | + title: { type: 'text', initialValue: 'Discard draft?' }, |
| 29 | + description: { |
| 30 | + type: 'text', |
| 31 | + initialValue: "You can't undo this action." |
| 32 | + } |
| 33 | + }, |
| 34 | + getCode |
| 35 | +}; |
| 36 | + |
| 37 | +export const controlledDemo = { |
| 38 | + type: 'code', |
| 39 | + code: ` |
| 40 | + function ControlledAlertDialog() { |
| 41 | + const [open, setOpen] = React.useState(false); |
| 42 | +
|
| 43 | + return ( |
| 44 | + <AlertDialog open={open} onOpenChange={setOpen}> |
| 45 | + <AlertDialog.Trigger render={<Button color="danger" />}> |
| 46 | + Delete Account |
| 47 | + </AlertDialog.Trigger> |
| 48 | + <AlertDialog.Content width={450} showCloseButton={false}> |
| 49 | + <AlertDialog.Header> |
| 50 | + <AlertDialog.Title>Delete Account</AlertDialog.Title> |
| 51 | + </AlertDialog.Header> |
| 52 | + <AlertDialog.Body> |
| 53 | + <AlertDialog.Description> |
| 54 | + Are you sure you want to delete your account? All of your data |
| 55 | + will be permanently removed. This action cannot be undone. |
| 56 | + </AlertDialog.Description> |
| 57 | + </AlertDialog.Body> |
| 58 | + <AlertDialog.Footer> |
| 59 | + <AlertDialog.Close render={<Button variant="outline" color="neutral">Cancel</Button>} /> |
| 60 | + <Button color="danger" onClick={() => setOpen(false)}>Yes, delete account</Button> |
| 61 | + </AlertDialog.Footer> |
| 62 | + </AlertDialog.Content> |
| 63 | + </AlertDialog> |
| 64 | + ); |
| 65 | + }` |
| 66 | +}; |
| 67 | + |
| 68 | +export const menuDemo = { |
| 69 | + type: 'code', |
| 70 | + code: ` |
| 71 | + function MenuWithAlertDialog() { |
| 72 | + const [dialogOpen, setDialogOpen] = React.useState(false); |
| 73 | +
|
| 74 | + return ( |
| 75 | + <React.Fragment> |
| 76 | + <Menu> |
| 77 | + <Menu.Trigger render={<Button variant="outline" />}> |
| 78 | + Actions |
| 79 | + </Menu.Trigger> |
| 80 | + <Menu.Content> |
| 81 | + <Menu.Item>Edit</Menu.Item> |
| 82 | + <Menu.Item>Duplicate</Menu.Item> |
| 83 | + <Menu.Separator /> |
| 84 | + <Menu.Item onClick={() => setDialogOpen(true)}> |
| 85 | + Delete |
| 86 | + </Menu.Item> |
| 87 | + </Menu.Content> |
| 88 | + </Menu> |
| 89 | +
|
| 90 | + <AlertDialog open={dialogOpen} onOpenChange={setDialogOpen}> |
| 91 | + <AlertDialog.Content width={400} showCloseButton={false}> |
| 92 | + <AlertDialog.Body> |
| 93 | + <AlertDialog.Title>Delete item?</AlertDialog.Title> |
| 94 | + <AlertDialog.Description> |
| 95 | + This will permanently delete the item. You can't undo this action. |
| 96 | + </AlertDialog.Description> |
| 97 | + </AlertDialog.Body> |
| 98 | + <AlertDialog.Footer> |
| 99 | + <AlertDialog.Close render={<Button variant="outline" color="neutral">Cancel</Button>} /> |
| 100 | + <Button color="danger" onClick={() => setDialogOpen(false)}>Delete</Button> |
| 101 | + </AlertDialog.Footer> |
| 102 | + </AlertDialog.Content> |
| 103 | + </AlertDialog> |
| 104 | + </React.Fragment> |
| 105 | + ); |
| 106 | + }` |
| 107 | +}; |
| 108 | + |
| 109 | +export const discardDemo = { |
| 110 | + type: 'code', |
| 111 | + code: ` |
| 112 | + <AlertDialog> |
| 113 | + <AlertDialog.Trigger render={<Button variant="outline" />}> |
| 114 | + Discard Changes |
| 115 | + </AlertDialog.Trigger> |
| 116 | + <AlertDialog.Content width={400} showCloseButton={false}> |
| 117 | + <AlertDialog.Header> |
| 118 | + <AlertDialog.Title>Unsaved Changes</AlertDialog.Title> |
| 119 | + </AlertDialog.Header> |
| 120 | + <AlertDialog.Body> |
| 121 | + <AlertDialog.Description> |
| 122 | + You have unsaved changes. Do you want to discard them or continue editing? |
| 123 | + </AlertDialog.Description> |
| 124 | + </AlertDialog.Body> |
| 125 | + <AlertDialog.Footer> |
| 126 | + <AlertDialog.Close render={<Button variant="outline" color="neutral">Continue Editing</Button>} /> |
| 127 | + <AlertDialog.Close render={<Button color="danger">Discard</Button>} /> |
| 128 | + </AlertDialog.Footer> |
| 129 | + </AlertDialog.Content> |
| 130 | + </AlertDialog>` |
| 131 | +}; |
| 132 | + |
| 133 | +export const nestedDemo = { |
| 134 | + type: 'code', |
| 135 | + code: ` |
| 136 | + function NestedAlertDialogExample() { |
| 137 | + return ( |
| 138 | + <AlertDialog> |
| 139 | + <AlertDialog.Trigger render={<Button color="danger" />}> |
| 140 | + Delete Workspace |
| 141 | + </AlertDialog.Trigger> |
| 142 | + <AlertDialog.Content width={450}> |
| 143 | + <AlertDialog.Header> |
| 144 | + <AlertDialog.Title>Delete Workspace</AlertDialog.Title> |
| 145 | + </AlertDialog.Header> |
| 146 | + <AlertDialog.Body> |
| 147 | + <AlertDialog.Description> |
| 148 | + This will delete the workspace and all its projects. Are you sure? |
| 149 | + </AlertDialog.Description> |
| 150 | + <AlertDialog> |
| 151 | + <AlertDialog.Trigger render={<Button color="danger" size="small" />}> |
| 152 | + Confirm Delete |
| 153 | + </AlertDialog.Trigger> |
| 154 | + <AlertDialog.Content width={400} showCloseButton={false}> |
| 155 | + <AlertDialog.Body> |
| 156 | + <AlertDialog.Title>Final Confirmation</AlertDialog.Title> |
| 157 | + <AlertDialog.Description> |
| 158 | + This is your last chance. This action is permanent and cannot be reversed. |
| 159 | + </AlertDialog.Description> |
| 160 | + </AlertDialog.Body> |
| 161 | + <AlertDialog.Footer> |
| 162 | + <AlertDialog.Close render={<Button variant="outline" color="neutral">Go Back</Button>} /> |
| 163 | + <AlertDialog.Close render={<Button color="danger">Delete Everything</Button>} /> |
| 164 | + </AlertDialog.Footer> |
| 165 | + </AlertDialog.Content> |
| 166 | + </AlertDialog> |
| 167 | + </AlertDialog.Body> |
| 168 | + <AlertDialog.Footer> |
| 169 | + <AlertDialog.Close render={<Button variant="outline" color="neutral">Cancel</Button>} /> |
| 170 | + </AlertDialog.Footer> |
| 171 | + </AlertDialog.Content> |
| 172 | + </AlertDialog> |
| 173 | + ); |
| 174 | + }` |
| 175 | +}; |
0 commit comments