Skip to content

Commit

Permalink
fix(system): space nested values
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Aug 9, 2019
1 parent 348803c commit 4119e8c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/system/src/style.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ describe('#style', () => {
it('reads from theme', () => {
const scope = themeGetter({ key: 'scope' })
expect(scope('value')({ theme: { scope: { value: 'foo' } } })).toBe('foo')
expect(
scope('a.b.c')({ theme: { scope: { a: { b: { c: 'd' } } } } }),
).toBe('d')
})

it('uses defaultVariants', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/system/src/styles/space.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { style, themeGetter, compose } from '../style'
import { is, string, negative } from '../util'
import { is, string, negative, get } from '../util'
import { getPx } from './basics'

function toNegative(value) {
Expand All @@ -18,7 +18,7 @@ export const getSpace = themeGetter({
if (string(rawValue)) {
const neg = rawValue.startsWith('-')
const absoluteValue = neg ? rawValue.substr(1) : rawValue
const variantValue = variants[absoluteValue]
const variantValue = get(variants, absoluteValue)
const value = is(variantValue) ? variantValue : absoluteValue
return neg ? toNegative(value) : value
}
Expand Down
3 changes: 3 additions & 0 deletions packages/system/src/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ describe('util', () => {
it('gets a value from the theme', () => {
expect(getThemeValue({}, 'foo')).toBe(undefined)
expect(getThemeValue({ theme: { foo: 'bar' } }, 'foo')).toBe('bar')
expect(getThemeValue({ theme: { a: { b: { c: 'd' } } } }, 'a.b.c')).toBe(
'd',
)
expect(getThemeValue({ theme: { foo: 'bar' } }, 'x')).toBe(undefined)
})

Expand Down
2 changes: 2 additions & 0 deletions packages/system/tests/styled-components/th.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ describe('#th', () => {
[-2, '-8px'],
['16rpx', '1rem'],
['-16rpx', '-1rem'],
['button.md', '100px'],
],
theme: { space: { 1: '4px', 2: '8px', button: { md: '100px' } } },
},
],
[
Expand Down

0 comments on commit 4119e8c

Please sign in to comment.