Skip to content

Commit

Permalink
Relax editable TS types to allow creating editable versions of all th…
Browse files Browse the repository at this point in the history
…e JSX.IntrinsicElements elements. (theatre-js#237)

Enable custom editable components through relaxed typescript types
  • Loading branch information
AndrewPrifer authored Jun 28, 2022
1 parent 2d3466e commit a3d9892
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
33 changes: 33 additions & 0 deletions packages/playground/src/shared/custom-editable-components/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {editable as e, SheetProvider} from '@theatre/r3f'
import {getProject} from '@theatre/core'
import React from 'react'
import {Canvas} from '@react-three/fiber'

const EditablePoints = e('points', 'mesh')

function App() {
return (
<div
style={{
height: '100vh',
}}
>
<Canvas
dpr={[1.5, 2]}
linear
gl={{preserveDrawingBuffer: true}}
frameloop="demand"
>
<SheetProvider sheet={getProject('Space').sheet('Scene')}>
<ambientLight intensity={0.75} />
<EditablePoints uniqueName="points">
<torusKnotGeometry args={[1, 0.3, 128, 64]} />
<meshNormalMaterial />
</EditablePoints>
</SheetProvider>
</Canvas>
</div>
)
}

export default App
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import studio from '@theatre/studio'
import extension from '@theatre/r3f/dist/extension'

studio.extend(extension)
studio.initialize()

ReactDOM.render(<App />, document.getElementById('root'))
4 changes: 2 additions & 2 deletions packages/r3f/src/main/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const createEditable = <Keys extends keyof JSX.IntrinsicElements>(
config: EditableFactoryConfig,
) => {
const editable = <
T extends ComponentType<any> | Keys | 'primitive',
U extends T extends Keys ? T : Keys,
T extends ComponentType<any> | keyof JSX.IntrinsicElements | 'primitive',
U extends Keys,
>(
Component: T,
type: T extends 'primitive' ? null : U,
Expand Down

0 comments on commit a3d9892

Please sign in to comment.