Skip to content

Commit 79ab0fb

Browse files
Allow negative theme lookup of space objects
1 parent af94aad commit 79ab0fb

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/css/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ type Scales = typeof scales
129129

130130
const positiveOrNegative = (scale: object, value: string | number) => {
131131
if (typeof value !== 'number' || value >= 0) {
132+
if (typeof value === 'string' && value.startsWith('-')) {
133+
const valueWithoutMinus = value.substring(1)
134+
const n = get(scale, valueWithoutMinus, valueWithoutMinus)
135+
return `-${n}`
136+
}
132137
return get(scale, value, value)
133138
}
134139
const absolute = Math.abs(value)

packages/css/test/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,18 @@ test('handles negative top, left, bottom, and right from scale', () => {
259259
})
260260
})
261261

262+
test('handles negative margins from scale that is an object', () => {
263+
const result = css({
264+
mt: '-s',
265+
mx: '-m',
266+
})({...theme, space: { s: '16px', m: '32px' }})
267+
expect(result).toEqual({
268+
marginTop: '-16px',
269+
marginLeft: '-32px',
270+
marginRight: '-32px',
271+
})
272+
})
273+
262274
test('skip breakpoints', () => {
263275
const result = css({
264276
width: ['100%', , '50%'],

0 commit comments

Comments
 (0)