(Right to left / left to right) dynamic inline styles processing.
RTL processor for React inline styler react-inline-styler
This processor adds new syntax for the inline styles mainly, "start" and "end" which are dynamically changed to left or right depending on the wanted app language direction, by specifing isRTL
in the ReactInlineStylerProvider
.
npm install react-inline-styler-processor-rtl
//App.js
import rtlProcessor from 'react-inline-styler-processor-rtl'
// or var rtlProcessor = require('react-inline-styler-processor-rtl')
const pipeline = [rtlProcessor];
const configs = {isRTL: true};
<ReactInlineStylerProvider configs={configs} pipeline={pipeline}>
</ReactInlineStylerProvider>
//styles.js
const styles = function() {
return {
rootStyle: {
float: 'start',
paddingStart: ...
}
}
}
localizing styles happens on the key of the attibute, or its value. in LTR configurations start is translated into "left" and "end" is translated into "right". in RTL, the other way around.
- float
{
float: 'start',
float: 'end',
}
- direction
{
direction: 'start',
direction: 'end',
}
- transformOrigin
{
transformOrigin: 'start',
transformOrigin: 'end',
}
- transform
{
transform: translate
transform: skew
}
- textAlign
text-align
values' start
and end
are supported in all browers but not in IE11+ and Edge. Therefore, this transform was added.
{
textAlign: 'start'
textAlign: 'end'
}
- margins and paddings
{
marginStart: ...
marginEnd: ...
paddingStart: ...
paddingEnd: ...
}
- positions
{
start: ...
end: ...
}
- borders
{
borderStart: ...
borderStartWidth: ...
borderStartStyle: ...
borderStartColor: ...
borderEnd: ...
borderEndWidth: ...
borderEndStyle: ...
borderEndColor: ...
}
- borderRadius
{
borderTopStartRadius: ...
borderTopEndRadius: ...
borderBottomStartRadius: ...
borderBottomEndRadius: ...
}