forked from zakodium-oss/react-ocl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcanvas-editor.stories.tsx
More file actions
57 lines (53 loc) · 1.66 KB
/
canvas-editor.stories.tsx
File metadata and controls
57 lines (53 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import {useCallback, useState} from 'react';
import CanvasEditor from '../src/components/CanvasEditor.js';
import type {Molecule} from "openchemlib/full";
export default {
title: 'CanvasEditor',
component: CanvasEditor,
args: {
mode: "molecule",
fragment: false,
width: 675,
height: 450,
},
parameters: {
docs: {
description: {
component: 'StructureEditor is an uncontrolled component.',
},
},
},
};
const initialIDCode = 'gJX@@eKU@@ gFp@DiTt@@@!gGQHDHaImfh@##!B_vp@[G|S@AL !BmpJH@ox@?`BH?@ !Bb@K~@Hc}b@JH?P';
export function TheCanvasEditor()
{
const [idCode, setIDCode] = useState(initialIDCode);
const [previous, setPrevious] = useState<string | null>(null);
const cb = useCallback(
(molfile: string | null, molecule: Molecule | null, newIDCode: string | null) => {
if (!newIDCode) {
setIDCode("");
} else {
setIDCode(newIDCode);
}
setPrevious(idCode);
},
[setIDCode, setPrevious, idCode],
);
return (
<div>
<h2>Editor</h2>
<CanvasEditor initialIDCode={idCode} onChange={cb} mode={"molecule"}/>
<div style={{display: 'flex'}}>
<div style={{flex: 1}}>
<h2 style={{textAlign: 'center'}}>Current</h2>
<pre>{idCode}</pre>
</div>
<div style={{flex: 1}}>
<h2 style={{textAlign: 'center'}}>Previous</h2>
<pre>{previous}</pre>
</div>
</div>
</div>
);
}