Skip to content

Commit 9eef32c

Browse files
committed
chore: wip csf3
1 parent 965519d commit 9eef32c

30 files changed

+877
-846
lines changed

.storybook/main.ts

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ const config: StorybookConfig = {
1414

1515
typescript: {
1616
reactDocgen: 'react-docgen-typescript',
17+
reactDocgenTypescriptOptions: {
18+
propFilter: (prop, component) => {
19+
// Only include props that belong to the current component
20+
const fileName = prop.declarations?.at(0)?.fileName // 'drei/src/core/AccumulativeShadows.tsx'
21+
const componentName = fileName?.split('/').at(-1)?.split('.').at(0) // 'AccumulativeShadows'
22+
return component.name === componentName
23+
},
24+
},
1725
},
1826
}
1927

Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
import * as THREE from 'three'
22
import * as React from 'react'
3+
import { ComponentProps } from 'react'
34
import { FlakesTexture } from 'three/examples/jsm/textures/FlakesTexture'
5+
import { Meta, StoryObj } from '@storybook/react'
46

57
import { Setup } from '../Setup'
68

79
import { useGLTF, AccumulativeShadows, RandomizedLight, OrbitControls, Environment } from '../../src'
810

911
export default {
1012
title: 'Staging/AccumulativeShadows',
11-
component: AccumulativeShadowScene,
13+
component: AccumulativeShadows,
1214
decorators: [(storyFn) => <Setup> {storyFn()}</Setup>],
13-
}
15+
} satisfies Meta<typeof AccumulativeShadows>
16+
17+
type Story = StoryObj<typeof AccumulativeShadows>
1418

