Skip to content

Commit e839bd2

Browse files
authored
Merge pull request #389 from BeAPI/feature/rtl
Feature/rtl
2 parents 88d8d59 + 982b2df commit e839bd2

File tree

15 files changed

+113
-14
lines changed

15 files changed

+113
-14
lines changed

config/loaders.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ module.exports = {
6464
'postcss-preset-env': {
6565
browsers: 'last 2 versions, > 2%, not dead',
6666
stage: 2,
67+
features: {
68+
// https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values
69+
// https://stackoverflow.com/questions/64565180/how-to-prevent-postcss-preset-env-from-removing-css-logical-properties#answer-66966232
70+
// Use stage 2 features + disable logical properties and values rule
71+
'logical-properties-and-values': false,
72+
},
6773
},
6874
'postcss-pxtorem': { propWhiteList: [] },
6975
'postcss-sort-media-queries': {},

src/js/classes/Header.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import AbstractDomElement from './AbstractDomElement'
22
import each from '../utils/each'
33
import { Tween } from 'oneloop.js'
4+
import isRTL from '../utils/isRTL'
45

56
class Header extends AbstractDomElement {
67
constructor(element, options) {
@@ -28,7 +29,13 @@ class Header extends AbstractDomElement {
2829
duration: 1000,
2930
easing: 'easeInOutExpo',
3031
onUpdate: function (timestamp, tick, percent) {
31-
const direction = window.innerWidth >= 768 ? -1 : 1
32+
const bp = 768
33+
let direction = window.innerWidth >= bp ? -1 : 1
34+
35+
if (isRTL()) {
36+
direction = window.innerWidth >= bp ? 1 : -1
37+
}
38+
3239
menu.style.transform = 'translateX(' + 100 * (percent - 1) * direction + '%)'
3340
},
3441
onComplete: function (timestamp, tick, lastValue) {

src/js/utils/isRTL.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function isRTL() {
2+
return (
3+
document.documentElement.dir === 'rtl' ||
4+
document.documentElement.lang === 'ar' ||
5+
document.documentElement.lang === 'iw'
6+
)
7+
}

src/scss/02-tools/_f-get-svg-url.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
$svgs: (
3636
// name-of-the-svg: (viewBox, content of the svg element)
3737
"arrow": ("0 0 18 14", "%3Cpath d='M17.25 7 10.37.12l-.96.97 5.2 5.22H.76V7.7h13.87L9.4 12.9l.96.96L17.25 7Z'/%3E"),
38-
"down": ("0 0 11.2 6.7", "3Cpath d='M0 .5C0 .4.1.2.2.1c.2-.2.5-.1.7.1l4.6 5.3.1.1s.1 0 .1-.1L10.3.1c.2-.1.5-.2.7 0 .2.2.2.5.1.7L6.5 6.2c-.2.3-.5.5-.9.5s-.7-.2-.9-.6L.1.8C0 .7 0 .6 0 .5z'/%3E")
38+
"down": ("0 0 11.2 6.7", "3Cpath d='M0 .5C0 .4.1.2.2.1c.2-.2.5-.1.7.1l4.6 5.3.1.1s.1 0 .1-.1L10.3.1c.2-.1.5-.2.7 0 .2.2.2.5.1.7L6.5 6.2c-.2.3-.5.5-.9.5s-.7-.2-.9-.6L.1.8C0 .7 0 .6 0 .5z'/%3E"),
39+
"close": ("0 0 20 20", "3Cpath d='M5.442 5.442 5 5.883l2.058 2.059L9.116 10l-2.058 2.058L5 14.117l.442.441.441.442 2.059-2.058L10 10.884l2.058 2.058L14.117 15l.441-.442.442-.441-2.058-2.059L10.884 10l2.058-2.058L15 5.883l-.442-.441L14.117 5l-2.059 2.058L10 9.116 7.942 7.058 5.883 5l-.441.442'/%3E"),
3940
);
4041

4142
@if not map-has-key($svgs, $name) {

src/scss/02-tools/_m-align.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
float: $direction;
2222

2323
@if ($direction == left) {
24-
margin-right: var(--spacing--block-1);
24+
margin-inline-end: var(--spacing--block-1);
2525
} @else {
26-
margin-left: var(--spacing--block-1);
26+
margin-inline-start: var(--spacing--block-1);
2727
}
2828
}

src/scss/02-tools/_m-checkbox-custom.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
+ label {
2828
position: relative;
2929
display: block;
30-
padding-left: $size + 20;
30+
padding-inline-start: $size + 20;
3131
cursor: pointer;
3232

3333
&::before {
@@ -40,6 +40,11 @@
4040
content: "";
4141
background-color: $color-light;
4242
border: $border-width solid $color;
43+
44+
@include rtl {
45+
right: 0;
46+
left: auto;
47+
}
4348
}
4449

4550
&::after {
@@ -55,6 +60,12 @@
5560
opacity: 0;
5661
transition: opacity .2s;
5762
transform: translate(-50%, -50%) rotate(-45deg);
63+
64+
@include rtl {
65+
right: math.round(math.div($size, 2));
66+
left: auto;
67+
transform: translate(50%, -50%) rotate(-45deg);
68+
}
5869
}
5970
}
6071
}

src/scss/02-tools/_m-rtl.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@
2020
@content;
2121
}
2222
}
23+
24+
@mixin set-rtl-direction {
25+
&:lang(ar),
26+
&:lang(iw) {
27+
direction: rtl;
28+
}
29+
}

src/scss/02-tools/_m-select-custom.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
border-radius: 10px;
3232
appearance: none;
3333

34+
@include rtl {
35+
background-position: left 10px top 50%, 0 0;
36+
}
37+
3438
// Set options to normal weight
3539
option {
3640
font-weight: 400;

src/scss/03-base/_forms.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ $all-text-inputs: assign-inputs($text-inputs-list);
101101
height: 16px;
102102
cursor: pointer;
103103
background-image: get-svg-url("close", $color-dark);
104+
background-repeat: no-repeat;
104105
background-size: contain;
105106
-webkit-appearance: none;
106107
-moz-appearance: none;

src/scss/03-base/_reset.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ h6 {
3939
*/
4040

4141
html {
42+
/* Set automatic RTL direction depending on lang attribute */
43+
@include set-rtl-direction;
44+
4245
/* Apply border-box across the entire page. */
4346
box-sizing: border-box;
4447

0 commit comments

Comments
 (0)