Skip to content

Commit f154102

Browse files
committed
Added png loading example
1 parent 5d3c1e8 commit f154102

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

.storybook/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const config: StorybookConfig = {
1414
},
1515
docs: {
1616
autodocs: 'tag'
17-
}
17+
},
18+
staticDirs: ['../public']
1819
};
1920
export default config;

public/mydrawio.png

9.69 KB
Loading

stories/DiagramsEmbed.stories.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DrawIoEmbed } from '../src/DrawIoEmbed';
33
import { useEffect, useRef, useState } from 'react';
44
import { DrawIoEmbedRef } from '../src/types';
55
import React from 'react';
6+
import { useRemoteFile } from './hooks/useRemoteFile';
67

78
const meta: Meta<typeof DrawIoEmbed> = {
89
title: 'Components/DrawIoEmbed',
@@ -49,6 +50,21 @@ export const WithData: Story = {
4950
}
5051
};
5152

53+
export const WithRemotePng: Story = {
54+
decorators: [
55+
(Story) => {
56+
const { inputXml, urlToBase64 } = useRemoteFile();
57+
58+
useEffect(() => {
59+
urlToBase64('/mydrawio.png');
60+
}, []);
61+
62+
return <Story args={{ xml: inputXml }} />;
63+
}
64+
],
65+
args: {}
66+
};
67+
5268
export const WithConfigurations: Story = {
5369
args: {
5470
xml: '<mxfile host="embed.diagrams.net" modified="2023-08-27T13:33:23.800Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" version="21.6.9" etag="xthbfrarG6SmZwCYJPbt" type="embed"><diagram id="kaqXdMjmixOsNJA9w4jU" name="Page-1"><mxGraphModel dx="314" dy="361" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0"><root><mxCell id="0" /><mxCell id="1" parent="0" /><mxCell id="2" value="" style="shape=cube;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;darkOpacity=0.05;darkOpacity2=0.1;fillColor=#99FFFF;strokeColor=#0066CC;" vertex="1" parent="1"><mxGeometry x="110" y="150" width="120" height="80" as="geometry" /></mxCell></root></mxGraphModel></diagram></mxfile>',

stories/hooks/useRemoteFile.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { useState } from 'react';
2+
3+
export const useRemoteFile = () => {
4+
const [inputXml, setInputXml] = useState<string>('');
5+
6+
const urlToBase64 = async (url: string) => {
7+
const data = await fetch(url);
8+
9+
console.log(data);
10+
11+
if (data) {
12+
const blob = await data.blob();
13+
14+
const reader = new FileReader();
15+
reader.readAsDataURL(blob);
16+
reader.onloadend = () => {
17+
const base64data = reader.result;
18+
19+
setInputXml(base64data as string);
20+
};
21+
}
22+
};
23+
24+
return {
25+
inputXml,
26+
urlToBase64
27+
};
28+
};

0 commit comments

Comments
 (0)