@aarhus-university/au-lib-react-components 12.5.1 → 12.6.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.
Files changed (115) hide show
  1. package/.claude/settings.local.json +12 -0
  2. package/.eslintrc.js +35 -35
  3. package/.storybook/main.js +34 -34
  4. package/.storybook/preview.js +17 -17
  5. package/.vscode/settings.json +22 -0
  6. package/README.md +19 -19
  7. package/__tests__/jest/AUButtonComponent.test.tsx +165 -165
  8. package/__tests__/jest/AUDynamicContentComponent.test.tsx +386 -0
  9. package/__tests__/jest/AUErrorComponent.test.tsx +142 -142
  10. package/__tests__/jest/AUModalComponent.test.tsx +186 -186
  11. package/__tests__/jest/AUNotificationComponent.test.tsx +115 -115
  12. package/__tests__/jest/AUSpinnerComponent.test.tsx +57 -57
  13. package/__tests__/jest/AUToolbarComponent.test.tsx +46 -46
  14. package/__tests__/jest/context.test.ts +25 -25
  15. package/__tests__/jest/helpers.test.ts +15 -15
  16. package/__tests__/jest/setupTests.ts +2 -2
  17. package/babel.config.js +8 -8
  18. package/build/umd/all.css +3 -2
  19. package/build/umd/all.css.map +1 -7
  20. package/build/umd/all.js +2 -45
  21. package/build/umd/all.js.map +1 -7
  22. package/build/umd/alphabox.js +2 -45
  23. package/build/umd/alphabox.js.map +1 -7
  24. package/build/umd/databox.js +2 -45
  25. package/build/umd/databox.js.map +1 -7
  26. package/build/umd/diagramme.js +2 -44
  27. package/build/umd/diagramme.js.map +1 -7
  28. package/build/umd/flowbox.js +2 -44
  29. package/build/umd/flowbox.js.map +1 -7
  30. package/build/umd/universe.js +1 -1
  31. package/build-storybook.log +386 -386
  32. package/esbuild.mjs +22 -22
  33. package/package.json +107 -105
  34. package/src/components/AUAlertComponent.tsx +128 -128
  35. package/src/components/AUAutoSuggestComponent.js +148 -148
  36. package/src/components/AUButtonComponent.tsx +99 -97
  37. package/src/components/AUCalendarComponent.tsx +497 -497
  38. package/src/components/AUCharacterCountComponent.tsx +56 -56
  39. package/src/components/AUComboBoxComponent.tsx +195 -195
  40. package/src/components/AUContentToggleComponent.tsx +50 -50
  41. package/src/components/AUDatepickerComponent.tsx +124 -124
  42. package/src/components/AUDialogModalComponent.tsx +124 -124
  43. package/src/components/AUDynamicContentComponent.tsx +137 -0
  44. package/src/components/AUEditorComponent.tsx +126 -117
  45. package/src/components/AUErrorComponent.tsx +73 -73
  46. package/src/components/AUMobilePrefixComponent.tsx +20 -20
  47. package/src/components/AUModalComponent.tsx +72 -72
  48. package/src/components/AUNotificationComponent.tsx +44 -44
  49. package/src/components/AUReceiptComponent.tsx +34 -34
  50. package/src/components/AUSpinnerComponent.tsx +40 -40
  51. package/src/components/AUStepComponent.tsx +75 -75
  52. package/src/components/AUSubNavComponent.tsx +57 -57
  53. package/src/components/AUSubmitButtonContainerComponent.tsx +38 -38
  54. package/src/components/AUTabbedContentComponent.tsx +154 -154
  55. package/src/components/AUTableComponent.tsx +29 -29
  56. package/src/components/AUToastComponent.tsx +104 -104
  57. package/src/components/AUToolbarComponent.tsx +108 -108
  58. package/src/components/AUTruncatorComponent.tsx +141 -141
  59. package/src/components/wrapping/AUEmbedComponent.js +47 -47
  60. package/src/layout-2016/components/alphabox/AlphaBoxComponent.js +142 -143
  61. package/src/layout-2016/components/alphabox/AlphaBoxContentComponent.js +136 -136
  62. package/src/layout-2016/components/common/AUCollapsibleComponent.js +152 -152
  63. package/src/layout-2016/components/common/AUSpinnerComponent.js +103 -103
  64. package/src/layout-2016/components/databox/DataBoxAlphabetComponent.js +144 -144
  65. package/src/layout-2016/components/databox/DataBoxAssociationComponent.js +122 -122
  66. package/src/layout-2016/components/databox/DataBoxButtonComponent.js +157 -157
  67. package/src/layout-2016/components/databox/DataBoxComponent.js +297 -297
  68. package/src/layout-2016/components/databox/DataBoxGroupingComponent.js +64 -64
  69. package/src/layout-2016/components/databox/DataBoxSearchResultComponent.js +36 -36
  70. package/src/layout-2016/components/databox/DataBoxStackedAssociationComponent.js +54 -54
  71. package/src/layout-2016/components/databox/DataBoxSuggestionComponent.js +39 -39
  72. package/src/layout-2016/components/diagramme/AUDiagrammeComponent.js +309 -309
  73. package/src/layout-2016/components/flowbox/FlowBoxComponent.js +126 -126
  74. package/src/layout-2016/components/flowbox/FlowBoxPhoneComponent.js +104 -104
  75. package/src/layout-2016/lib/all.js +3 -3
  76. package/src/layout-2016/lib/au-alphabox.js +99 -100
  77. package/src/layout-2016/lib/au-databox.js +399 -400
  78. package/src/layout-2016/lib/au-diagramme.js +85 -85
  79. package/src/layout-2016/lib/au-flowbox.js +119 -93
  80. package/src/lib/context.tsx +59 -59
  81. package/src/lib/dates.ts +52 -52
  82. package/src/lib/helpers.ts +208 -208
  83. package/src/lib/hooks.ts +157 -157
  84. package/src/lib/i18n.ts +600 -600
  85. package/src/lib/portals.tsx +150 -150
  86. package/src/lib/tinymce.ts +84 -84
  87. package/src/lib/wrapping.ts +21 -21
  88. package/src/styles/_settings.scss +10 -10
  89. package/src/styles/alphabox.scss +222 -222
  90. package/src/styles/app.scss +7 -7
  91. package/src/styles/autosuggest.scss +57 -57
  92. package/src/styles/databox.scss +563 -563
  93. package/src/styles/diagramme.scss +119 -119
  94. package/src/styles/flowbox.scss +72 -72
  95. package/src/styles/maps.scss +395 -395
  96. package/stories/AUAlertComponent.stories.tsx +133 -133
  97. package/stories/AUAutoSuggestComponent.stories.tsx +95 -95
  98. package/stories/AUButtonComponent.stories.tsx +139 -139
  99. package/stories/AUCharacterCountComponent.stories.tsx +121 -121
  100. package/stories/AUComboBoxComponent.stories.tsx +101 -101
  101. package/stories/AUContentToggleComponent.stories.tsx +87 -87
  102. package/stories/AUDialogModalComponent.stories.tsx +75 -75
  103. package/stories/AUDynamicContentComponent.stories.tsx +119 -0
  104. package/stories/AUEditorComponent.stories.tsx +66 -66
  105. package/stories/AUErrorComponent.stories.tsx +132 -132
  106. package/stories/AUModalComponent.stories.tsx +160 -160
  107. package/stories/AUNotificationComponent.stories.tsx +151 -151
  108. package/stories/AUSpinnerComponent.stories.tsx +44 -44
  109. package/stories/AUStepComponent.stories.tsx +91 -91
  110. package/stories/AUToolbarComponent.stories.tsx +389 -389
  111. package/stories/AUTruncatorComponent.stories.tsx +123 -123
  112. package/stories/lib/helpers.tsx +146 -146
  113. package/tsconfig.json +46 -46
  114. package/webpack.config.js +88 -88
  115. package/src/lib/tracking.ts +0 -69
