-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs(Example): an Example component * docs: inner-links
- Loading branch information
Showing
7 changed files
with
14,266 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import * as THREE from 'three' | ||
import * as React from 'react' | ||
import { withKnobs } from '@storybook/addon-knobs' | ||
import { Vector3 } from 'three' | ||
|
||
import { Setup } from '../Setup' | ||
|
||
import { Example, ExampleApi, Sparkles } from '../../src' | ||
|
||
export default { | ||
title: 'Misc/Example', | ||
component: Example, | ||
decorators: [ | ||
withKnobs, | ||
(storyFn) => ( | ||
<Setup cameraPosition={new Vector3(1, 2, 4)} cameraFov={60}> | ||
{storyFn()} | ||
</Setup> | ||
), | ||
], | ||
} | ||
|
||
export const ExampleSt = ({ fontUrl, color, bevelSize, debug }) => { | ||
const apiRef = React.useRef<ExampleApi>(null) | ||
|
||
return ( | ||
<> | ||
<color attach="background" args={['#303030']} /> | ||
<axesHelper /> | ||
|
||
<Example | ||
font={fontUrl} | ||
color={color} | ||
bevelSize={bevelSize} | ||
debug={debug} | ||
ref={apiRef} | ||
onClick={(e) => { | ||
if ((e as any as PointerEvent).metaKey) { | ||
apiRef.current?.decr() | ||
} else { | ||
apiRef.current?.incr() | ||
} | ||
}} | ||
> | ||
<Sparkles scale={2} /> | ||
</Example> | ||
</> | ||
) | ||
} | ||
ExampleSt.args = { | ||
fontUrl: '/fonts/Inter_Bold.json', | ||
bevelSize: undefined, | ||
color: '#cbcbcb', | ||
debug: false, | ||
} | ||
|
||
ExampleSt.argTypes = { | ||
fontUrl: { control: 'select', options: ['/fonts/Inter_Bold.json', '/fonts/helvetiker_regular.typeface.json'] }, | ||
bevelSize: { control: { type: 'range', min: 0, max: 0.1, step: 0.01 } }, | ||
color: { control: { type: 'color' } }, | ||
debug: { control: { type: 'boolean' } }, | ||
} | ||
|
||
ExampleSt.storyName = 'Default' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint react-hooks/exhaustive-deps: 1 */ | ||
import * as React from 'react' | ||
import * as THREE from 'three' | ||
import { type Color } from '@react-three/fiber' | ||
|
||
import { Text3D } from './Text3D' | ||
import { Center } from './Center' | ||
|
||
export type ExampleProps = { | ||
color?: Color | ||
debug?: boolean | ||
bevelSize?: number | ||
font?: string | ||
} & JSX.IntrinsicElements['group'] | ||
|
||
export type ExampleApi = { | ||
incr: (x?: number) => void | ||
decr: (x?: number) => void | ||
} | ||
|
||
export const Example = React.forwardRef<ExampleApi, ExampleProps>( | ||
( | ||
{ font = '/fonts/Inter_Bold.json', color = '#cbcbcb', bevelSize = 0.04, debug = false, children, ...props }, | ||
fref | ||
) => { | ||
const [counter, setCounter] = React.useState(0) | ||
|
||
const incr = React.useCallback((x = 1) => setCounter(counter + x), [counter]) | ||
const decr = React.useCallback((x = 1) => setCounter(counter - x), [counter]) | ||
|
||
// ref-API | ||
const api = React.useMemo<ExampleApi>(() => ({ incr, decr }), [incr, decr]) | ||
React.useImperativeHandle(fref, () => api, [api]) | ||
|
||
return ( | ||
<group {...props}> | ||
<Center top cacheKey={JSON.stringify({ counter, font })}> | ||
<Text3D bevelEnabled bevelSize={bevelSize} font={font}> | ||
{counter} | ||
{debug ? <meshNormalMaterial wireframe /> : <meshStandardMaterial color={color} />} | ||
</Text3D> | ||
</Center> | ||
{children} | ||
</group> | ||
) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a5e16eb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
drei – ./
drei.vercel.app
drei-git-master-pmndrs.vercel.app
drei-pmndrs.vercel.app
drei.react-spring.io
drei.pmnd.rs