Skip to content

Commit 0649960

Browse files
author
v 1 r t l
authored
Merge pull request #52 from saitonakamura/storybook
Added storybook and basic configuration and example
2 parents fd78957 + 52249f0 commit 0649960

File tree

8 files changed

+6273
-154
lines changed

8 files changed

+6273
-154
lines changed

.storybook/Setup.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react'
2+
import * as THREE from 'three'
3+
import { Canvas } from '@react-three/fiber'
4+
import { OrbitControls } from '@react-three/drei'
5+
6+
export function Setup({
7+
children,
8+
cameraFov = 75,
9+
cameraPosition = new THREE.Vector3(0, 0, 5),
10+
controls = true,
11+
lights = false,
12+
...restProps
13+
}: {
14+
children: React.ReactNode | React.ReactNode[]
15+
cameraFov?: number
16+
cameraPosition?: THREE.Camera['position']
17+
controls?: boolean
18+
lights?: boolean
19+
}) {
20+
return (
21+
<Canvas shadows camera={{ position: cameraPosition, fov: cameraFov }} dpr={window.devicePixelRatio} {...restProps}>
22+
{children}
23+
{lights && (
24+
<>
25+
<ambientLight intensity={0.8} />
26+
<pointLight intensity={1} position={[0, 6, 0]} />
27+
</>
28+
)}
29+
{controls && <OrbitControls />}
30+
</Canvas>
31+
)
32+
}

.storybook/index.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
html,
2+
body,
3+
#root {
4+
width: 100%;
5+
height: 100%;
6+
margin: 0;
7+
padding: 0;
8+
-webkit-touch-callout: none;
9+
-webkit-user-select: none;
10+
-khtml-user-select: none;
11+
-moz-user-select: none;
12+
-ms-user-select: none;
13+
user-select: none;
14+
overflow: hidden;
15+
background-color: #121212;
16+
}
17+
18+
#root {
19+
overflow: auto;
20+
}

.storybook/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
stories: ['../.storybook/stories/**/*.stories.@(js|jsx|ts|tsx)'],
3+
addons: ['@storybook/addon-controls', '@storybook/addon-storysource'],
4+
}

.storybook/preview.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import './index.css'
2+
3+
export const parameters = {
4+
layout: 'fullscreen',
5+
}

.storybook/stories/List.stories.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react'
2+
import { ComponentStory, ComponentMeta } from '@storybook/react'
3+
4+
import { Flex, Box } from '../../src'
5+
import { Setup } from '../Setup'
6+
7+
const List = ({ width, height }: { width: number; height: number }) => {
8+
return (
9+
<Flex position={[-width / 2, height / 2, -2]} size={[width, height, 0]} flexDirection="row" flexWrap="wrap">
10+
{new Array(8).fill(undefined).map((_, i) => (
11+
<Box margin={0.3} key={i} width={1.6} height={2} centerAnchor>
12+
{(width, height) => (
13+
<mesh>
14+
<planeBufferGeometry args={[width, height]} />
15+
<meshBasicMaterial color={0x0000ff} />
16+
</mesh>
17+
)}
18+
</Box>
19+
))}
20+
</Flex>
21+
)
22+
}
23+
24+
export default {
25+
title: 'Example/List',
26+
component: List,
27+
} as ComponentMeta<typeof List>
28+
29+
const Template: ComponentStory<typeof List> = (args) => (
30+
<Setup>
31+
<List {...args} />
32+
</Setup>
33+
)
34+
35+
export const Primary = Template.bind({})
36+
Primary.args = {
37+
width: 12,
38+
height: 7,
39+
}

.storybook/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["./stories/**/*"]
4+
}

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
"eslint": "eslint src --fix --ext=js,ts,tsx,jsx",
5454
"eslint-examples": "eslint examples/src --fix --ext=js,ts,tsx,jsx",
5555
"eslint:ci": "eslint src examples/src --fix --ext=js,ts,tsx,jsx",
56-
"test": "echo no tests yet"
56+
"test": "echo no tests yet",
57+
"storybook": "start-storybook -p 6006",
58+
"build-storybook": "build-storybook"
5759
},
5860
"dependencies": {
5961
"yoga-layout-prebuilt": "^1.9.6"
@@ -68,11 +70,15 @@
6870
"@babel/preset-env": "7.15.0",
6971
"@babel/preset-react": "7.14.5",
7072
"@babel/preset-typescript": "^7.10.4",
73+
"@react-three/drei": "^7.3.1",
7174
"@react-three/fiber": "^7.0.6",
7275
"@rollup/plugin-babel": "^5.2.0",
7376
"@rollup/plugin-commonjs": "^20.0.0",
7477
"@rollup/plugin-json": "^4.1.0",
7578
"@rollup/plugin-node-resolve": "^13.0.4",
79+
"@storybook/addon-controls": "^6.3.7",
80+
"@storybook/addon-storysource": "^6.3.7",
81+
"@storybook/react": "^6.3.7",
7682
"@types/jest": "^26.0.8",
7783
"@types/node": "^16.4.13",
7884
"@types/react": "^17.0.16",
@@ -81,6 +87,7 @@
8187
"@types/three": "^0.131.0",
8288
"@typescript-eslint/eslint-plugin": "^4.29.1",
8389
"@typescript-eslint/parser": "^4.29.1",
90+
"babel-loader": "^8.2.2",
8491
"eslint": "^7.6.0",
8592
"eslint-config-prettier": "^8.3.0",
8693
"eslint-import-resolver-alias": "^1.1.2",

0 commit comments

Comments
 (0)