All Projects → gasolin → postcss-bidirection

gasolin / postcss-bidirection

Licence: MIT license
PostCSS plugin that polyfill Bi-directional CSS properties and values to suppot rtl and ltr rules in all browsers

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to postcss-bidirection

Rtlcss
Framework for transforming Cascading Style Sheets (CSS) from Left-To-Right (LTR) to Right-To-Left (RTL)
Stars: ✭ 1,363 (+5579.17%)
Mutual labels:  postcss, rtl
jekyll-theme-mehdix-rtl
A right-to-left theme for Jekyll with Jalali support and some other goodies.
Stars: ✭ 38 (+58.33%)
Mutual labels:  rtl, right-to-left
easy-materialize-rtl
Simple way to set RTL for materializecss.com.
Stars: ✭ 20 (-16.67%)
Mutual labels:  rtl, right-to-left
Postcss Rtl
PostCSS plugin for RTL-adaptivity
Stars: ✭ 143 (+495.83%)
Mutual labels:  postcss, rtl
Postcss Start To End
PostCSS plugin that lets you control your layout (LTR or RTL) through logical rather than physical rules
Stars: ✭ 18 (-25%)
Mutual labels:  postcss, rtl
ui
Add right-to-left support to the NativeScript framework
Stars: ✭ 22 (-8.33%)
Mutual labels:  rtl, right-to-left
ironhide
Ironhide, the data transformer. Main repo:
Stars: ✭ 16 (-33.33%)
Mutual labels:  bidirectional
materialize-rtl
RTL version of materializecss framework v1.0.0
Stars: ✭ 80 (+233.33%)
Mutual labels:  rtl
Bootstrap4-RTL
🅱 An Awesome RTL bootstrap 4 with gulp and postcss
Stars: ✭ 89 (+270.83%)
Mutual labels:  postcss
oojs-ui
OOUI is a modern JavaScript UI library with strong cross-browser support. It is the standard library for MediaWiki and Wikipedia. This is a mirror from https://gerrit.wikimedia.org. Main website:
Stars: ✭ 45 (+87.5%)
Mutual labels:  rtl
react-cli
基于 create-react-app 搭建的前端脚手架
Stars: ✭ 18 (-25%)
Mutual labels:  postcss
dva-typescript-antd-starter-kit
A admin dashboard application demo based on antd by typescript and dva
Stars: ✭ 61 (+154.17%)
Mutual labels:  postcss
SwiftUI-Flux
🚀 This is a tiny experimental application using SwiftUI with Flux architecture.
Stars: ✭ 52 (+116.67%)
Mutual labels:  bidirectional
postcss-sort-media-queries
PostCSS plugin for combine and sort CSS media queries with mobile first or desktop first methods.
Stars: ✭ 118 (+391.67%)
Mutual labels:  postcss
tailwindcss-postcss-browsersync-boilerplate
Tailwind CSS + PostCSS + BrowserSync boilerplate
Stars: ✭ 28 (+16.67%)
Mutual labels:  postcss
postcss-clean
PostCss plugin to minify your CSS with clean-css
Stars: ✭ 41 (+70.83%)
Mutual labels:  postcss
postcss-aspect-ratio
A PostCSS plugin to fix an element's dimensions to an aspect ratio.
Stars: ✭ 38 (+58.33%)
Mutual labels:  postcss
webpack-typescript-react
Webpack 5 boilerplate with support of most common loaders and modules (see tags and description)
Stars: ✭ 185 (+670.83%)
Mutual labels:  postcss
aik
Frontend Playground
Stars: ✭ 43 (+79.17%)
Mutual labels:  postcss
nova-rtl-theme
RTL layout for Laravel Nova.
Stars: ✭ 38 (+58.33%)
Mutual labels:  rtl

PostCSS Bidirection Build Status Npm version

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

Examples

PostCSS Bidirection support syntax based on https://wiki.mozilla.org/Gaia/CSS_Guidelines

Text alignment example

Input

.foo {
  text-align: start;
}

Output

.foo {
  text-align: left;
}

html[dir="rtl"] .foo {
  text-align: right;
}

Padding Example

Input

.foo {
  padding-inline-start: 1px;
}

Output

.foo {
  padding-left: 1px;
}

html[dir="rtl"] .foo {
  padding-right: 1px;
}

Border Width Example

Input

.foo {
  border-inline-start-width: 1px;
}

Output

.foo {
  border-left-width: 1px;
}

html[dir="rtl"] .foo {
  border-right-width: 1px;
}

Absolute Positioning Example

Input

.foo {
  inset-inline-start: 1px;
}

Output

.foo {
  left: 1px;
}

html[dir="rtl"] .foo {
  right: 1px;
}

All supported syntax are listed below

left/right begin/end
text alignment
text-align: left text-align: start
text-align: right text-align: end
float: left float: start
float: right float: end
clear: left clear: start
clear: right clear: end
padding, margin, border
padding-left padding-inline-start
padding-right padding-inline-end
border-left border-inline-start
border-right border-inline-end
border-left-color border-inline-end-color
border-right-color border-inline-start-color
border-left-style border-inline-start-style
border-right-style border-inline-end-style
border-left-width border-inline-start-width
border-right-width border-inline-end-width
border-top-left-radius border-top-inline-start-radius
border-top-right-radius border-top-inline-end-radius
border-bottom-left-radius border-bottom-inline-start-radius
border-bottom-right-radius border-bottom-inline-end-radius
margin-left margin-inline-start
margin-right margin-inline-end
absolute positioning
left inset-inline-start
right inset-inline-end
left offset-inline-start (obsolete)
right offset-inline-end (obsolete)

Options

postcss-bidirection accepts an options object.

const plugin = require('postcss-bidirection');
const opts = {
    ...
};
postcss([ plugin(opts) ]).process(input) ...

Custom Selectors

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.

const opts = {
  buildSelector = function(selector, direction) {
    return '[dir=" + direction + '"] ' + selector;
  }
};

let bidirection = require('postcss-bidirection');
postcss([ bidirection(opts) ]);

Input

.foo {
  text-align: start;
}

Now we have [dir="rtl"] instead of html[dir="rtl"] in the output:

.foo {
  text-align: left;
}

[dir="rtl"] .foo {
  text-align: right;
}

Debugging

Install postcss-debug

npm install -g postcss-debug

Then run postcss-debug with command

postcss-debug sample.css

References

Firefox OS / B2G OS

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].