Skip to content

Commit

Permalink
update ViewSwitcher behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
metagrover committed Mar 21, 2017
1 parent 3adbf11 commit ea12074
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
25 changes: 22 additions & 3 deletions app/actuators/ViewSwitcher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import React, { Component } from "react";

export default class ViewSwitcher extends Component {
constructor(props) {
super(props);

this.state = {
active: this.props.defaultSelected || this.props.data[0].value
};
}

componentDidMount() {
this.switchView(this.props.defaultSelected);
}
Expand All @@ -14,6 +22,9 @@ export default class ViewSwitcher extends Component {
const el = document.querySelector("." + item.value);
if (el) {
if (element === item.value) {
this.setState({
active: item.value
});
document.querySelector("." + item.value).style.display = "block";
} else {
document.querySelector("." + item.value).style.display = "none";
Expand All @@ -23,9 +34,17 @@ export default class ViewSwitcher extends Component {
}

renderItems() {
return this.props.data.map(item => (
<div key={item.value} className="rbc-list-item" onClick={() => this.switchView(item.value)}>{item.label}</div>
));
return this.props.data.map((item) => {
let cx = "";

if (item.value === this.state.active) {
cx = "active";
}

return (
<div key={item.value} className={`rbc-list-item ${cx}`} onClick={() => this.switchView(item.value)}>{item.label}</div>
);
});
}

render() {
Expand Down
6 changes: 5 additions & 1 deletion app/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@
background-color: #fff;
border: 1px solid #eaeaea;
border-left: 0;
cursor: pointer; }
cursor: pointer;
transition: all .3s ease;
-webkit-transition: all .3s ease; }
.rbc.rbc-viewswitcher .rbc-list-container .rbc-list-item.active {
background-color: #f2f2f2; }
.rbc.rbc-viewswitcher .rbc-list-container .rbc-list-item:first-child {
border-left: 1px solid #eaeaea; }
6 changes: 6 additions & 0 deletions app/assets/styles/partials/components/_viewswitcher.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
border: 1px solid #eaeaea;
border-left: 0;
cursor: pointer;
transition: all .3s ease;
-webkit-transition: all .3s ease;

&.active {
background-color: #f2f2f2;
}

&:first-child {
border-left: 1px solid #eaeaea;
Expand Down
2 changes: 1 addition & 1 deletion dist/css/style.min.css

Large diffs are not rendered by default.

0 comments on commit ea12074

Please sign in to comment.