/* eslint-disable react-perf/jsx-no-new-object-as-prop */ import { useCallback, useState } from 'react'; import { createElements, createLinks, GraphProvider, MeasuredNode, Paper, usePaper, type GraphProps, type InferElement, } from '@joint/react'; import '../../examples/index.css'; import { BUTTON_CLASSNAME } from 'storybook-config/theme'; // Define initial elements const initialElements = createElements([ { id: '1', data: { label: 'Hello' }, x: 100, y: 0, width: 100, height: 25 }, { id: '2', data: { label: 'World' }, x: 100, y: 200, width: 100, height: 25 }, ]); // Define initial edges const initialEdges = createLinks([ { id: 'e1-2', source: '1', target: '2', type: 'standard.Link', // If you define type, it provides intellisense support attrs: { line: { stroke: '#3498db', // Primary color strokeWidth: 2, }, }, }, ]); let zoomLevel = 1; function Controls() { const paper = usePaper(); return (
); } function Main() { const [isHTMLEnabled, setHTMLEnabled] = useState(true); // Infer element type from the initial elements type CustomElement = InferElement; const renderItem = useCallback( ({ data: { label }, width, height }: CustomElement) => { if (isHTMLEnabled) { return (
{label}
); } return ; }, [isHTMLEnabled] ); return ( ); } export default function App(props: Readonly) { return (
); }