Add file playground
This commit is contained in:
parent
10b82772ed
commit
fc849a5e7a
3 changed files with 63 additions and 4 deletions
11
packages/playground/src/shared/file/index.html
Normal file
11
packages/playground/src/shared/file/index.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Theatre.js Playground</title>
|
||||||
|
<script src="./index.tsx" type="module"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
52
packages/playground/src/shared/file/index.tsx
Normal file
52
packages/playground/src/shared/file/index.tsx
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
import {getProject, types} from '@theatre/core'
|
||||||
|
import studio from '@theatre/studio'
|
||||||
|
import React, {useEffect, useState} from 'react'
|
||||||
|
import ReactDom from 'react-dom/client'
|
||||||
|
import styled from 'styled-components'
|
||||||
|
|
||||||
|
const project = getProject('Image type playground', {
|
||||||
|
assets: {
|
||||||
|
baseUrl: '/',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
studio.initialize()
|
||||||
|
const sheet = project.sheet('Image type')
|
||||||
|
|
||||||
|
const Wrapper = styled.div`
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
`
|
||||||
|
|
||||||
|
const FileTypeExample: React.FC<{}> = (props) => {
|
||||||
|
const [fileUrl, setFileUrl] = useState<string>()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const object = sheet.object('File holder', {
|
||||||
|
f: types.file('', {
|
||||||
|
label: 'The OBJ',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
object.onValuesChange(({f}) => {
|
||||||
|
setFileUrl(project.getAssetUrl(f))
|
||||||
|
})
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
sheet.detachObject('canvas')
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return <Wrapper>File url is: {fileUrl}</Wrapper>
|
||||||
|
}
|
||||||
|
|
||||||
|
project.ready
|
||||||
|
.then(() => {
|
||||||
|
ReactDom.createRoot(document.getElementById('root')!).render(
|
||||||
|
<FileTypeExample />,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err)
|
||||||
|
})
|
|
@ -1,7 +1,3 @@
|
||||||
/**
|
|
||||||
* A super basic Turtle geometry renderer hooked up to Theatre, so the parameters
|
|
||||||
* can be tweaked and animated.
|
|
||||||
*/
|
|
||||||
import {getProject, types} from '@theatre/core'
|
import {getProject, types} from '@theatre/core'
|
||||||
import studio from '@theatre/studio'
|
import studio from '@theatre/studio'
|
||||||
import React, {useEffect, useState} from 'react'
|
import React, {useEffect, useState} from 'react'
|
||||||
|
|
Loading…
Reference in a new issue