Skip to content

Commit 01de0f0

Browse files
feat: add native RtL css support
1 parent a043a4f commit 01de0f0

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/__tests__/boxModel.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ it('transforms margin, padding with 1 value', () => {
1515
})
1616
})
1717

18+
// RTL
19+
it('transforms margin-inline-start with marginStart', () => {
20+
expect(transformCss([['margin-inline-start', '1px']])).toEqual({
21+
marginStart: 1,
22+
})
23+
})
24+
25+
it('transforms start with start', () => {
26+
expect(transformCss([['start', '1px']])).toEqual({
27+
start: 1,
28+
})
29+
})
30+
1831
it('transforms margin, padding with 2 values', () => {
1932
expect(transformCss([['margin', '1px 2px']])).toEqual({
2033
marginTop: 1,
@@ -117,6 +130,8 @@ it('transforms margin shorthand with auto', () => {
117130
})
118131
})
119132

133+
134+
120135
it('transforms border width', () => {
121136
expect(transformCss([['border-width', '1px 2px 3px 4px']])).toEqual({
122137
borderTopWidth: 1,

src/index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ const transformShorthandValue =
5252
process.env.NODE_ENV === 'production'
5353
? baseTransformShorthandValue
5454
: (propName, value) => {
55-
try {
56-
return baseTransformShorthandValue(propName, value)
57-
} catch (e) {
58-
throw new Error(`Failed to parse declaration "${propName}: ${value}"`)
59-
}
55+
try {
56+
return baseTransformShorthandValue(propName, value)
57+
} catch (e) {
58+
throw new Error(`Failed to parse declaration "${propName}: ${value}"`)
6059
}
60+
}
6161

6262
export const getStylesForProperty = (propName, inputValue, allowShorthand) => {
6363
const isRawValue = allowShorthand === false || !(propName in transforms)
@@ -70,12 +70,21 @@ export const getStylesForProperty = (propName, inputValue, allowShorthand) => {
7070
return propValues
7171
}
7272

73+
const cssRtLToNativeCamelized = {
74+
"margin-inline-start": "marginStart",
75+
"margin-inline-end": "marginEnd",
76+
"padding-inline-start": "paddingStart",
77+
"padding-inline-end": "paddingEnd",
78+
"inset-inline-start": "start",
79+
"inset-inline-end": "end"
80+
}
81+
7382
export const getPropertyName = propName => {
7483
const isCustomProp = /^--\w+/.test(propName)
7584
if (isCustomProp) {
7685
return propName
7786
}
78-
return camelizeStyleName(propName)
87+
return cssRtLToNativeCamelized[propName] || camelizeStyleName(propName)
7988
}
8089

8190
export default (rules, shorthandBlacklist = []) =>

0 commit comments

Comments
 (0)