Skip to content

Commit 20d7dc7

Browse files
committed
♻️ Use pss functions to create space in FlexGrid
1 parent 11fbca3 commit 20d7dc7

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

src/flex-grid/styles.js

+31-32
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { isNum, isArr, path, fallbackTo } from '@exah/utils'
1+
import { isNum, fallbackTo } from '@exah/utils'
22

33
import {
4-
themePath,
5-
rule,
64
boolValue,
5+
createSpaceValue,
6+
createStyles,
7+
px,
8+
rule,
79
sizeValue,
8-
createStyles
10+
style,
11+
themePath
912
} from 'pss'
1013

1114
function getSize (value, props) {
@@ -61,40 +64,36 @@ const gridItem = createStyles({
6164
const getItemsSpaceStyles = (axis, {
6265
childSelector,
6366
rowSelector
64-
}) => (step, props, mediaKey) => {
65-
let spaces = themePath([ 'space' ], [])(props)
66-
67-
if (!isArr(spaces)) {
68-
spaces = path(mediaKey, path('all')(spaces))(spaces)
69-
}
70-
71-
const value = path(step, 0)(spaces)
72-
const size = step === 0 ? 0 : value / 2
67+
}) => style({
68+
getValue: createSpaceValue()(),
69+
getStyle (value, step, props) {
70+
const size = px(step === 0 ? 0 : value / 2)
7371

74-
return {
75-
...(axis.x && {
76-
marginLeft: size * -1,
77-
marginRight: size * -1
78-
}),
79-
...(axis.y && {
80-
marginTop: size * -1,
81-
marginBottom: size * -1,
82-
[rowSelector(props)]: {
83-
marginTop: size
84-
}
85-
}),
86-
[childSelector(props)]: {
72+
return {
8773
...(axis.x && {
88-
paddingLeft: size,
89-
paddingRight: size
74+
marginLeft: `-${size}`,
75+
marginRight: `-${size}`
9076
}),
9177
...(axis.y && {
92-
paddingTop: size,
93-
paddingBottom: size
94-
})
78+
marginTop: `-${size}`,
79+
marginBottom: `-${size}`,
80+
[rowSelector(props)]: {
81+
marginTop: size
82+
}
83+
}),
84+
[childSelector(props)]: {
85+
...(axis.x && {
86+
paddingLeft: size,
87+
paddingRight: size
88+
}),
89+
...(axis.y && {
90+
paddingTop: size,
91+
paddingBottom: size
92+
})
93+
}
9594
}
9695
}
97-
}
96+
})
9897

9998
const gridRow = (selectors) => createStyles({
10099
space: getItemsSpaceStyles({ x: true, y: true }, selectors),

0 commit comments

Comments
 (0)