Skip to content

Commit

Permalink
fix: handle outline style/width
Browse files Browse the repository at this point in the history
  • Loading branch information
cdoublev committed May 3, 2021
1 parent 0e42fb2 commit dac15bb
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/CSSStyleDeclaration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ describe('CSSStyleDeclaration', () => {
expect(style.borderTopWidth).toEqual('0px');
expect(style.borderLeftStyle).toEqual('solid');
expect(style.borderBottomColor).toEqual('black');
style.outline = 'black solid 0';
expect(style.outlineWidth).toEqual('0px');
expect(style.outlineStyle).toEqual('solid');
expect(style.outlineColor).toEqual('black');
style.font = '12em monospace';
expect(style.fontSize).toEqual('12em');
expect(style.fontFamily).toEqual('monospace');
Expand Down
1 change: 1 addition & 0 deletions lib/properties/borderWidth.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var parser = function(v) {
}
return undefined;
};
module.exports.parse = parser;

module.exports.definition = {
set: implicitSetter('border', 'width', isValid, parser),
Expand Down
17 changes: 17 additions & 0 deletions lib/properties/outline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

var shorthandSetter = require('../parsers').shorthandSetter;
var shorthandGetter = require('../parsers').shorthandGetter;

var shorthand_for = {
'outline-color': require('./outlineColor'),
'outline-style': require('./outlineStyle'),
'outline-width': require('./outlineWidth'),
};

module.exports.definition = {
set: shorthandSetter('outline', shorthand_for),
get: shorthandGetter('outline', shorthand_for),
enumerable: true,
configurable: true,
};
6 changes: 4 additions & 2 deletions lib/properties/outlineColor.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict';

var parseColor = require('../parsers').parseColor;
var isValid = (module.exports.isValid = require('./borderColor').isValid);

module.exports.definition = {
set: function(v) {
this._setProperty('outline-color', parseColor(v));
if (isValid(v)) {
this._setProperty('outline-color', v);
}
},
get: function() {
return this.getPropertyValue('outline-color');
Expand Down
20 changes: 20 additions & 0 deletions lib/properties/outlineStyle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

var isValid = (module.exports.isValid = require('./borderStyle').isValid);

module.exports.definition = {
set: function(v) {
if (isValid(v)) {
if (v.toLowerCase() === 'none') {
v = '';
this.removeProperty('outline-style');
}
this._setProperty('outline-style', v);
}
},
get: function() {
return this.getPropertyValue('outline-style');
},
enumerable: true,
configurable: true,
};
18 changes: 18 additions & 0 deletions lib/properties/outlineWidth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

var borderWidth = require('./borderWidth');
var isValid = (module.exports.isValid = borderWidth.isValid);
var parse = borderWidth.parse;

module.exports.definition = {
set: function(v) {
if (isValid(v)) {
this._setProperty('outline-width', parse(v));
}
},
get: function() {
return this.getPropertyValue('outline-width');
},
enumerable: true,
configurable: true,
};

0 comments on commit dac15bb

Please sign in to comment.