@@ -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,93 +1,119 @@
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
- tracking: '/virtual/flowbox/',
13
- render: 'ul',
14
- },
15
- data: {
16
- mode: 'list',
17
- source: '.au_flowbox_list',
18
- headline: 'Overskrift',
19
- prepend: '',
20
- },
21
- };
22
-
23
- class AUFlowbox {
24
- constructor(lang, boxes) {
25
- this.boxes = boxes;
26
- this.lang = lang;
27
- }
28
-
29
- static mergeOptions(_box) {
30
- const box = _box;
31
- if (!box.hasOwnProperty('config')) {
32
- box.config = {};
33
- }
34
-
35
- for (const conf in defaultOptions.config) {
36
- if (!box.config.hasOwnProperty(conf)) {
37
- box.config[conf] = defaultOptions.config[conf];
38
- }
39
- }
40
-
41
- if (!box.hasOwnProperty('data')) {
42
- box.data = {};
43
- }
44
-
45
- for (const data in defaultOptions.data) {
46
- if (!box.data.hasOwnProperty(data)) {
47
- box.data[data] = defaultOptions.data[data];
48
- }
49
- }
50
- }
51
-
52
- static parse(box) {
53
- const parseList = (data, elements, selector) => {
54
- elements.forEach((e) => {
55
- const subElements = e.querySelectorAll(selector);
56
- subElements.forEach((s) => {
57
- const obj = {
58
- name: s.innerHTML,
59
- children: [],
60
- parent: data,
61
- };
62
-
63
- data.children.push(obj);
64
- const parent = s.parentElement;
65
- const children = parent.querySelectorAll(':scope > ul');
66
- if (children.length > 0) {
67
- parseList(obj, children, ':scope > li > p'); // Det her skal vi altid gøre
68
- }
69
- });
70
- });
71
- };
72
-
73
- parseList(box.item, document.querySelectorAll(box.data.source), window.flowboxScopeSelector || ':scope > li > p'); // Her kan selectoren være en anden, hvis der fx er global content i spil, så der kommer en <div> ind...
74
- }
75
-
76
- init() {
77
- for (let i = 0; i < this.boxes.length; i += 1) {
78
- const box = this.boxes[i];
79
- AUFlowbox.mergeOptions(box);
80
- box.id = i;
81
- box.item = {
82
- name: box.data.headline,
83
- children: [],
84
- parent: null,
85
- };
86
- AUFlowbox.parse(box);
87
- const mountNode = document.querySelector(box.config.container);
88
- ReactDOM.render(<FlowBoxComponent box={box} lang={this.lang} />, mountNode);
89
- }
90
- }
91
- }
92
-
93
- 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: 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,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);