MCPcopy
hub / github.com/marimo-team/marimo / useImperativeModal

Function useImperativeModal

frontend/src/components/modal/ImperativeModal.tsx:51–187  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49 * ```
50 */
51export 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}

Callers 15

SessionShutdownButtonFunction · 0.90
ChatPanelBodyFunction · 0.90
RecoveryButtonFunction · 0.90
useCopyNotebookFunction · 0.90
useNotebookActionsFunction · 0.90
useCellActionButtonsFunction · 0.90
useRestartKernelFunction · 0.90
form-renderers.tsxFile · 0.90
ContributeSnippetButtonFunction · 0.90
FeedbackButtonFunction · 0.90
SecretsPanelFunction · 0.90
ShutdownButtonFunction · 0.90

Calls 1

closeModalFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…