Skip to content

Commit

Permalink
Add stylable-require property on Component Model
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Nov 8, 2017
1 parent 2354274 commit 687e150
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/dom_components/model/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ module.exports = Backbone.Model.extend(Styleable).extend({
// All other properties will be hidden from the style manager
stylable: true,

// Indicate an array of style properties to show up which has been marked as `toRequire`
'stylable-require': '',

// Indicate an array of style properties which should be hidden from the style manager
unstylable: '',

Expand Down
7 changes: 7 additions & 0 deletions src/style_manager/model/Property.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ module.exports = require('backbone').Model.extend({
status: '',
visible: true,
fixedValues: ['initial', 'inherit'],

// If true, will be hidden by default and will show up only for targets
// which require this property (via `stylable-require`)
// Use case:
// you can add all SVG CSS properties with toRequire as true
// and then require them on SVG Components
toRequire: 0,
},


Expand Down
13 changes: 12 additions & 1 deletion src/style_manager/view/PropertyView.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,15 @@ module.exports = Backbone.View.extend({
* @return {Boolean}
*/
isTargetStylable(target) {
if (this.model.get('id') == 'flex-width') {
//debugger;
}
const trg = target || this.getTarget();
const property = this.model.get('property');
const model = this.model;
const property = model.get('property');
const toRequire = model.get('toRequire');
const unstylable = trg.get('unstylable');
const stylableReq = trg.get('stylable-require');
let stylable = trg.get('stylable');

// Stylable could also be an array indicating with which property
Expand All @@ -391,6 +397,11 @@ module.exports = Backbone.View.extend({
stylable = unstylable.indexOf(property) < 0;
}

// Check if the property is available only if requested
if (toRequire) {
stylable = (stylableReq && stylableReq.indexOf(property) >= 0) || !target;
}

return stylable;
},

Expand Down

0 comments on commit 687e150

Please sign in to comment.