Implement drag and drop (#21)
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: https://git.siklos-chaneru.duckdns.org/Siklos/svg-layout-designer-react/pulls/21
This commit is contained in:
Siklos 2022-08-09 06:08:04 -04:00
parent f1e2326073
commit 1fc11adbaa
5 changed files with 172 additions and 45 deletions

View file

@ -8,14 +8,21 @@ interface ISidebarProps {
buttonOnClick: (type: string) => void
}
function handleDragStart(event: React.DragEvent<HTMLButtonElement>): void {
event.dataTransfer.setData('type', (event.target as HTMLButtonElement).id);
}
export default class Sidebar extends React.PureComponent<ISidebarProps> {
public render(): JSX.Element {
const listElements = this.props.componentOptions.map(componentOption =>
<button
className='justify-center transition-all sidebar-component'
key={componentOption.Type}
id={componentOption.Type}
title={componentOption.Type}
onClick={() => this.props.buttonOnClick(componentOption.Type)}
draggable={true}
onDragStart={(event) => handleDragStart(event)}
>
{truncateString(componentOption.Type, 5)}
</button>