@aarhus-university/au-lib-react-components 8.80.0 → 8.83.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": "8.80.0",
4
+ "version": "8.83.0",
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"
@@ -1,6 +1,6 @@
1
1
  /* eslint-env browser */
2
2
  import React, { useEffect, FC } from 'react';
3
- import { isElementInViewport } from '@aarhus-university/au-designsystem-delphinus/source/js/components/helpers';
3
+ import { isElementInViewport } from '../lib/helpers';
4
4
 
5
5
  const AUSpinnerComponent: FC<AUSpinnerComponentProps> = ({
6
6
  domID,
@@ -0,0 +1,42 @@
1
+ /* eslint-env browser */
2
+ import React, { FC, memo } from 'react';
3
+ import AUProfileWidgetComponent from './AUProfileWidgetV3Component';
4
+ import AUSubNavComponent from '../AUSubNavComponent';
5
+
6
+ const AUProfileAvatarComponent: FC<AUProfileAvatarComponentProps> = memo(({
7
+ user,
8
+ settings,
9
+ profileLabels,
10
+ logoutUri,
11
+ changeLanguageUri,
12
+ lang,
13
+ }: AUProfileAvatarComponentProps) => {
14
+ const {
15
+ auId,
16
+ firstNames,
17
+ lastName,
18
+ } = user;
19
+
20
+ return (
21
+ <AUSubNavComponent
22
+ id="profile-menu-toggle"
23
+ className="nav__item nav__item--icon nav__item--icon--right"
24
+ dataIcon=""
25
+ text={firstNames}
26
+ ariaLabel={`${profileLabels[lang].profileFor} ${firstNames} ${lastName}`}
27
+ >
28
+ <AUProfileWidgetComponent
29
+ lang={lang}
30
+ name={`${firstNames} ${lastName}`}
31
+ auId={auId}
32
+ settings={settings}
33
+ profileLabels={profileLabels}
34
+ changeLanguageUri={changeLanguageUri || ''}
35
+ logoutUri={logoutUri}
36
+ />
37
+ </AUSubNavComponent>
38
+ );
39
+ });
40
+
41
+ AUProfileAvatarComponent.displayName = 'AUProfileAvatarComponent';
42
+ export default AUProfileAvatarComponent;
@@ -1,13 +1,12 @@
1
1
  /* eslint-env browser */
2
- import React from 'react';
3
- import PropTypes from 'prop-types';
2
+ import React, { FC } from 'react';
4
3
 
5
- const AUProfileLoginComponent = ({
4
+ const AUProfileLoginComponent: FC<AUProfileLoginComponentProps> = ({
6
5
  loggedIn,
7
6
  loginUri,
8
7
  children,
9
8
  text,
10
- }) => {
9
+ }: AUProfileLoginComponentProps) => {
11
10
  if (!loggedIn) {
12
11
  return (
13
12
  <a
@@ -23,17 +22,5 @@ const AUProfileLoginComponent = ({
23
22
  return children;
24
23
  };
25
24
 
26
- AUProfileLoginComponent.defaultProps = {
27
- loggedIn: false,
28
- loginUri: '',
29
- };
30
-
31
- AUProfileLoginComponent.propTypes = {
32
- loggedIn: PropTypes.bool,
33
- loginUri: PropTypes.string,
34
- children: PropTypes.element.isRequired,
35
- text: PropTypes.string.isRequired,
36
- };
37
-
38
25
  AUProfileLoginComponent.displayName = 'AUProfileLoginComponent';
39
26
  export default AUProfileLoginComponent;
@@ -1,21 +1,28 @@
1
1
  /* eslint-env browser */
2
- import React, { useEffect, useState, useRef } from 'react';
3
- import PropTypes from 'prop-types';
2
+ import React, {
3
+ FC, useEffect, useState, useRef, memo,
4
+ } from 'react';
4
5
  import { setCopyToClipboard } from '@aarhus-university/au-designsystem-delphinus/source/js/components/nav';
5
6
 
6
- const AUProfileWidgetComponent = React.memo(({
7
+ const AUProfileWidgetComponent: FC<AUProfileWidgetComponentProps> = memo(({
7
8
  lang,
8
9
  name,
9
- auid,
10
+ auId,
10
11
  studentNumber,
11
12
  settings,
12
- changeLanguageUrl,
13
+ changeLanguageUri,
13
14
  logoutUri,
14
15
  profileLabels,
15
- }) => {
16
- const [ctcSet, setCtcSet] = useState(false);
17
- const renderSettings = settings.map((s) => {
18
- const btnRef = useRef();
16
+ }: AUProfileWidgetComponentProps) => {
17
+ const [ctcSet, setCtcSet] = useState<boolean>(false);
18
+ const btnRefs = useRef<HTMLButtonElement[]>([]);
19
+ btnRefs.current = [];
20
+ const addToRefs = (el: HTMLButtonElement) => {
21
+ if (el && !btnRefs.current.includes(el)) {
22
+ btnRefs.current.push(el);
23
+ }
24
+ };
25
+ const renderSettings = settings.map((s, i) => {
19
26
  if (s.type === 'anchor') {
20
27
  return (
21
28
  <a
@@ -32,11 +39,15 @@ const AUProfileWidgetComponent = React.memo(({
32
39
  return (
33
40
  <button
34
41
  key={s.text}
35
- ref={btnRef}
42
+ ref={addToRefs}
36
43
  type="button"
37
44
  disabled={s.disabled}
38
45
  className={`sub-nav__item ${s.classNames}`}
39
- onClick={() => s.onClick(btnRef.current)}
46
+ onClick={() => {
47
+ if (typeof s.onClick === 'function') {
48
+ s.onClick(btnRefs.current[i]);
49
+ }
50
+ }}
40
51
  data-icon={s.icon}
41
52
  data-gtm={s.dataGtm}
42
53
  >
@@ -46,7 +57,7 @@ const AUProfileWidgetComponent = React.memo(({
46
57
  });
47
58
 
48
59
  useEffect(() => {
49
- if (auid > 0 && !ctcSet) {
60
+ if (auId > 0 && !ctcSet) {
50
61
  setCopyToClipboard(lang);
51
62
  setCtcSet(true);
52
63
  }
@@ -60,11 +71,11 @@ const AUProfileWidgetComponent = React.memo(({
60
71
  type="button"
61
72
  className="copy-to-clipboard"
62
73
  title={profileLabels[lang].copyAuid}
63
- aria-label={`${profileLabels[lang].auId}: AU${auid}`}
74
+ aria-label={`${profileLabels[lang].auId}: AU${auId}`}
64
75
  data-gtm="au-btn-header-copy-auid"
65
76
  >
66
77
  {`${profileLabels[lang].auId}: `}
67
- <span className="copy-to-clipboard__this">{`AU${auid}`}</span>
78
+ <span className="copy-to-clipboard__this">{`AU${auId}`}</span>
68
79
  </button>
69
80
  {
70
81
  studentNumber && (
@@ -84,9 +95,9 @@ const AUProfileWidgetComponent = React.memo(({
84
95
  {renderSettings}
85
96
  <hr />
86
97
  {
87
- changeLanguageUrl && (
98
+ changeLanguageUri && (
88
99
  <>
89
- <a className="sub-nav__item sub-nav__item--icon" href={changeLanguageUrl} data-icon="" data-gtm="au-btn-header-profile-changelanguage">{profileLabels[lang].changeLanguage}</a>
100
+ <a className="sub-nav__item sub-nav__item--icon" href={changeLanguageUri} data-icon="" data-gtm="au-btn-header-profile-changelanguage">{profileLabels[lang].changeLanguage}</a>
90
101
  <hr />
91
102
  </>
92
103
  )
@@ -104,26 +115,7 @@ const AUProfileWidgetComponent = React.memo(({
104
115
  });
105
116
 
106
117
  AUProfileWidgetComponent.defaultProps = {
107
- studentNumber: null,
108
- changeLanguageUrl: '',
109
- };
110
-
111
- AUProfileWidgetComponent.propTypes = {
112
- lang: PropTypes.string.isRequired,
113
- name: PropTypes.string.isRequired,
114
- auid: PropTypes.number.isRequired,
115
- studentNumber: PropTypes.string,
116
- settings: PropTypes.arrayOf(PropTypes.shape({
117
- type: PropTypes.string.isRequired,
118
- url: PropTypes.string,
119
- text: PropTypes.string.isRequired,
120
- onClick: PropTypes.func,
121
- classNames: PropTypes.string,
122
- icon: PropTypes.string,
123
- })).isRequired,
124
- profileLabels: PropTypes.shape({}).isRequired,
125
- changeLanguageUrl: PropTypes.string,
126
- logoutUri: PropTypes.string.isRequired,
118
+ studentNumber: '',
127
119
  };
128
120
 
129
121
  AUProfileWidgetComponent.displayName = 'AUProfileWidgetComponent';
@@ -47,7 +47,8 @@ const isElementPartlyInViewport = (element: HTMLElement): boolean => {
47
47
 
48
48
  const setCookie = (
49
49
  cookieName: string,
50
- value: string,
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ value: any,
51
52
  maxAge: number | null = null,
52
53
  exdays: number | null = null,
53
54
  path = ';path=/;domain=au.dk',
@@ -139,11 +140,11 @@ const splitPhoneNumber = (countryCodes: ICountryCode[], phoneNumber: string): IP
139
140
  if (countryCodes.length > 0) {
140
141
  const skip = '';
141
142
  let count = 1;
142
- let prefix = countryCodes.find((x) => x.important)?.code;
143
+ let prefix = `${countryCodes.find((x) => x.important)?.code}`;
143
144
  while (count < phoneNumber.length) {
144
145
  const split = phoneNumber.substring(skip.length, skip.length + count);
145
146
  if (countryCodeFound(split)) {
146
- prefix = parseInt(split, 10);
147
+ prefix = split;
147
148
  }
148
149
  count += 1;
149
150
  }
@@ -62,3 +62,30 @@ interface ITrackers {
62
62
  account: string,
63
63
  name: string,
64
64
  }
65
+
66
+ interface IProfileSettings {
67
+ type: string,
68
+ url: string,
69
+ classNames?: string,
70
+ icon?: string,
71
+ dataGtm: string,
72
+ text: string,
73
+ disabled?: boolean,
74
+ onClick?: (el: Element) => void,
75
+ }
76
+
77
+ interface IUserContext {
78
+ auId: number,
79
+ firstNames: string,
80
+ lastName: string,
81
+ name: string,
82
+ preferredLanguage: string,
83
+ userName: string,
84
+ memberOfGroups: IAdGroup[],
85
+ impersonatingUser: IUserContext | null,
86
+ }
87
+
88
+ interface IAdGroup {
89
+ id: string,
90
+ name: string,
91
+ }
@@ -136,3 +136,30 @@ interface AUReceiptComponentProps {
136
136
  showGoTo: boolean,
137
137
  buttons: IReceiptButton[],
138
138
  }
139
+
140
+ interface AUProfileWidgetComponentProps {
141
+ lang: string,
142
+ name: string,
143
+ auId: number,
144
+ studentNumber?: string,
145
+ settings: IProfileSettings[],
146
+ changeLanguageUri: string,
147
+ logoutUri: string,
148
+ profileLabels: any, // Noget med labels her?
149
+ }
150
+
151
+ interface AUProfileAvatarComponentProps {
152
+ user: IUserContext,
153
+ settings: IProfileSettings[],
154
+ profileLabels: any, // Noget med labels her?
155
+ logoutUri: string,
156
+ changeLanguageUri?: string,
157
+ lang: string,
158
+ }
159
+
160
+ interface AUProfileLoginComponentProps {
161
+ loggedIn: boolean,
162
+ loginUri: string,
163
+ children: JSX.Element,
164
+ text: string,
165
+ }
@@ -1,80 +0,0 @@
1
- /* eslint-env browser */
2
- import React, { useEffect } from 'react';
3
- import PropTypes from 'prop-types';
4
- import AUProfileWidgetComponent from './AUProfileWidgetV3Component';
5
- import AUSubNavComponent from '../delphinus/AUSubNavComponent';
6
-
7
- const AUProfileAvatarComponent = React.memo(({
8
- user,
9
- settings,
10
- onLoad,
11
- onLoadAction,
12
- profileLabels,
13
- logoutUri,
14
- changeLanguageUrl,
15
- lang,
16
- }) => {
17
- const {
18
- auId,
19
- firstNames,
20
- lastName,
21
- } = user;
22
-
23
- useEffect(() => {
24
- if (typeof onLoad === 'function') {
25
- onLoad(onLoadAction);
26
- }
27
- }, []);
28
-
29
- return (
30
- <AUSubNavComponent
31
- id="profile-menu-toggle"
32
- className="nav__item nav__item--icon nav__item--icon--right"
33
- dataIcon=""
34
- text={firstNames}
35
- ariaLabel={`${profileLabels[lang].profileFor} ${firstNames} ${lastName}`}
36
- >
37
- <AUProfileWidgetComponent
38
- lang={lang}
39
- name={`${firstNames} ${lastName}`}
40
- auid={auId}
41
- settings={settings}
42
- profileLabels={profileLabels}
43
- changeLanguageUrl={changeLanguageUrl}
44
- logoutUri={logoutUri}
45
- />
46
- </AUSubNavComponent>
47
- );
48
- });
49
-
50
- AUProfileAvatarComponent.defaultProps = {
51
- onLoad: null,
52
- onLoadAction: () => {
53
-
54
- },
55
- changeLanguageUrl: '',
56
- };
57
-
58
- AUProfileAvatarComponent.propTypes = {
59
- user: PropTypes.shape({
60
- auId: PropTypes.number.isRequired,
61
- firstNames: PropTypes.string.isRequired,
62
- lastName: PropTypes.string.isRequired,
63
- preferredLanguage: PropTypes.string.isRequired,
64
- }).isRequired,
65
- settings: PropTypes.arrayOf(PropTypes.shape({
66
- type: PropTypes.string.isRequired,
67
- url: PropTypes.string,
68
- text: PropTypes.string.isRequired,
69
- onClick: PropTypes.func,
70
- })).isRequired,
71
- onLoad: PropTypes.func,
72
- onLoadAction: PropTypes.func,
73
- profileLabels: PropTypes.shape({}).isRequired,
74
- logoutUri: PropTypes.string.isRequired,
75
- changeLanguageUrl: PropTypes.string,
76
- lang: PropTypes.string.isRequired,
77
- };
78
-
79
- AUProfileAvatarComponent.displayName = 'AUProfileAvatarComponent';
80
- export default AUProfileAvatarComponent;