Skip to content

Commit bf2bcca

Browse files
committed
displaying a dialog
1 parent 0f702ce commit bf2bcca

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

DevDocs/DeveloperNotes/GettingStarted/NewEditorPlugin.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,79 @@ pointing out that by using an accented theme, we automatically get a high
222222
contrast mode that stips out all of the superfluous colour, should the user wish
223223
to enable it (this is mentioned in the section titled "Accented Theme").
224224
225+
### Step 2.4: Displaying a dialog
226+
Now we just need to define `NewPluginDialog`, the UI that will actually be shown
227+
when the user triggers the plugin. This component needs to accept the three
228+
props that we're passing
229+
* `editor`, a reference the current TinyMCE editor.
230+
* `open`, a boolean indicating whether the dialog should be shown or not.
231+
* `onClose`, a function that will be called when the dialog should be closed.
232+
233+
We want `NewPluginDialog` to return something like this:
234+
```
235+
return (
236+
<Dialog open={open} onClose={onClose} fullWidth maxWidth="lg">
237+
<AppBar
238+
variant="dialog"
239+
currentPage="New Plugin"
240+
helpPage={{
241+
docLink: docLinks.newPlugin,
242+
title: "New Plugin help",
243+
}}
244+
/>
245+
<DialogTitle>Insert from New Plugin</DialogTitle>
246+
<DialogContent>
247+
{/* TODO: Implement the dialog content here. */}
248+
</DialogContent>
249+
<DialogActions>
250+
<Button onClick={() => onClose()}>Cancel</Button>
251+
<Button
252+
color="callToAction"
253+
variant="contained"
254+
onClick={() => {
255+
editor.execCommand(
256+
"mceInsertContent",
257+
false,
258+
/* TODO: Generate HTML content to be inserted into the editor */
259+
);
260+
onClose();
261+
}}
262+
>
263+
Insert
264+
</Button>
265+
</DialogActions>
266+
</Dialog>
267+
);
268+
```
269+
This gives us a few things
270+
1. A header, utilising the branding colours as previously defined
271+
2. A link to the help docs (once created the link will need to be added to [/src/main/webapp/ui/assets/DocLinks.js](/src/main/webapp/ui/assets/DocLinks.js)).
272+
3. A title, briefly describing the purpose of the dialog. This may seem
273+
superlfuous but in principle a single plugin, or any other integrations,
274+
could provide multiple actions with multiple dialogs.
275+
4. The DialogContent is where the behaviour of the plugins vary; it is here
276+
that some display a list of options, while others may require user input.
277+
If you would prefer, this could be the point where RSpace code calls out to
278+
a separate NPM package, displaying a UI with visual similarity to your main
279+
product, utilising a shared design system, component library, and be
280+
written in any compiled-to-JS language. The dialog content could even be an
281+
iframe if that would be easiest, although of course that comes with
282+
security implications that would need to be carefully considered.
283+
5. A cancel button for closing the dialog. No edits are made to the content of
284+
the editor and it is as if the user never opened the dialog.
285+
6. An insertion button that actually inserts some HTML content into the editor
286+
and closes the dialog.
287+
288+
The imports required for the dialog are as follows:
289+
```
290+
import Dialog from "@mui/material/Dialog";
291+
import DialogTitle from "@mui/material/DialogTitle";
292+
import DialogContent from "@mui/material/DialogContent";
293+
import DialogActions from "@mui/material/DialogActions";
294+
import Button from "@mui/material/Button";
295+
import AppBar from "../../components/AppBar";
296+
import docLinks from "../../assets/DocLinks";
297+
```
298+
225299
## Step 3: Testing
226300
- How will we know if the plugin stops working e.g. due to API changes/services being down?

0 commit comments

Comments
 (0)