import React, { useReducer, useEffect, useCallback, useState } from 'react';
import ReactDOM from 'react-dom';
import 'react-grid-layout/css/styles.css';
import 'react-resizable/css/styles.css';
import './index.css';
import VitessceGrid from '../../src';
/*
After installing from NPM, you'll use "from 'vitessce-grid'" instead.
*/
import layoutBlue from './layoutBlue.json';
import layoutRed from "./layoutRed.json";
/*
The layout could be represented in JSON, unless you need to provide function props.
*/
const handleClass = 'demo-handle';
function Block(props) {
const { text, onReady, removeGridComponent } = props;
const onReadyCallback = useCallback(onReady, []);
useEffect(() => {
onReadyCallback();
}, [onReadyCallback]);
/*
onReady is useful when we want the VitessceGrid parent to be able to send
onAllReady when the children are ready; What "ready" actually means
will depend on your code: It could just be didComponentMount, or we might
need to wait for outside resources.
*/
return (
/*
You may want to use a stylesheet, but for a demo this is more clear.
*/
<>
drag-me
{text}
>
);
}
function BlockBlue(props){
return (
);
}
function BlockRed(props) {
return (
);
}
function getComponent(name) {
/*
One interesting possibility here is to defer loading:
Tree shaking might be able to reduce the size of the main download.
registry = {
MyComponent: React.lazy(() => import('./BloatedOptionalComponent.js')),
}
*/
const registry = { BlockBlue, BlockRed };
return registry[name];
}
function Demo() {
const fixedHeight = 600;
const [isExpanded, toggleIsExpanded] = useReducer(v => !v, false);
const [currLayout, toggleLayout] = useReducer(v => (v === layoutBlue ? layoutRed : layoutBlue), layoutBlue);
return (
{
console.warn('onAllReady!');
}}
reactGridLayoutProps={{
/*
Use this to pass through to react-grid-layout.
See https://github.com/STRML/react-grid-layout#grid-layout-props
*/
onDragStop: () => { console.warn('Wrapped onDragStop works!'); },
}}
/>