Skip to content

Commit a28e45d

Browse files
authored
Merge pull request #120 from styled-components/housekeeping
Housekeeping
2 parents 6dce838 + 31839b8 commit a28e45d

24 files changed

+3710
-2585
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "presets": ["es2015"] }
1+
{ "presets": [["@babel/preset-env", { "loose": true }]] }

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
/node_modules
22
/index.js
3-
/package-lock.json

.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

index.d.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
export type StyleTuple = [string, string]
2+
13
export interface Style {
2-
[key: string]: string | number | Style;
4+
[key: string]: string | number | Style
35
}
46

5-
export function getPropertyName(name: string): string;
6-
export function getStylesForProperty(name: string, value: string, allowShorthand?: boolean): Style;
7+
export function getPropertyName(name: string): string
8+
export function getStylesForProperty(
9+
name: string,
10+
value: string,
11+
allowShorthand?: boolean
12+
): Style
713

8-
export default function transform(css: Array<[string, string]>, shorthandBlacklist?: string[]): Style;
14+
export default function transform(
15+
styleTuples: StyleTuple[],
16+
shorthandBlacklist?: string[]
17+
): Style

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "css-to-react-native",
3-
"version": "2.3.2",
3+
"version": "3.0.0",
44
"description": "Convert CSS text to a React Native stylesheet object",
55
"main": "index.js",
66
"scripts": {
@@ -37,22 +37,22 @@
3737
"testURL": "http://localhost"
3838
},
3939
"devDependencies": {
40-
"babel-cli": "^6.26.0",
41-
"babel-preset-es2015": "^6.24.1",
40+
"@babel/cli": "^7.6.2",
41+
"@babel/preset-env": "^7.6.2",
4242
"eslint": "^4.17.0",
4343
"eslint-config-airbnb-base": "^12.1.0",
4444
"eslint-config-prettier": "^2.9.0",
4545
"eslint-plugin-import": "^2.8.0",
4646
"eslint-plugin-prettier": "^2.6.0",
47-
"jest": "^22.2.2",
47+
"jest": "^24.9.0",
4848
"lint-staged": "^6.1.0",
49-
"prettier": "^1.10.2",
50-
"rollup": "^0.55.5"
49+
"prettier": "^1.18.2",
50+
"rollup": "^1.22.0"
5151
},
5252
"dependencies": {
5353
"camelize": "^1.0.0",
5454
"css-color-keywords": "^1.0.0",
55-
"postcss-value-parser": "^3.3.0"
55+
"postcss-value-parser": "^4.0.2"
5656
},
5757
"lint-staged": {
5858
"*.js": [

src/__tests__/border.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,15 @@ it('transforms border shorthand missing color & style', () => {
7171
borderStyle: 'solid',
7272
})
7373
})
74+
75+
it('transforms border for unsupported units', () => {
76+
expect(transformCss([['border', '3em solid black']])).toEqual({
77+
borderWidth: '3em',
78+
borderColor: 'black',
79+
borderStyle: 'solid',
80+
})
81+
})
82+
83+
it('does not transform border with percentage width', () => {
84+
expect(() => transformCss([['border', '3% solid black']])).toThrow()
85+
})

src/__tests__/flex.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ it('transforms flex shorthand with flex-basis set to auto', () => {
7777
})
7878
})
7979

