Skip to content

Commit 3280b28

Browse files
committed
feat(rtl): add postcss rtl plugin, browserlist and storybook toolbar
1 parent c8ad85d commit 3280b28

File tree

5 files changed

+142
-3
lines changed

5 files changed

+142
-3
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
3+
import {DirectionProvider} from '@radix-ui/react-direction';
4+
import type {Decorator} from '@storybook/react';
5+
6+
export const WithDirection: Decorator = (Story, context) => {
7+
const dir = context.globals.direction;
8+
9+
return (
10+
<DirectionProvider dir={dir}>
11+
<div dir={dir}>
12+
<Story {...context} />
13+
</div>
14+
</DirectionProvider>
15+
);
16+
};

.storybook/preview.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {Decorator, Preview} from '@storybook/react';
1111
import {Lang, MobileProvider, ThemeProvider, configure} from '../src';
1212
import {DocsDecorator} from '../src/demo/DocsDecorator/DocsDecorator';
1313

14+
import {WithDirection} from './decorators/withDirection';
1415
import {WithLang} from './decorators/withLang';
1516
import {WithMobile} from './decorators/withMobile';
1617
import {themes} from './theme';
@@ -32,7 +33,7 @@ const withContextProvider: Decorator = (Story, context) => {
3233
};
3334

3435
const preview: Preview = {
35-
decorators: [WithMobile, WithLang, withContextProvider],
36+
decorators: [WithMobile, WithLang, WithDirection, withContextProvider],
3637
parameters: {
3738
docs: {
3839
theme: themes.light,
@@ -78,6 +79,17 @@ const preview: Preview = {
7879
],
7980
},
8081
},
82+
direction: {
83+
name: 'Direction',
84+
defaultValue: 'rtl',
85+
toolbar: {
86+
icon: 'transfer',
87+
items: [
88+
{value: 'ltr', right: '->', title: 'left to right'},
89+
{value: 'rtl', right: '<-', title: 'right to left'},
90+
],
91+
},
92+
},
8193
platform: {
8294
defaultValue: 'desktop',
8395
toolbar: {

gulpfile.js

+4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ const path = require('path');
33

44
const {task, src, dest, series, parallel} = require('gulp');
55
const sass = require('gulp-dart-sass');
6+
const postcss = require('gulp-postcss');
67
const replace = require('gulp-replace');
78
const ts = require('gulp-typescript');
9+
const rtl = require('postcss-rtl');
810
const rimraf = require('rimraf');
911

1012
const BUILD_DIR = path.resolve('build');
@@ -58,12 +60,14 @@ task('copy-i18n', () => {
5860
task('styles-global', () => {
5961
return src(['styles/styles.scss', 'styles/fonts.scss'])
6062
.pipe(sass().on('error', sass.logError))
63+
.pipe(postcss([rtl()]))
6164
.pipe(dest('styles'));
6265
});
6366

6467
task('styles-components', () => {
6568
return src(['src/components/**/*.scss', '!src/components/**/__stories__/**/*'])
6669
.pipe(sass().on('error', sass.logError))
70+
.pipe(postcss([rtl()]))
6771
.pipe(dest(path.resolve(BUILD_DIR, 'esm', 'components')))
6872
.pipe(dest(path.resolve(BUILD_DIR, 'cjs', 'components')));
6973
});

package-lock.json

+99-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"@gravity-ui/i18n": "^1.1.0",
7979
"@gravity-ui/icons": "^2.5.0",
8080
"@popperjs/core": "^2.11.8",
81+
"@radix-ui/react-direction": "^1.0.1",
8182
"blueimp-md5": "^2.19.0",
8283
"focus-trap": "^7.5.2",
8384
"lodash": "^4.17.21",
@@ -98,6 +99,7 @@
9899
"@commitlint/cli": "^17.7.1",
99100
"@commitlint/config-conventional": "^17.7.0",
100101
"@faker-js/faker": "^8.0.2",
102+
"@gravity-ui/browserslist-config": "^4.1.0",
101103
"@gravity-ui/eslint-config": "^2.2.0",
102104
"@gravity-ui/prettier-config": "^1.0.1",
103105
"@gravity-ui/stylelint-config": "^2.0.0",
@@ -126,6 +128,7 @@
126128
"gulp": "^4.0.2",
127129
"gulp-cli": "^2.3.0",
128130
"gulp-dart-sass": "^1.1.0",
131+
"gulp-postcss": "^9.0.1",
129132
"gulp-replace": "^1.1.4",
130133
"gulp-typescript": "^5.0.1",
131134
"husky": "^8.0.3",
@@ -135,6 +138,7 @@
135138
"nano-staged": "^0.8.0",
136139
"npm-run-all": "^4.1.5",
137140
"postcss": "^8.4.28",
141+
"postcss-rtl": "^2.0.0",
138142
"prettier": "^2.8.8",
139143
"react": "^18.2.0",
140144
"react-docgen-typescript": "^2.2.2",
@@ -160,5 +164,10 @@
160164
"*.md": [
161165
"prettier --write"
162166
]
163-
}
167+
},
168+
"browserslist": [
169+
"extends @gravity-ui/browserslist-config",
170+
"Chrome >= 100",
171+
"Firefox >= 100"
172+
]
164173
}

0 commit comments

Comments
 (0)