Skip to content

Commit fa8ca2f

Browse files
authored
fix: CSF3 (#1974)
* chore: wip csf3 * chore: story not fn
1 parent 7645061 commit fa8ca2f

File tree

159 files changed

+5548
-3587
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+5548
-3587
lines changed

.storybook/main.ts

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

2424
typescript: {
2525
reactDocgen: 'react-docgen-typescript',
26+
reactDocgenTypescriptOptions: {
27+
propFilter: (prop, component) => {
28+
// Only include props that belong to the current component
29+
const fileName = prop.declarations?.at(0)?.fileName // 'drei/src/core/AccumulativeShadows.tsx'
30+
const componentName = fileName?.split('/').at(-1)?.split('.').at(0) // 'AccumulativeShadows'
31+
return component.name === componentName
32+
},
33+
},
2634
},
2735
}
2836

.storybook/public/images/tiger.svg

+730
Loading
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
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,
12-
decorators: [(storyFn) => <Setup> {storyFn()}</Setup>],
13-
}
13+
component: AccumulativeShadows,
14+
decorators: [
15+
(Story) => (
16+
<Setup>
17+
<Story />
18+
</Setup>
19+
),
20+
],
21+
} satisfies Meta<typeof AccumulativeShadows>
22+
23+
type Story = StoryObj<typeof AccumulativeShadows>
1424

