Skip to content

Commit

Permalink
Add calc() support for margin and padding
Browse files Browse the repository at this point in the history
Closes #154.
  • Loading branch information
BramMeerten authored Sep 7, 2024
1 parent b7af48e commit 25bace5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/properties/margin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var isValid = function (v) {
type === TYPES.NULL_OR_EMPTY_STR ||
type === TYPES.LENGTH ||
type === TYPES.PERCENT ||
type === TYPES.CALC ||
(type === TYPES.INTEGER && (v === '0' || v === 0))
);
};
Expand Down
1 change: 1 addition & 0 deletions lib/properties/padding.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var isValid = function (v) {
type === TYPES.NULL_OR_EMPTY_STR ||
type === TYPES.LENGTH ||
type === TYPES.PERCENT ||
type === TYPES.CALC ||
(type === TYPES.INTEGER && (v === '0' || v === 0))
);
};
Expand Down
20 changes: 15 additions & 5 deletions test/CSSStyleDeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,19 @@ describe('CSSStyleDeclaration', () => {
assert.strictEqual(style.getPropertyValue('--fOo'), 'purple');
});

it('supports calc', () => {
const style = new CSSStyleDeclaration();
style.setProperty('width', 'calc(100% - 100px)');
assert.strictEqual(style.getPropertyValue('width'), 'calc(100% - 100px)');
});
for (const property of [
'width',
'height',
'margin',
'margin-top',
'bottom',
'right',
'padding',
]) {
it(`supports calc for ${property}`, () => {
const style = new CSSStyleDeclaration();
style.setProperty(property, 'calc(100% - 100px)');
assert.strictEqual(style.getPropertyValue(property), 'calc(100% - 100px)');
});
}
});

0 comments on commit 25bace5

Please sign in to comment.