1
1
import * as React from 'react'
2
+ import { ComponentProps } from 'react'
2
3
import * as THREE from 'three'
4
+ import { Meta , StoryObj } from '@storybook/react'
3
5
4
6
import { Setup } from '../Setup'
5
7
@@ -17,27 +19,19 @@ export default {
17
19
</ Setup >
18
20
) ,
19
21
] ,
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 >
28
23
29
- type Anchor = THREE . Vector3 | [ number , number , number ]
24
+ type Story = StoryObj < typeof BBAnchor >
30
25
31
26
function BBAnchorScene ( {
32
- anchor,
33
27
drawBoundingBox,
34
28
children,
35
- } : {
36
- anchor : Anchor
29
+ ... props
30
+ } : ComponentProps < typeof BBAnchor > & {
37
31
drawBoundingBox : boolean
38
- children ?: React . ReactChild
32
+ children ?: React . ReactNode
39
33
} ) {
40
- const ref = React . useRef ( )
34
+ const ref = React . useRef ( null )
41
35
42
36
useHelper ( drawBoundingBox && ref , BoxHelper , 'cyan' )
43
37
@@ -46,16 +40,12 @@ function BBAnchorScene({
46
40
< OrbitControls autoRotate />
47
41
< Icosahedron ref = { ref } >
48
42
< meshBasicMaterial color = "hotpink" wireframe />
49
- < BBAnchor anchor = { anchor } > { children } </ BBAnchor >
43
+ < BBAnchor { ... props } > { children } </ BBAnchor >
50
44
</ Icosahedron >
51
45
</ >
52
46
)
53
47
}
54
48
55
- const Template = ( { drawBoundingBox, anchorX, anchorY, anchorZ, ...args } ) => (
56
- < BBAnchorScene drawBoundingBox = { drawBoundingBox } anchor = { [ anchorX , anchorY , anchorZ ] } { ...args } />
57
- )
58
-
59
49
function HtmlComp ( ) {
60
50
return (
61
51
< Html
@@ -70,15 +60,17 @@ function HtmlComp() {
70
60
)
71
61
}
72
62
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
82
74
83
75
function MeshComp ( ) {
84
76
return (
@@ -88,12 +80,14 @@ function MeshComp() {
88
80
)
89
81
}
90
82
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