15-
function AccumulativeShadowScene() {
25+
function AccumulativeShadowScene(props: ComponentProps<typeof AccumulativeShadows>) {
1626
return (
17-
<React.Suspense fallback={null}>
27+
<>
1828
<color attach="background" args={['goldenrod']} />
29+
1930
<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-
>
31+
32+
<AccumulativeShadows {...props} position={[0, -0.5, 0]}>
2933
<RandomizedLight amount={8} radius={4} ambient={0.5} bias={0.001} position={[5, 5, -10]} />
3034
</AccumulativeShadows>
35+
3136
<OrbitControls autoRotate={true} />
3237
<Environment preset="city" />
33-
</React.Suspense>
38+
</>
3439
)
3540
}
3641

37-
function Suzi(props) {
42+
function Suzi(props: ComponentProps<'group'>) {
3843
const { scene, materials } = useGLTF('/suzanne-high-poly.gltf')
3944
React.useLayoutEffect(() => {
4045
scene.traverse((obj) => (obj as any).isMesh && (obj.receiveShadow = obj.castShadow = true))
@@ -55,5 +60,18 @@ function Suzi(props) {
5560
return <primitive object={scene} {...props} />
5661
}
5762

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

.storybook/stories/Adaptive.stories.tsx

+19-10
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,9 +11,9 @@ import type { GLTF } from 'three-stdlib'
1011

1112
export default {
1213
title: 'Performance/Adaptive',
13-
component: useGLTF,
14+
component: AdaptiveDpr,
1415
decorators: [
15-
(storyFn) => (
16+
(Story) => (
1617
<Setup
1718
cameraPosition={new Vector3(0, 0, 30)}
1819
cameraFov={50}
@@ -21,11 +22,13 @@ export default {
2122
lights={false}
2223
performance={{ min: 0.2 }}
2324
>
24-
{storyFn()}
25+
<Story />
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

+37-26
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,49 @@
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,
32-
decorators: [(storyFn) => <Setup controls={false}>{storyFn()}</Setup>],
14+
decorators: [
15+
(Story) => (
16+
<Setup controls={false}>
17+
<Story />
18+
</Setup>
19+
),
20+
],
21+
args: {
22+
enablePan: true,
23+
enableRotate: true,
24+
enableZoom: true,
25+
},
26+
} satisfies Meta<typeof ArcballControls>
27+
28+
type Story = StoryObj<typeof ArcballControls>
29+
30+
function DefaultScene(props: ComponentProps<typeof ArcballControls>) {
31+
return (
32+
<>
33+
<ArcballControls {...props} />
34+
<Box>
35+
<meshBasicMaterial wireframe />
36+
</Box>
37+
</>
38+
)
3339
}
3440

35-
const CustomCamera = (props: ArcballControlsProps) => {
41+
export const ArcballControlsSt1 = {
42+
render: (args) => <DefaultScene {...args} />,
43+
name: 'Default',
44+
} satisfies Story
45+
46+
const CustomCamera = ({ ...props }: ComponentProps<typeof ArcballControls>) => {
3647
/**
3748
* we will render our scene in a render target and use it as a map.
3849
*/
@@ -73,7 +84,7 @@ const CustomCamera = (props: ArcballControlsProps) => {
7384
)
7485
}
7586

76-
export const CustomCameraStory = (props: ArcballControlsProps) => <CustomCamera {...props} />
77-
78-
CustomCameraStory.args = args
79-
CustomCameraStory.storyName = 'Custom Camera'
87+
export const ArcballControlsSt2 = {
88+
render: (args) => <CustomCamera {...args} />,
89+
name: 'Custom Camera',
90+
} satisfies Story
+33-40
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

@@ -10,34 +12,25 @@ export default {
1012
title: 'Staging/BBAnchor',
1113
component: BBAnchor,
1214
decorators: [
13-
(storyFn) => (
15+
(Story) => (
1416
<Setup cameraPosition={new THREE.Vector3(2, 2, 2)} controls={false}>
15-
{' '}
16-
{storyFn()}
17+
<Story />
1718
</Setup>
1819
),
1920
],
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-
}
21+
} satisfies Meta<typeof BBAnchor>
2822

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

3125
function BBAnchorScene({
32-
anchor,
3326
drawBoundingBox,
3427
children,
35-
}: {
36-
anchor: Anchor
28+
...props
29+
}: ComponentProps<typeof BBAnchor> & {
3730
drawBoundingBox: boolean
38-
children?: React.ReactChild
31+
children?: React.ReactNode
3932
}) {
40-
const ref = React.useRef()
33+
const ref = React.useRef(null)
4134

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

@@ -46,16 +39,12 @@ function BBAnchorScene({
4639
<OrbitControls autoRotate />
4740
<Icosahedron ref={ref}>
4841
<meshBasicMaterial color="hotpink" wireframe />
49-
<BBAnchor anchor={anchor}>{children}</BBAnchor>
42+
<BBAnchor {...props}>{children}</BBAnchor>
5043
</Icosahedron>
5144
</>
5245
)
5346
}
5447

55-
const Template = ({ drawBoundingBox, anchorX, anchorY, anchorZ, ...args }) => (
56-
<BBAnchorScene drawBoundingBox={drawBoundingBox} anchor={[anchorX, anchorY, anchorZ]} {...args} />
57-
)
58-
5948
function HtmlComp() {
6049
return (
6150
<Html
@@ -70,15 +59,17 @@ function HtmlComp() {
7059
)
7160
}
7261

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'
62+
export const BBAnchorWithHtml = {
63+
render: (args) => (
64+
<BBAnchorScene {...args} drawBoundingBox={true}>
65+
<HtmlComp />
66+
</BBAnchorScene>
67+
),
68+
args: {
69+
anchor: [1, 1, 1],
70+
},
71+
name: 'With Html component',
72+
} satisfies Story
8273

8374
function MeshComp() {
8475
return (
@@ -88,12 +79,14 @@ function MeshComp() {
8879
)
8980
}
9081

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'
82+
export const BBAnchorWithMesh = {
83+
render: (args) => (
84+
<BBAnchorScene {...args} drawBoundingBox={true}>
85+
<MeshComp />
86+
</BBAnchorScene>
87+
),
88+
args: {
89+
anchor: [1, 1, 1],
90+
},
91+
name: 'With other mesh',
92+
} satisfies Story

0 commit comments

Comments
 (0)