@aarhus-university/au-lib-react-components 11.4.1 → 11.5.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": "11.
|
|
4
|
+
"version": "11.5.0",
|
|
5
5
|
"description": "Library for shared React components for various applications on au.dk",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "jest",
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"webpack-cli": "^4.9.2"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@aarhus-university/au-designsystem-delphinus": "0.35.
|
|
75
|
+
"@aarhus-university/au-designsystem-delphinus": "0.35.2",
|
|
76
76
|
"@aarhus-university/au-designsystem-delphinus-dev": "0.2.0",
|
|
77
|
-
"@aarhus-university/types": "^0.17.
|
|
77
|
+
"@aarhus-university/types": "^0.17.14",
|
|
78
78
|
"@reduxjs/toolkit": "^1.8.3",
|
|
79
79
|
"@types/google.analytics": "^0.0.42",
|
|
80
80
|
"@types/history": "^5.0.0",
|
|
@@ -1,69 +1,101 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
/* eslint-env browser */
|
|
3
|
-
import React, { FC } from 'react';
|
|
3
|
+
import React, { FC, useState } from 'react';
|
|
4
4
|
import ReactDOM from 'react-dom';
|
|
5
|
+
import AUButtonComponent from './AUButtonComponent';
|
|
5
6
|
|
|
6
|
-
const AUAlertComponent: FC<
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
const AUAlertComponent: FC<AUButtonToastComponentUnionProps> = ({
|
|
8
|
+
confirm,
|
|
9
|
+
message: pMessage,
|
|
10
|
+
buttonText,
|
|
11
|
+
cancelButtonText,
|
|
12
|
+
label,
|
|
13
|
+
disabled,
|
|
14
|
+
size,
|
|
15
|
+
type,
|
|
16
|
+
icon,
|
|
17
|
+
iconPosition,
|
|
18
|
+
hideLabel,
|
|
19
|
+
mode,
|
|
20
|
+
btnRef,
|
|
21
|
+
classNames,
|
|
22
|
+
ariaExpanded,
|
|
23
|
+
dataGtm,
|
|
24
|
+
asSubmit,
|
|
25
|
+
onClick,
|
|
26
|
+
}: AUButtonToastComponentUnionProps) => {
|
|
27
|
+
const [alert, setAlert] = useState<boolean>(false);
|
|
28
|
+
const { type: mType, message, header } = pMessage;
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
{
|
|
30
|
-
ReactDOM.createPortal(
|
|
31
|
-
<div key="0" className="theme--normal toast-notification toast-notification--attention toast-notification--persistent">
|
|
32
|
-
<div className="toast-notification__content">
|
|
33
|
-
<p dangerouslySetInnerHTML={{ __html: message }} />
|
|
34
|
-
</div>
|
|
35
|
-
{renderButtons}
|
|
36
|
-
</div>,
|
|
37
|
-
document.querySelector('body')!,
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
{children}
|
|
41
|
-
</>
|
|
42
|
-
);
|
|
30
|
+
let className = 'toast-notification toast-notification--persistent';
|
|
31
|
+
if (mType !== 'default') {
|
|
32
|
+
className = `${className} toast-notification--${mType}`;
|
|
43
33
|
}
|
|
44
34
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
{
|
|
38
|
+
alert && (
|
|
39
|
+
<>
|
|
40
|
+
{
|
|
41
|
+
ReactDOM.createPortal(
|
|
42
|
+
<div className={className}>
|
|
43
|
+
<div className="toast-notification__content">
|
|
44
|
+
{
|
|
45
|
+
header && (
|
|
46
|
+
<h2 className="toast-notification__header">
|
|
47
|
+
{header}
|
|
48
|
+
</h2>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
<p dangerouslySetInnerHTML={{ __html: message }} />
|
|
52
|
+
</div>
|
|
53
|
+
<AUButtonComponent
|
|
54
|
+
label={buttonText as string}
|
|
55
|
+
onClick={(event) => {
|
|
56
|
+
if (typeof onClick === 'function') {
|
|
57
|
+
onClick(event, btnRef);
|
|
58
|
+
}
|
|
59
|
+
setAlert(false);
|
|
60
|
+
}}
|
|
61
|
+
/>
|
|
62
|
+
{
|
|
63
|
+
confirm && (
|
|
64
|
+
<AUButtonComponent
|
|
65
|
+
label={cancelButtonText as string}
|
|
66
|
+
onClick={() => {
|
|
67
|
+
setAlert(false);
|
|
68
|
+
}}
|
|
69
|
+
/>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
</div>,
|
|
73
|
+
document.querySelector('body')!,
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
</>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
<AUButtonComponent
|
|
80
|
+
label={label}
|
|
81
|
+
disabled={disabled}
|
|
82
|
+
size={size}
|
|
83
|
+
type={type}
|
|
84
|
+
icon={icon}
|
|
85
|
+
iconPosition={iconPosition}
|
|
86
|
+
hideLabel={hideLabel}
|
|
87
|
+
mode={mode}
|
|
88
|
+
btnRef={btnRef}
|
|
89
|
+
classNames={classNames}
|
|
90
|
+
ariaExpanded={ariaExpanded}
|
|
91
|
+
dataGtm={dataGtm}
|
|
92
|
+
asSubmit={asSubmit}
|
|
93
|
+
onClick={() => {
|
|
94
|
+
setAlert(true);
|
|
95
|
+
}}
|
|
96
|
+
/>
|
|
97
|
+
</>
|
|
98
|
+
);
|
|
67
99
|
};
|
|
68
100
|
|
|
69
101
|
AUAlertComponent.displayName = 'AUAlertComponent';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
|
3
|
+
import AUAlertComponent from '../src/components/AUAlertComponent';
|
|
4
|
+
import { ThemeWrapper } from './lib/helpers';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Delphinus/Alert and Confirm',
|
|
8
|
+
component: AUAlertComponent,
|
|
9
|
+
argTypes: {
|
|
10
|
+
children: {
|
|
11
|
+
table: {
|
|
12
|
+
disable: true,
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
buttonChild: {
|
|
16
|
+
table: {
|
|
17
|
+
disable: true,
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
decorators: [
|
|
22
|
+
(Story, context) => (
|
|
23
|
+
<ThemeWrapper theme={context.globals.theme}>
|
|
24
|
+
{Story()}
|
|
25
|
+
</ThemeWrapper>
|
|
26
|
+
)
|
|
27
|
+
],
|
|
28
|
+
} as ComponentMeta<typeof AUAlertComponent>;
|
|
29
|
+
|
|
30
|
+
const Template: ComponentStory<typeof AUAlertComponent> = (args) => <AUAlertComponent {...args} />;
|
|
31
|
+
|
|
32
|
+
export const Alert = Template.bind({});
|
|
33
|
+
|
|
34
|
+
Alert.args = {
|
|
35
|
+
label: 'Slet',
|
|
36
|
+
mode: 'ireversable-action',
|
|
37
|
+
message: {
|
|
38
|
+
message: 'Den valgte fil vil blive slettet.',
|
|
39
|
+
type: 'attention',
|
|
40
|
+
header: 'Advarsel!',
|
|
41
|
+
},
|
|
42
|
+
buttonText: 'Ok, forstået',
|
|
43
|
+
onClick: () => console.log('Clicked'),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const Confirm = Template.bind({});
|
|
47
|
+
|
|
48
|
+
Confirm.args = {
|
|
49
|
+
confirm: true,
|
|
50
|
+
label: 'Slet',
|
|
51
|
+
mode: 'ireversable-action',
|
|
52
|
+
message: {
|
|
53
|
+
message: 'Er du sikker på, at du vil slette den valgte fil?',
|
|
54
|
+
type: 'warning',
|
|
55
|
+
header: 'Advarsel!',
|
|
56
|
+
},
|
|
57
|
+
buttonText: 'Ja',
|
|
58
|
+
cancelButtonText: 'Annuller',
|
|
59
|
+
onClick: () => console.log('Clicked'),
|
|
60
|
+
};
|