aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/src/i18n/RtlCacheProvider.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/renderer/src/i18n/RtlCacheProvider.tsx')
-rw-r--r--packages/renderer/src/i18n/RtlCacheProvider.tsx55
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
21import createCache from '@emotion/cache';
22import { CacheProvider } from '@emotion/react';
23import { observer } from 'mobx-react-lite';
24import React, { ReactNode } from 'react';
25import { prefixer } from 'stylis';
26import rtlPlugin from 'stylis-plugin-rtl';
27
28import { useStore } from '../components/StoreProvider';
29
30const rtlCache = createCache({
31 key: 'muirtl',
32 stylisPlugins: [prefixer, rtlPlugin],
33});
34
35function 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
51RtlCacheProvider.defaultProps = {
52 children: undefined,
53};
54
55export default observer(RtlCacheProvider);