Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return negative number from lookup if theme value is a number #1665

Merged
merged 2 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/css/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ const positiveOrNegative = (scale: object, value: string | number) => {
if (typeof value === 'string' && value.startsWith('-')) {
const valueWithoutMinus = value.substring(1)
const n = get(scale, valueWithoutMinus, valueWithoutMinus)
if (typeof n === 'number') {
return n * -1
}
return `-${n}`
}
return get(scale, value, value)
Expand Down
14 changes: 13 additions & 1 deletion packages/css/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ test('handles negative top, left, bottom, and right from scale', () => {
})
})

test('handles negative margins from scale that is an object', () => {
test('handles negative margins from scale that is an object and value is string', () => {
const result = css({
mt: '-s',
mx: '-m',
Expand All @@ -417,6 +417,18 @@ test('handles negative margins from scale that is an object', () => {
})
})

test('handles negative margins from scale that is an object and value is number', () => {
const result = css({
mt: '-s',
mx: '-m',
})({ ...theme, space: { s: 16, m: 32 } })
expect(result).toEqual({
marginTop: -16,
marginLeft: -32,
marginRight: -32,
})
})

test('skip breakpoints', () => {
const result = css({
width: ['100%', , '50%'],
Expand Down