refactor: Make the example React app reusable without duplication (#6188)
@ -80,7 +80,13 @@ const COMMENT_ICON_DIMENSION = 32;
|
|||||||
const COMMENT_INPUT_HEIGHT = 50;
|
const COMMENT_INPUT_HEIGHT = 50;
|
||||||
const COMMENT_INPUT_WIDTH = 150;
|
const COMMENT_INPUT_WIDTH = 150;
|
||||||
|
|
||||||
export default function App() {
|
export interface AppProps {
|
||||||
|
appTitle: string;
|
||||||
|
useCustom: (api: ExcalidrawImperativeAPI | null, customArgs?: any[]) => void;
|
||||||
|
customArgs?: any[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function App({ appTitle, useCustom, customArgs }: AppProps) {
|
||||||
const appRef = useRef<any>(null);
|
const appRef = useRef<any>(null);
|
||||||
const [viewModeEnabled, setViewModeEnabled] = useState(false);
|
const [viewModeEnabled, setViewModeEnabled] = useState(false);
|
||||||
const [zenModeEnabled, setZenModeEnabled] = useState(false);
|
const [zenModeEnabled, setZenModeEnabled] = useState(false);
|
||||||
@ -107,6 +113,8 @@ export default function App() {
|
|||||||
const [excalidrawAPI, setExcalidrawAPI] =
|
const [excalidrawAPI, setExcalidrawAPI] =
|
||||||
useState<ExcalidrawImperativeAPI | null>(null);
|
useState<ExcalidrawImperativeAPI | null>(null);
|
||||||
|
|
||||||
|
useCustom(excalidrawAPI, customArgs);
|
||||||
|
|
||||||
useHandleLibrary({ excalidrawAPI });
|
useHandleLibrary({ excalidrawAPI });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -114,7 +122,7 @@ export default function App() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
const res = await fetch("/rocket.jpeg");
|
const res = await fetch("/images/rocket.jpeg");
|
||||||
const imageData = await res.blob();
|
const imageData = await res.blob();
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.readAsDataURL(imageData);
|
reader.readAsDataURL(imageData);
|
||||||
@ -150,7 +158,7 @@ export default function App() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<button
|
<button
|
||||||
onClick={() => alert("This is dummy top right UI")}
|
onClick={() => alert("This is an empty top right UI")}
|
||||||
style={{ height: "2.5rem" }}
|
style={{ height: "2.5rem" }}
|
||||||
>
|
>
|
||||||
{" "}
|
{" "}
|
||||||
@ -397,7 +405,7 @@ export default function App() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="comment-avatar">
|
<div className="comment-avatar">
|
||||||
<img src="doremon.png" alt="doremon" />
|
<img src="images/doremon.png" alt="doremon" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -525,7 +533,7 @@ export default function App() {
|
|||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div className="App" ref={appRef}>
|
<div className="App" ref={appRef}>
|
||||||
<h1> Excalidraw Example</h1>
|
<h1>{appTitle}</h1>
|
||||||
<ExampleSidebar>
|
<ExampleSidebar>
|
||||||
<div className="button-wrapper">
|
<div className="button-wrapper">
|
||||||
<button onClick={loadSceneOrLibrary}>Load Scene or Library</button>
|
<button onClick={loadSceneOrLibrary}>Load Scene or Library</button>
|
||||||
@ -611,15 +619,15 @@ export default function App() {
|
|||||||
const collaborators = new Map();
|
const collaborators = new Map();
|
||||||
collaborators.set("id1", {
|
collaborators.set("id1", {
|
||||||
username: "Doremon",
|
username: "Doremon",
|
||||||
avatarUrl: "doremon.png",
|
avatarUrl: "images/doremon.png",
|
||||||
});
|
});
|
||||||
collaborators.set("id2", {
|
collaborators.set("id2", {
|
||||||
username: "Excalibot",
|
username: "Excalibot",
|
||||||
avatarUrl: "excalibot.png",
|
avatarUrl: "images/excalibot.png",
|
||||||
});
|
});
|
||||||
collaborators.set("id3", {
|
collaborators.set("id3", {
|
||||||
username: "Pika",
|
username: "Pika",
|
||||||
avatarUrl: "pika.jpeg",
|
avatarUrl: "images/pika.jpeg",
|
||||||
});
|
});
|
||||||
collaborators.set("id4", {
|
collaborators.set("id4", {
|
||||||
username: "fallback",
|
username: "fallback",
|
||||||
|
@ -8,6 +8,9 @@ const root = createRoot(rootElement);
|
|||||||
|
|
||||||
root.render(
|
root.render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
<App />
|
<App
|
||||||
|
appTitle={"Excalidraw Example"}
|
||||||
|
useCustom={(api: any, args?: any[]) => {}}
|
||||||
|
/>
|
||||||
</StrictMode>,
|
</StrictMode>,
|
||||||
);
|
);
|
||||||
|
Before Width: | Height: | Size: 197 KiB After Width: | Height: | Size: 197 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
@ -10,8 +10,8 @@ export default function Sidebar({ children }: { children: React.ReactNode }) {
|
|||||||
x
|
x
|
||||||
</button>
|
</button>
|
||||||
<div className="sidebar-links">
|
<div className="sidebar-links">
|
||||||
<button>Dummy Home</button>
|
<button>Empty Home</button>
|
||||||
<button>Dummy About</button>{" "}
|
<button>Empty About</button>{" "}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={`${open ? "sidebar-open" : ""}`}>
|
<div className={`${open ? "sidebar-open" : ""}`}>
|
||||||
|