Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit 192a3aa

Browse files
authored
fix(system): fix issue with space utilities (#97)
1 parent ea162a3 commit 192a3aa

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

β€Žpackages/system/src/style.jsβ€Ž

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { minBreakpoint, minWidth, DEFAULT_BREAKPOINTS } from './media'
2-
import { is, num, string, obj, identity, merge, get, func } from './util'
2+
import { is, num, string, obj, merge, get, func } from './util'
33

44
function callOrReturn(fn, arg) {
55
if (!func(fn)) return fn
@@ -28,7 +28,12 @@ function styleFromValue(cssProperties, value, theme, themeKey, transform) {
2828
if (string(computedValue) || num(computedValue)) {
2929
const style = {}
3030
for (let i = 0; i < cssProperties.length; i++) {
31-
style[cssProperties[i]] = transform(computedValue, variants)
31+
style[cssProperties[i]] = transform
32+
? transform(computedValue, {
33+
rawValue: value,
34+
variants,
35+
})
36+
: computedValue
3237
}
3338
return style
3439
}
@@ -112,7 +117,7 @@ export function style({
112117
prop,
113118
cssProperties,
114119
themeKey = null,
115-
transform = identity,
120+
transform = null,
116121
}) {
117122
function getStyle(attrs, theme) {
118123
const value = attrs[prop]

β€Žpackages/system/src/styles/space.jsβ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { num, negative } from '../util'
33

44
const DEFAULT_SPACING = [0, 8, 16, 24, 32, 40, 48, 56, 64, 72]
55

6-
function transform(n, variants = DEFAULT_SPACING) {
7-
if (!num(n)) {
8-
return variants[n] || n
6+
function transform(transformedValue, { rawValue, variants = DEFAULT_SPACING }) {
7+
if (!num(rawValue)) {
8+
return variants[rawValue] || rawValue
99
}
10-
const abs = Math.abs(n)
11-
const neg = negative(n)
10+
const abs = Math.abs(rawValue)
11+
const neg = negative(rawValue)
1212
const value = variants[abs] || abs
1313
if (!num(value)) {
1414
return neg ? `-${value}` : value

β€Žpackages/system/src/styles/space.test.jsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { space } from './space'
22

33
describe('space', () => {
44
it('should support m', () => {
5+
expect(space.props({ m: 1 })).toEqual({ margin: 8 })
56
expect(space.props({ m: 2 })).toEqual({ margin: 16 })
67
expect(space.props({ m: -2 })).toEqual({ margin: -16 })
78
expect(space.props({ m: 10 })).toEqual({ margin: 10 })

β€Žpackages/system/src/util.jsβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export const num = n => typeof n === 'number' && !Number.isNaN(n)
55
export const string = n => typeof n === 'string' && n !== ''
66
export const obj = n => typeof n === 'object' && n !== null
77
export const func = n => typeof n === 'function'
8-
export const identity = n => n
98
export const negative = n => n < 0
109

1110
export const get = (obj, path) =>

0 commit comments

Comments
Β (0)