80+
it('transforms flex shorthand with flex-basis set to percent', () => {
81+
expect(transformCss([['flex', '1 2 30%']])).toEqual({
82+
flexGrow: 1,
83+
flexShrink: 2,
84+
flexBasis: '30%',
85+
})
86+
})
87+
88+
it('transforms flex shorthand with flex-basis set to unsupported unit', () => {
89+
expect(transformCss([['flex', '1 2 30em']])).toEqual({
90+
flexGrow: 1,
91+
flexShrink: 2,
92+
flexBasis: '30em',
93+
})
94+
})
95+
8096
it('transforms flex shorthand with flex-basis set to auto appearing first', () => {
8197
expect(transformCss([['flex', 'auto 0 1']])).toEqual({
8298
flexGrow: 0,

src/__tests__/index.js

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,55 @@
11
import transformCss, { getStylesForProperty } from '..'
22

33
it('transforms numbers', () => {
4-
expect(
5-
transformCss([['top', '0'], ['left', '0'], ['right', '0'], ['bottom', '0']])
6-
).toEqual({
7-
top: 0,
8-
left: 0,
9-
right: 0,
10-
bottom: 0,
11-
})
4+
expect(transformCss([['z-index', '0']])).toEqual({ zIndex: 0 })
5+
})
6+
7+
it('warns if missing units on unspecialized transform', () => {
8+
const consoleSpy = jest
9+
.spyOn(global.console, 'warn')
10+
.mockImplementation(() => {
11+
// Silence the warning from the test output
12+
})
13+
14+
transformCss([['top', '1']])
15+
expect(consoleSpy).toHaveBeenCalledWith(
16+
'Expected style "top: 1" to contain units'
17+
)
18+
19+
consoleSpy.mockRestore()
20+
})
21+
22+
it('does not warn for unitless 0 length on unspecialized transform', () => {
23+
const consoleSpy = jest.spyOn(global.console, 'warn')
24+
25+
transformCss([['top', '0']])
26+
expect(consoleSpy).not.toHaveBeenCalled()
27+
28+
consoleSpy.mockRestore()
29+
})
30+
31+
it('warns if adding etraneous units on unspecialized transform', () => {
32+
const consoleSpy = jest
33+
.spyOn(global.console, 'warn')
34+
.mockImplementation(() => {
35+
// Silence the warning from the test output
36+
})
37+
38+
transformCss([['opacity', '1px']])
39+
expect(consoleSpy).toHaveBeenCalledWith(
40+
'Expected style "opacity: 1px" to be unitless'
41+
)
42+
43+
consoleSpy.mockRestore()
44+
})
45+
46+
it('does not warn for unitless 0 length on unitless transform', () => {
47+
const consoleSpy = jest.spyOn(global.console, 'warn')
48+
49+
transformCss([['opacity', '0']])
50+
expect(consoleSpy).not.toHaveBeenCalled()
51+
52+
consoleSpy.mockRestore()
1253
})
1354

1455
it('allows pixels in unspecialized transform', () => {
@@ -86,6 +127,13 @@ it('allows negative values in transformed values', () => {
86127
})
87128
})
88129

130+
it('allows uppercase units', () => {
131+
expect(transformCss([['top', '0PX']])).toEqual({ top: 0 })
132+
expect(transformCss([['transform', 'rotate(30DEG)']])).toEqual({
133+
transform: [{ rotate: '30deg' }],
134+
})
135+
})
136+
89137
it('allows percent values in transformed values', () => {
90138
expect(transformCss([['margin', '10%']])).toEqual({
91139
marginTop: '10%',

src/__tests__/placeContent.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import transformCss from '..'
2+
3+
it('transforms place content', () => {
4+
expect(transformCss([['place-content', 'center center']])).toEqual({
5+
alignContent: 'center',
6+
justifyContent: 'center',
7+
})
8+
})
9+
10+
it('transforms place content with one value', () => {
11+
expect(transformCss([['place-content', 'center']])).toEqual({
12+
alignContent: 'center',
13+
justifyContent: 'stretch',
14+
})
15+
})
16+
17+
it('does not allow justify content without align content', () => {
18+
expect(() => transformCss([['place-content', 'space-evenly']])).toThrow()
19+
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
let propertiesWithoutUnits
2+
if (process.env.NODE_ENV !== 'production') {
3+
propertiesWithoutUnits = [
4+
'aspectRatio',
5+
'elevation',
6+
'flexGrow',
7+
'flexShrink',
8+
'opacity',
9+
'shadowOpacity',
10+
'zIndex',
11+
]
12+
}
13+
14+
const devPropertiesWithUnitsRegExp =
15+
propertiesWithoutUnits != null
16+
? new RegExp(propertiesWithoutUnits.join('|'))
17+
: null
18+
19+
export default devPropertiesWithUnitsRegExp

0 commit comments

Comments
 (0)