UNPKG

@datalayer/core

Version:
45 lines (44 loc) 1.76 kB
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; /* * Copyright (c) 2023-2025 Datalayer, Inc. * Distributed under the terms of the Modified BSD License. */ import { useEffect } from "react"; import { Box } from "@primer/react"; import { useScreenshot, useToast } from '..'; import { lazyWithPreload, WithSuspense } from "../../utils"; import { useLayoutStore } from '../../state'; import './LayoutScreenshot.css'; const ScreenCapture = WithSuspense(lazyWithPreload(() => import("../../components/screenshot/ScreenCapture"))); const Capture = (props) => { const { onStartCapture } = props; useEffect(() => { onStartCapture(); }, []); return _jsx(_Fragment, {}); }; const ScreenshotContent = (props) => { // const { screenshotDisplay } = props; const { enqueueToast } = useToast(); const { setScreenCapture, hideScreenshot } = useLayoutStore(); const handleScreenCapture = (screenCapture) => { setScreenCapture(screenCapture); hideScreenshot(); enqueueToast('Screen is captured.', { variant: 'success' }); }; return (_jsx(Box, { children: _jsx(ScreenCapture, { onEndCapture: handleScreenCapture, children: ({ onStartCapture }) => (_jsx(Capture, { onStartCapture: onStartCapture })) }) })); }; export const LayoutScreenshot = () => { const { screenshot } = useLayoutStore(); const { displayScreenshot, closeScreenshot } = useScreenshot(); useEffect(() => { if (screenshot && screenshot.open) { displayScreenshot(() => _jsx(ScreenshotContent, { screenshotDisplay: screenshot })); } else { closeScreenshot(); } }, [screenshot]); return _jsx(_Fragment, {}); }; export default LayoutScreenshot;