@aarhus-university/au-lib-react-components 10.17.3 → 10.18.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 +1 -1
- package/src/lib/helpers.ts +14 -0
- package/stories/lib/helpers.tsx +17 -7
package/package.json
CHANGED
package/src/lib/helpers.ts
CHANGED
|
@@ -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
|
};
|
package/stories/lib/helpers.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useTranslation } from 'lib/hooks';
|
|
1
2
|
import React, { useEffect, StrictMode } from 'react';
|
|
2
3
|
|
|
3
4
|
const globalTheme = {
|
|
@@ -28,7 +29,14 @@ const globalLang = (items = ['da', 'en'], defaultValue = 'da') => ({
|
|
|
28
29
|
},
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
const ThemeWrapper = ({
|
|
32
|
+
const ThemeWrapper = ({
|
|
33
|
+
theme,
|
|
34
|
+
children,
|
|
35
|
+
defaultLabels,
|
|
36
|
+
importPromises,
|
|
37
|
+
translationContext,
|
|
38
|
+
}) => {
|
|
39
|
+
const translations = useTranslation<typeof defaultLabels>(defaultLabels, importPromises);
|
|
32
40
|
useEffect(() => {
|
|
33
41
|
const body = document.querySelector('body');
|
|
34
42
|
if (body) {
|
|
@@ -39,13 +47,15 @@ const ThemeWrapper = ({ theme, children }) => {
|
|
|
39
47
|
});
|
|
40
48
|
return (
|
|
41
49
|
<StrictMode>
|
|
42
|
-
<
|
|
43
|
-
<
|
|
44
|
-
<div className="
|
|
45
|
-
|
|
50
|
+
<translationContext.Provider value={translations}>
|
|
51
|
+
<main className={`theme--${theme}`}>
|
|
52
|
+
<div className="page">
|
|
53
|
+
<div className="page__content__block">
|
|
54
|
+
{children}
|
|
55
|
+
</div>
|
|
46
56
|
</div>
|
|
47
|
-
</
|
|
48
|
-
</
|
|
57
|
+
</main>
|
|
58
|
+
</translationContext.Provider>
|
|
49
59
|
</StrictMode>
|
|
50
60
|
);
|
|
51
61
|
}
|