Adds react tests, build tsconfigs
This commit is contained in:
parent
af159655e3
commit
b8f410b752
82 changed files with 588 additions and 165 deletions
64
packages/core/src/components/renderer/renderer.tsx
Normal file
64
packages/core/src/components/renderer/renderer.tsx
Normal file
|
@ -0,0 +1,64 @@
|
|||
import * as React from 'react'
|
||||
import type {
|
||||
TLShape,
|
||||
TLPage,
|
||||
TLPageState,
|
||||
TLSettings,
|
||||
TLCallbacks,
|
||||
TLShapeUtils,
|
||||
TLTheme,
|
||||
TLBounds,
|
||||
TLBinding,
|
||||
} from '../../types'
|
||||
import { Canvas } from '../canvas'
|
||||
import { useTLTheme, TLContext } from '../../hooks'
|
||||
|
||||
export interface RendererProps<T extends TLShape>
|
||||
extends Partial<TLSettings>,
|
||||
Partial<TLCallbacks> {
|
||||
shapeUtils: TLShapeUtils<T>
|
||||
page: TLPage<T, TLBinding>
|
||||
pageState: TLPageState
|
||||
theme?: Partial<TLTheme>
|
||||
hideBounds?: boolean
|
||||
hideHandles?: boolean
|
||||
hideIndicators?: boolean
|
||||
}
|
||||
|
||||
export function Renderer<T extends TLShape>({
|
||||
shapeUtils,
|
||||
page,
|
||||
pageState,
|
||||
theme,
|
||||
hideHandles = false,
|
||||
hideIndicators = false,
|
||||
hideBounds = false,
|
||||
...rest
|
||||
}: RendererProps<T>): JSX.Element {
|
||||
useTLTheme(theme)
|
||||
const rScreenBounds = React.useRef<TLBounds>(null)
|
||||
const rPageState = React.useRef<TLPageState>(pageState)
|
||||
|
||||
React.useEffect(() => {
|
||||
rPageState.current = pageState
|
||||
}, [pageState])
|
||||
|
||||
const [context] = React.useState(() => ({
|
||||
callbacks: rest,
|
||||
shapeUtils,
|
||||
rScreenBounds,
|
||||
rPageState,
|
||||
}))
|
||||
|
||||
return (
|
||||
<TLContext.Provider value={context}>
|
||||
<Canvas
|
||||
page={page}
|
||||
pageState={pageState}
|
||||
hideBounds={hideBounds}
|
||||
hideIndicators={hideIndicators}
|
||||
hideHandles={hideHandles}
|
||||
/>
|
||||
</TLContext.Provider>
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue