Skip to content

Commit

Permalink
fix(specificity): re-order rules to run in proper css order
Browse files Browse the repository at this point in the history
  • Loading branch information
casserni committed Nov 19, 2018
1 parent e565940 commit 1c2534d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 43 deletions.
40 changes: 21 additions & 19 deletions src/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
bgColor,
borderColor,
borderRadius,
borders,
bottom,
boxShadow,
Expand Down Expand Up @@ -148,31 +146,35 @@ export interface IBoxProps {
}

export const Box = styled<IBoxProps, 'div'>('div')(
borderRadius,
borderColor,
// Order matters
// @ts-ignore
bgColor,
textColor,
borders,
bottom,
boxShadow,
css,
cursor,
display,
flex,

fontSize,
fontWeight,
height,
textAlign,

space,
display,
flex,
cursor,
opacity,
zIndex,

position,
top,
right,
bottom,
left,

height,
width,
maxHeight,
maxWidth,
minHeight,
minWidth,
opacity,
position,
right,
space,
textAlign,
textColor,
top,
width,
zIndex
css
);
27 changes: 14 additions & 13 deletions src/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { IBorderRadius, IBorderWidth, IFontSize, IFullSpace, ValueOf } from './t

import {
bgColor,
borderColor,
borderRadius,
borders,
bottom,
css,
Expand Down Expand Up @@ -85,20 +83,23 @@ export const Icon = styled<IIconProps>((props: IIconProps) => {
<FontAwesomeIcon className={className} icon={icon} spin={spin} pulse={pulse} flip={flip} rotation={rotation} />
);
})(
borderRadius,
borderColor,
// @ts-ignore
bgColor,
textColor,
borders,
bottom,
css,
fontSize,
left,
opacity,
position,
right,

space,
fontSize,
textAlign,
textColor,

position,
top,
zIndex
right,
bottom,
left,

opacity,
zIndex,

css
);
31 changes: 20 additions & 11 deletions src/utils/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,6 @@ export const bgColor = styleColor({
cssProperty: 'backgroundColor',
});

export const borderRadius = style({
prop: 'radius',
cssProperty: 'borderRadius',
key: 'base.radius',
transformValue: px,
});

export const boxShadow = style({
prop: 'shadow',
cssProperty: 'boxShadow',
Expand All @@ -147,9 +140,9 @@ const overflowDefault = style({

export const overflow = compose(
// @ts-ignore FIXME
overflowDefault,
overflowX,
overflowY,
overflowDefault
overflowY
);

export const zIndex = style({
Expand Down Expand Up @@ -190,17 +183,27 @@ export const borderLeft = style({
transformValue: getBorder,
});

export const borderRadius = style({
prop: 'radius',
cssProperty: 'borderRadius',
key: 'base.radius',
transformValue: px,
});

export const borderColor = styleColor({
prop: 'borderColor',
});

// use compose to ensure proper css order
export const borders = compose(
// @ts-ignore FIXME
border,
borderTop,
borderRight,
borderBottom,
borderLeft
borderLeft,
borderColor,
borderRadius
);

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

// to ensure proper order
const keys = [
...Object.keys(props).filter(key => /^[mp]$/.test(key)),
...Object.keys(props).filter(key => /^[mp][xy]$/.test(key)),
...Object.keys(props).filter(key => /^[mp][trbl]$/.test(key)),
];

// return all style functions for every direction
return keys
.map(key => {
Expand Down

0 comments on commit 1c2534d

Please sign in to comment.