Skip to content

Commit a34483b

Browse files
authored
Merge pull request #865 from kenny-f/space-object-negative-lookup
Allow negative theme lookup of space objects
2 parents 350b018 + 79ab0fb commit a34483b

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
@@ -130,6 +130,11 @@ type Scales = typeof scales
130130

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

packages/css/test/index.ts

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

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

0 commit comments

Comments
 (0)