diff options
Diffstat (limited to 'packages/renderer/src/i18n/RtlCacheProvider.tsx')
-rw-r--r-- | packages/renderer/src/i18n/RtlCacheProvider.tsx | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/packages/renderer/src/i18n/RtlCacheProvider.tsx b/packages/renderer/src/i18n/RtlCacheProvider.tsx new file mode 100644 index 0000000..d54308b --- /dev/null +++ b/packages/renderer/src/i18n/RtlCacheProvider.tsx | |||
@@ -0,0 +1,55 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com> | ||
3 | * | ||
4 | * This file is part of Sophie. | ||
5 | * | ||
6 | * Sophie is free software: you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU Affero General Public License as | ||
8 | * published by the Free Software Foundation, version 3. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | * | ||
18 | * SPDX-License-Identifier: AGPL-3.0-only | ||
19 | */ | ||
20 | |||
21 | import createCache from '@emotion/cache'; | ||
22 | import { CacheProvider } from '@emotion/react'; | ||
23 | import { observer } from 'mobx-react-lite'; | ||
24 | import React, { ReactNode } from 'react'; | ||
25 | import { prefixer } from 'stylis'; | ||
26 | import rtlPlugin from 'stylis-plugin-rtl'; | ||
27 | |||
28 | import { useStore } from '../components/StoreProvider'; | ||
29 | |||
30 | const rtlCache = createCache({ | ||
31 | key: 'muirtl', | ||
32 | stylisPlugins: [prefixer, rtlPlugin], | ||
33 | }); | ||
34 | |||
35 | function RtlCacheProvider({ children }: { children?: ReactNode }): JSX.Element { | ||
36 | const { | ||
37 | shared: { writingDirection }, | ||
38 | } = useStore(); | ||
39 | |||
40 | return writingDirection === 'rtl' ? ( | ||
41 | <CacheProvider value={rtlCache}>{children}</CacheProvider> | ||
42 | ) : ( | ||
43 | /* | ||
44 | eslint-disable-next-line react/jsx-no-useless-fragment -- | ||
45 | Wrap expression in a fragment to satisfy typescript. | ||
46 | */ | ||
47 | <>{children}</> | ||
48 | ); | ||
49 | } | ||
50 | |||
51 | RtlCacheProvider.defaultProps = { | ||
52 | children: undefined, | ||
53 | }; | ||
54 | |||
55 | export default observer(RtlCacheProvider); | ||