项目作者: Bamieh

项目描述 :
RTL processor for React inline styler
高级语言: JavaScript
项目地址: git://github.com/Bamieh/react-inline-styler-processor-rtl.git
创建时间: 2017-03-29T17:32:58Z
项目社区:https://github.com/Bamieh/react-inline-styler-processor-rtl

开源协议:MIT License

下载


npm version
Build Status
Coverage Status
License: MIT

react-inline-styler-processor-rtl

(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.

Getting started

  1. npm install react-inline-styler-processor-rtl

Example Usage

  1. //App.js
  2. import rtlProcessor from 'react-inline-styler-processor-rtl'
  3. // or var rtlProcessor = require('react-inline-styler-processor-rtl')
  4. const pipeline = [rtlProcessor];
  5. const configs = {isRTL: true};
  6. <ReactInlineStylerProvider configs={configs} pipeline={pipeline}>
  7. </ReactInlineStylerProvider>
  1. //styles.js
  2. const styles = function() {
  3. return {
  4. rootStyle: {
  5. float: 'start',
  6. paddingStart: ...
  7. }
  8. }
  9. }

Localization list

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.

Localed Values

  1. float
  1. {
  2. float: 'start',
  3. float: 'end',
  4. }
  1. direction
  1. {
  2. direction: 'start',
  3. direction: 'end',
  4. }
  1. transformOrigin
  1. {
  2. transformOrigin: 'start',
  3. transformOrigin: 'end',
  4. }
  1. transform
    1. {
    2. transform: translate
    3. transform: skew
    4. }
  2. textAlign

    text-align values’ start and end are supported in all browers but not in IE11+ and Edge. Therefore, this transform was added.

    1. {
    2. textAlign: 'start'
    3. textAlign: 'end'
    4. }

    Localed Keys

  3. margins and paddings

  1. {
  2. marginStart: ...
  3. marginEnd: ...
  4. paddingStart: ...
  5. paddingEnd: ...
  6. }
  1. positions

    1. {
    2. start: ...
    3. end: ...
    4. }
  2. borders

  1. {
  2. borderStart: ...
  3. borderStartWidth: ...
  4. borderStartStyle: ...
  5. borderStartColor: ...
  6. borderEnd: ...
  7. borderEndWidth: ...
  8. borderEndStyle: ...
  9. borderEndColor: ...
  10. }
  1. borderRadius
    1. {
    2. borderTopStartRadius: ...
    3. borderTopEndRadius: ...
    4. borderBottomStartRadius: ...
    5. borderBottomEndRadius: ...
    6. }