1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-30 00:00:13 +01:00
VILLASweb/src/components/widget.js
Markus Grigull d9a2ae55a9 Add widget context menu
Widget deletion render is kinda broken, but deletion works
2017-03-03 16:58:35 +01:00

63 lines
2.1 KiB
JavaScript

/**
* File: widget.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 02.03.2017
* Copyright: 2017, Institute for Automation of Complex Power Systems, EONERC
* This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential.
* Unauthorized copying of this file, via any medium is strictly prohibited.
**********************************************************************************/
import React, { Component } from 'react';
import Rnd from 'react-rnd';
import { ContextMenuTrigger } from 'react-contextmenu';
import '../styles/widgets.css';
class Widget extends Component {
resizeStop(direction, styleSize, clientSize, delta) {
// update widget
var widget = this.props.data;
widget.width = styleSize.width;
widget.height = styleSize.height;
this.props.onWidgetChange(widget, this.props.index);
}
dragStop(event, ui) {
// update widget
var widget = this.props.data;
widget.x = ui.position.left;
widget.y = ui.position.top;
this.props.onWidgetChange(widget, this.props.index);
}
render() {
const widget = this.props.data;
if (this.props.editing) {
return (
<Rnd
ref={c => { this.rnd = c; }}
initial={{ x: Number(widget.x), y: Number(widget.y), width: widget.width, height: widget.height }}
bounds={'parent'}
className="widget"
onResizeStop={(direction, styleSize, clientSize, delta) => this.resizeStop(direction, styleSize, clientSize, delta)}
onDragStop={(event, ui) => this.dragStop(event, ui)}
>
<ContextMenuTrigger id={'widgetMenu' + this.props.index} attributes={{ style: { width: '100%', height: '100%' } }}>
<div>{widget.name}</div>
</ContextMenuTrigger>
</Rnd>
);
} else {
return (
<div className="widget" style={{ width: Number(widget.width), height: Number(widget.height), left: Number(widget.x), top: Number(widget.y), position: 'absolute' }}>
{widget.name}
</div>
);
}
}
}
export default Widget;