Skip to content

Commit 1c2534d

Browse files
committed
fix(specificity): re-order rules to run in proper css order
1 parent e565940 commit 1c2534d

File tree

3 files changed

+55
-43
lines changed

3 files changed

+55
-43
lines changed

src/Box.tsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import {
22
bgColor,
3-
borderColor,
4-
borderRadius,
53
borders,
64
bottom,
75
boxShadow,
@@ -148,31 +146,35 @@ export interface IBoxProps {
148146
}
149147

150148
export const Box = styled<IBoxProps, 'div'>('div')(
151-
borderRadius,
152-
borderColor,
149+
// Order matters
150+
// @ts-ignore
153151
bgColor,
152+
textColor,
154153
borders,
155-
bottom,
156154
boxShadow,
157-
css,
158-
cursor,
159-
display,
160-
flex,
155+
161156
fontSize,
162157
fontWeight,
163-
height,
158+
textAlign,
159+
160+
space,
161+
display,
162+
flex,
163+
cursor,
164+
opacity,
165+
zIndex,
166+
167+
position,
168+
top,
169+
right,
170+
bottom,
164171
left,
172+
173+
height,
174+
width,
165175
maxHeight,
166176
maxWidth,
167177
minHeight,
168178
minWidth,
169-
opacity,
170-
position,
171-
right,
172-
space,
173-
textAlign,
174-
textColor,
175-
top,
176-
width,
177-
zIndex
179+
css
178180
);

src/Icon.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { IBorderRadius, IBorderWidth, IFontSize, IFullSpace, ValueOf } from './t
66

77
import {
88
bgColor,
9-
borderColor,
10-
borderRadius,
119
borders,
1210
bottom,
1311
css,
@@ -85,20 +83,23 @@ export const Icon = styled<IIconProps>((props: IIconProps) => {
8583
<FontAwesomeIcon className={className} icon={icon} spin={spin} pulse={pulse} flip={flip} rotation={rotation} />
8684
);
8785
})(
88-
borderRadius,
89-
borderColor,
86+
// @ts-ignore
9087
bgColor,
88+
textColor,
9189
borders,
92-
bottom,
93-
css,
94-
fontSize,
95-
left,
96-
opacity,
97-
position,
98-
right,
90+
9991
space,
92+
fontSize,
10093
textAlign,
101-
textColor,
94+
95+
position,
10296
top,
103-
zIndex
97+
right,
98+
bottom,
99+
left,
100+
101+
opacity,
102+
zIndex,
103+
104+
css
104105
);

src/utils/rules.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ export const bgColor = styleColor({
116116
cssProperty: 'backgroundColor',
117117
});
118118

119-
export const borderRadius = style({
120-
prop: 'radius',
121-
cssProperty: 'borderRadius',
122-
key: 'base.radius',
123-
transformValue: px,
124-
});
125-
126119
export const boxShadow = style({
127120
prop: 'shadow',
128121
cssProperty: 'boxShadow',
@@ -147,9 +140,9 @@ const overflowDefault = style({
147140

148141
export const overflow = compose(
149142
// @ts-ignore FIXME
143+
overflowDefault,
150144
overflowX,
151-
overflowY,
152-
overflowDefault
145+
overflowY
153146
);
154147

155148
export const zIndex = style({
@@ -190,17 +183,27 @@ export const borderLeft = style({
190183
transformValue: getBorder,
191184
});
192185

186+
export const borderRadius = style({
187+
prop: 'radius',
188+
cssProperty: 'borderRadius',
189+
key: 'base.radius',
190+
transformValue: px,
191+
});
192+
193193
export const borderColor = styleColor({
194194
prop: 'borderColor',
195195
});
196196

197+
// use compose to ensure proper css order
197198
export const borders = compose(
198199
// @ts-ignore FIXME
199200
border,
200201
borderTop,
201202
borderRight,
202203
borderBottom,
203-
borderLeft
204+
borderLeft,
205+
borderColor,
206+
borderRadius
204207
);
205208

206209
// @ts-ignore FIXME
@@ -293,12 +296,18 @@ const getSpaceValue = scale => propVal => {
293296
// @ts-ignore FIXME
294297
export const space = props => {
295298
// test for spacing props, so m* and p*
296-
const keys = Object.keys(props).filter(key => /^[mp][trblxy]?$/.test(key));
297299
// get space configuration from theme
298300
const scale = get(props.theme, 'base.space');
299301
// function to convert propVal -> cssVal
300302
const getStyle = getSpaceValue(scale);
301303

304+
// to ensure proper order
305+
const keys = [
306+
...Object.keys(props).filter(key => /^[mp]$/.test(key)),
307+
...Object.keys(props).filter(key => /^[mp][xy]$/.test(key)),
308+
...Object.keys(props).filter(key => /^[mp][trbl]$/.test(key)),
309+
];
310+
302311
// return all style functions for every direction
303312
return keys
304313
.map(key => {

0 commit comments

Comments
 (0)