@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/alert.esm.js CHANGED
@@ -1,482 +1,399 @@
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;
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
- 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;
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
- var classnamesExports = requireClassnames();
76
- const classNames = /* @__PURE__ */ getDefaultExportFromCjs(classnamesExports);
77
- const iconsMap = {
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: "Suksessmelding"
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: "Varselmelding"
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: { icon: ValidationInfoIcon, description: "Infomelding" },
90
- error: { icon: ValidationErrorIcon, description: "Feilmelding" }
49
+ info: {
50
+ icon: ValidationInfoIcon,
51
+ description: 'Infomelding'
52
+ },
53
+ error: {
54
+ icon: ValidationErrorIcon,
55
+ description: 'Feilmelding'
56
+ }
91
57
  };
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);
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
- const handleClose = () => {
80
+ var handleClose = function handleClose() {
109
81
  setClosed(true);
110
82
  onClose();
111
83
  };
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
- );
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
- 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
- {
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
- "eds-alert-box--fit-content": width === "fit-content"
185
- }),
186
- ...rest,
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
- const EXIT_ANIMATION_TIME = 400;
194
- const ToastContext = React.createContext(null);
195
- const toastReducer = (prevToasts, action) => {
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 "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 };
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 "REMOVE_TOAST":
206
- return prevToasts.filter((toast) => toast.id !== action.payload);
160
+ case 'REMOVE_TOAST':
161
+ return prevToasts.filter(function (toast) {
162
+ return toast.id !== action.payload;
163
+ });
207
164
  }
208
165
  };
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 };
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 { id, variant: "success", isBeingRemoved: false, ...toast };
178
+ return _extends({
179
+ id: id,
180
+ variant: 'success',
181
+ isBeingRemoved: false
182
+ }, toast);
215
183
  }
216
184
  };
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) => {
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({ type: "REMOVE_TOAST", payload: id });
202
+ dispatch({
203
+ type: 'REMOVE_TOAST',
204
+ payload: id
205
+ });
230
206
  delete timeoutIdRefs.current[id];
231
207
  }, []);
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"];
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
- 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);
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
- timeoutIdRefs.current = {};
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
- const handleMouseLeave = () => {
268
- setHovering(void 0);
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
- const handleClose = (toastId) => () => {
274
- removeToast(toastId);
275
- handleMouseLeave();
249
+ var handleClose = function handleClose(toastId) {
250
+ return function () {
251
+ removeToast(toastId);
252
+ handleMouseLeave();
253
+ };
276
254
  };
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
- ] });
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
- const useToast = () => {
311
- const context = React.useContext(ToastContext);
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
- const { addToast } = context;
285
+ var addToast = context.addToast;
318
286
  return {
319
- addToast
287
+ addToast: addToast
320
288
  };
321
289
  };
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 = () => {
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({ title: successHeading, content: _successMessage });
310
+ }) && addToast({
311
+ title: successHeading,
312
+ content: _successMessage
313
+ });
383
314
  };
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
- );
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
- const SmallExpandableAlertBox = (props) => {
411
- return /* @__PURE__ */ jsx(ExpandableAlertBox, { size: "small", ...props });
412
- };
413
- const BannerExpandableAlertBox = (props) => {
414
- return /* @__PURE__ */ jsx(ExpandableAlertBox, { size: "banner", ...props });
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
- 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
- );
342
+ var BannerExpandableAlertBox = function BannerExpandableAlertBox(props) {
343
+ return React.createElement(ExpandableAlertBox, _extends({
344
+ size: "banner"
345
+ }, props));
447
346
  };
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
- ] });
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
- warnAboutMissingStyles("alert", "icons");
472
- export {
473
- BannerAlertBox,
474
- BannerExpandableAlertBox,
475
- CopyableText,
476
- SmallAlertBox,
477
- SmallExpandableAlertBox,
478
- ToastAlertBox,
479
- ToastProvider,
480
- useToast
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