Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] move stories to TS #223

Merged
merged 26 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c2bb1b6
feat: setup TS for stories
joshuaellis Jan 8, 2021
500b4e5
fix: eslint was ignore .storybook
joshuaellis Jan 8, 2021
5f73107
feat: add TS to storybook
joshuaellis Jan 8, 2021
a46a9ea
refactor: move stories to TS (WIP)
joshuaellis Jan 8, 2021
6a23ee4
refactor: move more stories to TS (WIP)
joshuaellis Jan 9, 2021
566c87d
refactor: src changes for TS move over
joshuaellis Jan 9, 2021
bf855ad
fix: ContactShadows story
joshuaellis Jan 11, 2021
593506a
refactor: move more stories to TS
joshuaellis Jan 11, 2021
678a795
refactor: add MapControls.tsx after raising issues in three
joshuaellis Jan 11, 2021
b3f7111
Merge remote-tracking branch 'upstream/master' into feature/TS-Storie…
joshuaellis Jan 12, 2021
5f07765
fix: TS errors for passing refs & children
joshuaellis Jan 12, 2021
4ab1879
refactor: add more stories (WIP)
joshuaellis Jan 12, 2021
b0a1e95
fix: useContextBridge TS to accept array of children
joshuaellis Jan 12, 2021
df3eb07
refactor: convert more stories to TS
joshuaellis Jan 12, 2021
b876a1d
chore: update storybook
joshuaellis Jan 12, 2021
9cc340c
fix: revert useTexture
joshuaellis Jan 12, 2021
08eb038
refactor: move stories to TS (WIP)
joshuaellis Jan 12, 2021
3ea7304
refactor: revert useGLTF story
joshuaellis Jan 12, 2021
bd0d1ec
Minor type fixes
gsimone Jan 12, 2021
7b04a05
chore: update react-three-fiber to latest
joshuaellis Jan 14, 2021
f64cd54
refactor: move stories to TS
joshuaellis Jan 14, 2021
d191df6
fix: shaderMaterial on init returns void, not null
joshuaellis Jan 14, 2021
4d3cf11
refactor: remove unnecessary type in useFBX
joshuaellis Jan 14, 2021
8b59dcb
refactor: type Environment stronger
joshuaellis Jan 14, 2021
1ceb3bd
Fixes CSB CI (#230)
gsimone Jan 15, 2021
48c8e2a
Merge branch 'master' of github.com:react-spring/drei into feature/TS…
gsimone Jan 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# ignore base64 files because of Maximum call stack size exceeded error
src/assets/**/*.base64.ts
!.storybook
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{
"files": ["src"],
"parserOptions": {
"project": "./tsconfig.json"
"project": ["./tsconfig.json", "./storybook/tsconfig.json"]
}
}
]
Expand Down
10 changes: 8 additions & 2 deletions .storybook/Setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import { Canvas } from 'react-three-fiber'

import { OrbitControls } from '../src/OrbitControls'

