-
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 status checks…
feat: arrow-popup
1 parent
02736d4
commit a4195f7
Showing
5 changed files
with
169 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import classNames from 'classnames'; | ||
import { Island } from './island'; | ||
import Stack from './stack'; | ||
import { ToolButton } from './tool-button'; | ||
import { StraightArrowIcon, ElbowArrowIcon, CurveArrowIcon } from './icons'; | ||
import { useBoard } from '@plait/react-board'; | ||
import { BoardTransforms, PlaitBoard } from '@plait/core'; | ||
import * as Popover from '@radix-ui/react-popover'; | ||
import React from 'react'; | ||
import { BoardCreationMode, setCreationMode } from '@plait/common'; | ||
import { LineShape } from '@plait/draw'; | ||
|
||
export interface ArrowProps { | ||
icon: React.ReactNode; | ||
title: string; | ||
pointer: LineShape; | ||
} | ||
|
||
const ARROWS: ArrowProps[] = [ | ||
{ | ||
icon: StraightArrowIcon, | ||
title: 'Straight Arrow Line', | ||
pointer: LineShape.straight, | ||
}, | ||
{ | ||
icon: ElbowArrowIcon, | ||
title: 'Elbow Arrow Line', | ||
pointer: LineShape.elbow, | ||
}, | ||
{ | ||
icon: CurveArrowIcon, | ||
title: 'Curve Arrow Line', | ||
pointer: LineShape.curve, | ||
}, | ||
]; | ||
|
||
export const ArrowPopupContent: React.FC = () => { | ||
const board = useBoard(); | ||
const container = PlaitBoard.getBoardContainer(board); | ||
|
||
const onPointerDown = (pointer: LineShape) => { | ||
setCreationMode(board, BoardCreationMode.drawing); | ||
BoardTransforms.updatePointerType(board, pointer); | ||
}; | ||
|
||
const onPointerUp = () => {}; | ||
|
||
return ( | ||
<Popover.Portal container={container}> | ||
<Popover.Content sideOffset={12}> | ||
<Island padding={1}> | ||
<Stack.Row gap={1}> | ||
{ARROWS.map((arrow, index) => { | ||
return ( | ||
<ToolButton | ||
key={index} | ||
className={classNames({ fillable: false })} | ||
type="icon" | ||
size={'small'} | ||
visible={true} | ||
icon={arrow.icon} | ||
title={arrow.title} | ||
aria-label={arrow.title} | ||
onPointerDown={() => { | ||
onPointerDown(arrow.pointer); | ||
}} | ||
onPointerUp={() => { | ||
onPointerUp(); | ||
}} | ||
/> | ||
); | ||
})} | ||
</Stack.Row> | ||
</Island> | ||
</Popover.Content> | ||
</Popover.Portal> | ||
); | ||
}; |
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
Empty file.
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