()
| 49 | * ``` |
| 50 | */ |
| 51 | export function useImperativeModal() { |
| 52 | const context = React.use(ModalContext); |
| 53 | |
| 54 | if (context === undefined) { |
| 55 | throw new Error("useModal must be used within a ModalProvider"); |
| 56 | } |
| 57 | |
| 58 | const closeModal = () => { |
| 59 | context.setModal(null); |
| 60 | }; |
| 61 | |
| 62 | return { |
| 63 | openModal: (content: React.ReactNode) => { |
| 64 | context.setModal( |
| 65 | <Dialog |
| 66 | open={true} |
| 67 | onOpenChange={(open) => { |
| 68 | if (!open) { |
| 69 | closeModal(); |
| 70 | } |
| 71 | }} |
| 72 | > |
| 73 | {content} |
| 74 | </Dialog>, |
| 75 | ); |
| 76 | }, |
| 77 | openAlert: (content: React.ReactNode) => { |
| 78 | context.setModal( |
| 79 | <AlertDialog |
| 80 | open={true} |
| 81 | onOpenChange={(open) => { |
| 82 | if (!open) { |
| 83 | closeModal(); |
| 84 | } |
| 85 | }} |
| 86 | > |
| 87 | <AlertDialogContent> |
| 88 | {content} |
| 89 | <AlertDialogFooter> |
| 90 | <AlertDialogAction autoFocus={true} onClick={closeModal}> |
| 91 | Ok |
| 92 | </AlertDialogAction> |
| 93 | </AlertDialogFooter> |
| 94 | </AlertDialogContent> |
| 95 | </AlertDialog>, |
| 96 | ); |
| 97 | }, |
| 98 | openPrompt: (opts: { |
| 99 | title: React.ReactNode; |
| 100 | description?: React.ReactNode; |
| 101 | defaultValue?: string; |
| 102 | spellCheck?: boolean; |
| 103 | confirmText?: string; |
| 104 | onConfirm: (value: string) => void; |
| 105 | }) => { |
| 106 | context.setModal( |
| 107 | <AlertDialog |
| 108 | open={true} |
no test coverage detected
searching dependent graphs…