15-
function AccumulativeShadowScene() {
19+
function AccumulativeShadowScene(props: ComponentProps<typeof AccumulativeShadows>) {
1620
return (
1721
<React.Suspense fallback={null}>
1822
<color attach="background" args={['goldenrod']} />
23+
1924
<Suzi rotation={[-0.63, 0, 0]} scale={2} position={[0, -1.175, 0]} />
20-
<AccumulativeShadows
21-
temporal
22-
frames={100}
23-
color="goldenrod"
24-
alphaTest={0.65}
25-
opacity={2}
26-
scale={14}
27-
position={[0, -0.5, 0]}
28-
>
25+
26+
<AccumulativeShadows {...props} position={[0, -0.5, 0]}>
2927
<RandomizedLight amount={8} radius={4} ambient={0.5} bias={0.001} position={[5, 5, -10]} />
3028
</AccumulativeShadows>
29+
3130
<OrbitControls autoRotate={true} />
3231
<Environment preset="city" />
3332
</React.Suspense>
3433
)
3534
}
3635

37-
function Suzi(props) {
36+
function Suzi(props: ComponentProps<'group'>) {
3837
const { scene, materials } = useGLTF('/suzanne-high-poly.gltf')
3938
React.useLayoutEffect(() => {
4039
scene.traverse((obj) => (obj as any).isMesh && (obj.receiveShadow = obj.castShadow = true))
@@ -55,5 +54,18 @@ function Suzi(props) {
5554
return <primitive object={scene} {...props} />
5655
}
5756

58-
export const AccumulativeShadowSt = () => <AccumulativeShadowScene />
59-
AccumulativeShadowSt.storyName = 'Default'
57+
export const AccumulativeShadowSt = {
58+
name: 'Default',
59+
render: (args) => <AccumulativeShadowScene {...args} />,
60+
args: {
61+
temporal: true,
62+
frames: 100,
63+
color: 'goldenrod',
64+
alphaTest: 0.65,
65+
opacity: 2,
66+
scale: 14,
67+
},
68+
argTypes: {
69+
color: { control: 'color' },
70+
},
71+
} satisfies Story

.storybook/stories/Adaptive.stories.tsx

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React, { Suspense } from 'react'
1+
import React, { ComponentProps, Suspense } from 'react'
22
import { Vector3 } from 'three'
3+
import { Meta, StoryObj } from '@storybook/react'
34

45
import { Setup } from '../Setup'
56

@@ -10,7 +11,7 @@ import type { GLTF } from 'three-stdlib'
1011

1112
export default {
1213
title: 'Performance/Adaptive',
13-
component: useGLTF,
14+
component: AdaptiveDpr,
1415
decorators: [
1516
(storyFn) => (
1617
<Setup
@@ -25,7 +26,9 @@ export default {
2526
</Setup>
2627
),
2728
],
28-
}
29+
} satisfies Meta<typeof AdaptiveDpr>
30+
31+
type Story = StoryObj<typeof AdaptiveDpr>
2932

3033
interface ArcherGLTF extends GLTF {
3134
materials: { material_0: Material }
@@ -51,7 +54,7 @@ function Archer() {
5154
)
5255
}
5356

54-
function AdaptiveScene() {
57+
function AdaptiveScene(props: ComponentProps<typeof AdaptiveDpr>) {
5558
return (
5659
<>
5760
<Suspense fallback={null}>
@@ -65,14 +68,20 @@ function AdaptiveScene() {
6568
castShadow
6669
shadow-bias={-0.001}
6770
/>
68-
<AdaptiveDpr pixelated />
71+
<AdaptiveDpr {...props} />
6972
<AdaptiveEvents />
7073
<OrbitControls regress />
7174
</>
7275
)
7376
}
7477

75-
export const AdaptiveSceneSt = () => <AdaptiveScene />
76-
AdaptiveSceneSt.story = {
78+
export const AdaptiveSceneSt = {
7779
name: 'Default',
78-
}
80+
render: (args) => <AdaptiveScene {...args} />,
81+
args: {
82+
pixelated: true,
83+
},
84+
argTypes: {
85+
pixelated: { control: 'boolean' },
86+
},
87+
} satisfies Story

.storybook/stories/ArcballControls.stories.tsx

+30-25
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
11
import { createPortal, useFrame } from '@react-three/fiber'
2-
import React, { useRef, useState } from 'react'
2+
import React, { ComponentProps, useRef, useState } from 'react'
33
import { Scene } from 'three'
4+
import { Meta, StoryObj } from '@storybook/react'
45

56
import { Setup } from '../Setup'
67
import { ArcballControls, Box, PerspectiveCamera, Plane, useFBO } from '../../src'
78

89
import type { OrthographicCamera, PerspectiveCamera as PerspectiveCameraType } from 'three'
9-
import type { ArcballControlsProps } from '../../src'
10-
11-
const args = {
12-
enablePan: true,
13-
enableRotate: true,
14-
enableZoom: true,
15-
}
16-
17-
export const ArcballControlsStory = (props: ArcballControlsProps) => (
18-
<>
19-
<ArcballControls {...props} />
20-
<Box>
21-
<meshBasicMaterial wireframe />
22-
</Box>
23-
</>
24-
)
25-
26-
ArcballControlsStory.args = args
27-
ArcballControlsStory.storyName = 'Default'
2810

2911
export default {
3012
title: 'Controls/ArcballControls',
3113
component: ArcballControls,
3214
decorators: [(storyFn) => <Setup controls={false}>{storyFn()}</Setup>],
15+
args: {
16+
enablePan: true,
17+
enableRotate: true,
18+
enableZoom: true,
19+
},
20+
} satisfies Meta<typeof ArcballControls>
21+
22+
type Story = StoryObj<typeof ArcballControls>
23+
24+
function DefaultScene(props: ComponentProps<typeof ArcballControls>) {
25+
return (
26+
<>
27+
<ArcballControls {...props} />
28+
<Box>
29+
<meshBasicMaterial wireframe />
30+
</Box>
31+
</>
32+
)
3333
}
3434

35-
const CustomCamera = (props: ArcballControlsProps) => {
35+
export const ArcballControlsSt1 = {
36+
render: (args) => <DefaultScene {...args} />,
37+
name: 'Default',
38+
} satisfies Story
39+
40+
const CustomCamera = ({ ...props }: ComponentProps<typeof ArcballControls>) => {
3641
/**
3742
* we will render our scene in a render target and use it as a map.
3843
*/
@@ -73,7 +78,7 @@ const CustomCamera = (props: ArcballControlsProps) => {
7378
)
7479
}
7580

76-
export const CustomCameraStory = (props: ArcballControlsProps) => <CustomCamera {...props} />
77-
78-
CustomCameraStory.args = args
79-
CustomCameraStory.storyName = 'Custom Camera'
81+
export const ArcballControlsSt2 = {
82+
render: (args) => <CustomCamera {...args} />,
83+
name: 'Custom Camera',
84+
} satisfies Story
+31-37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as React from 'react'
2+
import { ComponentProps } from 'react'
23
import * as THREE from 'three'
4+
import { Meta, StoryObj } from '@storybook/react'
35

46
import { Setup } from '../Setup'
57

@@ -17,27 +19,19 @@ export default {
1719
</Setup>
1820
),
1921
],
20-
argTypes: {
21-
drawBoundingBox: { control: 'boolean' },
22-
anchorX: { control: { type: 'range', min: -1, max: 1, step: 0.1 } },
23-
anchorY: { control: { type: 'range', min: -1, max: 1, step: 0.1 } },
24-
anchorZ: { control: { type: 'range', min: -1, max: 1, step: 0.1 } },
25-
children: { table: { disable: true } },
26-
},
27-
}
22+
} satisfies Meta<typeof BBAnchor>
2823

29-
type Anchor = THREE.Vector3 | [number, number, number]
24+
type Story = StoryObj<typeof BBAnchor>
3025

3126
function BBAnchorScene({
32-
anchor,
3327
drawBoundingBox,
3428
children,
35-
}: {
36-
anchor: Anchor
29+
...props
30+
}: ComponentProps<typeof BBAnchor> & {
3731
drawBoundingBox: boolean
38-
children?: React.ReactChild
32+
children?: React.ReactNode
3933
}) {
40-
const ref = React.useRef()
34+
const ref = React.useRef(null)
4135

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

@@ -46,16 +40,12 @@ function BBAnchorScene({
4640
<OrbitControls autoRotate />
4741
<Icosahedron ref={ref}>
4842
<meshBasicMaterial color="hotpink" wireframe />
49-
<BBAnchor anchor={anchor}>{children}</BBAnchor>
43+
<BBAnchor {...props}>{children}</BBAnchor>
5044
</Icosahedron>
5145
</>
5246
)
5347
}
5448

55-
const Template = ({ drawBoundingBox, anchorX, anchorY, anchorZ, ...args }) => (
56-
<BBAnchorScene drawBoundingBox={drawBoundingBox} anchor={[anchorX, anchorY, anchorZ]} {...args} />
57-
)
58-
5949
function HtmlComp() {
6050
return (
6151
<Html
@@ -70,15 +60,17 @@ function HtmlComp() {
7060
)
7161
}
7262

73-
export const BBAnchorWithHtml = Template.bind({})
74-
BBAnchorWithHtml.args = {
75-
drawBoundingBox: true,
76-
anchorX: 1,
77-
anchorY: 1,
78-
anchorZ: 1,
79-
children: <HtmlComp />,
80-
}
81-
BBAnchorWithHtml.storyName = 'With Html component'
63+
export const BBAnchorWithHtml = {
64+
render: (args) => (
65+
<BBAnchorScene {...args} drawBoundingBox={true}>
66+
<HtmlComp />
67+
</BBAnchorScene>
68+
),
69+
args: {
70+
anchor: [1, 1, 1],
71+
},
72+
name: 'With Html component',
73+
} satisfies Story
8274

8375
function MeshComp() {
8476
return (
@@ -88,12 +80,14 @@ function MeshComp() {
8880
)
8981
}
9082

91-
export const BBAnchorWithMesh = Template.bind({})
92-
BBAnchorWithMesh.args = {
93-
drawBoundingBox: true,
94-
anchorX: 1,
95-
anchorY: 1,
96-
anchorZ: 1,
97-
children: <MeshComp />,
98-
}
99-
BBAnchorWithMesh.storyName = 'With other mesh'
83+
export const BBAnchorWithMesh = {
84+
render: (args) => (
85+
<BBAnchorScene {...args} drawBoundingBox={true}>
86+
<MeshComp />
87+
</BBAnchorScene>
88+
),
89+
args: {
90+
anchor: [1, 1, 1],
91+
},
92+
name: 'With other mesh',
93+
} satisfies Story

0 commit comments

Comments
 (0)