Skip to content

Commit 9342ada

Browse files
authored
Added types for more 'export' parameters (#22)
1 parent 29d1d9e commit 9342ada

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 0.1.8
2+
- Added types for more `export` parameters
3+
14
# 0.1.7
25
- Added `parentEvent` parameters to `onSave` and `onClose` events when the callbacks are triggered by another event.
36

src/types.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,28 @@ export type ActionExport = {
239239
message?: string;
240240
xml?: string;
241241
parentEvent?: string;
242+
/** Enable a spinner while the image is being generated */
243+
spin?: boolean;
244+
/** Specify the zoom (default is 1) */
245+
scale?: number;
246+
/** Define the array of visible layer IDs */
247+
layerIds?: string[];
248+
/** Specify the page to be exported */
249+
pageId?: string;
250+
/** Specify to export the current selected page */
251+
currentPage?: boolean;
252+
/** (px) Defines the width of the image to be exported */
253+
width?: string;
254+
/** (px) Defines the border */
255+
border?: string;
256+
/** Specifies if a shadow filter should be applied to the export */
257+
shadow?: boolean;
258+
/** Specifies if a grid should be added */
259+
grid?: boolean;
260+
/** Specifies if the theme should be kept (eg. for dark themes) */
261+
keepTheme?: boolean;
262+
/** Specifies if a transparent background should be used */
263+
transparent?: boolean;
264+
/** Specifies the background color */
265+
background?: string;
242266
};

stories/DiagramsEmbed.stories.tsx

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export const SetSpinner: Story = {
252252
]
253253
};
254254

255-
export const ExportData: Story = {
255+
export const ExportDataSvg: Story = {
256256
args: WithData.args,
257257
decorators: [
258258
(Story, context) => {
@@ -298,6 +298,58 @@ export const ExportData: Story = {
298298
]
299299
};
300300

301+
export const ExportDataPng: Story = {
302+
args: WithData.args,
303+
decorators: [
304+
(Story, context) => {
305+
const [isLoaded, setIsLoaded] = useState(false);
306+
const [imgData, setImgData] = useState<string | null>(null);
307+
const drawioRef = useRef<DrawIoEmbedRef>(null);
308+
309+
useEffect(() => {
310+
if (drawioRef.current && isLoaded) {
311+
drawioRef.current.exportDiagram({
312+
format: 'png',
313+
transparent: false,
314+
grid: true,
315+
scale: 1.5,
316+
shadow: true
317+
});
318+
}
319+
}, [drawioRef.current, isLoaded]);
320+
321+
return (
322+
<>
323+
<Story
324+
args={{
325+
...context.args,
326+
onLoad: () => setIsLoaded(true),
327+
onExport(data) {
328+
console.log('onExport', data);
329+
setImgData(data.data);
330+
},
331+
onSave(data) {
332+
console.log('onSave', data);
333+
},
334+
onClose(data) {
335+
console.log('onClose', data);
336+
},
337+
ref: drawioRef
338+
}}
339+
/>
340+
<div style={{ marginTop: '10px' }}>
341+
<strong>Result as transparent PNG (with extra options)</strong>
342+
<br />
343+
<div style={{ backgroundColor: '#DDD' }}>
344+
{imgData && <img src={imgData} />}
345+
</div>
346+
</div>
347+
</>
348+
);
349+
}
350+
]
351+
};
352+
301353
export const NoSaveAndExit: Story = {
302354
args: {
303355
urlParameters: {

0 commit comments

Comments
 (0)