@aarhus-university/au-lib-react-components 10.0.7 → 10.0.9
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/components/AUModalComponent.tsx +5 -1
- package/src/lib/helpers.ts +14 -0
- package/src/lib/hooks.ts +20 -0
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.0.
|
|
4
|
+
"version": "10.0.9",
|
|
5
5
|
"description": "Library for shared React components for various applications on au.dk",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "webpack --config ./webpack.config.js"
|
|
@@ -61,7 +61,11 @@ const AUModalComponent: FC<AUModalComponentProps> = ({
|
|
|
61
61
|
</button>
|
|
62
62
|
)
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
<div className="modal-view__container">
|
|
65
|
+
<div className="modal-view__body">
|
|
66
|
+
{children}
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
65
69
|
</div>
|
|
66
70
|
</div>,
|
|
67
71
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
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/src/lib/hooks.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
/* eslint-disable import/prefer-default-export */
|
|
2
3
|
import { useState, useEffect } from 'react';
|
|
3
4
|
import { showModal, hideModal } from '@aarhus-university/au-designsystem-delphinus/source/js/components/modal-view';
|
|
@@ -28,6 +29,25 @@ const useModal = (
|
|
|
28
29
|
return [modal, setModal];
|
|
29
30
|
};
|
|
30
31
|
|
|
32
|
+
const useTranslation = <T>(initialObject: T, promises: [Promise<any>, Promise<any> | null]): T => {
|
|
33
|
+
const [translations, setTranslations] = useState<T>(initialObject);
|
|
34
|
+
const loadTranslation = async (): Promise<void> => {
|
|
35
|
+
const translation = await Promise.all(promises);
|
|
36
|
+
if (translation[1] == null) {
|
|
37
|
+
setTranslations(translation[0].default);
|
|
38
|
+
} else {
|
|
39
|
+
setTranslations({ ...translation[0].default, ...translation[1].default });
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
loadTranslation();
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
return translations;
|
|
48
|
+
};
|
|
49
|
+
|
|
31
50
|
export {
|
|
32
51
|
useModal,
|
|
52
|
+
useTranslation,
|
|
33
53
|
};
|