Skip to content

Commit 809d288

Browse files
tupizzclaude
andcommitted
feat(examples): update getting-started examples to use @superdoc/react
- Update react example to use SuperDocEditor component - Remove manual lifecycle management (DocumentEditor.jsx) - Rename typescript example to react-typescript - Move react-wrapper example to getting-started/react-typescript Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent dfd522e commit 809d288

26 files changed

Lines changed: 54 additions & 469 deletions
File renamed without changes.
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
{
2-
"name": "react-wrapper-example",
2+
"name": "react-typescript-example",
33
"private": true,
44
"version": "0.0.1",
55
"type": "module",
66
"scripts": {
77
"dev": "vite"
88
},
99
"dependencies": {
10-
"@superdoc/react": "workspace:*",
11-
"react": "catalog:",
12-
"react-dom": "catalog:"
10+
"@superdoc/react": "*",
11+
"react": "^19.0.0",
12+
"react-dom": "^19.0.0"
1313
},
1414
"devDependencies": {
15+
"@types/react": "^19.0.0",
16+
"@types/react-dom": "^19.0.0",
1517
"@vitejs/plugin-react": "^4.0.4",
18+
"typescript": "^5.7.0",
1619
"vite": "^6.2.0"
1720
}
1821
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

examples/getting-started/react/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
"dev": "vite"
88
},
99
"dependencies": {
10+
"@superdoc/react": "*",
1011
"react": "^19.0.0",
11-
"react-dom": "^19.0.0",
12-
"styled-jsx": "^5.1.7",
13-
"superdoc": "0.20.0-next.13"
12+
"react-dom": "^19.0.0"
1413
},
1514
"devDependencies": {
1615
"@vitejs/plugin-react": "^4.0.4",

examples/getting-started/react/src/App.jsx

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { useRef, useState } from 'react';
2-
import DocumentEditor from './components/DocumentEditor';
2+
import { SuperDocEditor } from '@superdoc/react';
3+
import '@superdoc/react/style.css';
34

45
function App() {
56
const [documentFile, setDocumentFile] = useState(null);
67
const fileInputRef = useRef(null);
8+
const editorRef = useRef(null);
79

810
const handleFileChange = (event) => {
911
const file = event.target.files?.[0];
@@ -12,34 +14,53 @@ function App() {
1214
}
1315
};
1416

15-
const handleEditorReady = (editor) => {
16-
console.log('SuperDoc editor is ready', editor);
17+
const handleExport = async () => {
18+
await editorRef.current?.getInstance()?.export({ triggerDownload: true });
1719
};
1820

1921
return (
2022
<div className="app">
2123
<header>
22-
<h1>SuperDoc Example</h1>
24+
<h1>SuperDoc React Example</h1>
2325
<button onClick={() => fileInputRef.current?.click()}>
2426
Load Document
2527
</button>
2628
<input
2729
type="file"
2830
ref={fileInputRef}
29-
accept=".docx, application/vnd.openxmlformats-officedocument.wordprocessingml.document"
31+
accept=".docx"
3032
onChange={handleFileChange}
3133
style={{ display: 'none' }}
3234
/>
35+
{documentFile && (
36+
<button onClick={handleExport}>
37+
Export DOCX
38+
</button>
39+
)}
3340
</header>
3441

3542
<main>
36-
<DocumentEditor
37-
initialData={documentFile}
38-
onEditorReady={handleEditorReady}
39-
/>
43+
{documentFile ? (
44+
<SuperDocEditor
45+
ref={editorRef}
46+
document={documentFile}
47+
documentMode="editing"
48+
rulers
49+
onReady={({ superdoc }) => console.log('SuperDoc ready', superdoc)}
50+
onEditorCreate={({ editor }) => console.log('Editor created', editor)}
51+
renderLoading={() => (
52+
<div className="loading">Loading document...</div>
53+
)}
54+
style={{ height: '100%' }}
55+
/>
56+
) : (
57+
<div className="empty-state">
58+
<p>Click "Load Document" to open a .docx file</p>
59+
</div>
60+
)}
4061
</main>
4162

42-
<style jsx>{`
63+
<style>{`
4364
.app {
4465
height: 100vh;
4566
display: flex;
@@ -67,6 +88,20 @@ function App() {
6788
flex: 1;
6889
min-height: 0;
6990
}
91+
.empty-state {
92+
display: flex;
93+
align-items: center;
94+
justify-content: center;
95+
height: 100%;
96+
color: #666;
97+
}
98+
.loading {
99+
display: flex;
100+
align-items: center;
101+
justify-content: center;
102+
height: 100%;
103+
color: #666;
104+
}
70105
`}</style>
71106
</div>
72107
);

examples/getting-started/react/src/components/DocumentEditor.jsx

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)