All Projects → vkalinichev → Postcss Rtl

vkalinichev / Postcss Rtl

Licence: mit
PostCSS plugin for RTL-adaptivity

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Postcss Rtl

Rtlcss
Framework for transforming Cascading Style Sheets (CSS) from Left-To-Right (LTR) to Right-To-Left (RTL)
Stars: ✭ 1,363 (+853.15%)
Mutual labels:  rtl, postcss, postcss-plugin
Postcss Import
PostCSS plugin to inline @import rules content
Stars: ✭ 1,048 (+632.87%)
Mutual labels:  postcss, postcss-plugin
Postcss Alias
PostCSS plugin that allows you to create aliases for CSS properties
Stars: ✭ 47 (-67.13%)
Mutual labels:  postcss, postcss-plugin
Postcss Prefix Selector
Prefix all CSS rules with a selector
Stars: ✭ 75 (-47.55%)
Mutual labels:  postcss, postcss-plugin
Postcss Banner
PostCSS plugin to add text banner and footer to resulting file
Stars: ✭ 13 (-90.91%)
Mutual labels:  postcss, postcss-plugin
Postcss Register Custom Props
PostCSS plugin that transforms custom property registration in CSS to JS
Stars: ✭ 20 (-86.01%)
Mutual labels:  postcss, postcss-plugin
Postcss Nested Props
PostCSS plugin to unwrap nested properties.
Stars: ✭ 58 (-59.44%)
Mutual labels:  postcss, postcss-plugin
Purgecss
Remove unused CSS
Stars: ✭ 6,566 (+4491.61%)
Mutual labels:  postcss-plugin, postcss
Bootstrap Rtl
Bootstrap RTL Standard 3 and 4
Stars: ✭ 106 (-25.87%)
Mutual labels:  arabic, rtl
Postcss Plugins
The "officially unofficial" consolidated list of PostCSS plugins in a ready-to-use package
Stars: ✭ 107 (-25.17%)
Mutual labels:  postcss, postcss-plugin
Postcss Interpolate
PostCSS plugin for values interpolation between breakpoints.
Stars: ✭ 9 (-93.71%)
Mutual labels:  postcss, postcss-plugin
Postcss Aspect Ratio Mini
A PostCSS plugin to fix an element's dimensions to an aspect ratio
Stars: ✭ 123 (-13.99%)
Mutual labels:  postcss, postcss-plugin
Postcss Position
PostCSS plugin that adds shorthand declarations for position attributes
Stars: ✭ 26 (-81.82%)
Mutual labels:  postcss, postcss-plugin
Postcss Icon
PostCSS plugin that adds `css icons` from icon sets
Stars: ✭ 20 (-86.01%)
Mutual labels:  postcss, postcss-plugin
Postcss Start To End
PostCSS plugin that lets you control your layout (LTR or RTL) through logical rather than physical rules
Stars: ✭ 18 (-87.41%)
Mutual labels:  rtl, postcss
Postcss Triangle
PostCSS plugin to create a triangle.
Stars: ✭ 57 (-60.14%)
Mutual labels:  postcss, postcss-plugin
Bootstrap V4 Rtl
RTL edition of bootstrap v4 for rtl languages like Farsi and Arabic
Stars: ✭ 430 (+200.7%)
Mutual labels:  arabic, rtl
Postcss Easing Gradients
PostCSS plugin to create smooth linear-gradients that approximate easing functions.
Stars: ✭ 689 (+381.82%)
Mutual labels:  postcss, postcss-plugin
Postcss Less
PostCSS Syntax for parsing LESS
Stars: ✭ 93 (-34.97%)
Mutual labels:  postcss, postcss-plugin
Postcss Viewport Height Correction
PostCSS plugin to solve the popular problem when 100vh doesn’t fit the mobile browser screen.
Stars: ✭ 137 (-4.2%)
Mutual labels:  postcss, postcss-plugin

PostCSS-RTL


⚠️ Unmaintained ⚠️

The project is no longer maintained by the author.

It still may be helpful for MVP or small projects but for large projects it will be better to choose rtl.css (which this plugins uses under the hood) directly.

If you want to take care of this repo/npm package, you can contact author:


npm Build Status npm Package Quality license

PostCSS-plugin for RTL-adaptivity

Generates RTL rules with flipped properties. Use one file for both directions!

Examples

Simple properties

In most cases all you need is flip property name or value from left to right or change values order in full-valued shorthand from top-right-bottom-left to top-left-bottom-right.

LTR input:

.foo {
    float: right;
    margin-left: 13px;
    text-align: right;
    font-size: 13px;
    border-color: lightgray;
    border-width: 2px 0 2px 2px;
    border-style: solid dashed solid solid
}

.foo {
    text-align: center;
}

LTR+RTL output:

.foo {
    font-size: 13px
}

[dir] .foo {
    border-color: lightgray
}

[dir="ltr"] .foo {
    float: right;
    margin-left: 13px;
    text-align: right;
    border-width: 2px 0 2px 2px;
    border-style: solid dashed solid solid
}

[dir="rtl"] .foo {
    float: left;
    margin-right: 13px;
    text-align: left;
    border-width: 2px 2px 2px 0;
    border-style: solid solid solid dashed
}

[dir] .foo {
    text-align: center
}

Animations

Flippable keyframes-animations will be splitted to two direction-based rules with -ltr or -rtl suffixes

