Skip to content

Commit b8ea206

Browse files
authored
Merge pull request #200 from wojtekmaj/box-shadow-and-filter
Add support for box-shadow and filter properties
2 parents 5812808 + 0c0a79a commit b8ea206

7 files changed

Lines changed: 32 additions & 106 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ margin: 5px 7px 2px;
6363
}
6464
```
6565

66-
Shorthands will only accept values that are supported in React, so `background` will only accept a colour, `backgroundColor`
66+
Shorthands will only accept values that are supported in React Native, so `background` will only accept a colour, `backgroundColor` will not accept an image, and `font` will not accept font-variant values that React Native does not support.
6767

68-
There is also support for the `box-shadow` shorthand, and this converts into `shadow-` properties. Note that these only work on iOS.
68+
React Native's `box-shadow` and `filter` properties are passed through as
69+
`boxShadow` and `filter`, so support depends on your React Native version.
6970

7071
#### Shorthand Notes
7172

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "css-to-react-native",
3-
"version": "3.2.0",
3+
"version": "4.0.0",
44
"description": "Convert CSS text to a React Native stylesheet object",
55
"main": "index.js",
66
"types": "index.d.ts",

src/__tests__/boxShadow.js

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/__tests__/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,32 @@ it('allows CSS custom properties to pass through', () => {
9898
expect(transformCss([['--my-prop', '0%']])).toEqual({ '--my-prop': '0%' })
9999
})
100100

101+
it('passes filter through as a raw React Native property', () => {
102+
expect(transformCss([['filter', 'opacity(0.5)']])).toEqual({
103+
filter: 'opacity(0.5)',
104+
})
105+
})
106+
107+
it('passes multiple filter functions through unchanged', () => {
108+
expect(transformCss([['filter', 'opacity(0.5) blur(5px)']])).toEqual({
109+
filter: 'opacity(0.5) blur(5px)',
110+
})
111+
})
112+
113+
it('passes box-shadow through as a raw React Native property', () => {
114+
expect(transformCss([['box-shadow', '10px 20px 30px red']])).toEqual({
115+
boxShadow: '10px 20px 30px red',
116+
})
117+
})
118+
119+
it('passes multiple box-shadow values through unchanged', () => {
120+
expect(
121+
transformCss([['box-shadow', '5px 5px 5px red, -5px -5px 5px green']])
122+
).toEqual({
123+
boxShadow: '5px 5px 5px red, -5px -5px 5px green',
124+
})
125+
})
126+
101127
it('allows percent in unspecialized transform', () => {
102128
expect(transformCss([['top', '0%']])).toEqual({ top: '0%' })
103129
})

src/__tests__/units.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,11 @@ lengthUnits.forEach(unit => {
115115
})
116116
})
117117

118-
it('allows untis to be used with box-shadow', () => {
118+
it('allows units to be used with box-shadow', () => {
119119
expect(
120120
transformCss([['box-shadow', `10px ${value} ${value} red`]])
121121
).toEqual({
122-
shadowOffset: { width: 10, height: value },
123-
shadowRadius: value,
124-
shadowColor: 'red',
125-
shadowOpacity: 1,
122+
boxShadow: `10px ${value} ${value} red`,
126123
})
127124
})
128125
})

src/transforms/boxShadow.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/transforms/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
} from '../tokenTypes'
99
import aspectRatio from './aspectRatio'
1010
import border from './border'
11-
import boxShadow from './boxShadow'
1211
import flex from './flex'
1312
import flexFlow from './flexFlow'
1413
import font from './font'
@@ -58,7 +57,6 @@ export default {
5857
borderColor,
5958
borderRadius,
6059
borderWidth,
61-
boxShadow,
6260
flex,
6361
flexFlow,
6462
font,

0 commit comments

Comments
 (0)