export function Setup({ children, cameraPosition = new THREE.Vector3(-5, 5, 5), controls = true }) {
export function Setup({ children, cameraPosition = new THREE.Vector3(-5, 5, 5), controls = true, ...restProps }) {
return (
<Canvas colorManagement shadowMap camera={{ position: cameraPosition }} pixelRatio={window.devicePixelRatio}>
<Canvas
colorManagement
shadowMap
camera={{ position: cameraPosition }}
pixelRatio={window.devicePixelRatio}
{...restProps}
>
{children}
<ambientLight intensity={0.8} />
<pointLight intensity={1} position={[0, 6, 0]} />
Expand Down
2 changes: 1 addition & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path')

module.exports = {
stories: ['./stories/**/*.stories.js'],
stories: ['./stories/**/*.stories.{js,ts,tsx}'],
addons: ['@storybook/addon-knobs/register', '@storybook/addon-actions', '@storybook/addon-storysource'],
webpackFinal: (config) => {
config.module.rules.push({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import * as React from 'react'
import { withKnobs, boolean } from '@storybook/addon-knobs'
import { Vector3 } from 'three'

import { Setup } from '../Setup'

import { Billboard } from '../../src/Billboard'
import { OrbitControls } from '../../src/OrbitControls'
import { Billboard, OrbitControls } from '../../src'

export default {
title: 'Abstractions/Billboard',
component: Billboard,
decorators: [
(storyFn) => (
<Setup controls={false} cameraPosition={[0, 0, 10]}>
<Setup controls={false} cameraPosition={new Vector3(0, 0, 10)}>
{storyFn()}
</Setup>
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import * as React from 'react'
import { withKnobs } from '@storybook/addon-knobs'
import { Vector3 } from 'three'

import { Setup } from '../Setup'

import { Cloud } from '../../src/Cloud'
import { OrbitControls } from '../../src/OrbitControls'
import { Cloud, OrbitControls } from '../../src'

export default {
title: 'Abstractions/Cloud',
component: Cloud,
decorators: [
(storyFn) => (
<Setup controls={false} cameraPosition={[0, 0, 10]}>
<Setup controls={false} cameraPosition={new Vector3(0, 0, 10)}>
{storyFn()}
</Setup>
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as React from 'react'
import { useFrame } from 'react-three-fiber'
import { Mesh } from 'three'

import { Setup } from '../Setup'

import { ContactShadows } from '../../src/ContactShadows'
import { Icosahedron, Plane } from '../../src/shapes'
import { ContactShadows, Icosahedron, Plane } from '../../src'

export default {
title: 'Shaders/ContactShadows',
Expand All @@ -13,7 +13,7 @@ export default {
}

function ContactShadowScene() {
const mesh = React.useRef()
const mesh = React.useRef<Mesh>(null!)
useFrame(({ clock }) => {
mesh.current.position.y = Math.sin(clock.getElapsedTime()) + 2.5
})
Expand All @@ -24,7 +24,7 @@ function ContactShadowScene() {
<meshBasicMaterial attach="material" color="lightblue" />
</Icosahedron>

<ContactShadows width={10} height={10} far={20} rotation={[-Math.PI / 2, 0, 0]} />
<ContactShadows width={10} height={10} far={20} rotation={[Math.PI / 2, 0, 0]} />

<Plane args={[10, 10]} position={[0, -0.01, 0]} rotation={[-Math.PI / 2, 0, 0]}>
<meshBasicMaterial attach="material" color="white" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useFrame, useLoader } from 'react-three-fiber'

import { Setup } from '../Setup'

import { CurveModifier } from '../../src/CurveModifier'
import { CurveModifier, CurveModifierRef } from '../../src'

export default {
title: 'Modifiers/CurveModifier',
Expand All @@ -13,17 +13,19 @@ export default {
}

function CurveModifierScene() {
const curveRef = React.useRef()
const geomRef = React.useRef()
const curveRef = React.useRef<CurveModifierRef>()
const geomRef = React.useRef<THREE.TextGeometry>(null!)
const font = useLoader(THREE.FontLoader, '/fonts/helvetiker_regular.typeface.json')

const handlePos = React.useMemo(() =>
[
{ x: 10, y: 0, z: -10 },
{ x: 10, y: 0, z: 10 },
{ x: -10, y: 0, z: 10 },
{ x: -10, y: 0, z: -10 },
].map((hand) => new THREE.Vector3(...Object.values(hand)))
const handlePos = React.useMemo(
() =>
[
{ x: 10, y: 0, z: -10 },
{ x: 10, y: 0, z: 10 },
{ x: -10, y: 0, z: 10 },
{ x: -10, y: 0, z: -10 },
].map((hand) => new THREE.Vector3(...Object.values(hand))),
[]
)

const curve = React.useMemo(() => new THREE.CatmullRomCurve3(handlePos, true, 'centripetal'), [handlePos])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import * as React from 'react'
import { Vector3 } from 'three'

import { Setup } from '../Setup'

import { Detailed } from '../../src/Detailed'
import { Icosahedron } from '../../src/shapes'
import { OrbitControls } from '../../src/OrbitControls'
import { Detailed, Icosahedron, OrbitControls } from '../../src'

export default {
title: 'Abstractions/Detailed',
component: Detailed,
decorators: [
(storyFn) => (
<Setup controls={false} cameraPosition={[0, 0, 100]}>
{' '}
<Setup controls={false} cameraPosition={new Vector3(0, 0, 100)}>
{storyFn()}
</Setup>
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react'

import { Setup } from '../Setup'
import { DeviceOrientationControls } from '../../src/DeviceOrientationControls'
import { Box } from '../../src/shapes'

import { DeviceOrientationControls, Box } from '../../src'

export function DeviceOrientationControlsStory() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
import * as React from 'react'
import { Vector3 } from 'three'
import { withKnobs, select, boolean } from '@storybook/addon-knobs'

import { Setup } from '../Setup'

import { Environment } from '../../src/Environment'
import { OrbitControls } from '../../src/OrbitControls'
import { Environment, OrbitControls } from '../../src'

import { presetsObj } from '../../src/helpers/environment-assets'

export default {
title: 'Abstractions/Environment',
component: Environment,
decorators: [
(storyFn) => (
<Setup cameraPosition={[0, 0, 10]} controls={false}>
<Setup cameraPosition={new Vector3(0, 0, 10)} controls={false}>
{storyFn()}
</Setup>
),
withKnobs,
],
}

function TorusKnot() {
return (
<mesh>
<torusKnotBufferGeometry args={[1, 0.5, 128, 32]} />
<meshStandardMaterial metalness={1} roughness={0} specular={1} />
</mesh>
)
}

function EnvironmentStory() {
const presets = Object.keys(presetsObj)
const preset = select('Preset', presets, presets[0])
return (
<>
<React.Suspense fallback={null}>
<Environment preset={preset} background={boolean('Background', true)} />
<TorusKnot />
<mesh>
<torusKnotBufferGeometry args={[1, 0.5, 128, 32]} />
<meshStandardMaterial metalness={1} roughness={0} />
</mesh>
</React.Suspense>
<OrbitControls autoRotate />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { withKnobs, number, boolean } from '@storybook/addon-knobs'

import { Setup } from '../Setup'

import { FlyControls } from '../../src/FlyControls'
import { Box } from '../../src/shapes'
import { Box, FlyControls } from '../../src'

export function FlyControlsStory() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as React from 'react'
import * as THREE from 'three'

import { Setup } from '../Setup'

import { Icosahedron } from '../../src/shapes'
import { Html } from '../../src/Html'
import { useTurntable } from '../useTurntable'

import { Icosahedron, Html } from '../../src'

export default {
title: 'Misc/Html',
component: Html,
decorators: [(storyFn) => <Setup cameraPosition={[-20, 20, -20]}> {storyFn()}</Setup>],
decorators: [(storyFn) => <Setup cameraPosition={new THREE.Vector3(-20, 20, -20)}> {storyFn()}</Setup>],
}

function HTMLScene() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
import * as React from 'react'
import { GeometryUtils } from 'three/examples/jsm/utils/GeometryUtils'
import { Vector3 } from 'three'

import { GeometryUtils } from 'three/examples/jsm/utils/GeometryUtils'
import { withKnobs, number, color, boolean } from '@storybook/addon-knobs'

import { Setup } from '../Setup'

import { Line } from '../../src/Line'
import { OrbitControls } from '../../src/OrbitControls'
import { Line, OrbitControls } from '../../src'

export default {
title: 'Abstractions/Line',
component: Line,
}

const points = GeometryUtils.hilbert3D(new Vector3(0), 5).map((p) => [p.x, p.y, p.z])
const colors = new Array(points.length).fill().map(() => [Math.random(), Math.random(), Math.random()])
const points = GeometryUtils.hilbert3D(new Vector3(0), 5).map((p) => [p.x, p.y, p.z]) as [number, number, number][]

const colors = new Array(points.length).fill(0).map(() => [Math.random(), Math.random(), Math.random()]) as [
number,
number,
number
][]

export function BasicLine() {
return (
<>
<Line points={points} color={color('color', 'red')} lineWidth={number('lineWidth', 3)} dashed={boolean('dashed', false)} />
<Line
points={points}
color={color('color', 'red')}
lineWidth={number('lineWidth', 3)}
dashed={boolean('dashed', false)}
/>
<OrbitControls zoomSpeed={0.5} />
</>
)
Expand All @@ -30,7 +38,7 @@ BasicLine.storyName = 'Basic'
BasicLine.decorators = [
withKnobs,
(storyFn) => (
<Setup controls={false} cameraPosition={[0, 0, 17]}>
<Setup controls={false} cameraPosition={new Vector3(0, 0, 17)}>
{storyFn()}
</Setup>
),
Expand All @@ -39,7 +47,13 @@ BasicLine.decorators = [
export function VertexColorsLine() {
return (
<>
<Line points={points} color={color('color', 'white')} vertexColors={colors} lineWidth={number('lineWidth', 3)} dashed={boolean('dashed', false)} />
<Line
points={points}
color={color('color', 'white')}
vertexColors={colors}
lineWidth={number('lineWidth', 3)}
dashed={boolean('dashed', false)}
/>
<OrbitControls zoomSpeed={0.5} />
</>
)
Expand All @@ -49,7 +63,7 @@ VertexColorsLine.storyName = 'VertexColors'
VertexColorsLine.decorators = [
withKnobs,
(storyFn) => (
<Setup controls={false} cameraPosition={[0, 0, 17]}>
<Setup controls={false} cameraPosition={new Vector3(0, 0, 17)}>
{storyFn()}
</Setup>
),
Expand Down
Loading