2021-10-13 16:03:33 +00:00
|
|
|
import * as React from 'react'
|
|
|
|
import {
|
|
|
|
ArrowTopRightIcon,
|
|
|
|
CircleIcon,
|
2021-11-03 16:46:33 +00:00
|
|
|
CursorArrowIcon,
|
2021-10-13 16:03:33 +00:00
|
|
|
Pencil1Icon,
|
|
|
|
Pencil2Icon,
|
|
|
|
SquareIcon,
|
|
|
|
TextIcon,
|
|
|
|
} from '@radix-ui/react-icons'
|
2021-11-08 14:21:37 +00:00
|
|
|
import { TLDrawSnapshot, TLDrawShapeType } from '~types'
|
2021-10-13 16:03:33 +00:00
|
|
|
import { useTLDrawContext } from '~hooks'
|
2021-11-03 16:46:33 +00:00
|
|
|
import { ToolButtonWithTooltip } from '~components/ToolButton'
|
|
|
|
import { Panel } from '~components/Panel'
|
2021-10-13 16:03:33 +00:00
|
|
|
|
2021-11-08 14:21:37 +00:00
|
|
|
const activeToolSelector = (s: TLDrawSnapshot) => s.appState.activeTool
|
2021-10-13 16:03:33 +00:00
|
|
|
|
2021-11-06 11:19:15 +00:00
|
|
|
export const PrimaryTools = React.memo(function PrimaryTools(): JSX.Element {
|
2021-11-08 14:21:37 +00:00
|
|
|
const { state, useSelector } = useTLDrawContext()
|
2021-10-13 16:03:33 +00:00
|
|
|
|
|
|
|
const activeTool = useSelector(activeToolSelector)
|
|
|
|
|
2021-11-03 16:46:33 +00:00
|
|
|
const selectSelectTool = React.useCallback(() => {
|
2021-11-08 14:21:37 +00:00
|
|
|
state.selectTool('select')
|
|
|
|
}, [state])
|
2021-11-03 16:46:33 +00:00
|
|
|
|
2021-10-13 16:03:33 +00:00
|
|
|
const selectDrawTool = React.useCallback(() => {
|
2021-11-08 14:21:37 +00:00
|
|
|
state.selectTool(TLDrawShapeType.Draw)
|
|
|
|
}, [state])
|
2021-10-13 16:03:33 +00:00
|
|
|
|
|
|
|
const selectRectangleTool = React.useCallback(() => {
|
2021-11-08 14:21:37 +00:00
|
|
|
state.selectTool(TLDrawShapeType.Rectangle)
|
|
|
|
}, [state])
|
2021-10-13 16:03:33 +00:00
|
|
|
|
|
|
|
const selectEllipseTool = React.useCallback(() => {
|
2021-11-08 14:21:37 +00:00
|
|
|
state.selectTool(TLDrawShapeType.Ellipse)
|
|
|
|
}, [state])
|
2021-10-13 16:03:33 +00:00
|
|
|
|
|
|
|
const selectArrowTool = React.useCallback(() => {
|
2021-11-08 14:21:37 +00:00
|
|
|
state.selectTool(TLDrawShapeType.Arrow)
|
|
|
|
}, [state])
|
2021-10-13 16:03:33 +00:00
|
|
|
|
|
|
|
const selectTextTool = React.useCallback(() => {
|
2021-11-08 14:21:37 +00:00
|
|
|
state.selectTool(TLDrawShapeType.Text)
|
|
|
|
}, [state])
|
2021-10-13 16:03:33 +00:00
|
|
|
|
|
|
|
const selectStickyTool = React.useCallback(() => {
|
2021-11-08 14:21:37 +00:00
|
|
|
state.selectTool(TLDrawShapeType.Sticky)
|
|
|
|
}, [state])
|
2021-10-13 16:03:33 +00:00
|
|
|
|
|
|
|
return (
|
2021-11-03 16:46:33 +00:00
|
|
|
<Panel side="center">
|
|
|
|
<ToolButtonWithTooltip
|
2021-11-11 09:54:58 +00:00
|
|
|
kbd={'1'}
|
2021-11-03 16:46:33 +00:00
|
|
|
label={'select'}
|
2021-11-05 14:13:14 +00:00
|
|
|
onClick={selectSelectTool}
|
2021-11-03 16:46:33 +00:00
|
|
|
isActive={activeTool === 'select'}
|
|
|
|
>
|
|
|
|
<CursorArrowIcon />
|
|
|
|
</ToolButtonWithTooltip>
|
|
|
|
<ToolButtonWithTooltip
|
2021-10-13 16:03:33 +00:00
|
|
|
kbd={'2'}
|
|
|
|
label={TLDrawShapeType.Draw}
|
2021-11-05 14:13:14 +00:00
|
|
|
onClick={selectDrawTool}
|
2021-10-13 16:03:33 +00:00
|
|
|
isActive={activeTool === TLDrawShapeType.Draw}
|
|
|
|
>
|
|
|
|
<Pencil1Icon />
|
2021-11-03 16:46:33 +00:00
|
|
|
</ToolButtonWithTooltip>
|
|
|
|
<ToolButtonWithTooltip
|
2021-10-13 16:03:33 +00:00
|
|
|
kbd={'3'}
|
|
|
|
label={TLDrawShapeType.Rectangle}
|
2021-11-05 14:13:14 +00:00
|
|
|
onClick={selectRectangleTool}
|
2021-10-13 16:03:33 +00:00
|
|
|
isActive={activeTool === TLDrawShapeType.Rectangle}
|
|
|
|
>
|
|
|
|
<SquareIcon />
|
2021-11-03 16:46:33 +00:00
|
|
|
</ToolButtonWithTooltip>
|
|
|
|
<ToolButtonWithTooltip
|
2021-10-13 16:03:33 +00:00
|
|
|
kbd={'4'}
|
2021-11-11 09:54:58 +00:00
|
|
|
label={TLDrawShapeType.Ellipse}
|
2021-11-05 14:13:14 +00:00
|
|
|
onClick={selectEllipseTool}
|
2021-10-13 16:03:33 +00:00
|
|
|
isActive={activeTool === TLDrawShapeType.Ellipse}
|
|
|
|
>
|
|
|
|
<CircleIcon />
|
2021-11-03 16:46:33 +00:00
|
|
|
</ToolButtonWithTooltip>
|
|
|
|
<ToolButtonWithTooltip
|
2021-10-13 16:03:33 +00:00
|
|
|
kbd={'5'}
|
|
|
|
label={TLDrawShapeType.Arrow}
|
2021-11-05 14:13:14 +00:00
|
|
|
onClick={selectArrowTool}
|
2021-10-13 16:03:33 +00:00
|
|
|
isActive={activeTool === TLDrawShapeType.Arrow}
|
|
|
|
>
|
|
|
|
<ArrowTopRightIcon />
|
2021-11-03 16:46:33 +00:00
|
|
|
</ToolButtonWithTooltip>
|
|
|
|
<ToolButtonWithTooltip
|
2021-10-13 16:03:33 +00:00
|
|
|
kbd={'6'}
|
|
|
|
label={TLDrawShapeType.Text}
|
2021-11-05 14:13:14 +00:00
|
|
|
onClick={selectTextTool}
|
2021-10-13 16:03:33 +00:00
|
|
|
isActive={activeTool === TLDrawShapeType.Text}
|
|
|
|
>
|
|
|
|
<TextIcon />
|
2021-11-03 16:46:33 +00:00
|
|
|
</ToolButtonWithTooltip>
|
|
|
|
<ToolButtonWithTooltip
|
2021-10-13 16:03:33 +00:00
|
|
|
kbd={'7'}
|
|
|
|
label={TLDrawShapeType.Sticky}
|
2021-11-05 14:13:14 +00:00
|
|
|
onClick={selectStickyTool}
|
2021-10-13 16:03:33 +00:00
|
|
|
isActive={activeTool === TLDrawShapeType.Sticky}
|
|
|
|
>
|
|
|
|
<Pencil2Icon />
|
2021-11-03 16:46:33 +00:00
|
|
|
</ToolButtonWithTooltip>
|
|
|
|
</Panel>
|
2021-10-13 16:03:33 +00:00
|
|
|
)
|
|
|
|
})
|