swissup/module-rtl

Magento2 RTL detection

Installs: 302 384

Dependents: 3

Suggesters: 0

Security: 0

Stars: 4

Watchers: 8

Forks: 3

Open Issues: 0

Type:magento2-module

1.3.8 2024-11-27 15:17 UTC

This package is auto-updated.

Last update: 2024-11-27 15:17:48 UTC


README

Magento module that helps to add RTL support to your modules and themes.

Installation

composer require swissup/module-rtl
bin/magento module:enable Swissup_Rtl

Usage

CSS class

Module automatically adds rtl class name to the body element when current language is detected as RTL. This allows you to write plain RTL-specific styles in your css/less files:

.my-element {
    right: 20px;
}
.rtl .my-element {
    right: auto;
    left: 20px;
}

While this approach is nice for the small files, it becomes a headache when dealing with large portion of css that should be adjusted. Additionally, this approach make your style files larger.

We recommend to use LESS mixins for the best experience.

LESS mixins

This approach allows to keep minimal size of generated CSS file:

@import 'Swissup_Rtl::css/_modrtl.less';

.sidebar-popup {
    .left(0);
    .modrtl(transform, translateX(-100%), translateX(100%));

    &.shown {
        transform: translateX(0);
    }

    .close {
        .right(0);
    }
}

Additionally, you can use @modrtl-dir variable in & when statements:

@import 'Swissup_Rtl::css/_modrtl.less';

& when (@modrtl-dir = rtl) {
    .my-element {
        right: auto;
        left: 20px;
    }
}

Mixins list

PHP helper

class Example
{
    public function __construct(\Swissup\Rtl\Helper\Data $rtlHelper)
    {
        // Check current locale
        $rtlHelper->isRtl();

        // Check locale code
        $rtlHelper->isRtl('en_US');
    }
}

License

Distributed under the MIT license

Credits

Mixins are taken from anasnakawa/bi-app-sass. Thanks!