import * as React from 'react'
import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
import { Panel } from '~components/Primitives/Panel'
import { ToolButton } from '~components/Primitives/ToolButton'
import { TDShapeType, TDSnapshot, TDToolType } from '~types'
import { useTldrawApp } from '~hooks'
import { SquareIcon, CircleIcon, VercelLogoIcon } from '@radix-ui/react-icons'
import { Tooltip } from '~components/Primitives/Tooltip'
import { LineIcon } from '~components/Primitives/icons'
import { useIntl } from 'react-intl'
interface ShapesMenuProps {
activeTool: TDToolType
isToolLocked: boolean
}
type ShapeShape =
| TDShapeType.Rectangle
| TDShapeType.Ellipse
| TDShapeType.Triangle
| TDShapeType.Line
const shapeShapes: ShapeShape[] = [
TDShapeType.Rectangle,
TDShapeType.Ellipse,
TDShapeType.Triangle,
TDShapeType.Line,
]
const shapeShapeIcons = {
[TDShapeType.Rectangle]: ,
[TDShapeType.Ellipse]: ,
[TDShapeType.Triangle]: ,
[TDShapeType.Line]: ,
}
const statusSelector = (s: TDSnapshot) => s.appState.status
enum Status {
SpacePanning = 'spacePanning',
}
export const ShapesMenu = React.memo(function ShapesMenu({
activeTool,
isToolLocked,
}: ShapesMenuProps) {
const app = useTldrawApp()
const intl = useIntl()
const status = app.useStore(statusSelector)
const [lastActiveTool, setLastActiveTool] = React.useState(TDShapeType.Rectangle)
React.useEffect(() => {
if (shapeShapes.includes(activeTool as ShapeShape) && lastActiveTool !== activeTool) {
setLastActiveTool(activeTool as ShapeShape)
}
}, [activeTool])
const selectShapeTool = React.useCallback(() => {
app.selectTool(lastActiveTool)
}, [activeTool, app])
const handleDoubleClick = React.useCallback(() => {
app.toggleToolLock()
}, [app])
const handleKeyDown = React.useCallback((e: React.KeyboardEvent) => {
if (e.key === ' ') {
if (app.shiftKey) {
e.preventDefault()
}
}
}, [])
const isActive = shapeShapes.includes(activeTool as ShapeShape)
return (
{shapeShapeIcons[lastActiveTool]}
{shapeShapes.map((shape, i) => (
{
app.selectTool(shape)
setLastActiveTool(shape)
}}
>
{shapeShapeIcons[shape]}
))}
)
})