Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding download JSON button #85

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { useMemo } from 'react';

import { FileDownloadOutlined } from '@mui/icons-material';
import { IconButton, Tooltip } from '@mui/material';

import { useDocument } from '../../../documents/editor/EditorContext';

export default function DownloadJson() {
const doc = useDocument();
const href = useMemo(() => {
return `data:text/plain,${encodeURIComponent(JSON.stringify(doc, null, ' '))}`;
}, [doc]);
return (
<Tooltip title="Download JSON file">
<IconButton href={href} download="emailTemplate.json">
<FileDownloadOutlined fontSize="small" />
</IconButton>
</Tooltip>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';

import { UploadFileOutlined } from '@mui/icons-material';
import { FileUploadOutlined } from '@mui/icons-material';
import { IconButton, Tooltip } from '@mui/material';

import ImportJsonDialog from './ImportJsonDialog';
Expand All @@ -17,7 +17,7 @@ export default function ImportJson() {
<>
<Tooltip title="Import JSON">
<IconButton onClick={() => setOpen(true)}>
<UploadFileOutlined fontSize="small" />
<FileUploadOutlined fontSize="small" />
</IconButton>
</Tooltip>
{dialog}
Expand Down
2 changes: 2 additions & 0 deletions packages/editor-sample/src/App/TemplatePanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import ToggleInspectorPanelButton from '../InspectorDrawer/ToggleInspectorPanelButton';
import ToggleSamplesPanelButton from '../SamplesDrawer/ToggleSamplesPanelButton';

import DownloadJson from './DownloadJson';
import HtmlPanel from './HtmlPanel';
import ImportJson from './ImportJson';
import JsonPanel from './JsonPanel';
Expand Down Expand Up @@ -94,6 +95,7 @@ export default function TemplatePanel() {
<MainTabsGroup />
</Stack>
<Stack direction="row" spacing={2}>
<DownloadJson />
<ImportJson />
<ToggleButtonGroup value={selectedScreenSize} exclusive size="small" onChange={handleScreenSizeChange}>
<ToggleButton value="desktop">
Expand Down
Loading