Skip to content

Commit

Permalink
Add support for negative calc values
Browse files Browse the repository at this point in the history
  • Loading branch information
Ari Seyhun authored and Ari Seyhun committed Aug 1, 2019
1 parent 03b73b1 commit d3675eb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions __tests__/resolveConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@ test('custom properties are multiplied by -1 for negative values', () => {
'4': '4px',
foo: 'var(--foo)',
bar: 'var(--bar, 500px)',
baz: 'calc(50% - 10px)',
},
margin: (theme, { negative }) => ({
...theme('spacing'),
Expand Down Expand Up @@ -1171,6 +1172,7 @@ test('custom properties are multiplied by -1 for negative values', () => {
'4': '4px',
foo: 'var(--foo)',
bar: 'var(--bar, 500px)',
baz: 'calc(50% - 10px)',
},
margin: {
'1': '1px',
Expand All @@ -1179,12 +1181,14 @@ test('custom properties are multiplied by -1 for negative values', () => {
'4': '4px',
foo: 'var(--foo)',
bar: 'var(--bar, 500px)',
baz: 'calc(50% - 10px)',
'-1': '-1px',
'-2': '-2px',
'-3': '-3px',
'-4': '-4px',
'-foo': 'calc(var(--foo) * -1)',
'-bar': 'calc(var(--bar, 500px) * -1)',
'-baz': 'calc(calc(50% - 10px) * -1)',
},
},
variants: {},
Expand Down
2 changes: 1 addition & 1 deletion src/util/resolveConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const configUtils = {
.reduce(
(negativeScale, key) => ({
...negativeScale,
[`-${key}`]: startsWith(scale[key], 'var(')
[`-${key}`]: ['var(', 'calc('].some(prefix => startsWith(scale[key], prefix))
? `calc(${scale[key]} * -1)`
: `-${scale[key]}`,
}),
Expand Down

0 comments on commit d3675eb

Please sign in to comment.