Skip to content

A free and open-source block-based email template builder.

Adding drawers (#21)

cohitre4ed6cd01daea
diff --git a/packages/editor-sample/index.html b/packages/editor-sample/index.html
index 8cce52a..696a562 100644
--- a/packages/editor-sample/index.html
+++ b/packages/editor-sample/index.html
@@ -20,10 +20,7 @@
}
#root {
height: 100vh;
- position: relative;
- box-sizing: border-box;
- margin: 0;
- display: flex;
+ width: 100%;
}
</style>
</head>
diff --git a/packages/editor-sample/src/App/ExamplesButton.tsx b/packages/editor-sample/src/App/ExamplesButton.tsx
deleted file mode 100644
index ade32b8..0000000
--- a/packages/editor-sample/src/App/ExamplesButton.tsx
+++ /dev/null
@@ -1,42 +0,0 @@
-import React from 'react';
-
-import { Button, Menu, MenuItem } from '@mui/material';
-
-export default function ExamplesButton() {
- const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
- const open = Boolean(anchorEl);
- const handleOpen = (event: React.MouseEvent<HTMLButtonElement>) => {
- setAnchorEl(event.currentTarget);
- };
- const handleClose = () => {
- setAnchorEl(null);
- };
-
- const select = (val: string) => {
- window.location.hash = `#sample/${val}`;
- handleClose();
- };
-
- return (
- <>
- <Button onClick={handleOpen}>Samples</Button>
- <Menu
- id="basic-menu"
- anchorEl={anchorEl}
- open={open}
- onClose={handleClose}
- MenuListProps={{
- 'aria-labelledby': 'basic-button',
- }}
- >
- <MenuItem onClick={() => select('one-time-password')}>one-time-password</MenuItem>
- <MenuItem onClick={() => select('order-ecomerce')}>order-ecomerce</MenuItem>
- <MenuItem onClick={() => select('post-metrics-report')}>post-metrics-report</MenuItem>
- <MenuItem onClick={() => select('reservation-reminder')}>reservation-reminder</MenuItem>
- <MenuItem onClick={() => select('reset-password')}>reset-password</MenuItem>
- <MenuItem onClick={() => select('respond-to-message')}>respond-to-message</MenuItem>
- <MenuItem onClick={() => select('subscription-receipt')}>subscription-receipt</MenuItem>
- </Menu>
- </>
- );
-}
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/index.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/index.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/index.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/index.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/AvatarSidebarPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/AvatarSidebarPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/AvatarSidebarPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/AvatarSidebarPanel.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/ButtonSidebarPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/ButtonSidebarPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/ButtonSidebarPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/ButtonSidebarPanel.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/ColumnsContainerSidebarPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/ColumnsContainerSidebarPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/ColumnsContainerSidebarPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/ColumnsContainerSidebarPanel.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/ContainerSidebarPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/ContainerSidebarPanel.tsx
similarity index 84%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/ContainerSidebarPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/ContainerSidebarPanel.tsx
index c6777ab..25c1524 100644
--- a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/ContainerSidebarPanel.tsx
+++ b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/ContainerSidebarPanel.tsx
@@ -1,6 +1,7 @@
import React, { useState } from 'react';
-import { ContainerProps, ContainerPropsSchema } from '../../../../documents/blocks/Container';
+import { ContainerProps } from '../../../../documents/blocks/Container';
+import { ContainerPropsSchema } from '../../../../documents/blocks/Container/ContainerPropsSchema';
import BaseSidebarPanel from './helpers/BaseSidebarPanel';
import MultiStylePropertyPanel from './helpers/style-inputs/MultiStylePropertyPanel';
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/DividerSidebarPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/DividerSidebarPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/DividerSidebarPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/DividerSidebarPanel.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/EmailLayoutSidebarPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/EmailLayoutSidebarPanel.tsx
similarity index 97%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/EmailLayoutSidebarPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/EmailLayoutSidebarPanel.tsx
index fe4857d..bda6920 100644
--- a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/EmailLayoutSidebarPanel.tsx
+++ b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/EmailLayoutSidebarPanel.tsx
@@ -3,7 +3,7 @@ import { z } from 'zod';
import { Divider } from '@mui/material';
-import { EmailLayoutPropsSchema } from '../../../../documents/blocks/EmailLayout';
+import { EmailLayoutPropsSchema } from '../../../../documents/blocks/EmailLayout/EmailLayoutPropsSchema';
import BaseSidebarPanel from './helpers/BaseSidebarPanel';
import ColorInput from './helpers/inputs/ColorInput';
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/HeadingSidebarPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/HeadingSidebarPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/HeadingSidebarPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/HeadingSidebarPanel.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/HtmlSidebarPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/HtmlSidebarPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/HtmlSidebarPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/HtmlSidebarPanel.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/ImageSidebarPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/ImageSidebarPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/ImageSidebarPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/ImageSidebarPanel.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/SpacerSidebarPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/SpacerSidebarPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/SpacerSidebarPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/SpacerSidebarPanel.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/TextSidebarPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/TextSidebarPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/TextSidebarPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/TextSidebarPanel.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/BaseSidebarPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/BaseSidebarPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/BaseSidebarPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/BaseSidebarPanel.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/BooleanInput.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/BooleanInput.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/BooleanInput.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/BooleanInput.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/BaseColorInput.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/BaseColorInput.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/BaseColorInput.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/BaseColorInput.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/Picker.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/Picker.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/Picker.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/Picker.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/Swatch.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/Swatch.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/Swatch.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/Swatch.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/index.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/index.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/index.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/ColorInput/index.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/FontFamily.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/FontFamily.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/FontFamily.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/FontFamily.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/FontSizeInput.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/FontSizeInput.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/FontSizeInput.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/FontSizeInput.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/FontWeightInput.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/FontWeightInput.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/FontWeightInput.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/FontWeightInput.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/PaddingInput.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/PaddingInput.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/PaddingInput.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/PaddingInput.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/RadioGroupInput.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/RadioGroupInput.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/RadioGroupInput.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/RadioGroupInput.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/SliderInput.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/SliderInput.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/SliderInput.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/SliderInput.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/TextAlignInput.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/TextAlignInput.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/TextAlignInput.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/TextAlignInput.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/TextInput.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/TextInput.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/TextInput.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/TextInput.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/raw/RawSliderInput.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/raw/RawSliderInput.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/inputs/raw/RawSliderInput.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/inputs/raw/RawSliderInput.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/style-inputs/MultiStylePropertyPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/style-inputs/MultiStylePropertyPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/style-inputs/MultiStylePropertyPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/style-inputs/MultiStylePropertyPanel.tsx
diff --git a/packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/style-inputs/SingleStylePropertyPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/style-inputs/SingleStylePropertyPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/ConfigurationPanel/input-panels/helpers/style-inputs/SingleStylePropertyPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/helpers/style-inputs/SingleStylePropertyPanel.tsx
diff --git a/packages/editor-sample/src/App/sidebar/StylesPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/StylesPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/sidebar/StylesPanel.tsx
rename to packages/editor-sample/src/App/InspectorDrawer/StylesPanel.tsx
diff --git a/packages/editor-sample/src/App/InspectorDrawer/ToggleInspectorPanelButton.tsx b/packages/editor-sample/src/App/InspectorDrawer/ToggleInspectorPanelButton.tsx
new file mode 100644
index 0000000..84495be
--- /dev/null
+++ b/packages/editor-sample/src/App/InspectorDrawer/ToggleInspectorPanelButton.tsx
@@ -0,0 +1,16 @@
+import React from 'react';
+
+import { Button } from '@mui/material';
+
+import { useEditorState } from '../../documents/editor/EditorContext';
+
+export default function ToggleInspectorPanelButton() {
+ const [{ inspectorDrawerOpen }, setEditorState] = useEditorState();
+ const handleClick = () => {
+ setEditorState({ inspectorDrawerOpen: !inspectorDrawerOpen });
+ };
+ if (inspectorDrawerOpen) {
+ return <Button onClick={handleClick}>CLOSE</Button>;
+ }
+ return <Button onClick={handleClick}>OPEN</Button>;
+}
diff --git a/packages/editor-sample/src/App/InspectorDrawer/index.tsx b/packages/editor-sample/src/App/InspectorDrawer/index.tsx
new file mode 100644
index 0000000..f659566
--- /dev/null
+++ b/packages/editor-sample/src/App/InspectorDrawer/index.tsx
@@ -0,0 +1,44 @@
+import React from 'react';
+
+import { Box, Drawer, Tab, Tabs } from '@mui/material';
+
+import { useEditorState } from '../../documents/editor/EditorContext';
+
+import ConfigurationPanel from './ConfigurationPanel';
+import StylesPanel from './StylesPanel';
+
+export const INSPECTOR_DRAWER_WIDTH = 400;
+
+export default function InspectorDrawer() {
+ const [{ selectedSidebarTab, inspectorDrawerOpen }, setEditorState] = useEditorState();
+
+ const renderCurrentSidebarPanel = () => {
+ switch (selectedSidebarTab) {
+ case 'block-configuration':
+ return <ConfigurationPanel />;
+ case 'styles':
+ return <StylesPanel />;
+ }
+ };
+
+ return (
+ <Drawer
+ variant="persistent"
+ anchor="right"
+ open={inspectorDrawerOpen}
+ sx={{
+ width: inspectorDrawerOpen ? INSPECTOR_DRAWER_WIDTH : 0,
+ }}
+ >
+ <Box sx={{ width: INSPECTOR_DRAWER_WIDTH, height: 49, borderBottom: 1, borderColor: 'divider' }}>
+ <Box px={2}>
+ <Tabs value={selectedSidebarTab} onChange={(_, v) => setEditorState({ selectedSidebarTab: v })}>
+ <Tab value="styles" label="Styles" />
+ <Tab value="block-configuration" label="Inspect" />
+ </Tabs>
+ </Box>
+ </Box>
+ <Box sx={{ height: 'calc(100% - 49px)', overflow: 'auto' }}>{renderCurrentSidebarPanel()}</Box>
+ </Drawer>
+ );
+}
diff --git a/packages/editor-sample/src/App/SamplesDrawer/ToggleSamplesPanelButton.tsx b/packages/editor-sample/src/App/SamplesDrawer/ToggleSamplesPanelButton.tsx
new file mode 100644
index 0000000..fe672cb
--- /dev/null
+++ b/packages/editor-sample/src/App/SamplesDrawer/ToggleSamplesPanelButton.tsx
@@ -0,0 +1,16 @@
+import React from 'react';
+
+import { Button } from '@mui/material';
+
+import { useEditorState } from '../../documents/editor/EditorContext';
+
+export default function ToggleSamplesPanelButton() {
+ const [{ samplesDrawerOpen }, setEditorState] = useEditorState();
+ const handleClick = () => {
+ setEditorState({ samplesDrawerOpen: !samplesDrawerOpen });
+ };
+ if (samplesDrawerOpen) {
+ return <Button onClick={handleClick}>CLOSE</Button>;
+ }
+ return <Button onClick={handleClick}>OPEN</Button>;
+}
diff --git a/packages/editor-sample/src/App/SamplesDrawer/index.tsx b/packages/editor-sample/src/App/SamplesDrawer/index.tsx
new file mode 100644
index 0000000..7f7799a
--- /dev/null
+++ b/packages/editor-sample/src/App/SamplesDrawer/index.tsx
@@ -0,0 +1,36 @@
+import React from 'react';
+
+import { Box, Button, Drawer } from '@mui/material';
+
+import { useEditorState } from '../../documents/editor/EditorContext';
+
+export const SAMPLES_DRAWER_WIDTH = 400;
+
+export default function SamplesDrawer() {
+ const [{ samplesDrawerOpen }] = useEditorState();
+
+ const select = (val: string) => {
+ window.location.hash = `#sample/${val}`;
+ };
+
+ return (
+ <Drawer
+ variant="persistent"
+ anchor="left"
+ open={samplesDrawerOpen}
+ sx={{
+ width: samplesDrawerOpen ? SAMPLES_DRAWER_WIDTH : 0,
+ }}
+ >
+ <Box width={SAMPLES_DRAWER_WIDTH}>
+ <Button onClick={() => select('one-time-password')}>one-time-password</Button>
+ <Button onClick={() => select('order-ecomerce')}>order-ecomerce</Button>
+ <Button onClick={() => select('post-metrics-report')}>post-metrics-report</Button>
+ <Button onClick={() => select('reservation-reminder')}>reservation-reminder</Button>
+ <Button onClick={() => select('reset-password')}>reset-password</Button>
+ <Button onClick={() => select('respond-to-message')}>respond-to-message</Button>
+ <Button onClick={() => select('subscription-receipt')}>subscription-receipt</Button>
+ </Box>
+ </Drawer>
+ );
+}
diff --git a/packages/editor-sample/src/App/panels/HtmlPanel.tsx b/packages/editor-sample/src/App/TemplatePanel/HtmlPanel.tsx
similarity index 100%
rename from packages/editor-sample/src/App/panels/HtmlPanel.tsx
rename to packages/editor-sample/src/App/TemplatePanel/HtmlPanel.tsx
diff --git a/packages/editor-sample/src/App/ShareButton.tsx b/packages/editor-sample/src/App/TemplatePanel/ShareButton.tsx
similarity index 93%
rename from packages/editor-sample/src/App/ShareButton.tsx
rename to packages/editor-sample/src/App/TemplatePanel/ShareButton.tsx
index e470d95..0b67e99 100644
--- a/packages/editor-sample/src/App/ShareButton.tsx
+++ b/packages/editor-sample/src/App/TemplatePanel/ShareButton.tsx
@@ -2,7 +2,7 @@ import React, { useState } from 'react';
import { Button, Snackbar } from '@mui/material';
-import { useEditorState } from '../documents/editor/EditorContext';
+import { useEditorState } from '../../documents/editor/EditorContext';
export default function ShareButton() {
const [{ document }] = useEditorState();
diff --git a/packages/editor-sample/src/App/TemplatePanel/index.tsx b/packages/editor-sample/src/App/TemplatePanel/index.tsx
new file mode 100644
index 0000000..edb4a95
--- /dev/null
+++ b/packages/editor-sample/src/App/TemplatePanel/index.tsx
@@ -0,0 +1,62 @@
+import React from 'react';
+
+import { Box, Stack, Tab, Tabs } from '@mui/material';
+
+import EditorBlock from '../../documents/editor/EditorBlock';
+import { useEditorState } from '../../documents/editor/EditorContext';
+import ReaderBlock from '../../documents/reader/ReaderBlock';
+import { ReaderProvider } from '../../documents/reader/ReaderContext';
+import ToggleInspectorPanelButton from '../InspectorDrawer/ToggleInspectorPanelButton';
+import ToggleSamplesPanelButton from '../SamplesDrawer/ToggleSamplesPanelButton';
+
+import HtmlPanel from './HtmlPanel';
+import ShareButton from './ShareButton';
+
+export default function TemplatePanel() {
+ const [{ document, selectedMainTab }, setEditorState] = useEditorState();
+
+ const renderMainPanel = () => {
+ switch (selectedMainTab) {
+ case 'editor':
+ return <EditorBlock id="root" />;
+ case 'preview':
+ return (
+ <ReaderProvider value={document}>
+ <ReaderBlock id="root" />
+ </ReaderProvider>
+ );
+ case 'html':
+ return <HtmlPanel />;
+ case 'data':
+ return (
+ <Box p={3}>
+ <pre>{JSON.stringify(document, null, ' ')}</pre>
+ </Box>
+ );
+ }
+ };
+
+ return (
+ <>
+ <Stack
+ sx={{ height: 49, borderBottom: 1, borderColor: 'divider', backgroundColor: 'white' }}
+ direction="row"
+ justifyContent="space-between"
+ alignItems="center"
+ >
+ <ToggleSamplesPanelButton />
+ <Tabs value={selectedMainTab} onChange={(_, v) => setEditorState({ selectedMainTab: v })}>
+ <Tab value="editor" label="Edit" />
+ <Tab value="preview" label="Preview" />
+ <Tab value="html" label="HTML" />
+ <Tab value="data" label="JSON" />
+ </Tabs>
+ <Box pr={3}>
+ <ShareButton />
+ <ToggleInspectorPanelButton />
+ </Box>
+ </Stack>
+ <Box sx={{ height: 'calc(100% - 49px)', overflow: 'auto' }}>{renderMainPanel()}</Box>
+ </>
+ );
+}
diff --git a/packages/editor-sample/src/App/index.tsx b/packages/editor-sample/src/App/index.tsx
index 311b3e7..16d80f7 100644
--- a/packages/editor-sample/src/App/index.tsx
+++ b/packages/editor-sample/src/App/index.tsx
@@ -1,83 +1,45 @@
import React from 'react';
-import { Box, Grid, Stack, Tab, Tabs } from '@mui/material';
+import { Stack, useTheme } from '@mui/material';
-import EditorBlock from '../documents/editor/EditorBlock';
import { useEditorState } from '../documents/editor/EditorContext';
-import ReaderBlock from '../documents/reader/ReaderBlock';
-import { ReaderProvider } from '../documents/reader/ReaderContext';
-import ExamplesButton from './ExamplesButton';
-import HtmlPanel from './panels/HtmlPanel';
-import ShareButton from './ShareButton';
-import ConfigurationPanel from './sidebar/ConfigurationPanel';
-import StylesPanel from './sidebar/StylesPanel';
+import InspectorDrawer, { INSPECTOR_DRAWER_WIDTH } from './InspectorDrawer';
+import SamplesDrawer, { SAMPLES_DRAWER_WIDTH } from './SamplesDrawer';
+import TemplatePanel from './TemplatePanel';
export default function App() {
- const [{ document, selectedSidebarTab, selectedMainTab }, setEditorState] = useEditorState();
-
- const renderCurrentSidebarPanel = () => {
- switch (selectedSidebarTab) {
- case 'block-configuration':
- return <ConfigurationPanel />;
- case 'styles':
- return <StylesPanel />;
- }
- };
- const renderMainPanel = () => {
- switch (selectedMainTab) {
- case 'editor':
- return <EditorBlock id="root" />;
- case 'preview':
- return (
- <ReaderProvider value={document}>
- <ReaderBlock id="root" />
- </ReaderProvider>
- );
- case 'html':
- return <HtmlPanel />;
- case 'data':
- return (
- <Box p={3}>
- <pre>{JSON.stringify(document, null, ' ')}</pre>
- </Box>
- );
- }
- };
+ const theme = useTheme();
+ const [{ inspectorDrawerOpen, samplesDrawerOpen }] = useEditorState();
return (
- <Grid container height="100%">
- <Grid item xs={6} sm={6} md="auto" sx={{ height: '100%', backgroundColor: 'white' }}>
- <Box sx={{ height: 49, width: 400, borderBottom: 1, borderColor: 'divider' }}>
- <Box px={2}>
- <Tabs value={selectedSidebarTab} onChange={(_, v) => setEditorState({ selectedSidebarTab: v })}>
- <Tab value="styles" label="Styles" />
- <Tab value="block-configuration" label="Inspect" />
- </Tabs>
- </Box>
- </Box>
- <Box sx={{ height: 'calc(100% - 49px)', overflow: 'auto' }}>{renderCurrentSidebarPanel()}</Box>
- </Grid>
- <Grid item xs height="100%" padding={0} margin={0} sx={{ overflowY: 'auto' }}>
- <Stack
- sx={{ height: 49, borderBottom: 1, borderColor: 'divider', backgroundColor: 'white' }}
- direction="row"
- justifyContent="space-between"
- alignItems="center"
- >
- <Tabs value={selectedMainTab} onChange={(_, v) => setEditorState({ selectedMainTab: v })}>
- <Tab value="editor" label="Edit" />
- <Tab value="preview" label="Preview" />
- <Tab value="html" label="HTML" />
- <Tab value="data" label="JSON" />
- </Tabs>
- <Box pr={3}>
- <ExamplesButton />
- <ShareButton />
- </Box>
- </Stack>
- <Box sx={{ height: 'calc(100% - 49px)', overflow: 'auto' }}>{renderMainPanel()}</Box>
- </Grid>
- </Grid>
+ <>
+ <InspectorDrawer />
+ <SamplesDrawer />
+
+ <Stack
+ sx={{
+ marginRight: inspectorDrawerOpen ? `${INSPECTOR_DRAWER_WIDTH}px` : 0,
+ marginLeft: samplesDrawerOpen ? `${SAMPLES_DRAWER_WIDTH}px` : 0,
+
+ transition: [
+ theme.transitions.create('margin-left', {
+ easing: !samplesDrawerOpen ? theme.transitions.easing.sharp : theme.transitions.easing.easeOut,
+ duration: !samplesDrawerOpen
+ ? theme.transitions.duration.leavingScreen
+ : theme.transitions.duration.enteringScreen,
+ }),
+ theme.transitions.create('margin-right', {
+ easing: !inspectorDrawerOpen ? theme.transitions.easing.sharp : theme.transitions.easing.easeOut,
+ duration: !inspectorDrawerOpen
+ ? theme.transitions.duration.leavingScreen
+ : theme.transitions.duration.enteringScreen,
+ }),
+ ].join(', '),
+ }}
+ >
+ <TemplatePanel />
+ </Stack>
+ </>
);
}
diff --git a/packages/editor-sample/src/documents/blocks/Container/ContainerPropsSchema.tsx b/packages/editor-sample/src/documents/blocks/Container/ContainerPropsSchema.tsx
new file mode 100644
index 0000000..212ff6d
--- /dev/null
+++ b/packages/editor-sample/src/documents/blocks/Container/ContainerPropsSchema.tsx
@@ -0,0 +1,22 @@
+import { z } from 'zod';
+
+import { zColor, zPadding } from '../helpers/zod';
+
+export const ContainerPropsSchema = z.object({
+ style: z
+ .object({
+ backgroundColor: zColor().nullable().default(null),
+ borderColor: zColor().optional().nullable().default(null),
+ borderRadius: z.number().optional().nullable().default(0),
+ padding: zPadding().optional().default({
+ top: 16,
+ bottom: 16,
+ left: 24,
+ right: 24,
+ }),
+ })
+ .default({}),
+ props: z.object({
+ childrenIds: z.array(z.string()),
+ }),
+});
diff --git a/packages/editor-sample/src/documents/blocks/Container.tsx b/packages/editor-sample/src/documents/blocks/Container/index.tsx
similarity index 61%
rename from packages/editor-sample/src/documents/blocks/Container.tsx
rename to packages/editor-sample/src/documents/blocks/Container/index.tsx
index ab93065..2490305 100644
--- a/packages/editor-sample/src/documents/blocks/Container.tsx
+++ b/packages/editor-sample/src/documents/blocks/Container/index.tsx
@@ -1,32 +1,13 @@
import React from 'react';
import { z } from 'zod';
-import { TEditorBlock } from '../editor/core';
-import { useCurrentBlockId } from '../editor/EditorBlock';
-import { useEditorState } from '../editor/EditorContext';
-import ReaderBlock from '../reader/ReaderBlock';
+import { TEditorBlock } from '../../editor/core';
+import { useCurrentBlockId } from '../../editor/EditorBlock';
+import { useEditorState } from '../../editor/EditorContext';
+import ReaderBlock from '../../reader/ReaderBlock';
+import EditorChildrenIds from '../helpers/EditorChildrenIds';
-import EditorChildrenIds from './helpers/EditorChildrenIds';
-import { zColor, zPadding } from './helpers/zod';
-
-export const ContainerPropsSchema = z.object({
- style: z
- .object({
- backgroundColor: zColor().nullable().default(null),
- borderColor: zColor().optional().nullable().default(null),
- borderRadius: z.number().optional().nullable().default(0),
- padding: zPadding().optional().default({
- top: 16,
- bottom: 16,
- left: 24,
- right: 24,
- }),
- })
- .default({}),
- props: z.object({
- childrenIds: z.array(z.string()),
- }),
-});
+import { ContainerPropsSchema } from './ContainerPropsSchema';
export type ContainerProps = z.infer<typeof ContainerPropsSchema>;
diff --git a/packages/editor-sample/src/documents/blocks/EmailLayout/EmailLayoutPropsSchema.tsx b/packages/editor-sample/src/documents/blocks/EmailLayout/EmailLayoutPropsSchema.tsx
new file mode 100644
index 0000000..d3e7fdf
--- /dev/null
+++ b/packages/editor-sample/src/documents/blocks/EmailLayout/EmailLayoutPropsSchema.tsx
@@ -0,0 +1,11 @@
+import { z } from 'zod';
+
+import { zColor, zFontFamily } from '../helpers/zod';
+
+export const EmailLayoutPropsSchema = z.object({
+ backdropColor: zColor(),
+ canvasColor: zColor(),
+ textColor: zColor(),
+ fontFamily: zFontFamily().default('MODERN_SANS'),
+ childrenIds: z.array(z.string()),
+});
diff --git a/packages/editor-sample/src/documents/blocks/EmailLayout.tsx b/packages/editor-sample/src/documents/blocks/EmailLayout/index.tsx
similarity index 86%
rename from packages/editor-sample/src/documents/blocks/EmailLayout.tsx
rename to packages/editor-sample/src/documents/blocks/EmailLayout/index.tsx
index 0c53183..3a06ccf 100644
--- a/packages/editor-sample/src/documents/blocks/EmailLayout.tsx
+++ b/packages/editor-sample/src/documents/blocks/EmailLayout/index.tsx
@@ -1,13 +1,13 @@
import React, { CSSProperties } from 'react';
import { z } from 'zod';
-import { TEditorBlock } from '../editor/core';
-import { useCurrentBlockId } from '../editor/EditorBlock';
-import { useEditorState } from '../editor/EditorContext';
-import ReaderBlock from '../reader/ReaderBlock';
+import { TEditorBlock } from '../../editor/core';
+import { useCurrentBlockId } from '../../editor/EditorBlock';
+import { useEditorState } from '../../editor/EditorContext';
+import ReaderBlock from '../../reader/ReaderBlock';
+import EditorChildrenIds from '../helpers/EditorChildrenIds';
-import EditorChildrenIds from './helpers/EditorChildrenIds';
-import { zColor, zFontFamily } from './helpers/zod';
+import { EmailLayoutPropsSchema } from './EmailLayoutPropsSchema';
// Based on https://modernfontstacks.com/#font-stacks
const FONT_FAMILY_MAPPINGS = {
@@ -24,14 +24,6 @@ const FONT_FAMILY_MAPPINGS = {
MONOSPACE: '"Nimbus Mono PS", "Courier New", "Cutive Mono", monospace',
};
-export const EmailLayoutPropsSchema = z.object({
- backdropColor: zColor(),
- canvasColor: zColor(),
- textColor: zColor(),
- fontFamily: zFontFamily().default('MODERN_SANS'),
- childrenIds: z.array(z.string()),
-});
-
export type EmailLayoutProps = z.infer<typeof EmailLayoutPropsSchema>;
export function EmailLayout(props: EmailLayoutProps) {
diff --git a/packages/editor-sample/src/documents/blocks/helpers/EditorChildrenIds/AddBlockMenu/buttons.tsx b/packages/editor-sample/src/documents/blocks/helpers/EditorChildrenIds/AddBlockMenu/buttons.tsx
index b543871..344ac18 100644
--- a/packages/editor-sample/src/documents/blocks/helpers/EditorChildrenIds/AddBlockMenu/buttons.tsx
+++ b/packages/editor-sample/src/documents/blocks/helpers/EditorChildrenIds/AddBlockMenu/buttons.tsx
@@ -19,7 +19,7 @@ import { TEditorBlock } from '../../../../editor/core';
import { AvatarPropsSchema } from '../../../Avatar';
import { ButtonPropsSchema } from '../../../Button';
import ColumnsContainerPropsSchema from '../../../ColumnsContainer/ColumnsContainerPropsSchema';
-import { ContainerPropsSchema } from '../../../Container';
+import { ContainerPropsSchema } from '../../../Container/ContainerPropsSchema';
import { DividerPropsSchema } from '../../../Divider';
import { HtmlPropsSchema } from '../../../Html';
import { ImagePropsSchema } from '../../../Image';
diff --git a/packages/editor-sample/src/documents/editor/EditorContext.tsx b/packages/editor-sample/src/documents/editor/EditorContext.tsx
index 10e623c..db6adc0 100644
--- a/packages/editor-sample/src/documents/editor/EditorContext.tsx
+++ b/packages/editor-sample/src/documents/editor/EditorContext.tsx
@@ -8,6 +8,9 @@ type TValue = {
selectedBlockId: string | null;
selectedSidebarTab: 'block-configuration' | 'styles';
selectedMainTab: 'editor' | 'preview' | 'data' | 'html';
+
+ inspectorDrawerOpen: boolean;
+ samplesDrawerOpen: boolean;
};
type TEditorContextState = [state: TValue, setState: (v: Partial<TValue>) => void];
@@ -16,6 +19,9 @@ const DEFAULT_STATE: TValue = {
selectedBlockId: null,
selectedSidebarTab: 'styles',
selectedMainTab: 'editor',
+
+ inspectorDrawerOpen: false,
+ samplesDrawerOpen: false,
};
const EditorContext = createContext<TEditorContextState>([DEFAULT_STATE, () => {}]);
@@ -29,10 +35,8 @@ type EditorProviderProps = {
};
export function EditorProvider({ defaultValue, children }: EditorProviderProps) {
const [state, setState] = useState<TValue>(() => ({
+ ...DEFAULT_STATE,
document: defaultValue,
- selectedBlockId: null,
- selectedSidebarTab: 'styles',
- selectedMainTab: 'editor',
}));
const value = useMemo<TEditorContextState>(
() => [
diff --git a/packages/editor-sample/src/documents/editor/core.tsx b/packages/editor-sample/src/documents/editor/core.tsx
index 4c712c3..f01c0d2 100644
--- a/packages/editor-sample/src/documents/editor/core.tsx
+++ b/packages/editor-sample/src/documents/editor/core.tsx
@@ -9,9 +9,11 @@ import { Avatar, AvatarPropsSchema } from '../blocks/Avatar';
import { Button, ButtonPropsSchema } from '../blocks/Button';
import { EditorColumnsContainer } from '../blocks/ColumnsContainer';
import ColumnsContainerPropsSchema from '../blocks/ColumnsContainer/ColumnsContainerPropsSchema';
-import { ContainerPropsSchema, EditorContainer } from '../blocks/Container';
+import { EditorContainer } from '../blocks/Container';
+import { ContainerPropsSchema } from '../blocks/Container/ContainerPropsSchema';
import { Divider, DividerPropsSchema } from '../blocks/Divider';
-import { EditorEmailLayout, EmailLayoutProps, EmailLayoutPropsSchema } from '../blocks/EmailLayout';
+import { EditorEmailLayout, EmailLayoutProps } from '../blocks/EmailLayout';
+import { EmailLayoutPropsSchema } from '../blocks/EmailLayout/EmailLayoutPropsSchema';
import { addEditorBlockWrapper } from '../blocks/helpers/block-wrappers';
import EditorBlockWrapper from '../blocks/helpers/block-wrappers/EditorBlockWrapper';
import { Html, HtmlPropsSchema } from '../blocks/Html';
diff --git a/packages/editor-sample/src/documents/reader/core.tsx b/packages/editor-sample/src/documents/reader/core.tsx
index 86ce504..839eb6f 100644
--- a/packages/editor-sample/src/documents/reader/core.tsx
+++ b/packages/editor-sample/src/documents/reader/core.tsx
@@ -8,9 +8,11 @@ import { Avatar, AvatarPropsSchema } from '../blocks/Avatar';
import { Button, ButtonPropsSchema } from '../blocks/Button';
import { ColumnsContainer } from '../blocks/ColumnsContainer';
import ColumnsContainerPropsSchema from '../blocks/ColumnsContainer/ColumnsContainerPropsSchema';
-import { Container, ContainerPropsSchema } from '../blocks/Container';
+import { Container } from '../blocks/Container';
+import { ContainerPropsSchema } from '../blocks/Container/ContainerPropsSchema';
import { Divider, DividerPropsSchema } from '../blocks/Divider';
-import { EmailLayout, EmailLayoutPropsSchema } from '../blocks/EmailLayout';
+import { EmailLayout } from '../blocks/EmailLayout';
+import { EmailLayoutPropsSchema } from '../blocks/EmailLayout/EmailLayoutPropsSchema';
import { addReaderBlockWrapper } from '../blocks/helpers/block-wrappers';
import { Html, HtmlPropsSchema } from '../blocks/Html';
import { Image, ImagePropsSchema } from '../blocks/Image';