@aarhus-university/au-lib-react-components 12.6.2 → 12.6.3

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.
Files changed (109) hide show
  1. package/.eslintrc.js +35 -35
  2. package/.storybook/main.js +34 -34
  3. package/.storybook/preview.js +17 -17
  4. package/README.md +19 -19
  5. package/__tests__/jest/AUButtonComponent.test.tsx +165 -165
  6. package/__tests__/jest/AUDynamicContentComponent.test.tsx +386 -386
  7. package/__tests__/jest/AUErrorComponent.test.tsx +142 -142
  8. package/__tests__/jest/AUModalComponent.test.tsx +186 -186
  9. package/__tests__/jest/AUNotificationComponent.test.tsx +115 -115
  10. package/__tests__/jest/AUSpinnerComponent.test.tsx +57 -57
  11. package/__tests__/jest/AUToolbarComponent.test.tsx +46 -46
  12. package/__tests__/jest/context.test.ts +25 -25
  13. package/__tests__/jest/helpers.test.ts +15 -15
  14. package/__tests__/jest/setupTests.ts +2 -2
  15. package/babel.config.js +8 -8
  16. package/build/umd/all.css +2 -2
  17. package/build/umd/all.js +1 -1
  18. package/build/umd/alphabox.js +1 -1
  19. package/build/umd/databox.js +1 -1
  20. package/build/umd/diagramme.js +1 -1
  21. package/build/umd/flowbox.js +1 -1
  22. package/build/umd/flowbox.js.map +1 -1
  23. package/build/umd/universe.js +1 -1
  24. package/build-storybook.log +386 -386
  25. package/esbuild.mjs +22 -22
  26. package/package.json +107 -107
  27. package/src/components/AUAlertComponent.tsx +128 -128
  28. package/src/components/AUAutoSuggestComponent.js +148 -148
  29. package/src/components/AUButtonComponent.tsx +99 -99
  30. package/src/components/AUCalendarComponent.tsx +497 -497
  31. package/src/components/AUCharacterCountComponent.tsx +56 -56
  32. package/src/components/AUComboBoxComponent.tsx +195 -195
  33. package/src/components/AUContentToggleComponent.tsx +50 -50
  34. package/src/components/AUDatepickerComponent.tsx +124 -124
  35. package/src/components/AUDialogModalComponent.tsx +124 -124
  36. package/src/components/AUDynamicContentComponent.tsx +137 -137
  37. package/src/components/AUEditorComponent.tsx +126 -126
  38. package/src/components/AUErrorComponent.tsx +73 -73
  39. package/src/components/AUMobilePrefixComponent.tsx +20 -20
  40. package/src/components/AUModalComponent.tsx +72 -72
  41. package/src/components/AUNotificationComponent.tsx +44 -44
  42. package/src/components/AUReceiptComponent.tsx +34 -34
  43. package/src/components/AUSpinnerComponent.tsx +40 -40
  44. package/src/components/AUStepComponent.tsx +75 -75
  45. package/src/components/AUSubNavComponent.tsx +57 -57
  46. package/src/components/AUSubmitButtonContainerComponent.tsx +38 -38
  47. package/src/components/AUTabbedContentComponent.tsx +154 -154
  48. package/src/components/AUTableComponent.tsx +29 -29
  49. package/src/components/AUToastComponent.tsx +104 -104
  50. package/src/components/AUToolbarComponent.tsx +108 -108
  51. package/src/components/AUTruncatorComponent.tsx +141 -141
  52. package/src/components/wrapping/AUEmbedComponent.js +47 -47
  53. package/src/layout-2016/components/alphabox/AlphaBoxComponent.js +142 -142
  54. package/src/layout-2016/components/alphabox/AlphaBoxContentComponent.js +136 -136
  55. package/src/layout-2016/components/common/AUCollapsibleComponent.js +152 -152
  56. package/src/layout-2016/components/common/AUSpinnerComponent.js +103 -103
  57. package/src/layout-2016/components/databox/DataBoxAlphabetComponent.js +144 -144
  58. package/src/layout-2016/components/databox/DataBoxAssociationComponent.js +122 -122
  59. package/src/layout-2016/components/databox/DataBoxButtonComponent.js +157 -157
  60. package/src/layout-2016/components/databox/DataBoxComponent.js +297 -297
  61. package/src/layout-2016/components/databox/DataBoxGroupingComponent.js +64 -64
  62. package/src/layout-2016/components/databox/DataBoxSearchResultComponent.js +36 -36
  63. package/src/layout-2016/components/databox/DataBoxStackedAssociationComponent.js +54 -54
  64. package/src/layout-2016/components/databox/DataBoxSuggestionComponent.js +39 -39
  65. package/src/layout-2016/components/diagramme/AUDiagrammeComponent.js +309 -309
  66. package/src/layout-2016/components/flowbox/FlowBoxComponent.js +126 -126
  67. package/src/layout-2016/components/flowbox/FlowBoxPhoneComponent.js +104 -104
  68. package/src/layout-2016/lib/all.js +3 -3
  69. package/src/layout-2016/lib/au-alphabox.js +99 -99
  70. package/src/layout-2016/lib/au-databox.js +399 -399
  71. package/src/layout-2016/lib/au-diagramme.js +85 -85
  72. package/src/layout-2016/lib/au-flowbox.js +116 -119
  73. package/src/lib/context.tsx +59 -59
  74. package/src/lib/dates.ts +52 -52
  75. package/src/lib/helpers.ts +208 -208
  76. package/src/lib/hooks.ts +157 -157
  77. package/src/lib/i18n.ts +600 -600
  78. package/src/lib/portals.tsx +150 -150
  79. package/src/lib/tinymce.ts +84 -84
  80. package/src/lib/wrapping.ts +21 -21
  81. package/src/styles/_settings.scss +10 -10
  82. package/src/styles/alphabox.scss +222 -222
  83. package/src/styles/app.scss +7 -7
  84. package/src/styles/autosuggest.scss +57 -57
  85. package/src/styles/databox.scss +563 -563
  86. package/src/styles/diagramme.scss +119 -119
  87. package/src/styles/flowbox.scss +72 -72
  88. package/src/styles/maps.scss +395 -395
  89. package/stories/AUAlertComponent.stories.tsx +133 -133
  90. package/stories/AUAutoSuggestComponent.stories.tsx +95 -95
  91. package/stories/AUButtonComponent.stories.tsx +139 -139
  92. package/stories/AUCharacterCountComponent.stories.tsx +121 -121
  93. package/stories/AUComboBoxComponent.stories.tsx +101 -101
  94. package/stories/AUContentToggleComponent.stories.tsx +87 -87
  95. package/stories/AUDialogModalComponent.stories.tsx +75 -75
  96. package/stories/AUDynamicContentComponent.stories.tsx +119 -119
  97. package/stories/AUEditorComponent.stories.tsx +66 -66
  98. package/stories/AUErrorComponent.stories.tsx +132 -132
  99. package/stories/AUModalComponent.stories.tsx +160 -160
  100. package/stories/AUNotificationComponent.stories.tsx +151 -151
  101. package/stories/AUSpinnerComponent.stories.tsx +44 -44
  102. package/stories/AUStepComponent.stories.tsx +91 -91
  103. package/stories/AUToolbarComponent.stories.tsx +389 -389
  104. package/stories/AUTruncatorComponent.stories.tsx +123 -123
  105. package/stories/lib/helpers.tsx +146 -146
  106. package/tsconfig.json +46 -46
  107. package/webpack.config.js +88 -88
  108. package/.claude/settings.local.json +0 -12
  109. package/.vscode/settings.json +0 -22
