Skip to content

Commit

Permalink
Merge pull request #7 from johncmckim/issue-6
Browse files Browse the repository at this point in the history
Merge Columns and Row components
  • Loading branch information
Raathigesh authored Sep 14, 2016
2 parents 0aed548 + 4b32993 commit 7bb2cb8
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 234 deletions.
127 changes: 0 additions & 127 deletions lib/components/Columns.js

This file was deleted.

7 changes: 3 additions & 4 deletions lib/components/LayoutRenderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { PropTypes } from 'react';
import Row from './Row';
import Columns from './Columns';

/**
* Renders the row, column layout based on the layout provided to the dashboard.
Expand All @@ -23,8 +22,9 @@ const LayoutRenderer = (props) => {

let rows = layout.rows.map((row, rowIndex) => {
return (
<Row key={rowIndex} rowClass={rowClass}>
<Columns
<Row
key={rowIndex}
rowClass={rowClass}
columns={row.columns}
widgets={widgets}
onRemove={onRemove}
Expand All @@ -39,7 +39,6 @@ const LayoutRenderer = (props) => {
addWidgetComponentText={addWidgetComponentText}
addWidgetComponent={addWidgetComponent}
/>
</Row>
);
});

Expand Down
123 changes: 117 additions & 6 deletions lib/components/Row.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,66 @@
import React, { PropTypes } from 'react';
import Column from './Column';
import Widgets from './Widgets';

/**
* Represents a row in the grid system.
* Returns a set of columns that belongs to a row.
*/
const Row = ({ rowClass, children }) => {
function Row(props) {
const {
rowClass,
columns,
widgets,
onRemove,
layout,
rowIndex,
editable,
frameComponent,
editableColumnClass,
droppableColumnClass,
addWidgetComponentText,
addWidgetComponent,
onAdd,
onMove,
} = props;

const items = columns.map((column, index) => {
return (
<Column
key={index}
className={column.className}
onAdd={onAdd}
layout={layout}
rowIndex={rowIndex}
columnIndex={index}
editable={editable}
onMove={onMove}
editableColumnClass={editableColumnClass}
droppableColumnClass={droppableColumnClass}
addWidgetComponent={addWidgetComponent}
addWidgetComponentText={addWidgetComponentText}
>
<Widgets
key={index}
widgets={column.widgets}
widgetTypes={widgets}
onRemove={onRemove}
layout={layout}
rowIndex={rowIndex}
columnIndex={index}
editable= {editable}
frameComponent = {frameComponent}
onMove={onMove}
/>
</Column>
);
});

return (
<div className={rowClass}>
{children}
{items}
</div>
);
};
}

Row.propTypes = {
/**
Expand All @@ -18,9 +69,69 @@ Row.propTypes = {
rowClass: PropTypes.string,

/**
* Children of the row component.
* Columns of the layout.
*/
columns: PropTypes.array,

/**
* Widgets that should be used in the dashboard.
*/
widgets: PropTypes.object,

/**
* Layout of the dashboard.
*/
layout: PropTypes.object,

/**
* Index of the row where this column is in.
*/
rowIndex: PropTypes.number,

/**
* Indicates weather the dashboard is in editable mode or not.
*/
editable: PropTypes.bool,

/**
* Custom frame that should be used with the widget.
*/
frameComponent: PropTypes.func,

/**
* Class to be used for columns in editable mode.
*/
editableColumnClass: PropTypes.string,

/**
* CSS class to be used for columns when a widget is droppable.
*/
droppableColumnClass: PropTypes.string,

/**
* Custom AddWidget component.
*/
addWidgetComponent: PropTypes.func,

/**
* Text that should be displyed in the AddWidget component.
*/
addWidgetComponentText: PropTypes.string,

/**
* Method that should be called when a component is added.
*/
onAdd: PropTypes.func,

/**
* Method that should be called when a component is removed.
*/
onRemove: PropTypes.func,

/**
* Method that should be called when a widget is moved.
*/
children: PropTypes.node,
onMove: PropTypes.func,
};

Row.defaultProps = {
Expand Down
92 changes: 0 additions & 92 deletions test/components/Columns.spec.js

This file was deleted.

Loading

0 comments on commit 7bb2cb8

Please sign in to comment.