@aarhus-university/au-lib-react-components 10.0.5 → 10.0.8

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.0.5",
4
+ "version": "10.0.8",
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"
@@ -45,7 +45,8 @@
45
45
  "webpack-cli": "^4.9.2"
46
46
  },
47
47
  "dependencies": {
48
- "@aarhus-university/au-designsystem-delphinus": "^0.26.1",
48
+ "@aarhus-university/au-designsystem-delphinus": "0.28.0",
49
+ "@aarhus-university/types": "^0.1.0",
49
50
  "@types/google.analytics": "^0.0.42",
50
51
  "@types/history": "^5.0.0",
51
52
  "@types/react": "^17.0.39",
@@ -65,8 +65,8 @@ const setCookie = (
65
65
  document.cookie = `${cookieName}=${cookieValue}${path}`;
66
66
  };
67
67
 
68
- const getCookie = (cookieName: string): string | null => {
69
- let cookieValue: string | null = document.cookie;
68
+ const getCookie = (cookieName: string): string | null | boolean => {
69
+ let cookieValue: string | null | boolean = document.cookie;
70
70
  let cookieStart = cookieValue.indexOf(` ${cookieName}=`);
71
71
  if (cookieStart === -1) {
72
72
  cookieStart = cookieValue.indexOf(`${cookieName}=`);
@@ -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
  };
package/tsconfig.json CHANGED
@@ -41,7 +41,7 @@
41
41
  "resolveJsonModule": true,
42
42
  "typeRoots": [
43
43
  "./node_modules/@types",
44
- "./node_modules/@aarhus-university/au-designsystem-delphinus/types"
44
+ "./node_modules/@aarhus-university/types"
45
45
  ]
46
46
  },
47
47
  }
@@ -1,64 +0,0 @@
1
- interface IAlertButton {
2
- className: string,
3
- text: string,
4
- dataIcon: string |null,
5
- onClick: () => void,
6
- }
7
-
8
- interface IToastMessage {
9
- header?: string,
10
- message: string,
11
- type: string,
12
- }
13
-
14
- interface IModal {
15
- modal: boolean,
16
- sender: HTMLElement | null,
17
- }
18
-
19
- interface ICalendarState {
20
- day: number,
21
- month: number,
22
- year: number,
23
- hour: number,
24
- minute: number,
25
- selected: Date,
26
- }
27
-
28
- interface IProgressable {
29
- onProgress: () => Promise<IProgressable>,
30
- progressed: boolean,
31
- }
32
-
33
- interface IReceiptButton {
34
- gotoLink: string,
35
- gotoText: string,
36
- }
37
-
38
- interface ITrackers {
39
- account: string,
40
- name: string,
41
- }
42
-
43
- interface IProfileSettings {
44
- type: string,
45
- url: string,
46
- classNames?: string,
47
- icon?: string,
48
- dataGtm: string,
49
- text: string,
50
- disabled?: boolean,
51
- onClick?: (el: Element) => void,
52
- }
53
-
54
- interface ITabbedObject {
55
- domElement: Element,
56
- rendered: boolean,
57
- content?: JSX.Element,
58
- }
59
-
60
- interface ITabbedTab {
61
- href: string,
62
- text: string,
63
- dataGtm: string,
64
- }
@@ -1,29 +0,0 @@
1
- declare namespace AU {
2
- export interface IUserContext {
3
- auId: number,
4
- firstNames: string,
5
- lastName: string,
6
- name: string,
7
- preferredLanguage: string,
8
- userName: string,
9
- memberOfGroups: IAdGroup[],
10
- impersonatingUser: IUserContext | null,
11
- }
12
-
13
- export interface IAdGroup {
14
- id: string,
15
- name: string,
16
- }
17
-
18
- export interface ICountryCode {
19
- da: string,
20
- en: string,
21
- code: number,
22
- important?: boolean | undefined,
23
- }
24
-
25
- export interface IPhoneNumber {
26
- prefix: string,
27
- number: string,
28
- }
29
- }
@@ -1,5 +0,0 @@
1
- /* eslint-disable @typescript-eslint/triple-slash-reference */
2
- /// <reference path="./interfaces/gui.d.ts" />
3
- /// <reference path="./interfaces/model.d.ts" />
4
- /// <reference path="./payloads.d.ts" />
5
- /// <reference path="./props.d.ts" />
@@ -1,5 +0,0 @@
1
- {
2
- "name": "common",
3
- "version": "1.0.0",
4
- "typings": "main.d.ts"
5
- }
File without changes
@@ -1,166 +0,0 @@
1
- interface AUAlertComponentProps {
2
- message: string,
3
- children: JSX.Element,
4
- alert: boolean,
5
- buttons?: IAlertButton[],
6
- }
7
-
8
- interface AUCalendarComponentProps {
9
- lang?: string,
10
- day: number,
11
- month: number,
12
- year: number,
13
- hour: number,
14
- minute: number,
15
- selected?: Date,
16
- onSelected: (selected: Date) => void,
17
- highlightWeekend?: boolean,
18
- highlightHolidays?: boolean,
19
- yearSpanMinus?: number,
20
- yearSpanPlus?: number,
21
- minuteInterval?: number,
22
- showTime?: boolean,
23
- closeable?: boolean,
24
- onClose?: () => void,
25
- limitStart?: Date | null,
26
- limitEnd?: Date | null,
27
- controls: string,
28
- }
29
-
30
- interface AUContentToggleComponentProps {
31
- toggled: boolean,
32
- classNames?: string | undefined,
33
- children: JSX.Element,
34
- }
35
-
36
- interface AUDatepickerComponentProps {
37
- id: string;
38
- lang?: string;
39
- date?: Date;
40
- onDateChange: (date: Date, formatted: string) => void;
41
- onHide: (date: Date, dateFormatted: string) => void;
42
- format?: string;
43
- showTime?: boolean;
44
- showLabel?: boolean;
45
- labelInline?: boolean;
46
- labelText?: string;
47
- fullWidth?: boolean;
48
- yearSpanMinus?: number;
49
- yearSpanPlus?: number;
50
- limitStart?: Date | null;
51
- limitEnd?: Date | null;
52
- disabled?: boolean;
53
- }
54
-
55
- interface AUModalComponentProps {
56
- domId: string,
57
- children?: JSX.Element,
58
- onClose?: () => void,
59
- closeButton?: boolean,
60
- closeButtonDisabled?: boolean,
61
- lang?: string,
62
- sender: HTMLElement | null,
63
- className?: string,
64
- }
65
-
66
- interface AUSpinnerComponentProps {
67
- domID?: string,
68
- className?: string,
69
- children: JSX.Element,
70
- visible?: boolean,
71
- loaded: boolean,
72
- loadingCondition: boolean,
73
- height?: string,
74
- init?: string,
75
- onLoad: () => void,
76
- }
77
-
78
- interface AUSubNavComponentProps {
79
- children: JSX.Element,
80
- className: string,
81
- dataIcon: string,
82
- text: string,
83
- ariaLabel: string,
84
- id: string,
85
- }
86
-
87
- interface AUTableComponentProps {
88
- children: JSX.Element,
89
- className: string,
90
- }
91
-
92
- interface TabRoutesProps {
93
- onRouteChange: (location: any) => void, // Noget react-router-dom halløj her der ikke spiller...
94
- content: JSX.Element[],
95
- }
96
-
97
- interface AUTabbedContentComponentProps {
98
- tabKey?: number,
99
- tabs: ITabbedTab[],
100
- tabContent?: ITabbedObject[] | null,
101
- children?: JSX.Element | null,
102
- focus?: boolean,
103
- initial?: number,
104
- lang?: string,
105
- callback?: () => void,
106
- withRouter?: boolean,
107
- classNames?: string,
108
- }
109
-
110
- interface AUToastComponentProps {
111
- message: IToastMessage,
112
- buttonText?: string,
113
- dismiss?: () => void,
114
- onOpen?: () => void,
115
- }
116
-
117
- interface AUToolbarComponentProps {
118
- lang: string,
119
- elements: JSX.Element[],
120
- }
121
-
122
- interface AUSubmitButtonContainerComponentProps {
123
- lang: string,
124
- disabled: boolean,
125
- onSubmit: () => void,
126
- onCancel: () => void,
127
- }
128
-
129
- interface AUMobilePrefixComponentProps {
130
- countryCodes: AU.ICountryCode[],
131
- important: boolean,
132
- }
133
-
134
- interface AUReceiptComponentProps {
135
- receiptText: string,
136
- helpText: JSX.Element | null,
137
- showGoTo: boolean,
138
- buttons: IReceiptButton[],
139
- }
140
-
141
- interface AUProfileWidgetComponentProps {
142
- lang: string,
143
- name: string,
144
- auId: number,
145
- studentNumber?: string,
146
- settings: IProfileSettings[],
147
- changeLanguageUri: string,
148
- logoutUri: string,
149
- profileLabels: any, // Noget med labels her?
150
- }
151
-
152
- interface AUProfileAvatarComponentProps {
153
- user: AU.IUserContext,
154
- settings: IProfileSettings[],
155
- profileLabels: any, // Noget med labels her?
156
- logoutUri: string,
157
- changeLanguageUri?: string,
158
- lang: string,
159
- }
160
-
161
- interface AUProfileLoginComponentProps {
162
- loggedIn: boolean,
163
- loginUri: string,
164
- children: JSX.Element,
165
- text: string,
166
- }