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