PostCSS plugin that polyfill Mozilla's Bi-directional CSS proposal to suppot direction-sensitive rules, a.k.a Left-To-Right (LTR) and Right-To-Left (RTL), in single syntax
PostCSS plugin that polyfill Bi-directional CSS proposal from W3C to suppot direction-sensitive rules, a.k.a Left-To-Right (LTR) and Right-To-Left (RTL) in all browsers.
Install
npm install --save-dev postcss-bidirection
Usage
Install postcss-bidirection via npm:
postcss([ require('postcss-bidirection') ])
See PostCSS docs for examples for your environment.
To check the layout change, in your HTML file, add attribute in your html tags
<html dir="rtl">
Or, in your js file, set document.dir = 'rtl' or document.dir = 'ltr'.
By default, postcss-bidirection prefixes generated CSS selectors with html[dir="rtl"] or html[dir="ltr"]. The buildSelector option allows you to override this behavior.
This callback gets called once for every selector of every rule that contains translated properties. If the rule has multiple selectors separated by commas, then it will be called multiple times for that rule.
It takes two arguments:
the original CSS selector of the rule that we are translating
The direction to which it is being translated. Can be rtl or ltr.
It should return a CSS selector string, which will be attached to the translated CSS rule.
For example, to drop html from generated selectors, pass a custom buildSelector function to the plugin.
These CSS syntax are already in production in Mozilla's Firefox OS, which could be installed as an Android launcher. Once its started, open Settings > Language and choose an sample RTL Language to check the result.