LTR input:

.foo {
    animation: 1s slide 0s ease-in-out
}

@keyframes slide {
    from {
        transform: translate( -1000px )
    }
    to {
        transform: translate( 0 )
    }
}

LTR+RTL output:

[dir="ltr"] .foo {
    animation: 1s slide-ltr 0s ease-in-out
}

[dir="rtl"] .foo {
    animation: 1s slide-rtl 0s ease-in-out
}

@keyframes slide-ltr {
    from {
        transform: translate( -1000px )
    }
    to {
        transform: translate( 0 )
    }
}

@keyframes slide-rtl {
    from {
        transform: translate( 1000px )
    }
    to {
        transform: translate( 0 )
    }
}

Value directives

To transform declaration values use value directives:

  • /* rtl:prepend:{value} */ - to prepend the {value} before the current value
  • /* rtl:append:{value} */ - to append the {value} after the current value
  • /* rtl:{value} */ - to replace the current value with the supplied value

Source

.foo {
    font-weight: bold;
    font-family: "Droid Sans", "Helvetica Neue", Arial, sans-serif/*rtl:prepend:"Droid Arabic Kufi",*/;
    transform: rotate(45deg)/* rtl:append: scaleX(-1) */;
    flex-direction: row/* rtl: row-reverse */;
}

Result

.foo {
    font-weight: bold;
}

[dir=ltr] .foo {
    font-family: "Droid Sans", "Helvetica Neue", Arial, sans-serif/*rtl:prepend:"Droid Arabic Kufi",*/;
    transform: rotate(45deg)/* rtl:append: scaleX(-1) */;
    flex-direction: row/* rtl: row-reverse */;
}

[dir=rtl] .foo {
    font-family: "Droid Arabic Kufi", "Droid Sans", "Helvetica Neue", Arial, sans-serif;
    transform: rotate(45deg) scaleX(-1);
    flex-direction: row-reverse;
}

Property directives

To transform declaration property name use property directives:

  • /* rtl:as:{prop} */ - to process the property as {prop}. Usable for custom properties

Source

:root {
    --padding /* rtl:as:padding */: 1rem 2rem 3rem 4rem;
}

Result

[dir=ltr]:root {
    --padding /* rtl:as:padding */: 1rem 2rem 3rem 4rem;
}

[dir=rtl]:root {
    --padding /* rtl:as:padding */: 1rem 4rem 3rem 2rem;
}

Ignoring specific declarations

To skip flipping specific declarations use some of supported directives:

  • /* rtl:ignore */ - to ignore the following rule or the containing declaration
  • /* rtl:begin:ignore */ and /* rtl🔚ignore */ - to ignore rules within scope

Ignore one rule:

/* rtl:ignore */
.foo {
    padding-left: 0
}

Block-syntax to ignore rules within scope:

/* rtl:begin:ignore */
.foo {
    padding-left: 0
}
.bar {
    direction: ltr
}
/* rtl🔚ignore */

Value-syntax to ignore a single CSS declaration:

.foo {
    margin-left: 20px;
    padding-right: 20px /* rtl:ignore */;
}

/*! notation will work too:

/*! rtl:ignore */
.foo {
    padding-left: 0
}

Usage

  1. Plug it to PostCSS

    const postcss = require('postcss')
    const rtl = require('postcss-rtl')
    
    postcss([ rtl( options ) ])
    

    See PostCSS docs for examples for your environment.

  2. Manage direction by switching between dir="ltr" and dir="rtl" on <html> element.

With Webpack:

module.exports = {
  module: {
    rules: [ {
      test: /\.css$/,
      use: [
        { loader: 'style-loader' },
        { loader: 'css-loader' },
        { loader: 'postcss-loader',
          options: {
            plugins: function () {
              return [ require( 'postcss-rtl' )( options ) ]
            }
          }
        }
      ]
    } ]
  }
}

With Gulp:

gulp.src( 'style.css' )
    .pipe( postcss( [ rtl( options ) ]) )
    .pipe( gulp.dest( './dest' ) )

Options

  • addPrefixToSelector: Custom function for adding prefix to selector. Optional. Example:

    function addPrefixToSelector ( selector, prefix ) {
        return `${prefix} > ${selector}` // Make selectors like [dir=rtl] > .selector
    }
    

    note: the returned string must include prefix to avoid an infinite recursion

  • onlyDirection: generate only one-direction version: ltr or rtl

  • prefixType: Switches between adding attributes and classes. Optional:

    • attribute (by default, recommended): .foo => [dir=rtl] .foo
    • class (useful for IE6): .foo => .dir-rtl .foo
  • prefix: Uses a custom string, instead of 'dir', for the added attribute and class selectors

    • e.g. 'data-my-custom-dir' (for attribute prefixType): .foo => [data-my-custom-dir=rtl] .foo
    • e.g. 'my-custom-dir' (for class prefixType): .foo => .my-custom-dir-rtl .foo
  • removeComments (default: true): remove rtl:* comments after process them

  • fromRTL (default: false): assume all styles are written in RTL direction and generate corresponding LTR styles for them

  • blacklist: the array of css properties which processing will be ignored Example:

    ['padding-left', 'padding-right']
    
  • whitelist: the array of css properties which (and only them) will be processed Example:

    ['margin', 'border-color']
    

Thanks

Great thanks to projects:

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