UNPKG

react-dazzle-couban

Version:

The simple yet flexible dashbording solution for React

88 lines (75 loc) 2.09 kB
import React, { createElement } from 'react'; import PropTypes from 'prop-types'; import WidgetFrame from './WidgetFrame'; /** * Component that renders the widget which belongs to a column. */ /* eslint max-len: "off" */ const Widgets = ({ widgets, widgetTypes, onRemove, onEdit, layout, columnIndex, rowIndex, editable, frameComponent, onMove }) => { let createdWidgets = widgets.map((widget, index) => { // eslint-disable-line arrow-body-style return ( widgetTypes[widget.key] && <WidgetFrame key={widget.key} widgetName={widget.key} title={widgetTypes[widget.key].title} onRemove={onRemove} onEdit={onEdit} layout={layout} columnIndex={columnIndex} rowIndex={rowIndex} widgetIndex={index} editable={editable} frameComponent={frameComponent} onMove={onMove} > { createElement(widgetTypes[widget.key].type, widgetTypes[widget.key].props) } </WidgetFrame> ); }); return <div>{createdWidgets}</div>; }; Widgets.propTypes = { /** * Widgets that should be rendered. */ widgets: PropTypes.array, /** * Widgets that are available in the dashboard. */ widgetTypes: PropTypes.object, /** * Function that should be called when a widget is about to be removed. */ onRemove: PropTypes.func, /** * Function that should be called when a widget is about to be eddited. */ onEdit: PropTypes.func, /** * Layout of the dahsboard. */ layout: PropTypes.object, /** * Index of the column these widgets should be placed. */ columnIndex: PropTypes.number, /** * Index of the row these widgets should be placed. */ rowIndex: PropTypes.number, /** * Indicates weatehr dashboard is in ediable mode or not. */ editable: PropTypes.bool, /** * User provided widget frame that should be used instead of the default one. */ frameComponent: PropTypes.func, /** * Method to call when a widget is moved. */ onMove: PropTypes.func, }; export default Widgets;