main
Last change
on this file since 5d6f37a was 5d6f37a, checked in by Naum Shapkarovski <naumshapkarovski@…>, 7 weeks ago |
add customer
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | import { useEffect } from 'react';
|
---|
2 | // rtl
|
---|
3 | import rtlPlugin from 'stylis-plugin-rtl';
|
---|
4 | // emotion
|
---|
5 | import createCache from '@emotion/cache';
|
---|
6 | import { CacheProvider } from '@emotion/react';
|
---|
7 |
|
---|
8 | // ----------------------------------------------------------------------
|
---|
9 |
|
---|
10 | type Props = {
|
---|
11 | themeDirection: 'rtl' | 'ltr';
|
---|
12 | children: React.ReactNode;
|
---|
13 | };
|
---|
14 |
|
---|
15 | export default function RTL({ children, themeDirection }: Props) {
|
---|
16 | useEffect(() => {
|
---|
17 | document.dir = themeDirection;
|
---|
18 | }, [themeDirection]);
|
---|
19 |
|
---|
20 | const cacheRtl = createCache({
|
---|
21 | key: 'rtl',
|
---|
22 | prepend: true,
|
---|
23 | // @ts-ignore
|
---|
24 | // https://github.com/styled-components/stylis-plugin-rtl/issues/35
|
---|
25 | stylisPlugins: [rtlPlugin],
|
---|
26 | });
|
---|
27 |
|
---|
28 | if (themeDirection === 'rtl') {
|
---|
29 | return <CacheProvider value={cacheRtl}>{children}</CacheProvider>;
|
---|
30 | }
|
---|
31 |
|
---|
32 | return <>{children}</>;
|
---|
33 | }
|
---|
34 |
|
---|
35 | // ----------------------------------------------------------------------
|
---|
36 |
|
---|
37 | export function direction(themeDirection: 'rtl' | 'ltr') {
|
---|
38 | const theme = {
|
---|
39 | direction: themeDirection,
|
---|
40 | };
|
---|
41 |
|
---|
42 | return theme;
|
---|
43 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.