Skip to content

Commit

Permalink
chore(stories): remove use of deprecated types
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Jan 4, 2025
1 parent d38d935 commit e187dcd
Show file tree
Hide file tree
Showing 45 changed files with 118 additions and 114 deletions.
4 changes: 2 additions & 2 deletions .storybook/stories/AccumulativeShadows.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as THREE from 'three'
import * as React from 'react'
import { ComponentProps } from 'react'
import { FlakesTexture } from 'three/examples/jsm/textures/FlakesTexture'
import { FlakesTexture } from 'three-stdlib'
import { Meta, StoryObj } from '@storybook/react'

import { Setup } from '../Setup'
Expand Down Expand Up @@ -48,7 +48,7 @@ function Suzi(props: ComponentProps<'group'>) {
material.color.set('orange')
material.roughness = 0
material.normalMap = new THREE.CanvasTexture(
new FlakesTexture(),
new FlakesTexture() as HTMLCanvasElement,
THREE.UVMapping,
THREE.RepeatWrapping,
THREE.RepeatWrapping
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/ArcballControls.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const CustomCamera = ({ ...props }: ComponentProps<typeof ArcballControls>) => {
* we will render our scene in a render target and use it as a map.
*/
const fbo = useFBO(400, 400)
const virtualCamera = useRef<OrthographicCamera | PerspectiveCameraType>()
const virtualCamera = useRef<PerspectiveCameraType>(null!)
const [virtualScene] = useState(() => new Scene())

useFrame(({ gl }) => {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/BBAnchor.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function BBAnchorScene({
drawBoundingBox: boolean
children?: React.ReactNode
}) {
const ref = React.useRef(null)
const ref = React.useRef<THREE.Mesh<THREE.IcosahedronGeometry>>(null!)

useHelper(drawBoundingBox && ref, BoxHelper, 'cyan')

Expand Down
4 changes: 2 additions & 2 deletions .storybook/stories/Bvh.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
type Story = StoryObj<typeof Bvh>

function TorusBVH({ z = 0, ...props }: { z: number } & React.ComponentProps<typeof Bvh>) {
const mesh = React.useRef<React.ElementRef<typeof TorusKnot>>(null!)
const mesh = React.useRef<React.ComponentRef<typeof TorusKnot>>(null!)

useHelper(mesh, MeshBVHHelper)

Expand Down Expand Up @@ -122,7 +122,7 @@ const DebugRayCast = ({ grp }) => {
}

function Scene(props: React.ComponentProps<typeof Bvh>) {
const grp = React.useRef<React.ElementRef<'group'>>(null)
const grp = React.useRef<React.ComponentRef<'group'>>(null)

const { raycaster } = useThree()
raycaster.firstHitOnly = true
Expand Down
8 changes: 4 additions & 4 deletions .storybook/stories/CameraControls.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createPortal, useFrame } from '@react-three/fiber'
import React, { ComponentProps, useRef, useState } from 'react'
import { Scene } from 'three'
import * as THREE from 'three'
import { Meta, StoryObj } from '@storybook/react'

import { Setup } from '../Setup'
Expand Down Expand Up @@ -47,9 +47,9 @@ const CameraControlsScene2 = (props: ComponentProps<typeof CameraControls>) => {
* we will render our scene in a render target and use it as a map.
*/
const fbo = useFBO(400, 400)
const virtualCamera = useRef<CameraControls['camera']>()
const [virtualScene] = useState(() => new Scene())
const cameraControlRef = useRef<CameraControls>(null)
const virtualCamera = useRef<THREE.PerspectiveCamera>(null!)
const [virtualScene] = useState(() => new THREE.Scene())
const cameraControlRef = useRef<CameraControls>(null!)

useFrame(({ gl }) => {
if (virtualCamera.current) {
Expand Down
4 changes: 2 additions & 2 deletions .storybook/stories/CubeCamera.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ declare module '@react-three/fiber' {
}

function Sphere({ offset = 0, ...props }: ComponentProps<typeof CubeCamera> & { offset?: number }) {
const ref = React.useRef<React.ElementRef<'mesh'>>(null)
const ref = React.useRef<THREE.Mesh>(null!)
useFrame(({ clock }) => {
ref.current!.position.y = Math.sin(offset + clock.elapsedTime) * 5
ref.current.position.y = Math.sin(offset + clock.elapsedTime) * 5
})

return (
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/Extrude.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
type Story = StoryObj<typeof Extrude>

function ExtrudeScene(props: React.ComponentProps<typeof Extrude>) {
const ref = useTurntable<React.ElementRef<typeof Extrude>>()
const ref = useTurntable<React.ComponentRef<typeof Extrude>>()

return (
<>
Expand Down
8 changes: 4 additions & 4 deletions .storybook/stories/FaceControls.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as easing from 'maath/easing'
import { Setup } from '../Setup'

import { FaceLandmarker, FaceControls, Box, WebcamVideoTexture } from '../../src'
import { ComponentProps, ElementRef, useRef, useState } from 'react'
import { ComponentProps, ComponentRef, useRef, useState } from 'react'
import { FaceLandmarkerResult } from '@mediapipe/tasks-vision'
import { useFrame, useThree } from '@react-three/fiber'

Expand Down Expand Up @@ -55,8 +55,8 @@ export const FaceControlsSt = {
//

function FaceControlsScene2(props: ComponentProps<typeof FaceControls>) {
const faceLandmarkerRef = useRef<ElementRef<typeof FaceLandmarker>>(null)
const videoTextureRef = useRef<ElementRef<typeof WebcamVideoTexture>>(null)
const faceLandmarkerRef = useRef<ComponentRef<typeof FaceLandmarker>>(null)
const videoTextureRef = useRef<ComponentRef<typeof WebcamVideoTexture>>(null)

const [faceLandmarkerResult, setFaceLandmarkerResult] = useState<FaceLandmarkerResult>()

Expand Down Expand Up @@ -99,7 +99,7 @@ export const FaceControlsSt2 = {
//

function FaceControlsScene3(props: ComponentProps<typeof FaceControls>) {
const faceControlsRef = useRef<ElementRef<typeof FaceControls>>(null)
const faceControlsRef = useRef<ComponentRef<typeof FaceControls>>(null)

const camera = useThree((state) => state.camera)
const [current] = useState(() => new THREE.Object3D())
Expand Down
4 changes: 2 additions & 2 deletions .storybook/stories/Fbo.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
type Story = StoryObj<typeof Fbo>

function SpinningThing() {
const mesh = React.useRef<React.ElementRef<typeof TorusKnot>>(null!)
const mesh = React.useRef<React.ComponentRef<typeof TorusKnot>>(null!)

useFrame(() => {
mesh.current.rotation.x = mesh.current.rotation.y = mesh.current.rotation.z += 0.01
Expand All @@ -40,7 +40,7 @@ function FboScene(props: React.ComponentProps<typeof Fbo>) {
}

function TargetWrapper({ target }: { target: THREE.WebGLRenderTarget }) {
const cam = React.useRef<React.ElementRef<typeof PerspectiveCamera>>(null!)
const cam = React.useRef<React.ComponentRef<typeof PerspectiveCamera>>(null!)

const scene = React.useMemo(() => {
const scene = new THREE.Scene()
Expand Down
6 changes: 3 additions & 3 deletions .storybook/stories/HTML.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function HTMLScene({
color?: React.ComponentProps<'meshBasicMaterial'>['color']
children?: React.ReactNode
} & HtmlProps) {
const ref = useTurntable<React.ElementRef<'group'>>()
const ref = useTurntable<React.ComponentRef<'group'>>()

return (
<group ref={ref}>
Expand Down Expand Up @@ -164,8 +164,8 @@ export const HTMLCalculatePositionSt = {
//

function HTMLOccluderScene(props: HtmlProps) {
const turntableRef = useTurntable<React.ElementRef<'group'>>()
const occluderRef = React.useRef<React.ElementRef<typeof Icosahedron>>(null)
const turntableRef = useTurntable<React.ComponentRef<'group'>>()
const occluderRef = React.useRef<React.ComponentRef<typeof Icosahedron>>(null)

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/Lathe.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
type Story = StoryObj<typeof Lathe>

function LatheScene(props: React.ComponentProps<typeof Lathe>) {
const ref = useTurntable<React.ElementRef<typeof Lathe>>()
const ref = useTurntable<React.ComponentRef<typeof Lathe>>()

return (
<Lathe ref={ref} {...props}>
Expand Down
4 changes: 2 additions & 2 deletions .storybook/stories/MarchingCubes.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ function MarchingCubesScene({
planeY?: boolean
planeZ?: boolean
} & React.ComponentProps<typeof MarchingCubes>) {
const cubeRefOne = React.useRef<React.ElementRef<typeof MarchingCube>>(null)
const cubeRefTwo = React.useRef<React.ElementRef<typeof MarchingCube>>(null)
const cubeRefOne = React.useRef<React.ComponentRef<typeof MarchingCube>>(null)
const cubeRefTwo = React.useRef<React.ComponentRef<typeof MarchingCube>>(null)

useFrame(({ clock }) => {
if (!cubeRefOne.current || !cubeRefTwo.current) return
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/MeshDistortMaterial.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const MeshDistortMaterialSt = {
//

function MeshDistortMaterialRefScene(props: React.ComponentProps<typeof MeshDistortMaterial>) {
const material = React.useRef<React.ElementRef<typeof MeshDistortMaterial>>(null!)
const material = React.useRef<React.ComponentRef<typeof MeshDistortMaterial>>(null!)

useFrame(({ clock }) => {
material.current.distort = Math.sin(clock.getElapsedTime())
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/MeshRefractionMaterial.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Diamond({
rotation: React.ComponentProps<'mesh'>['rotation']
position: React.ComponentProps<'mesh'>['position']
} & React.ComponentProps<typeof MeshRefractionMaterial>) {
const ref = React.useRef<React.ElementRef<'mesh'>>(null)
const ref = React.useRef<React.ComponentRef<'mesh'>>(null)
const { nodes } = useGLTF('/dflat.glb') as any
// Use a custom envmap/scene-backdrop for the diamond material
// This way we can have a clear BG while cube-cam can still film other objects
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/MeshWobbleMaterial.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const MeshWobbleMaterialSt = {
//

function MeshWobbleMaterialRefScene(props: React.ComponentProps<typeof MeshWobbleMaterial>) {
const material = React.useRef<React.ElementRef<typeof MeshWobbleMaterial>>(null)
const material = React.useRef<React.ComponentRef<typeof MeshWobbleMaterial>>(null)

useFrame(({ clock }) => {
if (material.current === null) return
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/OrbitControls.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const CustomCamera = (props: OrbitControlsProps) => {
* we will render our scene in a render target and use it as a map.
*/
const fbo = useFBO(400, 400)
const virtualCamera = useRef<React.ElementRef<typeof PerspectiveCamera> | null>(null)
const virtualCamera = useRef<React.ComponentRef<typeof PerspectiveCamera> | null>(null)
const [virtualScene] = useState(() => new Scene())

useFrame(({ gl }) => {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/Reflector.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function ReflectorScene({
const roughnessMap = useTexture('roughness_floor.jpeg')
const normalMap = useTexture('NORM.jpg')
const distortionMap = useTexture('dist_map.jpeg')
const $box = React.useRef<React.ElementRef<typeof TorusKnot>>(null!)
const $box = React.useRef<React.ComponentRef<typeof TorusKnot>>(null!)

React.useEffect(() => {
distortionMap.wrapS = distortionMap.wrapT = RepeatWrapping
Expand Down
4 changes: 2 additions & 2 deletions .storybook/stories/RoundedBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
type Story = StoryObj<typeof RoundedBox>

function RoundedBoxScene(props: React.ComponentProps<typeof RoundedBox>) {
const ref = useTurntable<React.ElementRef<typeof RoundedBox>>()
const ref = useTurntable<React.ComponentRef<typeof RoundedBox>>()

return (
<RoundedBox ref={ref} {...props}>
Expand All @@ -44,7 +44,7 @@ export const RoundedBoxSt = {
//

function RoundedBoxScene2(props: React.ComponentProps<typeof RoundedBox>) {
const ref = useTurntable<React.ElementRef<typeof RoundedBox>>()
const ref = useTurntable<React.ComponentRef<typeof RoundedBox>>()

return (
<>
Expand Down
6 changes: 3 additions & 3 deletions .storybook/stories/Sampler.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Meta, StoryObj } from '@storybook/react'
import { Setup } from '../Setup'

import { Sampler, ComputedAttribute, TransformFn } from '../../src'
import { BufferAttribute, Vector3 } from 'three'
import { BufferAttribute, InstancedMesh, Mesh, Vector3 } from 'three'

export default {
title: 'Misc/Sampler',
Expand Down Expand Up @@ -49,8 +49,8 @@ export const SamplerSt = {
//

function RefAPIScene(props: React.ComponentProps<typeof Sampler>) {
const meshRef = React.useRef(null)
const instancesRef = React.useRef(null)
const meshRef = React.useRef<Mesh>(null!)
const instancesRef = React.useRef<InstancedMesh>(null!)

return (
<>
Expand Down
14 changes: 6 additions & 8 deletions .storybook/stories/ScreenQuad.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import * as THREE from 'three'
import { extend, useThree, useFrame } from '@react-three/fiber'
import { extend, useThree, useFrame, ThreeElements } from '@react-three/fiber'
import { Meta, StoryObj } from '@storybook/react'

import { Setup } from '../Setup'
Expand Down Expand Up @@ -47,20 +47,18 @@ const ColorShiftMaterial = shaderMaterial(

extend({ ColorShiftMaterial })

type ColorShiftMaterialImpl = {
time: number
resolution: number[]
} & ThreeElements['shaderMaterial']

declare module '@react-three/fiber' {
interface ThreeElements {
colorShiftMaterial: ColorShiftMaterialImpl
colorShiftMaterial: ThreeElements['shaderMaterial'] & {
time: number
resolution: number[]
}
}
}

function ScreenQuadScene(props: React.ComponentProps<typeof ScreenQuad>) {
const size = useThree((state) => state.size)
const ref = React.useRef<React.ElementRef<'colorShiftMaterial'>>(null!)
const ref = React.useRef<ThreeElements['colorShiftMaterial']>(null!)

useFrame((state) => {
if (ref.current.uniforms) {
Expand Down
13 changes: 11 additions & 2 deletions .storybook/stories/Segments.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const BasicSegmentsSt = {
//

function AnimatedSegments(props: React.ComponentProps<typeof Segments>) {
const ref = React.useRef<React.ElementRef<typeof Segment>[]>([])
const ref = React.useRef<React.ComponentRef<typeof Segment>[]>([])
useFrame(({ clock }) => {
ref.current.forEach((r, i) => {
const time = clock.elapsedTime
Expand All @@ -64,7 +64,16 @@ function AnimatedSegments(props: React.ComponentProps<typeof Segments>) {
return (
<Segments {...props}>
{Array.from({ length: 10000 }).map((_, i) => (
<Segment key={i} ref={(r) => (ref.current[i] = r!)} color="orange" start={[0, 0, 0]} end={[0, 0, 0]} />
<Segment
key={i}
ref={(r) => {
ref.current[i] = r!
return () => void (ref.current[i] = null!)
}}
color="orange"
start={[0, 0, 0]}
end={[0, 0, 0]}
/>
))}
</Segments>
)
Expand Down
4 changes: 2 additions & 2 deletions .storybook/stories/Shadow.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default {
type Story = StoryObj<typeof Shadow>

function ShadowScene(props: React.ComponentProps<typeof Shadow>) {
const shadow = React.useRef<React.ElementRef<typeof Shadow>>(null!)
const mesh = React.useRef<React.ElementRef<typeof Icosahedron>>(null!)
const shadow = React.useRef<React.ComponentRef<typeof Shadow>>(null!)
const mesh = React.useRef<React.ComponentRef<typeof Icosahedron>>(null!)

useFrame(({ clock }) => {
shadow.current.scale.x = Math.sin(clock.getElapsedTime()) + 3
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/Shapes.Box.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
type Story = StoryObj<typeof Box>

function BoxScene(props: React.ComponentProps<typeof Box>) {
const ref = useTurntable<React.ElementRef<typeof Box>>()
const ref = useTurntable<React.ComponentRef<typeof Box>>()

return (
<Box ref={ref} {...props}>
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/Shapes.Circle.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
type Story = StoryObj<typeof Circle>

function CircleScene(props: React.ComponentProps<typeof Circle>) {
const ref = useTurntable<React.ElementRef<typeof Circle>>()
const ref = useTurntable<React.ComponentRef<typeof Circle>>()

return (
<Circle ref={ref} {...props}>
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/Shapes.Cone.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
type Story = StoryObj<typeof Cone>

function ConeScene(props: React.ComponentProps<typeof Cone>) {
const ref = useTurntable<React.ElementRef<typeof Cone>>()
const ref = useTurntable<React.ComponentRef<typeof Cone>>()

return (
<Cone ref={ref} {...props}>
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/Shapes.Cylinder.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
type Story = StoryObj<typeof Cylinder>

function CylinderScene(props: React.ComponentProps<typeof Cylinder>) {
const ref = useTurntable<React.ElementRef<typeof Cylinder>>()
const ref = useTurntable<React.ComponentRef<typeof Cylinder>>()

return (
<Cylinder ref={ref} {...props}>
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/Shapes.Dodecahedron.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
type Story = StoryObj<typeof Dodecahedron>

function DodecahedronScene(props: React.ComponentProps<typeof Dodecahedron>) {
const ref = useTurntable<React.ElementRef<typeof Dodecahedron>>()
const ref = useTurntable<React.ComponentRef<typeof Dodecahedron>>()

return (
<Dodecahedron ref={ref} {...props}>
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/Shapes.Icosahedron.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
type Story = StoryObj<typeof Icosahedron>

function IcosahedronScene(props: React.ComponentProps<typeof Icosahedron>) {
const ref = useTurntable<React.ElementRef<typeof Icosahedron>>()
const ref = useTurntable<React.ComponentRef<typeof Icosahedron>>()

return (
<Icosahedron ref={ref} {...props}>
Expand Down
Loading

0 comments on commit e187dcd

Please sign in to comment.