diff options
Diffstat (limited to 'packages/renderer/src/i18n/RtlCacheProvider.tsx')
-rw-r--r-- | packages/renderer/src/i18n/RtlCacheProvider.tsx | 54 |
1 files changed, 54 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..8b6fcf2 --- /dev/null +++ b/packages/renderer/src/i18n/RtlCacheProvider.tsx | |||
@@ -0,0 +1,54 @@ | |||
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 type { EmotionCache } from '@emotion/cache'; | ||
22 | import { CacheProvider } from '@emotion/react'; | ||
23 | import { observer } from 'mobx-react-lite'; | ||
24 | import React, { type ReactNode } from 'react'; | ||
25 | |||
26 | import type RendererStore from '../stores/RendererStore.js'; | ||
27 | |||
28 | function RtlCacheProvider({ | ||
29 | children, | ||
30 | store: { | ||
31 | shared: { writingDirection }, | ||
32 | }, | ||
33 | rtlCache, | ||
34 | }: { | ||
35 | children?: ReactNode; | ||
36 | store: RendererStore; | ||
37 | rtlCache: EmotionCache; | ||
38 | }): JSX.Element { | ||
39 | return writingDirection === 'rtl' ? ( | ||
40 | <CacheProvider value={rtlCache}>{children}</CacheProvider> | ||
41 | ) : ( | ||
42 | /* | ||
43 | eslint-disable-next-line react/jsx-no-useless-fragment -- | ||
44 | Wrap expression in a fragment to satisfy typescript. | ||
45 | */ | ||
46 | <>{children}</> | ||
47 | ); | ||
48 | } | ||
49 | |||
50 | RtlCacheProvider.defaultProps = { | ||
51 | children: undefined, | ||
52 | }; | ||
53 | |||
54 | export default observer(RtlCacheProvider); | ||