@aarhus-university/au-lib-react-components 10.17.3 → 10.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "@aarhus-university/au-lib-react-components",
4
- "version": "10.17.3",
4
+ "version": "10.19.0",
5
5
  "description": "Library for shared React components for various applications on au.dk",
6
6
  "scripts": {
7
7
  "test": "jest",
@@ -176,6 +176,19 @@ const prettyPrintPhone = (countryCodes: AU.ICountryCode[], phone: string) => {
176
176
 
177
177
  const scrollTo = (x = 0, y = 0) => window.scrollTo(x, y);
178
178
 
179
+ const replace = (text: string, find: string[], replaceWith: string[]): string => {
180
+ if (find.length !== replaceWith.length) {
181
+ return text;
182
+ }
183
+
184
+ let newText = text;
185
+ find.forEach((placeholder, index) => {
186
+ newText = newText.replace(`{{${placeholder}}}`, replaceWith[index]);
187
+ });
188
+
189
+ return newText;
190
+ };
191
+
179
192
  export {
180
193
  emailRegex,
181
194
  sortAlphaObj,
@@ -191,4 +204,5 @@ export {
191
204
  splitPhoneNumber,
192
205
  prettyPrintPhone,
193
206
  scrollTo,
207
+ replace,
194
208
  };
@@ -1,3 +1,4 @@
1
+ import { useTranslation } from '../../src/lib/hooks';
1
2
  import React, { useEffect, StrictMode } from 'react';
2
3
 
3
4
  const globalTheme = {
@@ -50,8 +51,41 @@ const ThemeWrapper = ({ theme, children }) => {
50
51
  );
51
52
  }
52
53
 
54
+ const ThemeLanguageWrapper = ({
55
+ theme,
56
+ children,
57
+ defaultLabels,
58
+ importPromises,
59
+ translationContext,
60
+ }) => {
61
+ const translations = useTranslation<typeof defaultLabels>(defaultLabels, importPromises);
62
+ useEffect(() => {
63
+ const body = document.querySelector('body');
64
+ if (body) {
65
+ body.classList.remove('theme--normal');
66
+ body.classList.remove('theme--dark');
67
+ body.classList.add(`theme--${theme}`);
68
+ }
69
+ });
70
+ return (
71
+ <StrictMode>
72
+ <translationContext.Provider value={translations}>
73
+ <main className={`theme--${theme}`}>
74
+ <div className="page">
75
+ <div className="page__content__block">
76
+ {children}
77
+ </div>
78
+ </div>
79
+ </main>
80
+ </translationContext.Provider>
81
+ </StrictMode>
82
+ );
83
+ }
84
+
85
+
53
86
  export {
54
87
  globalTheme,
55
88
  globalLang,
56
89
  ThemeWrapper,
90
+ ThemeLanguageWrapper,
57
91
  };