@@ -1,85 +1,85 @@
1
- /* eslint no-prototype-builtins: 0 */
2
- /* eslint no-restricted-syntax: 0 */
3
- /* eslint no-unused-vars: 0 */
4
- /* eslint-env browser */
5
- import React from 'react';
6
- import ReactDOM from 'react-dom';
7
- import AUDiagrammeComponent from '../components/diagramme/AUDiagrammeComponent';
8
-
9
- const defaultOptions = {
10
- config: {
11
- container: '.au_edutable_eddi_container',
12
- courseID: 0,
13
- track: 0,
14
- },
15
- };
16
-
17
- class AUDiagramme {
18
- constructor(lang, tables) {
19
- this.tables = tables;
20
- this.lang = lang;
21
- }
22
-
23
- static mergeOptions(_table) {
24
- const table = _table;
25
- if (!table.hasOwnProperty('config')) {
26
- table.config = {};
27
- }
28
-
29
- for (const conf in defaultOptions.config) {
30
- if (!table.config.hasOwnProperty(conf)) {
31
- table.config[conf] = defaultOptions.config[conf];
32
- }
33
- }
34
- }
35
-
36
- init() {
37
- const qsCourses = AU.helpers.getQuerystring('coursesprint');
38
- if (qsCourses !== '') {
39
- const coursesSplit = qsCourses.split(',');
40
- for (let j = 0; j < coursesSplit.length; j += 1) {
41
- const trackSplit = coursesSplit[j].split('|');
42
- if (trackSplit.length > 1) {
43
- this.tables.push({
44
- config: {
45
- container: `#print_course_${j}`,
46
- courseID: parseInt(trackSplit[0], 10),
47
- track: parseInt(trackSplit[1], 10),
48
- },
49
- });
50
- } else {
51
- this.tables.push({
52
- config: {
53
- container: `#print_course_${j}`,
54
- courseID: parseInt(trackSplit[0], 10),
55
- },
56
- });
57
- }
58
- ReactDOM.render(<div id={`print_course_${j}`} />, document.querySelector('body'));
59
- }
60
- }
61
- for (let i = 0; i < this.tables.length; i += 1) {
62
- const table = this.tables[i];
63
- table.id = i;
64
- AUDiagramme.mergeOptions(table);
65
- const url = `https://eddiprod.au.dk/EDDI/webservices/StudieoversigtService2.cfc?method=getLinjeListByDokordningId&tjekForVisningIstudieDiagram=true&allowOrigin=true&dokordningId=${table.config.courseID}`;
66
- fetch(url).then((promise) => promise.json()).then((data) => {
67
- const mountNode = document.querySelector(table.config.container);
68
- if (mountNode) {
69
- ReactDOM.render(
70
- <AUDiagrammeComponent
71
- lang={this.lang}
72
- response={data}
73
- course={table.config.courseID}
74
- track={table.config.track}
75
- print={qsCourses !== ''}
76
- />,
77
- mountNode,
78
- );
79
- }
80
- });
81
- }
82
- }
83
- }
84
-
85
- window.AUDiagramme = AUDiagramme;
1
+ /* eslint no-prototype-builtins: 0 */
2
+ /* eslint no-restricted-syntax: 0 */
3
+ /* eslint no-unused-vars: 0 */
4
+ /* eslint-env browser */
5
+ import React from 'react';
6
+ import ReactDOM from 'react-dom';
7
+ import AUDiagrammeComponent from '../components/diagramme/AUDiagrammeComponent';
8
+
9
+ const defaultOptions = {
10
+ config: {
11
+ container: '.au_edutable_eddi_container',
12
+ courseID: 0,
13
+ track: 0,
14
+ },
15
+ };
16
+
17
+ class AUDiagramme {
18
+ constructor(lang, tables) {
19
+ this.tables = tables;
20
+ this.lang = lang;
21
+ }
22
+
23
+ static mergeOptions(_table) {
24
+ const table = _table;
25
+ if (!table.hasOwnProperty('config')) {
26
+ table.config = {};
27
+ }
28
+
29
+ for (const conf in defaultOptions.config) {
30
+ if (!table.config.hasOwnProperty(conf)) {
31
+ table.config[conf] = defaultOptions.config[conf];
32
+ }
33
+ }
34
+ }
35
+
36
+ init() {
37
+ const qsCourses = AU.helpers.getQuerystring('coursesprint');
38
+ if (qsCourses !== '') {
39
+ const coursesSplit = qsCourses.split(',');
40
+ for (let j = 0; j < coursesSplit.length; j += 1) {
41
+ const trackSplit = coursesSplit[j].split('|');
42
+ if (trackSplit.length > 1) {
43
+ this.tables.push({
44
+ config: {
45
+ container: `#print_course_${j}`,
46
+ courseID: parseInt(trackSplit[0], 10),
47
+ track: parseInt(trackSplit[1], 10),
48
+ },
49
+ });
50
+ } else {
51
+ this.tables.push({
52
+ config: {
53
+ container: `#print_course_${j}`,
54
+ courseID: parseInt(trackSplit[0], 10),
55
+ },
56
+ });
57
+ }
58
+ ReactDOM.render(<div id={`print_course_${j}`} />, document.querySelector('body'));
59
+ }
60
+ }
61
+ for (let i = 0; i < this.tables.length; i += 1) {
62
+ const table = this.tables[i];
63
+ table.id = i;
64
+ AUDiagramme.mergeOptions(table);
65
+ const url = `https://eddiprod.au.dk/EDDI/webservices/StudieoversigtService2.cfc?method=getLinjeListByDokordningId&tjekForVisningIstudieDiagram=true&allowOrigin=true&dokordningId=${table.config.courseID}`;
66
+ fetch(url).then((promise) => promise.json()).then((data) => {
67
+ const mountNode = document.querySelector(table.config.container);
68
+ if (mountNode) {
69
+ ReactDOM.render(
70
+ <AUDiagrammeComponent
71
+ lang={this.lang}
72
+ response={data}
73
+ course={table.config.courseID}
74
+ track={table.config.track}
75
+ print={qsCourses !== ''}
76
+ />,
77
+ mountNode,
78
+ );
79
+ }
80
+ });
81
+ }
82
+ }
83
+ }
84
+
85
+ window.AUDiagramme = AUDiagramme;
@@ -1,119 +1,116 @@
1
- /* eslint-env browser */
2
- /* eslint no-prototype-builtins: 0 */
3
- /* eslint no-restricted-syntax: 0 */
4
- /* eslint no-unused-vars: 0 */
5
- import React from 'react';
6
- import ReactDOM from 'react-dom';
7
- import FlowBoxComponent from '../components/flowbox/FlowBoxComponent';
8
-
9
- const defaultOptions = {
10
- config: {
11
- container: '.au_flowbox',
12
- render: 'ul',
13
- },
14
- data: {
15
- mode: 'list',
16
- source: '.au_flowbox_list',
17
- headline: 'Overskrift',
18
- prepend: '',
19
- },
20
- };
21
-
22
- class AUFlowbox {
23
- constructor(lang, boxes) {
24
- this.boxes = boxes;
25
- this.lang = lang;
26
- }
27
-
28
- static mergeOptions(_box) {
29
- const box = _box;
30
- if (!box.hasOwnProperty('config')) {
31
- box.config = {};
32
- }
33
-
34
- for (const conf in defaultOptions.config) {
35
- if (!box.config.hasOwnProperty(conf)) {
36
- box.config[conf] = defaultOptions.config[conf];
37
- }
38
- }
39
-
40
- if (!box.hasOwnProperty('data')) {
41
- box.data = {};
42
- }
43
-
44
- for (const data in defaultOptions.data) {
45
- if (!box.data.hasOwnProperty(data)) {
46
- box.data[data] = defaultOptions.data[data];
47
- }
48
- }
49
- }
50
-
51
- static parse(box) {
52
- const getLabelFromLi = (li) => {
53
- // Primært: TYPO3v10/“p-wrapped” eller global content hvor der kommer en wrapper ind
54
- const labelEl = li.querySelector(':scope > p')
55
- || li.querySelector(':scope > div > p')
56
- || li.querySelector(':scope > div > p > span') // hvis editoren putter spans ind
57
- || null;
58
-
59
- if (labelEl) {
60
- return labelEl.innerHTML.trim();
61
- }
62
-
63
- // Sekundært: TYPO3v12 hvor label ofte er en text node direkte i <li>
64
- // Tag kun direkte textnodes (ignorer <ul> og andre elementer)
65
- const text = Array.from(li.childNodes)
66
- .filter((n) => n.nodeType === Node.TEXT_NODE)
67
- .map((n) => n.textContent)
68
- .join(' ')
69
- .replace(/\s+/g, ' ')
70
- .trim();
71
-
72
- // Fallback: hvis noget uventet er inde i et element, men stadig uden <p>
73
- if (text) return text;
74
-
75
- const firstNonUlElement = Array.from(li.children).find((c) => c.tagName !== 'UL');
76
- return firstNonUlElement ? firstNonUlElement.innerHTML.trim() : '';
77
- };
78
-
79
- const parseUl = (data, ulElements) => {
80
- ulElements.forEach((ul) => {
81
- const lis = ul.querySelectorAll(':scope > li');
82
- lis.forEach((li) => {
83
- const name = getLabelFromLi(li);
84
- if (!name) return;
85
-
86
- const obj = { name, children: [], parent: data };
87
- data.children.push(obj);
88
-
89
- const childUls = li.querySelectorAll(':scope > ul');
90
- if (childUls.length > 0) {
91
- parseUl(obj, childUls); // Det her skal vi altid gøre
92
- }
93
- });
94
- });
95
- };
96
-
97
- // Start: find root UL’er fra box.data.source (som før)
98
- const roots = document.querySelectorAll(box.data.source);
99
- parseUl(box.item, roots);
100
- }
101
-
102
- init() {
103
- for (let i = 0; i < this.boxes.length; i += 1) {
104
- const box = this.boxes[i];
105
- AUFlowbox.mergeOptions(box);
106
- box.id = i;
107
- box.item = {
108
- name: box.data.headline,
109
- children: [],
110
- parent: null,
111
- };
112
- AUFlowbox.parse(box);
113
- const mountNode = document.querySelector(box.config.container);
114
- ReactDOM.render(<FlowBoxComponent box={box} lang={this.lang} />, mountNode);
115
- }
116
- }
117
- }
118
-
119
- window.AUFlowbox = AUFlowbox;
1
+ /* eslint-env browser */
2
+ /* eslint no-prototype-builtins: 0 */
3
+ /* eslint no-restricted-syntax: 0 */
4
+ /* eslint no-unused-vars: 0 */
5
+ import React from 'react';
6
+ import ReactDOM from 'react-dom';
7
+ import FlowBoxComponent from '../components/flowbox/FlowBoxComponent';
8
+
9
+ const defaultOptions = {
10
+ config: {
11
+ container: '.au_flowbox',
12
+ render: 'ul',
13
+ },
14
+ data: {
15
+ mode: 'list',
16
+ source: '.au_flowbox_list',
17
+ headline: 'Overskrift',
18
+ prepend: '',
19
+ },
20
+ };
21
+
22
+ class AUFlowbox {
23
+ constructor(lang, boxes) {
24
+ this.boxes = boxes;
25
+ this.lang = lang;
26
+ }
27
+
28
+ static mergeOptions(_box) {
29
+ const box = _box;
30
+ if (!box.hasOwnProperty('config')) {
31
+ box.config = {};
32
+ }
33
+
34
+ for (const conf in defaultOptions.config) {
35
+ if (!box.config.hasOwnProperty(conf)) {
36
+ box.config[conf] = defaultOptions.config[conf];
37
+ }
38
+ }
39
+
40
+ if (!box.hasOwnProperty('data')) {
41
+ box.data = {};
42
+ }
43
+
44
+ for (const data in defaultOptions.data) {
45
+ if (!box.data.hasOwnProperty(data)) {
46
+ box.data[data] = defaultOptions.data[data];
47
+ }
48
+ }
49
+ }
50
+
51
+ static parse(box) {
52
+ const getLabelFromLi = (li) => {
53
+ // Primært: TYPO3v10/“p-wrapped” eller global content hvor der kommer en wrapper ind
54
+ const labelEl = li.querySelector(':scope > p')
55
+ || li.querySelector(':scope > div > p')
56
+ || li.querySelector(':scope > div > p > span') // hvis editoren putter spans ind
57
+ || null;
58
+
59
+ if (labelEl) {
60
+ return labelEl.innerHTML.trim();
61
+ }
62
+
63
+ // Sekundært: mixed content direkte i <li>
64
+ // Ignorer <ul> og <ol>, men behold alle andre nodes inkl. inline elementer
65
+ const html = Array.from(li.childNodes)
66
+ .filter((n) => !(n.nodeType === Node.ELEMENT_NODE
67
+ && (n.tagName === 'UL' || n.tagName === 'OL')))
68
+ .map((n) => (n.nodeType === Node.TEXT_NODE ? n.textContent : n.outerHTML))
69
+ .join('')
70
+ .replace(/\s+/g, ' ')
71
+ .trim();
72
+
73
+ return html;
74
+ };
75
+
76
+ const parseUl = (data, ulElements) => {
77
+ ulElements.forEach((ul) => {
78
+ const lis = ul.querySelectorAll(':scope > li');
79
+ lis.forEach((li) => {
80
+ const name = getLabelFromLi(li);
81
+ if (!name) return;
82
+
83
+ const obj = { name, children: [], parent: data };
84
+ data.children.push(obj);
85
+
86
+ const childUls = li.querySelectorAll(':scope > ul');
87
+ if (childUls.length > 0) {
88
+ parseUl(obj, childUls); // Det her skal vi altid gøre
89
+ }
90
+ });
91
+ });
92
+ };
93
+
94
+ // Start: find root UL’er fra box.data.source (som før)
95
+ const roots = document.querySelectorAll(box.data.source);
96
+ parseUl(box.item, roots);
97
+ }
98
+
99
+ init() {
100
+ for (let i = 0; i < this.boxes.length; i += 1) {
101
+ const box = this.boxes[i];
102
+ AUFlowbox.mergeOptions(box);
103
+ box.id = i;
104
+ box.item = {
105
+ name: box.data.headline,
106
+ children: [],
107
+ parent: null,
108
+ };
109
+ AUFlowbox.parse(box);
110
+ const mountNode = document.querySelector(box.config.container);
111
+ ReactDOM.render(<FlowBoxComponent box={box} lang={this.lang} />, mountNode);
112
+ }
113
+ }
114
+ }
115
+
116
+ window.AUFlowbox = AUFlowbox;
@@ -1,59 +1,59 @@
1
- import React, { createContext, useContext } from 'react';
2
- import { setLocale } from './dates';
3
- import { getPortalByName } from './portals';
4
-
5
- export const LangContext = createContext<string>('da');
6
- export const useLangContext = (): string => {
7
- const lang = useContext(LangContext);
8
- setLocale(lang);
9
- return lang;
10
- };
11
-
12
- export const AuthenticationContext = createContext<boolean>(false);
13
- export const useAuthenticationContext = (): boolean => useContext(AuthenticationContext);
14
-
15
- export const UserContext = createContext<AU.IUserContext | null>(null);
16
- export const useUserContext = (): AU.IUserContext | null => {
17
- const user = useContext(UserContext);
18
- return user;
19
- };
20
-
21
- export const PortalContext = createContext<AU.IPortalContext | null>(null);
22
-
23
- type PortalContextProviderProps = {
24
- name: AU.portalNames;
25
- children: JSX.Element;
26
- }
27
-
28
- export const AUPortal = {
29
- Provider: ({
30
- name,
31
- children,
32
- }: PortalContextProviderProps) => {
33
- const lang = useLangContext();
34
- const portal = getPortalByName(lang || 'da', name);
35
- return (
36
- <PortalContext.Provider value={portal}>
37
- <AuthenticationContext.Provider value={typeof window.authenticated === 'undefined' ? false : window.authenticated}>
38
- {children}
39
- </AuthenticationContext.Provider>
40
- </PortalContext.Provider>
41
- );
42
- },
43
- };
44
-
45
- export const usePortalContext = (): AU.IPortalContext | null => {
46
- const portal = useContext(PortalContext);
47
- return portal;
48
- };
49
-
50
- export const ImpersonationContext = createContext<AU.IImpersonationContext>({
51
- canImpersonate: false,
52
- isImpersonating: false,
53
- impersonatateError: false,
54
- });
55
- // eslint-disable-next-line max-len
56
- export const useImpersonationContext = (): AU.IImpersonationContext => useContext(ImpersonationContext);
57
-
58
- export const AUDialogModalContext = createContext<(() => void) | null>(null);
59
- export const useAUDialogModalContext = (): (() => void) | null => useContext(AUDialogModalContext);
1
+ import React, { createContext, useContext } from 'react';
2
+ import { setLocale } from './dates';
3
+ import { getPortalByName } from './portals';
4
+
5
+ export const LangContext = createContext<string>('da');
6
+ export const useLangContext = (): string => {
7
+ const lang = useContext(LangContext);
8
+ setLocale(lang);
9
+ return lang;
10
+ };
11
+
12
+ export const AuthenticationContext = createContext<boolean>(false);
13
+ export const useAuthenticationContext = (): boolean => useContext(AuthenticationContext);
14
+
15
+ export const UserContext = createContext<AU.IUserContext | null>(null);
16
+ export const useUserContext = (): AU.IUserContext | null => {
17
+ const user = useContext(UserContext);
18
+ return user;
19
+ };
20
+
21
+ export const PortalContext = createContext<AU.IPortalContext | null>(null);
22
+
23
+ type PortalContextProviderProps = {
24
+ name: AU.portalNames;
25
+ children: JSX.Element;
26
+ }
27
+
28
+ export const AUPortal = {
29
+ Provider: ({
30
+ name,
31
+ children,
32
+ }: PortalContextProviderProps) => {
33
+ const lang = useLangContext();
34
+ const portal = getPortalByName(lang || 'da', name);
35
+ return (
36
+ <PortalContext.Provider value={portal}>
37
+ <AuthenticationContext.Provider value={typeof window.authenticated === 'undefined' ? false : window.authenticated}>
38
+ {children}
39
+ </AuthenticationContext.Provider>
40
+ </PortalContext.Provider>
41
+ );
42
+ },
43
+ };
44
+
45
+ export const usePortalContext = (): AU.IPortalContext | null => {
46
+ const portal = useContext(PortalContext);
47
+ return portal;
48
+ };
49
+
50
+ export const ImpersonationContext = createContext<AU.IImpersonationContext>({
51
+ canImpersonate: false,
52
+ isImpersonating: false,
53
+ impersonatateError: false,
54
+ });
55
+ // eslint-disable-next-line max-len
56
+ export const useImpersonationContext = (): AU.IImpersonationContext => useContext(ImpersonationContext);
57
+
58
+ export const AUDialogModalContext = createContext<(() => void) | null>(null);
59
+ export const useAUDialogModalContext = (): (() => void) | null => useContext(AUDialogModalContext);
package/src/lib/dates.ts CHANGED
@@ -1,52 +1,52 @@
1
- import dayjs from 'dayjs';
2
- import 'dayjs/locale/da';
3
- import isoWeek from 'dayjs/plugin/isoWeek';
4
- import weekday from 'dayjs/plugin/weekday';
5
- import advancedFormat from 'dayjs/plugin/advancedFormat';
6
- import localizedFormat from 'dayjs/plugin/localizedFormat';
7
- import updateLocale from 'dayjs/plugin/updateLocale';
8
-
9
- dayjs.extend(isoWeek);
10
- dayjs.extend(weekday);
11
- dayjs.extend(advancedFormat);
12
- dayjs.extend(localizedFormat);
13
- dayjs.extend(updateLocale);
14
-
15
- dayjs.updateLocale('da', {
16
- weekdaysShort: 'søn_man_tir_ons_tor_fre_lør'.split('_'),
17
- monthsShort: 'jan_feb_mar_apr_maj_jun_jul_aug_sep_okt_nov_dec'.split('_'),
18
- });
19
-
20
- export const formatTime = (date: Date, format = 'HH:mm'): string => dayjs(date).format(format);
21
- export const getLocale = (): string => dayjs.locale();
22
- export const setLocale = (locale: string): string => dayjs.locale(locale);
23
- export const getThisYear = (): number => dayjs().year();
24
- export const getYearToString = (date: Date): string => formatTime(date, 'YYYY');
25
- export const getNumberOfWeeksInYear = (year: number): number => dayjs(`${year}-12-31`).isoWeek();
26
- export const skipWeeks = (date: Date, multiplier: number): Date => dayjs(date).clone().add(multiplier * 7, 'days').toDate();
27
- export const getWeek = (date: Date): number => dayjs(date).isoWeek();
28
- // eslint-disable-next-line max-len
29
- export const getDateByWeekday = (date: Date, index: number, locale = 'da'): Date => {
30
- const currentLocale = getLocale();
31
- setLocale(locale);
32
- const newDate = dayjs(date).weekday(index).toDate();
33
- if (currentLocale !== locale) {
34
- setLocale(currentLocale);
35
- }
36
- return newDate;
37
- };
38
- const dateIsSameMonthAsCurrent = (date: Date): boolean => formatTime(new Date(), 'M') === formatTime(date, 'M');
39
- export const getLongDate = (date: Date): string => formatTime(date, 'dddd, Do MMMM YYYY');
40
- export const getShortDate = (date: Date): string => formatTime(date, `ddd D${(dateIsSameMonthAsCurrent(date) ? '' : `${getLocale() === 'da' ? '.' : ''} MMM`)}`);
41
- export const isToday = (date: Date): boolean => dayjs(date).isSame(dayjs());
42
- export const multipleDaysFormatTime = (date: Date, index: number, format = 'ddd HH:mm', firstLetterToUpper = true): string => {
43
- if (index > 0) {
44
- const formatted = formatTime(date, format);
45
- if (firstLetterToUpper) {
46
- return formatted.charAt(0).toUpperCase() + formatted.slice(1);
47
- }
48
- return formatted;
49
- }
50
- return formatTime(date);
51
- };
52
- export const formatDayOfWeek = (date: Date): string => formatTime(date, 'dddd').charAt(0).toUpperCase() + formatTime(date, 'dddd').slice(1);
1
+ import dayjs from 'dayjs';
2
+ import 'dayjs/locale/da';
3
+ import isoWeek from 'dayjs/plugin/isoWeek';
4
+ import weekday from 'dayjs/plugin/weekday';
5
+ import advancedFormat from 'dayjs/plugin/advancedFormat';
6
+ import localizedFormat from 'dayjs/plugin/localizedFormat';
7
+ import updateLocale from 'dayjs/plugin/updateLocale';
8
+
9
+ dayjs.extend(isoWeek);
10
+ dayjs.extend(weekday);
11
+ dayjs.extend(advancedFormat);
12
+ dayjs.extend(localizedFormat);
13
+ dayjs.extend(updateLocale);
14
+
15
+ dayjs.updateLocale('da', {
16
+ weekdaysShort: 'søn_man_tir_ons_tor_fre_lør'.split('_'),
17
+ monthsShort: 'jan_feb_mar_apr_maj_jun_jul_aug_sep_okt_nov_dec'.split('_'),
18
+ });
19
+
20
+ export const formatTime = (date: Date, format = 'HH:mm'): string => dayjs(date).format(format);
21
+ export const getLocale = (): string => dayjs.locale();
22
+ export const setLocale = (locale: string): string => dayjs.locale(locale);
23
+ export const getThisYear = (): number => dayjs().year();
24
+ export const getYearToString = (date: Date): string => formatTime(date, 'YYYY');
25
+ export const getNumberOfWeeksInYear = (year: number): number => dayjs(`${year}-12-31`).isoWeek();
26
+ export const skipWeeks = (date: Date, multiplier: number): Date => dayjs(date).clone().add(multiplier * 7, 'days').toDate();
27
+ export const getWeek = (date: Date): number => dayjs(date).isoWeek();
28
+ // eslint-disable-next-line max-len
29
+ export const getDateByWeekday = (date: Date, index: number, locale = 'da'): Date => {
30
+ const currentLocale = getLocale();
31
+ setLocale(locale);
32
+ const newDate = dayjs(date).weekday(index).toDate();
33
+ if (currentLocale !== locale) {
34
+ setLocale(currentLocale);
35
+ }
36
+ return newDate;
37
+ };
38
+ const dateIsSameMonthAsCurrent = (date: Date): boolean => formatTime(new Date(), 'M') === formatTime(date, 'M');
39
+ export const getLongDate = (date: Date): string => formatTime(date, 'dddd, Do MMMM YYYY');
40
+ export const getShortDate = (date: Date): string => formatTime(date, `ddd D${(dateIsSameMonthAsCurrent(date) ? '' : `${getLocale() === 'da' ? '.' : ''} MMM`)}`);
41
+ export const isToday = (date: Date): boolean => dayjs(date).isSame(dayjs());
42
+ export const multipleDaysFormatTime = (date: Date, index: number, format = 'ddd HH:mm', firstLetterToUpper = true): string => {
43
+ if (index > 0) {
44
+ const formatted = formatTime(date, format);
45
+ if (firstLetterToUpper) {
46
+ return formatted.charAt(0).toUpperCase() + formatted.slice(1);
47
+ }
48
+ return formatted;
49
+ }
50
+ return formatTime(date);
51
+ };
52
+ export const formatDayOfWeek = (date: Date): string => formatTime(date, 'dddd').charAt(0).toUpperCase() + formatTime(date, 'dddd').slice(1);