@entur/alert 0.17.11 → 0.17.13-beta.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/dist/alert.cjs.js +482 -0
- package/dist/alert.cjs.js.map +1 -0
- package/dist/alert.esm.js +430 -347
- package/dist/alert.esm.js.map +1 -1
- package/dist/index.d.ts +174 -7
- package/dist/styles.css +487 -501
- package/package.json +36 -18
- package/dist/BannerAlertBox.d.ts +0 -27
- package/dist/BaseAlertBox.d.ts +0 -34
- package/dist/CopyableText.d.ts +0 -20
- package/dist/ExpandableAlertBox.d.ts +0 -33
- package/dist/SmallAlertBox.d.ts +0 -29
- package/dist/ToastAlertBox.d.ts +0 -23
- package/dist/ToastProvider.d.ts +0 -30
- package/dist/alert.cjs.development.js +0 -410
- package/dist/alert.cjs.development.js.map +0 -1
- package/dist/alert.cjs.production.min.js +0 -2
- package/dist/alert.cjs.production.min.js.map +0 -1
- package/dist/index.js +0 -8
package/dist/alert.esm.js
CHANGED
|
@@ -1,399 +1,482 @@
|
|
|
1
|
-
import { warnAboutMissingStyles } from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { IconButton } from
|
|
6
|
-
import { Tooltip } from
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function _extends() {
|
|
12
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
13
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
14
|
-
var t = arguments[e];
|
|
15
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
16
|
-
}
|
|
17
|
-
return n;
|
|
18
|
-
}, _extends.apply(null, arguments);
|
|
1
|
+
import { warnAboutMissingStyles } from "@entur/utils";
|
|
2
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { ValidationErrorIcon, ValidationInfoIcon, ValidationExclamationIcon, ValidationSuccessIcon, CloseIcon, CopyIcon } from "@entur/icons";
|
|
5
|
+
import { IconButton } from "@entur/button";
|
|
6
|
+
import { Tooltip } from "@entur/tooltip";
|
|
7
|
+
import { PreformattedText } from "@entur/typography";
|
|
8
|
+
import { BaseExpand, ExpandArrow } from "@entur/expand";
|
|
9
|
+
function getDefaultExportFromCjs(x) {
|
|
10
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
19
11
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
var classnames = { exports: {} };
|
|
13
|
+
/*!
|
|
14
|
+
Copyright (c) 2018 Jed Watson.
|
|
15
|
+
Licensed under the MIT License (MIT), see
|
|
16
|
+
http://jedwatson.github.io/classnames
|
|
17
|
+
*/
|
|
18
|
+
var hasRequiredClassnames;
|
|
19
|
+
function requireClassnames() {
|
|
20
|
+
if (hasRequiredClassnames) return classnames.exports;
|
|
21
|
+
hasRequiredClassnames = 1;
|
|
22
|
+
(function(module) {
|
|
23
|
+
(function() {
|
|
24
|
+
var hasOwn = {}.hasOwnProperty;
|
|
25
|
+
function classNames2() {
|
|
26
|
+
var classes = "";
|
|
27
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
28
|
+
var arg = arguments[i];
|
|
29
|
+
if (arg) {
|
|
30
|
+
classes = appendClass(classes, parseValue(arg));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return classes;
|
|
34
|
+
}
|
|
35
|
+
function parseValue(arg) {
|
|
36
|
+
if (typeof arg === "string" || typeof arg === "number") {
|
|
37
|
+
return arg;
|
|
38
|
+
}
|
|
39
|
+
if (typeof arg !== "object") {
|
|
40
|
+
return "";
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(arg)) {
|
|
43
|
+
return classNames2.apply(null, arg);
|
|
44
|
+
}
|
|
45
|
+
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
|
|
46
|
+
return arg.toString();
|
|
47
|
+
}
|
|
48
|
+
var classes = "";
|
|
49
|
+
for (var key in arg) {
|
|
50
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
51
|
+
classes = appendClass(classes, key);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return classes;
|
|
55
|
+
}
|
|
56
|
+
function appendClass(value, newClass) {
|
|
57
|
+
if (!newClass) {
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
if (value) {
|
|
61
|
+
return value + " " + newClass;
|
|
62
|
+
}
|
|
63
|
+
return value + newClass;
|
|
64
|
+
}
|
|
65
|
+
if (module.exports) {
|
|
66
|
+
classNames2.default = classNames2;
|
|
67
|
+
module.exports = classNames2;
|
|
68
|
+
} else {
|
|
69
|
+
window.classNames = classNames2;
|
|
70
|
+
}
|
|
71
|
+
})();
|
|
72
|
+
})(classnames);
|
|
73
|
+
return classnames.exports;
|
|
28
74
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
75
|
+
var classnamesExports = requireClassnames();
|
|
76
|
+
const classNames = /* @__PURE__ */ getDefaultExportFromCjs(classnamesExports);
|
|
77
|
+
const iconsMap = {
|
|
32
78
|
success: {
|
|
33
79
|
icon: ValidationSuccessIcon,
|
|
34
|
-
description:
|
|
35
|
-
},
|
|
36
|
-
information: {
|
|
37
|
-
icon: ValidationInfoIcon,
|
|
38
|
-
description: 'Infomelding'
|
|
80
|
+
description: "Suksessmelding"
|
|
39
81
|
},
|
|
82
|
+
information: { icon: ValidationInfoIcon, description: "Infomelding" },
|
|
40
83
|
warning: {
|
|
41
84
|
icon: ValidationExclamationIcon,
|
|
42
|
-
description:
|
|
43
|
-
},
|
|
44
|
-
negative: {
|
|
45
|
-
icon: ValidationErrorIcon,
|
|
46
|
-
description: 'Feilmelding'
|
|
85
|
+
description: "Varselmelding"
|
|
47
86
|
},
|
|
87
|
+
negative: { icon: ValidationErrorIcon, description: "Feilmelding" },
|
|
48
88
|
//deprecated
|
|
49
|
-
info: {
|
|
50
|
-
|
|
51
|
-
description: 'Infomelding'
|
|
52
|
-
},
|
|
53
|
-
error: {
|
|
54
|
-
icon: ValidationErrorIcon,
|
|
55
|
-
description: 'Feilmelding'
|
|
56
|
-
}
|
|
89
|
+
info: { icon: ValidationInfoIcon, description: "Infomelding" },
|
|
90
|
+
error: { icon: ValidationErrorIcon, description: "Feilmelding" }
|
|
57
91
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
title = _ref.title,
|
|
72
|
-
toastIsBeingRemoved = _ref.toastIsBeingRemoved,
|
|
73
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
74
|
-
var _React$useState = React.useState(false),
|
|
75
|
-
isClosed = _React$useState[0],
|
|
76
|
-
setClosed = _React$useState[1];
|
|
92
|
+
const BaseAlertBox = ({
|
|
93
|
+
children,
|
|
94
|
+
className,
|
|
95
|
+
closable = false,
|
|
96
|
+
closeButtonLabel = "Lukk",
|
|
97
|
+
variant,
|
|
98
|
+
onClose = () => ({}),
|
|
99
|
+
size,
|
|
100
|
+
title,
|
|
101
|
+
toastIsBeingRemoved,
|
|
102
|
+
...rest
|
|
103
|
+
}) => {
|
|
104
|
+
const [isClosed, setClosed] = React.useState(false);
|
|
77
105
|
if (isClosed) {
|
|
78
106
|
return null;
|
|
79
107
|
}
|
|
80
|
-
|
|
108
|
+
const handleClose = () => {
|
|
81
109
|
setClosed(true);
|
|
82
110
|
onClose();
|
|
83
111
|
};
|
|
84
|
-
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
112
|
+
const Icon = iconsMap[variant].icon;
|
|
113
|
+
return /* @__PURE__ */ jsxs(
|
|
114
|
+
"div",
|
|
115
|
+
{
|
|
116
|
+
className: classNames(
|
|
117
|
+
"eds-alert-box",
|
|
118
|
+
`eds-alert-box--${size}`,
|
|
119
|
+
`eds-alert-box--${variant}`,
|
|
120
|
+
{
|
|
121
|
+
"eds-alert-box--toast--exit-animation": toastIsBeingRemoved,
|
|
122
|
+
"eds-alert-box--no-title": !title
|
|
123
|
+
},
|
|
124
|
+
className
|
|
125
|
+
),
|
|
126
|
+
...rest,
|
|
127
|
+
children: [
|
|
128
|
+
/* @__PURE__ */ jsx(
|
|
129
|
+
Icon,
|
|
130
|
+
{
|
|
131
|
+
role: "img",
|
|
132
|
+
className: "eds-alert-box__icon",
|
|
133
|
+
"aria-label": iconsMap[variant].description
|
|
134
|
+
}
|
|
135
|
+
),
|
|
136
|
+
/* @__PURE__ */ jsxs(
|
|
137
|
+
"div",
|
|
138
|
+
{
|
|
139
|
+
className: classNames("eds-alert-box__content", {
|
|
140
|
+
"eds-alert-box__content--no-children": !children
|
|
141
|
+
}),
|
|
142
|
+
children: [
|
|
143
|
+
title && /* @__PURE__ */ jsx("div", { className: "eds-alert-box__title", children: title }),
|
|
144
|
+
children && children
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
),
|
|
148
|
+
closable && /* @__PURE__ */ jsx(
|
|
149
|
+
Tooltip,
|
|
150
|
+
{
|
|
151
|
+
className: "eds-alert-box__tooltip",
|
|
152
|
+
"aria-hidden": true,
|
|
153
|
+
placement: "bottom",
|
|
154
|
+
content: "Lukk",
|
|
155
|
+
children: /* @__PURE__ */ jsx(
|
|
156
|
+
IconButton,
|
|
157
|
+
{
|
|
158
|
+
className: "eds-alert-box__close-button",
|
|
159
|
+
"aria-label": closeButtonLabel,
|
|
160
|
+
onClick: handleClose,
|
|
161
|
+
type: "button",
|
|
162
|
+
children: /* @__PURE__ */ jsx(CloseIcon, {})
|
|
163
|
+
}
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
);
|
|
124
170
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
171
|
+
const BannerAlertBox = (props) => /* @__PURE__ */ jsx(BaseAlertBox, { ...props, size: "banner" });
|
|
172
|
+
const ToastAlertBox = (props) => /* @__PURE__ */ jsx(BaseAlertBox, { ...props, size: "toast", role: "status" });
|
|
173
|
+
const SmallAlertBox = ({
|
|
174
|
+
className,
|
|
175
|
+
width,
|
|
176
|
+
onClose,
|
|
177
|
+
closable = false,
|
|
178
|
+
closeButtonLabel,
|
|
179
|
+
...rest
|
|
180
|
+
}) => /* @__PURE__ */ jsx(
|
|
181
|
+
BaseAlertBox,
|
|
182
|
+
{
|
|
136
183
|
className: classNames(className, {
|
|
137
|
-
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
onClose
|
|
141
|
-
closable
|
|
142
|
-
closeButtonLabel
|
|
184
|
+
"eds-alert-box--fit-content": width === "fit-content"
|
|
185
|
+
}),
|
|
186
|
+
...rest,
|
|
187
|
+
onClose,
|
|
188
|
+
closable,
|
|
189
|
+
closeButtonLabel,
|
|
143
190
|
size: "small"
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
var toastReducer = function toastReducer(prevToasts, action) {
|
|
191
|
+
}
|
|
192
|
+
);
|
|
193
|
+
const EXIT_ANIMATION_TIME = 400;
|
|
194
|
+
const ToastContext = React.createContext(null);
|
|
195
|
+
const toastReducer = (prevToasts, action) => {
|
|
150
196
|
switch (action.type) {
|
|
151
|
-
case
|
|
152
|
-
return [action.payload]
|
|
153
|
-
case
|
|
154
|
-
return prevToasts.map(
|
|
155
|
-
if (toast.id === action.payload)
|
|
156
|
-
isBeingRemoved: true
|
|
157
|
-
});
|
|
197
|
+
case "ADD_TOAST":
|
|
198
|
+
return [action.payload, ...prevToasts];
|
|
199
|
+
case "PLAY_EXIT_ANIMATION":
|
|
200
|
+
return prevToasts.map((toast) => {
|
|
201
|
+
if (toast.id === action.payload)
|
|
202
|
+
return { ...toast, isBeingRemoved: true };
|
|
158
203
|
return toast;
|
|
159
204
|
});
|
|
160
|
-
case
|
|
161
|
-
return prevToasts.filter(
|
|
162
|
-
return toast.id !== action.payload;
|
|
163
|
-
});
|
|
205
|
+
case "REMOVE_TOAST":
|
|
206
|
+
return prevToasts.filter((toast) => toast.id !== action.payload);
|
|
164
207
|
}
|
|
165
208
|
};
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (typeof toast === 'string') {
|
|
171
|
-
return {
|
|
172
|
-
id: id,
|
|
173
|
-
content: toast,
|
|
174
|
-
variant: 'success',
|
|
175
|
-
isBeingRemoved: false
|
|
176
|
-
};
|
|
209
|
+
const createUniqueId = () => Math.random().toString().substring(2);
|
|
210
|
+
const createToast = (toast, id) => {
|
|
211
|
+
if (typeof toast === "string") {
|
|
212
|
+
return { id, content: toast, variant: "success", isBeingRemoved: false };
|
|
177
213
|
} else {
|
|
178
|
-
return
|
|
179
|
-
id: id,
|
|
180
|
-
variant: 'success',
|
|
181
|
-
isBeingRemoved: false
|
|
182
|
-
}, toast);
|
|
214
|
+
return { id, variant: "success", isBeingRemoved: false, ...toast };
|
|
183
215
|
}
|
|
184
216
|
};
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
var _React$useState = React.useState(),
|
|
197
|
-
hoveringId = _React$useState[0],
|
|
198
|
-
setHovering = _React$useState[1];
|
|
199
|
-
var timeoutIdRefs = React.useRef({});
|
|
200
|
-
var removeToast = React.useCallback(function (id) {
|
|
217
|
+
const ToastProvider = ({
|
|
218
|
+
delay = 6e3,
|
|
219
|
+
children,
|
|
220
|
+
position = "bottom-right",
|
|
221
|
+
className,
|
|
222
|
+
style
|
|
223
|
+
}) => {
|
|
224
|
+
const [toasts, dispatch] = React.useReducer(toastReducer, []);
|
|
225
|
+
const [hoveringId, setHovering] = React.useState();
|
|
226
|
+
const timeoutIdRefs = React.useRef({});
|
|
227
|
+
const removeToast = React.useCallback((id) => {
|
|
201
228
|
window.clearTimeout(timeoutIdRefs.current[id]);
|
|
202
|
-
dispatch({
|
|
203
|
-
type: 'REMOVE_TOAST',
|
|
204
|
-
payload: id
|
|
205
|
-
});
|
|
229
|
+
dispatch({ type: "REMOVE_TOAST", payload: id });
|
|
206
230
|
delete timeoutIdRefs.current[id];
|
|
207
231
|
}, []);
|
|
208
|
-
|
|
209
|
-
window.clearTimeout(timeoutIdRefs.current[id +
|
|
210
|
-
dispatch({
|
|
211
|
-
|
|
212
|
-
payload: id
|
|
213
|
-
});
|
|
214
|
-
delete timeoutIdRefs.current[id + 'animation'];
|
|
232
|
+
const playExitAnimation = React.useCallback((id) => {
|
|
233
|
+
window.clearTimeout(timeoutIdRefs.current[id + "animation"]);
|
|
234
|
+
dispatch({ type: "PLAY_EXIT_ANIMATION", payload: id });
|
|
235
|
+
delete timeoutIdRefs.current[id + "animation"];
|
|
215
236
|
}, []);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
237
|
+
const removeToastWithAnimationAfterDelay = React.useCallback(
|
|
238
|
+
(id, delay2) => {
|
|
239
|
+
timeoutIdRefs.current[id + "animation"] = window.setTimeout(
|
|
240
|
+
() => playExitAnimation(id),
|
|
241
|
+
delay2 - EXIT_ANIMATION_TIME
|
|
242
|
+
);
|
|
243
|
+
timeoutIdRefs.current[id] = window.setTimeout(
|
|
244
|
+
() => removeToast(id),
|
|
245
|
+
delay2
|
|
246
|
+
);
|
|
247
|
+
},
|
|
248
|
+
[timeoutIdRefs, playExitAnimation, removeToast]
|
|
249
|
+
);
|
|
250
|
+
const addToast = React.useCallback(
|
|
251
|
+
(toast) => {
|
|
252
|
+
const id = createUniqueId();
|
|
253
|
+
const payload = createToast(toast, id);
|
|
254
|
+
dispatch({ type: "ADD_TOAST", payload });
|
|
255
|
+
removeToastWithAnimationAfterDelay(id, delay);
|
|
256
|
+
},
|
|
257
|
+
[delay, removeToastWithAnimationAfterDelay]
|
|
258
|
+
);
|
|
259
|
+
const handleMouseEnter = (toast) => () => {
|
|
260
|
+
if (toast.isBeingRemoved) return;
|
|
261
|
+
setHovering(toast.id);
|
|
262
|
+
Object.values(timeoutIdRefs.current).forEach((timeoutId) => {
|
|
263
|
+
window.clearTimeout(timeoutId);
|
|
230
264
|
});
|
|
231
|
-
|
|
232
|
-
}, [delay, removeToastWithAnimationAfterDelay]);
|
|
233
|
-
var handleMouseEnter = function handleMouseEnter(toast) {
|
|
234
|
-
return function () {
|
|
235
|
-
if (toast.isBeingRemoved) return;
|
|
236
|
-
setHovering(toast.id);
|
|
237
|
-
Object.values(timeoutIdRefs.current).forEach(function (timeoutId) {
|
|
238
|
-
window.clearTimeout(timeoutId);
|
|
239
|
-
});
|
|
240
|
-
timeoutIdRefs.current = {};
|
|
241
|
-
};
|
|
265
|
+
timeoutIdRefs.current = {};
|
|
242
266
|
};
|
|
243
|
-
|
|
244
|
-
setHovering(
|
|
245
|
-
toasts.forEach(
|
|
267
|
+
const handleMouseLeave = () => {
|
|
268
|
+
setHovering(void 0);
|
|
269
|
+
toasts.forEach((toast) => {
|
|
246
270
|
removeToastWithAnimationAfterDelay(toast.id, delay);
|
|
247
271
|
});
|
|
248
272
|
};
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
handleMouseLeave();
|
|
253
|
-
};
|
|
273
|
+
const handleClose = (toastId) => () => {
|
|
274
|
+
removeToast(toastId);
|
|
275
|
+
handleMouseLeave();
|
|
254
276
|
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
277
|
+
const contextValue = React.useMemo(
|
|
278
|
+
() => ({ toasts, addToast, removeToast }),
|
|
279
|
+
[addToast, removeToast, toasts]
|
|
280
|
+
);
|
|
281
|
+
return /* @__PURE__ */ jsxs(ToastContext.Provider, { value: contextValue, children: [
|
|
282
|
+
toasts.length > 0 && /* @__PURE__ */ jsx(
|
|
283
|
+
"div",
|
|
284
|
+
{
|
|
285
|
+
className: classNames(
|
|
286
|
+
"eds-toast-container",
|
|
287
|
+
`eds-toast-container--${position}`,
|
|
288
|
+
className
|
|
289
|
+
),
|
|
290
|
+
style,
|
|
291
|
+
children: toasts.slice(0, 3).map((toastToShow) => /* @__PURE__ */ jsx(
|
|
292
|
+
ToastAlertBox,
|
|
293
|
+
{
|
|
294
|
+
variant: toastToShow.variant,
|
|
295
|
+
title: toastToShow.title,
|
|
296
|
+
onClose: handleClose(toastToShow.id),
|
|
297
|
+
onMouseEnter: handleMouseEnter(toastToShow),
|
|
298
|
+
onMouseLeave: handleMouseLeave,
|
|
299
|
+
closable: hoveringId === toastToShow.id,
|
|
300
|
+
toastIsBeingRemoved: toastToShow.isBeingRemoved,
|
|
301
|
+
children: toastToShow.content
|
|
302
|
+
},
|
|
303
|
+
toastToShow.id
|
|
304
|
+
))
|
|
305
|
+
}
|
|
306
|
+
),
|
|
307
|
+
children
|
|
308
|
+
] });
|
|
279
309
|
};
|
|
280
|
-
|
|
281
|
-
|
|
310
|
+
const useToast = () => {
|
|
311
|
+
const context = React.useContext(ToastContext);
|
|
282
312
|
if (!context) {
|
|
283
|
-
throw new Error(
|
|
313
|
+
throw new Error(
|
|
314
|
+
"You need to wrap your component in a ToastProvider component in order to use the useToast hook"
|
|
315
|
+
);
|
|
284
316
|
}
|
|
285
|
-
|
|
317
|
+
const { addToast } = context;
|
|
286
318
|
return {
|
|
287
|
-
addToast
|
|
319
|
+
addToast
|
|
288
320
|
};
|
|
289
321
|
};
|
|
290
|
-
|
|
291
|
-
var
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
322
|
+
var copyTextToClipboard = { exports: {} };
|
|
323
|
+
var hasRequiredCopyTextToClipboard;
|
|
324
|
+
function requireCopyTextToClipboard() {
|
|
325
|
+
if (hasRequiredCopyTextToClipboard) return copyTextToClipboard.exports;
|
|
326
|
+
hasRequiredCopyTextToClipboard = 1;
|
|
327
|
+
const copyTextToClipboard$1 = (input, { target = document.body } = {}) => {
|
|
328
|
+
const element = document.createElement("textarea");
|
|
329
|
+
const previouslyFocusedElement = document.activeElement;
|
|
330
|
+
element.value = input;
|
|
331
|
+
element.setAttribute("readonly", "");
|
|
332
|
+
element.style.contain = "strict";
|
|
333
|
+
element.style.position = "absolute";
|
|
334
|
+
element.style.left = "-9999px";
|
|
335
|
+
element.style.fontSize = "12pt";
|
|
336
|
+
const selection = document.getSelection();
|
|
337
|
+
let originalRange = false;
|
|
338
|
+
if (selection.rangeCount > 0) {
|
|
339
|
+
originalRange = selection.getRangeAt(0);
|
|
340
|
+
}
|
|
341
|
+
target.append(element);
|
|
342
|
+
element.select();
|
|
343
|
+
element.selectionStart = 0;
|
|
344
|
+
element.selectionEnd = input.length;
|
|
345
|
+
let isSuccess = false;
|
|
346
|
+
try {
|
|
347
|
+
isSuccess = document.execCommand("copy");
|
|
348
|
+
} catch (_) {
|
|
349
|
+
}
|
|
350
|
+
element.remove();
|
|
351
|
+
if (originalRange) {
|
|
352
|
+
selection.removeAllRanges();
|
|
353
|
+
selection.addRange(originalRange);
|
|
354
|
+
}
|
|
355
|
+
if (previouslyFocusedElement) {
|
|
356
|
+
previouslyFocusedElement.focus();
|
|
357
|
+
}
|
|
358
|
+
return isSuccess;
|
|
359
|
+
};
|
|
360
|
+
copyTextToClipboard.exports = copyTextToClipboard$1;
|
|
361
|
+
copyTextToClipboard.exports.default = copyTextToClipboard$1;
|
|
362
|
+
return copyTextToClipboard.exports;
|
|
363
|
+
}
|
|
364
|
+
var copyTextToClipboardExports = requireCopyTextToClipboard();
|
|
365
|
+
const copy = /* @__PURE__ */ getDefaultExportFromCjs(copyTextToClipboardExports);
|
|
366
|
+
const CopyableText = ({
|
|
367
|
+
children,
|
|
368
|
+
successHeading = "Kopiert!",
|
|
369
|
+
successMessage,
|
|
370
|
+
textToCopy,
|
|
371
|
+
className,
|
|
372
|
+
"aria-label": ariaLabel = `Kopier ${textToCopy ?? children} til utklippstavlen`,
|
|
373
|
+
...rest
|
|
374
|
+
}) => {
|
|
375
|
+
const { addToast } = useToast();
|
|
376
|
+
const buttonRef = React.useRef(null);
|
|
377
|
+
const _textToCopy = textToCopy ?? children;
|
|
378
|
+
const _successMessage = successMessage ?? `${_textToCopy} ble kopiert til utklippstavlen.`;
|
|
379
|
+
const handleClick = () => {
|
|
308
380
|
buttonRef.current && copy(_textToCopy, {
|
|
309
381
|
target: buttonRef.current
|
|
310
|
-
}) && addToast({
|
|
311
|
-
title: successHeading,
|
|
312
|
-
content: _successMessage
|
|
313
|
-
});
|
|
382
|
+
}) && addToast({ title: successHeading, content: _successMessage });
|
|
314
383
|
};
|
|
315
|
-
return
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
384
|
+
return /* @__PURE__ */ jsx(
|
|
385
|
+
"div",
|
|
386
|
+
{
|
|
387
|
+
className: "eds-copyable-text " + className,
|
|
388
|
+
style: { ...rest.style },
|
|
389
|
+
type: "button",
|
|
390
|
+
onClick: handleClick,
|
|
391
|
+
tabIndex: -1,
|
|
392
|
+
"aria-label": "",
|
|
393
|
+
...rest,
|
|
394
|
+
children: /* @__PURE__ */ jsxs(PreformattedText, { className: "eds-copyable-text__preformatted-text", children: [
|
|
395
|
+
/* @__PURE__ */ jsx("span", { className: "eds-copyable-text__displayed-text", children }),
|
|
396
|
+
/* @__PURE__ */ jsx(
|
|
397
|
+
IconButton,
|
|
398
|
+
{
|
|
399
|
+
className: "eds-copyable-text__button",
|
|
400
|
+
"aria-label": ariaLabel,
|
|
401
|
+
type: "button",
|
|
402
|
+
ref: buttonRef,
|
|
403
|
+
children: /* @__PURE__ */ jsx(CopyIcon, { className: "eds-copyable-text__button__icon" })
|
|
404
|
+
}
|
|
405
|
+
)
|
|
406
|
+
] })
|
|
407
|
+
}
|
|
408
|
+
);
|
|
334
409
|
};
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}, props));
|
|
410
|
+
const SmallExpandableAlertBox = (props) => {
|
|
411
|
+
return /* @__PURE__ */ jsx(ExpandableAlertBox, { size: "small", ...props });
|
|
412
|
+
};
|
|
413
|
+
const BannerExpandableAlertBox = (props) => {
|
|
414
|
+
return /* @__PURE__ */ jsx(ExpandableAlertBox, { size: "banner", ...props });
|
|
341
415
|
};
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
416
|
+
const ExpandableAlertBox = ({
|
|
417
|
+
variant,
|
|
418
|
+
title,
|
|
419
|
+
children,
|
|
420
|
+
size,
|
|
421
|
+
className,
|
|
422
|
+
openLabel,
|
|
423
|
+
closeLabel,
|
|
424
|
+
...rest
|
|
425
|
+
}) => {
|
|
426
|
+
const [open, setopen] = React.useState(false);
|
|
427
|
+
return /* @__PURE__ */ jsx(
|
|
428
|
+
BaseAlertBox,
|
|
429
|
+
{
|
|
430
|
+
size,
|
|
431
|
+
variant,
|
|
432
|
+
className: classNames("eds-expandable-alert-box", className),
|
|
433
|
+
title: /* @__PURE__ */ jsx(
|
|
434
|
+
ExpandableAlertBoxTitle,
|
|
435
|
+
{
|
|
436
|
+
open,
|
|
437
|
+
title,
|
|
438
|
+
onClick: () => setopen(!open),
|
|
439
|
+
openLabel,
|
|
440
|
+
closeLabel
|
|
441
|
+
}
|
|
442
|
+
),
|
|
443
|
+
...rest,
|
|
444
|
+
children: /* @__PURE__ */ jsx(BaseExpand, { open, children })
|
|
445
|
+
}
|
|
446
|
+
);
|
|
346
447
|
};
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
openLabel: openLabel,
|
|
370
|
-
closeLabel: closeLabel
|
|
371
|
-
})
|
|
372
|
-
}, rest), React.createElement(BaseExpand, {
|
|
373
|
-
open: open
|
|
374
|
-
}, children));
|
|
448
|
+
const ExpandableAlertBoxTitle = ({
|
|
449
|
+
title,
|
|
450
|
+
open,
|
|
451
|
+
openLabel = "Les mer",
|
|
452
|
+
closeLabel = "Lukk",
|
|
453
|
+
onClick
|
|
454
|
+
}) => {
|
|
455
|
+
return /* @__PURE__ */ jsxs("div", { className: "eds-expandable-alert-box__title", children: [
|
|
456
|
+
/* @__PURE__ */ jsx("div", { children: title }),
|
|
457
|
+
/* @__PURE__ */ jsxs(
|
|
458
|
+
"button",
|
|
459
|
+
{
|
|
460
|
+
className: "eds-expandable-alert-box__button",
|
|
461
|
+
onClick,
|
|
462
|
+
type: "button",
|
|
463
|
+
children: [
|
|
464
|
+
open ? closeLabel : openLabel,
|
|
465
|
+
/* @__PURE__ */ jsx(ExpandArrow, { open, inline: true })
|
|
466
|
+
]
|
|
467
|
+
}
|
|
468
|
+
)
|
|
469
|
+
] });
|
|
375
470
|
};
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}, React.createElement("div", null, title), React.createElement("button", {
|
|
387
|
-
className: "eds-expandable-alert-box__button",
|
|
388
|
-
onClick: onClick,
|
|
389
|
-
type: "button"
|
|
390
|
-
}, open ? closeLabel : openLabel, React.createElement(ExpandArrow, {
|
|
391
|
-
open: open,
|
|
392
|
-
inline: true
|
|
393
|
-
})));
|
|
471
|
+
warnAboutMissingStyles("alert", "icons");
|
|
472
|
+
export {
|
|
473
|
+
BannerAlertBox,
|
|
474
|
+
BannerExpandableAlertBox,
|
|
475
|
+
CopyableText,
|
|
476
|
+
SmallAlertBox,
|
|
477
|
+
SmallExpandableAlertBox,
|
|
478
|
+
ToastAlertBox,
|
|
479
|
+
ToastProvider,
|
|
480
|
+
useToast
|
|
394
481
|
};
|
|
395
|
-
|
|
396
|
-
warnAboutMissingStyles('alert', 'icons');
|
|
397
|
-
|
|
398
|
-
export { BannerAlertBox, BannerExpandableAlertBox, CopyableText, SmallAlertBox, SmallExpandableAlertBox, ToastAlertBox, ToastProvider, useToast };
|
|
399
482
|
//# sourceMappingURL=alert.esm.js.map
|