Skip to content

Commit

Permalink
Update hovered state in layers
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed May 17, 2018
1 parent 0b28430 commit dd9e091
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/css/grapes.min.css

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions src/dom_components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
* }
* ...
*/
import { isEmpty } from 'underscore';

module.exports = () => {
var c = {};
let em;
Expand Down Expand Up @@ -190,6 +192,7 @@ module.exports = () => {
c.am = em.get('AssetManager') || '';
em.get('Parser').compTypes = componentTypes;
em.on('change:selectedComponent', this.componentChanged, this);
em.on('change:componentHovered', this.componentHovered, this);
}

// Build wrapper
Expand Down Expand Up @@ -525,6 +528,27 @@ module.exports = () => {
});

model && model.set('status', 'selected');
},

/**
* Triggered when the component is hovered
* @private
*/
componentHovered() {
const em = c.em;
const model = em.get('componentHovered');
const previous = em.previous('componentHovered');
const state = 'hovered';

// Deselect the previous component
previous &&
previous.get('status') == state &&
previous.set({
status: '',
state: ''
});

model && isEmpty(model.get('status')) && model.set('status', state);
}
};
};
22 changes: 14 additions & 8 deletions src/dom_components/view/ComponentView.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,17 @@ module.exports = Backbone.View.extend({
* @private
* */
updateStatus(e) {
var el = this.el;
var status = this.model.get('status');
var pfx = this.pfx;
var ppfx = this.ppfx;
var selectedCls = pfx + 'selected';
var selectedParentCls = selectedCls + '-parent';
var freezedCls = `${ppfx}freezed`;
this.$el.removeClass(`${selectedCls} ${selectedParentCls} ${freezedCls}`);
const em = this.em;
const el = this.el;
const status = this.model.get('status');
const pfx = this.pfx;
const ppfx = this.ppfx;
const selectedCls = `${pfx}selected`;
const selectedParentCls = `${selectedCls}-parent`;
const freezedCls = `${ppfx}freezed`;
const hoveredCls = `${ppfx}hovered`;
const toRemove = [selectedCls, selectedParentCls, freezedCls, hoveredCls];
this.$el.removeClass(toRemove.join(' '));
var actualCls = el.getAttribute('class') || '';
var cls = '';

Expand All @@ -123,6 +126,9 @@ module.exports = Backbone.View.extend({
case 'freezed-selected':
cls = `${actualCls} ${freezedCls} ${selectedCls}`;
break;
case 'hovered':
cls = `${actualCls} ${hoveredCls}`;
break;
}

cls = cls.trim();
Expand Down
4 changes: 4 additions & 0 deletions src/styles/scss/_gjs_layers.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
top: 0;
}

&.#{$nv-prefix}hovered .#{$nv-prefix}layer-title {
background-color: rgba(255, 255, 255, 0.015);
}

&.#{$nv-prefix}selected .#{$nv-prefix}layer-title {
background-color: rgba(255, 255, 255, 0.1);
}
Expand Down

0 comments on commit dd9e091

Please sign in to comment.