|
| 1 | +import { Sandbox } from "@components/sandbox"; |
| 2 | +import { GoabButton, GoabModal } from "@abgov/react-components"; |
| 3 | +import { CodeSnippet } from "@components/code-snippet/CodeSnippet.tsx"; |
| 4 | +import { useContext, useState } from "react"; |
| 5 | +import { LanguageVersionContext } from "@contexts/LanguageVersionContext.tsx"; |
| 6 | + |
| 7 | +export const BasicModalWithClose = () => { |
| 8 | + const {version} = useContext(LanguageVersionContext); |
| 9 | + const [basicModalOpen, setBasicModalOpen] = useState<boolean>(); |
| 10 | + return ( |
| 11 | + <Sandbox skipRender> |
| 12 | + <GoabButton onClick={() => setBasicModalOpen(true)}>Open Basic Modal</GoabButton> |
| 13 | + <GoabModal |
| 14 | + heading="Modal" |
| 15 | + open={basicModalOpen} |
| 16 | + onClose={() => setBasicModalOpen(false)} |
| 17 | + > |
| 18 | + <p>This modal uses an icon button to close it.</p> |
| 19 | + </GoabModal> |
| 20 | + {/*Angular*/} |
| 21 | + <CodeSnippet |
| 22 | + lang="typescript" |
| 23 | + tags="angular" |
| 24 | + allowCopy={true} |
| 25 | + code={` |
| 26 | + export class SomeOtherComponent { |
| 27 | + open = false; |
| 28 | + toggleModal() { |
| 29 | + this.open = !this.open; |
| 30 | + } |
| 31 | + } |
| 32 | + `} |
| 33 | + /> |
| 34 | + |
| 35 | + {version === "old" && ( |
| 36 | + <CodeSnippet |
| 37 | + lang="typescript" |
| 38 | + tags="angular" |
| 39 | + allowCopy={true} |
| 40 | + code={` |
| 41 | + <goa-button (_click)="toggleModal();">Open Basic Modal</goa-button> |
| 42 | + <goa-modal [open]="open" (_close)="toggleModal()" heading="Modal"> |
| 43 | + <p>This modal uses an icon button to close it.</p> |
| 44 | + </goa-modal> |
| 45 | + `} |
| 46 | + /> |
| 47 | + )} |
| 48 | + |
| 49 | + {version === "new" && ( |
| 50 | + <CodeSnippet |
| 51 | + lang="typescript" |
| 52 | + tags="angular" |
| 53 | + allowCopy={true} |
| 54 | + code={` |
| 55 | + <goab-button (onClick)="toggleModal();">Open Basic Modal</goab-button> |
| 56 | + <goab-modal [open]="open" (close)="toggleModal()" heading="Modal" [actions]="actions"> |
| 57 | + <p>This modal uses an icon button to close it.</p> |
| 58 | + </goab-modal> |
| 59 | + `} |
| 60 | + /> |
| 61 | + )} |
| 62 | + |
| 63 | + {/*React code*/} |
| 64 | + <CodeSnippet |
| 65 | + lang="typescript" |
| 66 | + tags="react" |
| 67 | + allowCopy={true} |
| 68 | + code={` |
| 69 | + const [open, setOpen] = useState(false); |
| 70 | + `} |
| 71 | + /> |
| 72 | + |
| 73 | + {version === "old" && ( |
| 74 | + <CodeSnippet |
| 75 | + lang="typescript" |
| 76 | + tags="react" |
| 77 | + allowCopy={true} |
| 78 | + code={` |
| 79 | + <GoAButton onClick={() => setOpen(true)}>Open Basic Modal</GoAButton> |
| 80 | + <GoAModal |
| 81 | + heading="Modal" |
| 82 | + open={open} |
| 83 | + onClose={() => setOpen(false)} |
| 84 | + > |
| 85 | + <p>This modal uses an icon button to close it.</p> |
| 86 | + </GoAModal> |
| 87 | + `} |
| 88 | + /> |
| 89 | + )} |
| 90 | + |
| 91 | + {version === "new" && ( |
| 92 | + <CodeSnippet |
| 93 | + lang="typescript" |
| 94 | + tags="react" |
| 95 | + allowCopy={true} |
| 96 | + code={` |
| 97 | + <GoabButton onClick={() => setOpen(true)}>Open Basic Modal</GoabButton> |
| 98 | + <GoabModal |
| 99 | + heading="Modal" |
| 100 | + open={open} |
| 101 | + onClose={() => setOpen(false)} |
| 102 | + > |
| 103 | + <p>This modal uses an icon button to close it.</p> |
| 104 | + </GoabModal> |
| 105 | + `} |
| 106 | + /> |
| 107 | + )} |
| 108 | + </Sandbox> |
| 109 | + ) |
| 110 | +} |
| 111 | + |
| 112 | +export default BasicModalWithClose; |
0 commit comments