Skip to content

Commit

Permalink
feat(title): add optional title to dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
VilliGunn authored and Raphaël Benitte committed Apr 1, 2016
1 parent fc13697 commit e0eaf28
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
28 changes: 23 additions & 5 deletions src/browser/components/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,26 @@ var Dashboard = React.createClass({
},

render() {
var columns = this.props.dashboard.columns;
var rows = this.props.dashboard.rows;
var columns = this.props.dashboard.columns;
var rows = this.props.dashboard.rows;
var title = this.props.dashboard.title || '';
var titleHeight = 10;

var widgetNodes = _.map(this.props.dashboard.widgets, (widget, index) => {
var widgetHeight = widget.rows / rows * 100 + '%';
var widgetY = widget.y / rows * 100 + '%';
if (title) {
widgetHeight = 'calc(' + widgetHeight + ' - ' + (titleHeight / rows) + 'vmin)';
widgetY = 'calc(' + widgetY + ' + ' + (titleHeight / (widget.y === 0 ? 1 : rows)) + 'vmin)';
}

var props = _.extend({}, _.omit(widget, ['columns', 'rows']), {
key: index,
type: widget.type,
w: (widget.columns / columns * 100) + '%',
h: (widget.rows / rows * 100) + '%',
h: widgetHeight,
x: (widget.x / columns * 100) + '%',
y: (widget.y / rows * 100) + '%'
y: widgetY
});

return React.createElement(Widget, props);
Expand All @@ -45,12 +54,21 @@ var Dashboard = React.createClass({
cssClasses += ' _is-current';
}

var titleNode = null;

if (title) {
titleNode = (
<div className="dashboard__title">{title}</div>
);
}

return (
<div className={cssClasses}>
{titleNode}
{widgetNodes}
</div>
);
}
});

module.exports = Dashboard;
module.exports = Dashboard;
2 changes: 2 additions & 0 deletions src/styl/__vars.styl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// GENERIC
$main-bg-color = #fff
$main-txt-color = #555
$main-title-color = #fafafa
$main-title-font = normal normal 400 unquote("4vmin/8vmin") "Open sans", sans-serif
$main-margin = 4vmin
$main-font = normal normal 400 unquote("2.4vmin/3.6vmin") "Open sans", sans-serif

Expand Down
13 changes: 12 additions & 1 deletion src/styl/_main.styl
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@ h1, h2, h3, h4, h5, h6 {
&__value {
color: $prop-value-txt-color;
}
}
}

.dashboard__title {
color: $main-title-color;
font: $main-title-font;
position: absolute;
top: 0;
left: 0;
right: 0;
padding: 1vmin 3vmin;
height: 10vmin;
}

0 comments on commit e0eaf28

Please sign in to comment.