-
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.
chore(web): fix text and camera button blocks (#797)
- Loading branch information
Showing
10 changed files
with
329 additions
and
281 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
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
92 changes: 92 additions & 0 deletions
92
web/src/beta/lib/core/StoryPanel/Block/builtin/Camera/Content.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,92 @@ | ||
import { useCallback, useContext, useMemo, useState } from "react"; | ||
|
||
import Button from "@reearth/beta/components/Button"; | ||
import { useVisualizer } from "@reearth/beta/lib/core/Visualizer"; | ||
import { useT } from "@reearth/services/i18n"; | ||
import { styled } from "@reearth/services/theme"; | ||
|
||
import { BlockContext } from "../common/Wrapper"; | ||
|
||
import CameraEditor, { type CameraBlock as CameraBlockType } from "./Editor"; | ||
|
||
type Props = { | ||
propertyId?: string; | ||
cameraButtons: CameraBlockType[]; | ||
isEditable?: boolean; | ||
}; | ||
|
||
const Content: React.FC<Props> = ({ propertyId, cameraButtons, isEditable }) => { | ||
const t = useT(); | ||
const context = useContext(BlockContext); | ||
const visualizer = useVisualizer(); | ||
const [selected, setSelected] = useState<string>(cameraButtons[0]?.id); | ||
|
||
const handleFlyTo = useMemo(() => visualizer.current?.engine.flyTo, [visualizer]); | ||
|
||
const handleClick = useCallback( | ||
(itemId: string) => { | ||
if (isEditable) { | ||
setSelected(itemId); | ||
return; | ||
} | ||
const item = cameraButtons.find(i => i.id === itemId); | ||
if (!item?.cameraPosition?.value) return; | ||
handleFlyTo?.(item.cameraPosition?.value); | ||
}, | ||
[cameraButtons, isEditable, handleFlyTo], | ||
); | ||
|
||
return ( | ||
<Wrapper> | ||
<ButtonWrapper> | ||
{cameraButtons.map(({ title, color, bgColor, id }) => { | ||
return ( | ||
<StyledButton | ||
key={id} | ||
color={color?.value} | ||
bgColor={bgColor?.value} | ||
icon="cameraButtonStoryBlock" | ||
buttonType="primary" | ||
text={title?.value ?? t("New Camera")} | ||
size="small" | ||
onClick={() => handleClick(id)} | ||
/> | ||
); | ||
})} | ||
</ButtonWrapper> | ||
{context?.editMode && ( | ||
<CameraEditor | ||
items={cameraButtons} | ||
propertyId={propertyId} | ||
selected={selected} | ||
setSelected={setSelected} | ||
/> | ||
)} | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export default Content; | ||
|
||
const Wrapper = styled.div` | ||
width: 100%; | ||
`; | ||
|
||
const ButtonWrapper = styled.div` | ||
width: 100%; | ||
display: flex; | ||
gap: 4px; | ||
max-width: 400px; | ||
flex-wrap: wrap; | ||
`; | ||
|
||
const StyledButton = styled(Button)<{ color?: string; bgColor?: string }>` | ||
color: ${({ color }) => color}; | ||
background-color: ${({ bgColor }) => bgColor}; | ||
border-color: ${({ color }) => color}; | ||
&:hover { | ||
color: ${({ bgColor }) => bgColor}; | ||
background-color: ${({ color }) => color}; | ||
} | ||
`; |
182 changes: 0 additions & 182 deletions
182
web/src/beta/lib/core/StoryPanel/Block/builtin/Camera/Editor.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.