-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41326d9
commit dfa05b1
Showing
9 changed files
with
459 additions
and
29 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
93 changes: 93 additions & 0 deletions
93
web/src/beta/components/fields/CameraField/index.stories.tsx
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,93 @@ | ||
import { useArgs } from "@storybook/preview-api"; | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
import { useCallback } from "react"; | ||
|
||
import { styled } from "@reearth/services/theme"; | ||
|
||
import CameraField, { Props, CameraValue } from "."; | ||
|
||
const meta: Meta<typeof CameraField> = { | ||
component: CameraField, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof CameraField>; | ||
|
||
export const Default: Story = (args: Props) => { | ||
const [_, updateArgs] = useArgs(); | ||
|
||
const handleChange = useCallback( | ||
(value: CameraValue) => updateArgs({ value: value }), | ||
[updateArgs], | ||
); | ||
|
||
const handleClean = useCallback(() => updateArgs({ value: undefined }), [updateArgs]); | ||
|
||
const handleJump = useCallback( | ||
(value: CameraValue) => console.log("Jumping to camera value", value), | ||
[], | ||
); | ||
|
||
const handleCapture = useCallback(() => { | ||
console.log("on capture updates a random value"); | ||
updateArgs({ | ||
value: { | ||
lat: (Math.random() * 180).toFixed(2), | ||
lng: (Math.random() * 180).toFixed(2), | ||
altitude: (Math.random() * 100).toFixed(2), | ||
heading: (Math.random() * 10).toFixed(2), | ||
pitch: (Math.random() * 10).toFixed(2), | ||
roll: (Math.random() * 10).toFixed(2), | ||
fov: (Math.random() * 180).toFixed(2), | ||
}, | ||
}); | ||
}, [updateArgs]); | ||
|
||
return ( | ||
<Wrapper> | ||
<div> | ||
<CameraField | ||
{...args} | ||
onChange={handleChange} | ||
onClean={handleClean} | ||
onJump={handleJump} | ||
onCapture={handleCapture} | ||
/> | ||
</div> | ||
<div> | ||
<CameraField {...args} disabled={true} /> | ||
</div> | ||
<div> | ||
<CameraField | ||
{...args} | ||
name="Camera field without controls" | ||
onChange={handleChange} | ||
onClean={undefined} | ||
onJump={undefined} | ||
onCapture={undefined} | ||
/> | ||
</div> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
Default.args = { | ||
name: "Camera field", | ||
description: "Camera field description", | ||
value: undefined, | ||
disabled: false, | ||
onCapture: () => console.log("captured"), | ||
onJump: (input: CameraValue) => console.log("Jump to", input), | ||
onClean: () => console.log("clean camera value"), | ||
onChange: (value: CameraValue) => console.log("updated camera value", value), | ||
}; | ||
|
||
const Wrapper = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10%; | ||
margin-left: 2rem; | ||
margin-top: 2rem; | ||
height: 300px; | ||
`; |
Oops, something went wrong.