@aarhus-university/au-lib-react-components 10.18.1 → 10.19.1

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.18.1",
4
+ "version": "10.19.1",
5
5
  "description": "Library for shared React components for various applications on au.dk",
6
6
  "scripts": {
7
7
  "test": "jest",
@@ -73,7 +73,7 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "@aarhus-university/au-designsystem-delphinus": "0.30.1",
76
- "@aarhus-university/types": "0.10.2",
76
+ "@aarhus-university/types": "0.13.5",
77
77
  "@reduxjs/toolkit": "^1.8.3",
78
78
  "@types/google.analytics": "^0.0.42",
79
79
  "@types/history": "^5.0.0",
@@ -93,7 +93,7 @@
93
93
  },
94
94
  "peerDependencies": {
95
95
  "react": "18.2.0",
96
- "react-dom": "^18.2.0"
96
+ "react-dom": "18.2.0"
97
97
  },
98
98
  "jest": {
99
99
  "rootDir": "__tests__/jest",
@@ -14,6 +14,7 @@ const AUButtonComponent: FC<AUButtonComponentProps> = ({
14
14
  btnRef,
15
15
  classNames,
16
16
  ariaExpanded,
17
+ asSubmit,
17
18
  onClick,
18
19
  }: AUButtonComponentProps) => {
19
20
  const sizeClass = size === 'default' ? '' : `button--${size}`;
@@ -37,7 +38,7 @@ const AUButtonComponent: FC<AUButtonComponentProps> = ({
37
38
  return (
38
39
  <button
39
40
  ref={btnRef}
40
- type="button"
41
+ type={asSubmit ? 'submit' : 'button'}
41
42
  disabled={disabled}
42
43
  className={[
43
44
  'button',
@@ -71,6 +72,7 @@ AUButtonComponent.defaultProps = {
71
72
  mode: 'none',
72
73
  classNames: [],
73
74
  ariaExpanded: false,
75
+ asSubmit: false,
74
76
  // eslint-disable-next-line no-console
75
77
  onClick: (
76
78
  event: MouseEvent<HTMLButtonElement>,
@@ -1,29 +1,27 @@
1
1
  import React, { FC } from 'react';
2
- import { profileLabels } from '../lib/i18n';
2
+ import AUButtonComponent from './AUButtonComponent';
3
3
 
4
4
  const AUSubmitButtonContainerComponent: FC<AUSubmitButtonContainerComponentProps> = ({
5
- lang,
6
5
  disabled,
6
+ submitText,
7
+ cancelText,
7
8
  onSubmit,
8
9
  onCancel,
9
10
  }: AUSubmitButtonContainerComponentProps) => (
10
11
  <div className="submit button-container">
11
- <button
12
- type="submit"
13
- className={`button${disabled ? ' button--processing' : ''}`}
12
+ <AUButtonComponent
13
+ asSubmit
14
+ label={submitText}
15
+ classNames={[disabled ? 'button--processing' : '']}
14
16
  disabled={disabled}
15
17
  onClick={onSubmit}
16
- >
17
- {profileLabels[lang].save}
18
- </button>
19
- <button
20
- type="button"
21
- className="button button--text"
18
+ />
19
+ <AUButtonComponent
20
+ label={cancelText}
21
+ type="text"
22
22
  disabled={disabled}
23
23
  onClick={onCancel}
24
- >
25
- {profileLabels[lang].cancel}
26
- </button>
24
+ />
27
25
  </div>
28
26
  );
29
27
 
@@ -2,6 +2,7 @@
2
2
  import React, {
3
3
  useEffect, useLayoutEffect, useRef, FC,
4
4
  } from 'react';
5
+ import AUButtonComponent from './AUButtonComponent';
5
6
 
6
7
  const dismissTimeout = 5000;
7
8
  let timeoutId: NodeJS.Timeout | null = null;
@@ -56,10 +57,13 @@ const AUToastComponent: FC<AUToastComponentProps> = ({
56
57
  }
57
58
  }, []);
58
59
 
59
- let className = `toast-notification toast-notification--${type}`;
60
+ let className = 'toast-notification';
60
61
  if (persistent) {
61
62
  className = `${className} toast-notification--persistent`;
62
63
  }
64
+ if (type !== 'default') {
65
+ className = `${className} toast-notification--${type}`;
66
+ }
63
67
  return (
64
68
  <div ref={toastRef} className={className}>
65
69
  <div className="toast-notification__content">
@@ -74,17 +78,14 @@ const AUToastComponent: FC<AUToastComponentProps> = ({
74
78
  </div>
75
79
  {
76
80
  persistent && (
77
- <button
78
- type="button"
79
- className="button"
81
+ <AUButtonComponent
82
+ label={buttonText as string}
80
83
  onClick={() => {
81
84
  if (toastRef.current) {
82
85
  moveOut(toastRef.current);
83
86
  }
84
87
  }}
85
- >
86
- {buttonText}
87
- </button>
88
+ />
88
89
  )
89
90
  }
90
91
  </div>
@@ -141,7 +141,7 @@ const splitPhoneNumber = (
141
141
 
142
142
  const findPrefix = (): string => {
143
143
  if (countryCodes.length > 0) {
144
- const skip = '';
144
+ const skip = phoneNumber.length > 0 ? '' : '+'; // Hackish...
145
145
  let count = 1;
146
146
  let prefix = `${countryCodes.find((x) => x.important)?.code}`;
147
147
  while (count < phoneNumber.length) {
@@ -29,7 +29,29 @@ const globalLang = (items = ['da', 'en'], defaultValue = 'da') => ({
29
29
  },
30
30
  });
31
31
 
32
- const ThemeWrapper = ({
32
+ const ThemeWrapper = ({ theme, children }) => {
33
+ useEffect(() => {
34
+ const body = document.querySelector('body');
35
+ if (body) {
36
+ body.classList.remove('theme--normal');
37
+ body.classList.remove('theme--dark');
38
+ body.classList.add(`theme--${theme}`);
39
+ }
40
+ });
41
+ return (
42
+ <StrictMode>
43
+ <main className={`theme--${theme}`}>
44
+ <div className="page">
45
+ <div className="page__content__block">
46
+ {children}
47
+ </div>
48
+ </div>
49
+ </main>
50
+ </StrictMode>
51
+ );
52
+ }
53
+
54
+ const ThemeLanguageWrapper = ({
33
55
  theme,
34
56
  children,
35
57
  defaultLabels,
@@ -60,8 +82,10 @@ const ThemeWrapper = ({
60
82
  );
61
83
  }
62
84
 
85
+
63
86
  export {
64
87
  globalTheme,
65
88
  globalLang,
66
89
  ThemeWrapper,
90
+ ThemeLanguageWrapper,
67
91
  };
@@ -1,128 +0,0 @@
1
- /* eslint-disable import/prefer-default-export */
2
- export const GET_BASIC_USER = 'GET_BASIC_USER';
3
- export const SAVING_USER = 'SAVING_USER';
4
- export const PATCH_NAME = 'PATCH_NAME';
5
- export const PATCH_MAIL = 'PATCH_MAIL';
6
- export const PATCH_MOBILE = 'PATCH_MOBILE';
7
- export const PATCH_LANGUAGE = 'PATCH_LANGUAGE';
8
- export const PATCH_NEXTOFKIN = 'PATCH_NEXTOFKIN';
9
- export const DISMISS_MESSAGES = 'DISMISS_MESSAGES';
10
- export const SET_SAVED = 'SET_SAVED';
11
- export const GET_WORKMAIL_DOMAIN = 'GET_WORKMAIL_DOMAIN';
12
-
13
- export const getActionCreators = () => {
14
- const actionCreators = {
15
- getBasicUser: (callback) => async (dispatch) => { // Tror simpelthen ikke det her er i brug...
16
- callback((ok, status, json) => {
17
- const result = {};
18
- result[ok ? 'user' : 'error'] = json;
19
- result.status = status;
20
- dispatch({
21
- type: GET_BASIC_USER,
22
- result,
23
- });
24
- });
25
- },
26
- getWorkMailDomain: () => async (dispatch) => {
27
- const url = '/v1/person/getworkmaildomain';
28
- const response = await fetch(url);
29
- const json = await response.json();
30
- const result = {};
31
- result[response.ok ? 'user' : 'error'] = response.ok ? {
32
- workMailDomain: json
33
- } : json;
34
- result.status = response.status;
35
- dispatch({
36
- type: GET_WORKMAIL_DOMAIN,
37
- result,
38
- });
39
- },
40
- clear: () => (dispatch) => {
41
- dispatch({
42
- type: SET_SAVED,
43
- });
44
- },
45
- dismissMessages: () => (dispatch) => {
46
- dispatch({
47
- type: DISMISS_MESSAGES,
48
- });
49
- },
50
- patchName: (data, callback) => async (dispatch) => {
51
- dispatch({
52
- type: SAVING_USER,
53
- });
54
-
55
- callback(data, (ok, status, json) => {
56
- const result = {};
57
- result[ok ? 'user' : 'error'] = json;
58
- result.status = status;
59
- dispatch({
60
- type: PATCH_NAME,
61
- result,
62
- });
63
- });
64
- },
65
- patchMail: (data, callback) => async (dispatch) => {
66
- dispatch({
67
- type: SAVING_USER,
68
- });
69
-
70
- callback(data, (ok, status, json) => {
71
- const result = {};
72
- result[ok ? 'user' : 'error'] = json;
73
- result.status = status;
74
- dispatch({
75
- type: PATCH_MAIL,
76
- result,
77
- });
78
- });
79
- },
80
- patchMobile: (data, callback) => async (dispatch) => {
81
- dispatch({
82
- type: SAVING_USER,
83
- });
84
-
85
- callback(data, (ok, status, json) => {
86
- const result = {};
87
- result[ok ? 'user' : 'error'] = json;
88
- result.status = status;
89
- dispatch({
90
- type: PATCH_MOBILE,
91
- result,
92
- });
93
- });
94
- },
95
- patchLanguage: (data, callback) => async (dispatch) => {
96
- dispatch({
97
- type: SAVING_USER,
98
- });
99
-
100
- callback(data, (ok, status, json) => {
101
- const result = {};
102
- result[ok ? 'user' : 'error'] = json;
103
- result.status = status;
104
- dispatch({
105
- type: PATCH_LANGUAGE,
106
- result,
107
- });
108
- });
109
- },
110
- patchNextOfKin: (data, callback) => async (dispatch) => {
111
- dispatch({
112
- type: SAVING_USER,
113
- });
114
-
115
- callback(data, (ok, status, json) => {
116
- const result = {};
117
- result[ok ? 'user' : 'error'] = json;
118
- result.status = status;
119
- dispatch({
120
- type: PATCH_NEXTOFKIN,
121
- result,
122
- });
123
- });
124
- },
125
- };
126
-
127
- return actionCreators;
128
- };
@@ -1,83 +0,0 @@
1
- /* eslint-env browser */
2
- import React, { useEffect } from 'react';
3
- // eslint-disable-next-line import/extensions
4
- // import whyDidYouRender from '@welldone-software/
5
- // why-did-you-render/dist/no-classes-transpile/umd/whyDidYouRender.min.js';
6
- import PropTypes from 'prop-types';
7
- import AUProfileWidgetComponent from './AUProfileWidgetComponent';
8
- import AUSubNavComponent from '../delphinus/AUSubNavComponent';
9
-
10
- // whyDidYouRender(React);
11
-
12
- const AUProfileAvatarComponent = React.memo(({
13
- user,
14
- settings,
15
- onLoad,
16
- onLoadAction,
17
- profileLabels,
18
- logoutUri,
19
- changeLanguageUrl,
20
- }) => {
21
- const {
22
- chosenFirstNames,
23
- chosenLastName,
24
- preferredLanguage,
25
- auId,
26
- studentNumber,
27
- } = user;
28
-
29
- useEffect(() => {
30
- onLoad(onLoadAction);
31
- }, []);
32
-
33
- return (
34
- <AUSubNavComponent
35
- id="profile-menu-toggle"
36
- className="nav__item nav__item--icon nav__item--icon--right"
37
- dataIcon=""
38
- text={chosenFirstNames}
39
- ariaLabel={`${profileLabels[preferredLanguage].profileFor} ${chosenFirstNames} ${chosenLastName}`}
40
- >
41
- <AUProfileWidgetComponent
42
- lang={preferredLanguage}
43
- name={`${chosenFirstNames} ${chosenLastName}`}
44
- auid={auId}
45
- studentNumber={studentNumber}
46
- settings={settings}
47
- profileLabels={profileLabels}
48
- changeLanguageUrl={changeLanguageUrl}
49
- logoutUri={logoutUri}
50
- />
51
- </AUSubNavComponent>
52
- );
53
- });
54
-
55
- // AUProfileAvatarComponent.whyDidYouRender = true;
56
-
57
- AUProfileAvatarComponent.defaultProps = {
58
- onLoadAction: () => {
59
-
60
- },
61
- };
62
-
63
- AUProfileAvatarComponent.propTypes = {
64
- user: PropTypes.shape({
65
- chosenFirstNames: PropTypes.string.isRequired,
66
- chosenLastName: PropTypes.string.isRequired,
67
- preferredLanguage: PropTypes.string.isRequired,
68
- auId: PropTypes.number.isRequired,
69
- studentNumber: PropTypes.string.isRequired,
70
- }).isRequired,
71
- settings: PropTypes.arrayOf(PropTypes.shape({
72
- url: PropTypes.string.isRequired,
73
- text: PropTypes.string.isRequired,
74
- })).isRequired,
75
- onLoad: PropTypes.func.isRequired,
76
- onLoadAction: PropTypes.func,
77
- profileLabels: PropTypes.shape({}).isRequired,
78
- logoutUri: PropTypes.string.isRequired,
79
- changeLanguageUrl: PropTypes.string.isRequired,
80
- };
81
-
82
- AUProfileAvatarComponent.displayName = 'AUProfileAvatarComponent';
83
- export default AUProfileAvatarComponent;
@@ -1,91 +0,0 @@
1
- /* eslint-env browser */
2
- import React, { useEffect } from 'react';
3
- import PropTypes from 'prop-types';
4
- import AUProfileWidgetComponent from './AUProfileWidgetV2Component';
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
- }) => {
16
- const {
17
- person: {
18
- auPerson: {
19
- auId, foretrukketSprog, kaldeFornavne, kaldeEfternavn,
20
- },
21
- },
22
- } = user;
23
- const studentNumber = user.studerende?.auUddannelsesidentitet?.studienr;
24
-
25
- useEffect(() => {
26
- if (typeof onLoad === 'function') {
27
- onLoad(onLoadAction);
28
- }
29
- }, []);
30
-
31
- return (
32
- <AUSubNavComponent
33
- id="profile-menu-toggle"
34
- className="nav__item nav__item--icon nav__item--icon--right"
35
- dataIcon=""
36
- text={kaldeFornavne}
37
- ariaLabel={`${profileLabels[foretrukketSprog].profileFor} ${kaldeFornavne} ${kaldeEfternavn}`}
38
- >
39
- <AUProfileWidgetComponent
40
- lang={foretrukketSprog}
41
- name={`${kaldeFornavne} ${kaldeEfternavn}`}
42
- auid={auId}
43
- studentNumber={studentNumber}
44
- settings={settings}
45
- profileLabels={profileLabels}
46
- changeLanguageUrl={changeLanguageUrl}
47
- logoutUri={logoutUri}
48
- />
49
- </AUSubNavComponent>
50
- );
51
- });
52
-
53
- AUProfileAvatarComponent.defaultProps = {
54
- onLoad: null,
55
- onLoadAction: () => {
56
-
57
- },
58
- changeLanguageUrl: '',
59
- };
60
-
61
- AUProfileAvatarComponent.propTypes = {
62
- user: PropTypes.shape({
63
- person: PropTypes.shape({
64
- auPerson: PropTypes.shape({
65
- kaldeFornavne: PropTypes.string.isRequired,
66
- kaldeEfternavn: PropTypes.string.isRequired,
67
- auId: PropTypes.number.isRequired,
68
- foretrukketSprog: PropTypes.string.isRequired,
69
- }).isRequired,
70
- }).isRequired,
71
- studerende: PropTypes.shape({
72
- auUddannelsesidentitet: PropTypes.shape({
73
- studienr: PropTypes.number.isRequired,
74
- }),
75
- }),
76
- }).isRequired,
77
- settings: PropTypes.arrayOf(PropTypes.shape({
78
- type: PropTypes.string.isRequired,
79
- url: PropTypes.string,
80
- text: PropTypes.string.isRequired,
81
- onClick: PropTypes.func,
82
- })).isRequired,
83
- onLoad: PropTypes.func,
84
- onLoadAction: PropTypes.func,
85
- profileLabels: PropTypes.shape({}).isRequired,
86
- logoutUri: PropTypes.string.isRequired,
87
- changeLanguageUrl: PropTypes.string,
88
- };
89
-
90
- AUProfileAvatarComponent.displayName = 'AUProfileAvatarComponent';
91
- export default AUProfileAvatarComponent;
@@ -1,42 +0,0 @@
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;