@equinor/cpl-error-snackbar-react 0.0.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/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Equinor ASA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ [<-- Go back](../../README.md)
2
+
3
+ # @equinor/cpl-error-snackbar-react
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ yarn add @equinor/cpl-error-snackbar-react
9
+ ```
10
+
11
+ ## Components
12
+
13
+ See [Implementation Guide](https://equinor.github.io/cpl-react/?path=/docs/cpl-error-snackbar-react-implementationguide--docs) for component details and implementations guide.
@@ -0,0 +1,115 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { ReactNode } from 'react';
4
+
5
+ interface CopyToClipboardButtonProps {
6
+ value: string;
7
+ }
8
+ declare function CopyToClipboardButton({ value }: CopyToClipboardButtonProps): react_jsx_runtime.JSX.Element;
9
+
10
+ interface Error {
11
+ /**
12
+ * @example https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404
13
+ */
14
+ type?: string;
15
+ /**
16
+ * @example "Resource not found"
17
+ */
18
+ title: string;
19
+ /**
20
+ * @example 404
21
+ */
22
+ status?: number;
23
+ /**
24
+ * @example "88fa66bf-0bd9-492f-85f0-6511372a1a98"
25
+ */
26
+ instance?: string;
27
+ /**
28
+ * @example "Access denied"
29
+ */
30
+ detail?: string;
31
+ error?: InnerError;
32
+ timestamp?: string;
33
+ traceId?: string;
34
+ }
35
+ interface InnerError {
36
+ /**
37
+ * @example "Forbidden"
38
+ */
39
+ code?: string;
40
+ /**
41
+ * @example "You do not meet any of the requirements to access the underlying data."
42
+ */
43
+ message?: string;
44
+ property?: string;
45
+ attemptedValue?: string;
46
+ resourceIdentifier?: string;
47
+ possibleAction?: string;
48
+ accessRequirements?: AccessRequirement[];
49
+ }
50
+ interface AccessRequirement {
51
+ /**
52
+ * @example "AccountClassification"
53
+ */
54
+ code: string;
55
+ /**
56
+ * @example "User must be of type Employee."
57
+ */
58
+ description: string;
59
+ /**
60
+ * @example "Your account classification is Consultant."
61
+ */
62
+ outcome: string;
63
+ /**
64
+ * @example true
65
+ */
66
+ wasEvaluated: boolean;
67
+ }
68
+
69
+ interface ErrorSnackbarProps {
70
+ error: Error;
71
+ onClose: () => void;
72
+ /**
73
+ * Provide custom icon if needed. Fallback to default 'error_filled' from EDS if not provided.
74
+ *
75
+ * @default <Icon data={error_filled} /> // EDS
76
+ */
77
+ icon?: ReactNode;
78
+ /**
79
+ * @default false
80
+ */
81
+ hideCopyToClipboardButton?: boolean;
82
+ }
83
+ declare function ErrorSnackbar({ error, icon, onClose, hideCopyToClipboardButton, }: ErrorSnackbarProps): react_jsx_runtime.JSX.Element;
84
+
85
+ interface ErrorSnackbarObject {
86
+ id: string;
87
+ error: Error;
88
+ }
89
+ type ErrorSnackbarState = {
90
+ errorSnackbarObjects: ErrorSnackbarObject[];
91
+ addError: (error: Error) => string;
92
+ removeErrorSnackbarObjectById: (id: string) => void;
93
+ removeAllErrorSnackbarObjects: () => void;
94
+ };
95
+ declare const ErrorSnackbarContext: react.Context<ErrorSnackbarState>;
96
+ declare function useErrorSnackbarContext(): ErrorSnackbarState;
97
+ declare function ErrorSnackbarContextProvider({ children, errorSnackbarObjects: initialErrorSnackbarObjects, }: {
98
+ children: ReactNode;
99
+ errorSnackbarObjects?: ErrorSnackbarObject[];
100
+ }): react_jsx_runtime.JSX.Element;
101
+
102
+ interface ErrorSnackbarsContainerProps {
103
+ /**
104
+ * This component is fixed to the bottom of the screen by default. To disable this behaviour,
105
+ * pass `disablePositionFixed` as a prop.
106
+ *
107
+ * @default false
108
+ */
109
+ disablePositionFixed?: boolean;
110
+ }
111
+ declare function ErrorSnackbarListContainer({ disablePositionFixed, }: ErrorSnackbarsContainerProps): react_jsx_runtime.JSX.Element;
112
+
113
+ declare function parseUnknownError(unknownError: unknown): Error;
114
+
115
+ export { type AccessRequirement, CopyToClipboardButton, type Error, ErrorSnackbar, ErrorSnackbarContext, ErrorSnackbarContextProvider, ErrorSnackbarListContainer, type ErrorSnackbarObject, type InnerError, parseUnknownError, useErrorSnackbarContext };
@@ -0,0 +1,115 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { ReactNode } from 'react';
4
+
5
+ interface CopyToClipboardButtonProps {
6
+ value: string;
7
+ }
8
+ declare function CopyToClipboardButton({ value }: CopyToClipboardButtonProps): react_jsx_runtime.JSX.Element;
9
+
10
+ interface Error {
11
+ /**
12
+ * @example https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404
13
+ */
14
+ type?: string;
15
+ /**
16
+ * @example "Resource not found"
17
+ */
18
+ title: string;
19
+ /**
20
+ * @example 404
21
+ */
22
+ status?: number;
23
+ /**
24
+ * @example "88fa66bf-0bd9-492f-85f0-6511372a1a98"
25
+ */
26
+ instance?: string;
27
+ /**
28
+ * @example "Access denied"
29
+ */
30
+ detail?: string;
31
+ error?: InnerError;
32
+ timestamp?: string;
33
+ traceId?: string;
34
+ }
35
+ interface InnerError {
36
+ /**
37
+ * @example "Forbidden"
38
+ */
39
+ code?: string;
40
+ /**
41
+ * @example "You do not meet any of the requirements to access the underlying data."
42
+ */
43
+ message?: string;
44
+ property?: string;
45
+ attemptedValue?: string;
46
+ resourceIdentifier?: string;
47
+ possibleAction?: string;
48
+ accessRequirements?: AccessRequirement[];
49
+ }
50
+ interface AccessRequirement {
51
+ /**
52
+ * @example "AccountClassification"
53
+ */
54
+ code: string;
55
+ /**
56
+ * @example "User must be of type Employee."
57
+ */
58
+ description: string;
59
+ /**
60
+ * @example "Your account classification is Consultant."
61
+ */
62
+ outcome: string;
63
+ /**
64
+ * @example true
65
+ */
66
+ wasEvaluated: boolean;
67
+ }
68
+
69
+ interface ErrorSnackbarProps {
70
+ error: Error;
71
+ onClose: () => void;
72
+ /**
73
+ * Provide custom icon if needed. Fallback to default 'error_filled' from EDS if not provided.
74
+ *
75
+ * @default <Icon data={error_filled} /> // EDS
76
+ */
77
+ icon?: ReactNode;
78
+ /**
79
+ * @default false
80
+ */
81
+ hideCopyToClipboardButton?: boolean;
82
+ }
83
+ declare function ErrorSnackbar({ error, icon, onClose, hideCopyToClipboardButton, }: ErrorSnackbarProps): react_jsx_runtime.JSX.Element;
84
+
85
+ interface ErrorSnackbarObject {
86
+ id: string;
87
+ error: Error;
88
+ }
89
+ type ErrorSnackbarState = {
90
+ errorSnackbarObjects: ErrorSnackbarObject[];
91
+ addError: (error: Error) => string;
92
+ removeErrorSnackbarObjectById: (id: string) => void;
93
+ removeAllErrorSnackbarObjects: () => void;
94
+ };
95
+ declare const ErrorSnackbarContext: react.Context<ErrorSnackbarState>;
96
+ declare function useErrorSnackbarContext(): ErrorSnackbarState;
97
+ declare function ErrorSnackbarContextProvider({ children, errorSnackbarObjects: initialErrorSnackbarObjects, }: {
98
+ children: ReactNode;
99
+ errorSnackbarObjects?: ErrorSnackbarObject[];
100
+ }): react_jsx_runtime.JSX.Element;
101
+
102
+ interface ErrorSnackbarsContainerProps {
103
+ /**
104
+ * This component is fixed to the bottom of the screen by default. To disable this behaviour,
105
+ * pass `disablePositionFixed` as a prop.
106
+ *
107
+ * @default false
108
+ */
109
+ disablePositionFixed?: boolean;
110
+ }
111
+ declare function ErrorSnackbarListContainer({ disablePositionFixed, }: ErrorSnackbarsContainerProps): react_jsx_runtime.JSX.Element;
112
+
113
+ declare function parseUnknownError(unknownError: unknown): Error;
114
+
115
+ export { type AccessRequirement, CopyToClipboardButton, type Error, ErrorSnackbar, ErrorSnackbarContext, ErrorSnackbarContextProvider, ErrorSnackbarListContainer, type ErrorSnackbarObject, type InnerError, parseUnknownError, useErrorSnackbarContext };
package/dist/index.js ADDED
@@ -0,0 +1,428 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var __async = (__this, __arguments, generator) => {
30
+ return new Promise((resolve, reject) => {
31
+ var fulfilled = (value) => {
32
+ try {
33
+ step(generator.next(value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ };
38
+ var rejected = (value) => {
39
+ try {
40
+ step(generator.throw(value));
41
+ } catch (e) {
42
+ reject(e);
43
+ }
44
+ };
45
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
+ step((generator = generator.apply(__this, __arguments)).next());
47
+ });
48
+ };
49
+
50
+ // src/index.ts
51
+ var src_exports = {};
52
+ __export(src_exports, {
53
+ CopyToClipboardButton: () => CopyToClipboardButton,
54
+ ErrorSnackbar: () => ErrorSnackbar,
55
+ ErrorSnackbarContext: () => ErrorSnackbarContext,
56
+ ErrorSnackbarContextProvider: () => ErrorSnackbarContextProvider,
57
+ ErrorSnackbarListContainer: () => ErrorSnackbarListContainer,
58
+ parseUnknownError: () => parseUnknownError,
59
+ useErrorSnackbarContext: () => useErrorSnackbarContext
60
+ });
61
+ module.exports = __toCommonJS(src_exports);
62
+
63
+ // src/CopyToClipboardButton.tsx
64
+ var import_eds_core_react = require("@equinor/eds-core-react");
65
+ var import_eds_icons = require("@equinor/eds-icons");
66
+ var import_react = require("react");
67
+ var import_styled_components = __toESM(require("styled-components"));
68
+ var import_jsx_runtime = require("react/jsx-runtime");
69
+ function CopyToClipboardButton({ value }) {
70
+ const [showPopover, setShowPopover] = (0, import_react.useState)(false);
71
+ (0, import_react.useEffect)(() => {
72
+ let timer;
73
+ if (showPopover) {
74
+ timer = setTimeout(() => {
75
+ setShowPopover(false);
76
+ }, 2e3);
77
+ }
78
+ return () => {
79
+ if (timer) clearTimeout(timer);
80
+ };
81
+ }, [showPopover]);
82
+ const handleCopy = () => __async(this, null, function* () {
83
+ try {
84
+ yield navigator.clipboard.writeText(value);
85
+ setShowPopover(true);
86
+ } catch (error) {
87
+ console.error("Failed to copy text: ", error);
88
+ }
89
+ });
90
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StyledButton, { onClick: handleCopy, title: "Copy to Clipboard", variant: "ghost", color: "secondary", children: showPopover ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
91
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_eds_core_react.Icon, { data: import_eds_icons.check, size: 16 }),
92
+ "Copied"
93
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
94
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_eds_core_react.Icon, { data: import_eds_icons.copy, size: 16 }),
95
+ "Copy"
96
+ ] }) });
97
+ }
98
+ var StyledButton = (0, import_styled_components.default)(import_eds_core_react.Button)`
99
+ color: inherit;
100
+ `;
101
+
102
+ // src/ErrorSnackbar.tsx
103
+ var import_eds_core_react2 = require("@equinor/eds-core-react");
104
+ var import_eds_icons2 = require("@equinor/eds-icons");
105
+ var import_eds_tokens = require("@equinor/eds-tokens");
106
+ var import_styled_components2 = __toESM(require("styled-components"));
107
+ var import_jsx_runtime2 = require("react/jsx-runtime");
108
+ function ErrorSnackbar({
109
+ error,
110
+ icon,
111
+ onClose,
112
+ hideCopyToClipboardButton = false
113
+ }) {
114
+ var _a;
115
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(ErrorSnackbarWrapper, { tabIndex: 0, children: [
116
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconWrapper, { children: icon || /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
117
+ import_eds_core_react2.Icon,
118
+ {
119
+ size: 24,
120
+ data: import_eds_icons2.error_filled,
121
+ color: import_eds_tokens.tokens.colors.interactive.danger__resting.rgba
122
+ }
123
+ ) }),
124
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(MainColumn, { children: [
125
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(HeaderWrapper, { children: [
126
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
127
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_eds_core_react2.Typography, { variant: "h6", children: error.title }),
128
+ error.detail && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BodyTypography, { children: error.detail })
129
+ ] }),
130
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
131
+ CloseButton,
132
+ {
133
+ variant: "ghost_icon",
134
+ onClick: onClose,
135
+ title: "Close error snackbar",
136
+ color: "secondary",
137
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_eds_core_react2.Icon, { data: import_eds_icons2.close, size: 24 })
138
+ }
139
+ )
140
+ ] }),
141
+ error.error && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
142
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_eds_core_react2.Typography, { variant: "h6", children: "Error details:" }),
143
+ error.error.message && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BodyTypography, { children: error.error.message }),
144
+ error.error.possibleAction && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BodyTypography, { children: error.error.possibleAction }),
145
+ ((_a = error.error.accessRequirements) == null ? void 0 : _a.length) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StyledList, { style: { color: "inherit" }, children: error.error.accessRequirements.map((accessRequirement) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StyledList.Item, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(BodyTypography, { children: [
146
+ accessRequirement.description,
147
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("br", {}),
148
+ "Outcome: ",
149
+ accessRequirement.outcome
150
+ ] }) }, accessRequirement.code + accessRequirement.description)) })
151
+ ] }),
152
+ (error.timestamp || error.traceId) && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(MetadataWrapper, { children: [
153
+ error.timestamp && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(MetadataTypography, { children: [
154
+ "Timestamp: ",
155
+ error.timestamp,
156
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("br", {})
157
+ ] }),
158
+ error.traceId && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(MetadataTypography, { children: [
159
+ "Trace ID: ",
160
+ error.traceId
161
+ ] })
162
+ ] }),
163
+ !hideCopyToClipboardButton && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CopyWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CopyToClipboardButton, { value: JSON.stringify(error, null, 2) }) })
164
+ ] })
165
+ ] });
166
+ }
167
+ var IconWrapper = import_styled_components2.default.div`
168
+ padding: 0.25rem 0;
169
+ `;
170
+ var CopyWrapper = import_styled_components2.default.div`
171
+ margin: -0.5rem -1rem;
172
+ color: inherit;
173
+ `;
174
+ var MainColumn = import_styled_components2.default.div`
175
+ flex: 1;
176
+
177
+ display: flex;
178
+ flex-direction: column;
179
+ gap: 1rem;
180
+ `;
181
+ var HeaderWrapper = import_styled_components2.default.div`
182
+ display: flex;
183
+ justify-content: space-between;
184
+ `;
185
+ var BodyTypography = (0, import_styled_components2.default)(import_eds_core_react2.Typography)`
186
+ font-size: 0.857rem; // 14px
187
+ `;
188
+ var MetadataWrapper = import_styled_components2.default.div`
189
+ display: flex;
190
+ flex-direction: column;
191
+ gap: 0.25rem;
192
+ `;
193
+ var MetadataTypography = (0, import_styled_components2.default)(import_eds_core_react2.Typography)`
194
+ font-size: 0.625rem; // 10px
195
+ `;
196
+ var CloseButton = (0, import_styled_components2.default)(import_eds_core_react2.Button)`
197
+ margin: -0.5rem;
198
+ color: inherit;
199
+ flex-shrink: 0;
200
+ `;
201
+ var ErrorSnackbarWrapper = import_styled_components2.default.div`
202
+ background-color: ${import_eds_tokens.tokens.colors.ui.background__default.rgba};
203
+ border: 2px solid ${import_eds_tokens.tokens.colors.ui.background__medium.rgba};
204
+ border-radius: ${import_eds_tokens.tokens.shape.button.borderRadius};
205
+ padding: 0.75rem 1rem 1rem 1rem;
206
+
207
+ display: flex;
208
+ color: ${import_eds_tokens.tokens.colors.text.static_icons__default.rgba};
209
+ gap: 0.5rem;
210
+
211
+ // Focus border copied from EDS button
212
+ &:focus-visible {
213
+ outline: 2px dashed ${import_eds_tokens.tokens.colors.interactive.primary__resting.hex};
214
+ outline-offset: 3px;
215
+ }
216
+ `;
217
+ var StyledList = (0, import_styled_components2.default)(import_eds_core_react2.List)`
218
+ color: inherit;
219
+ `;
220
+
221
+ // src/ErrorSnackbarContext.tsx
222
+ var import_react2 = require("react");
223
+ var import_jsx_runtime3 = require("react/jsx-runtime");
224
+ var defaultState = {
225
+ errorSnackbarObjects: [],
226
+ addError: () => "",
227
+ removeAllErrorSnackbarObjects: () => null,
228
+ removeErrorSnackbarObjectById: () => null
229
+ };
230
+ var ErrorSnackbarContext = (0, import_react2.createContext)(defaultState);
231
+ function useErrorSnackbarContext() {
232
+ return (0, import_react2.useContext)(ErrorSnackbarContext);
233
+ }
234
+ function ErrorSnackbarContextProvider({
235
+ children,
236
+ errorSnackbarObjects: initialErrorSnackbarObjects = []
237
+ }) {
238
+ const [errorSnackbarObjects, setErrorSnackbarObjects] = (0, import_react2.useState)(
239
+ initialErrorSnackbarObjects
240
+ );
241
+ const addError = (0, import_react2.useCallback)(
242
+ (error) => {
243
+ const id = crypto.randomUUID();
244
+ setErrorSnackbarObjects([{ id, error }, ...errorSnackbarObjects]);
245
+ return id;
246
+ },
247
+ [errorSnackbarObjects]
248
+ );
249
+ const removeAllErrorSnackbarObjects = (0, import_react2.useCallback)(() => {
250
+ setErrorSnackbarObjects([]);
251
+ }, []);
252
+ const removeErrorSnackbarObjectById = (0, import_react2.useCallback)((errorSnackbarId) => {
253
+ setErrorSnackbarObjects(
254
+ (old) => old.filter((errorSnackbar) => errorSnackbar.id !== errorSnackbarId)
255
+ );
256
+ }, []);
257
+ const value = (0, import_react2.useMemo)(
258
+ () => ({
259
+ errorSnackbarObjects,
260
+ addError,
261
+ removeAllErrorSnackbarObjects,
262
+ removeErrorSnackbarObjectById
263
+ }),
264
+ [addError, errorSnackbarObjects, removeAllErrorSnackbarObjects, removeErrorSnackbarObjectById]
265
+ );
266
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorSnackbarContext.Provider, { value, children });
267
+ }
268
+
269
+ // src/ErrorSnackbarFixedList.tsx
270
+ var import_styled_components3 = __toESM(require("styled-components"));
271
+ var import_jsx_runtime4 = require("react/jsx-runtime");
272
+ var ERROR_SNACKBARS_FIXED_WRAPPER_TESTID = "error-snackbars-fixed-wrapper";
273
+ function ErrorSnackbarFixedList({
274
+ disablePositionFixed = false,
275
+ errorSnackbarObjects,
276
+ removeErrorSnackbarObjectById
277
+ }) {
278
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
279
+ FixedWrapper,
280
+ {
281
+ $disablePositionFixed: disablePositionFixed,
282
+ "data-testid": ERROR_SNACKBARS_FIXED_WRAPPER_TESTID,
283
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SnackbarList, { children: errorSnackbarObjects.map((errorSnackbarObject) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
284
+ ErrorSnackbar,
285
+ {
286
+ error: errorSnackbarObject.error,
287
+ onClose: () => removeErrorSnackbarObjectById(errorSnackbarObject.id)
288
+ }
289
+ ) }, errorSnackbarObject.id)) })
290
+ }
291
+ );
292
+ }
293
+ var SnackbarList = import_styled_components3.default.ul`
294
+ list-style: none;
295
+ padding: 1rem;
296
+ margin: 0;
297
+
298
+ width: 50rem;
299
+ max-width: calc(100dvw - 4rem);
300
+
301
+ // Add gap between list items
302
+ li + li {
303
+ margin-top: 0.5rem;
304
+ }
305
+ `;
306
+ var FixedWrapper = import_styled_components3.default.div`
307
+ display: flex;
308
+ gap: 0.5rem;
309
+ flex: 1;
310
+ flex-direction: column;
311
+
312
+ ${({ $disablePositionFixed }) => {
313
+ if ($disablePositionFixed) {
314
+ return "";
315
+ }
316
+ return `
317
+ position: fixed;
318
+ bottom: 0;
319
+ left: 0;
320
+ width: 100%;
321
+ max-height: 90%;
322
+ overflow: auto;
323
+ `;
324
+ }};
325
+ `;
326
+
327
+ // src/ErrorSnackbarListContainer.tsx
328
+ var import_jsx_runtime5 = require("react/jsx-runtime");
329
+ function ErrorSnackbarListContainer({
330
+ disablePositionFixed = false
331
+ }) {
332
+ const { errorSnackbarObjects, removeErrorSnackbarObjectById } = useErrorSnackbarContext();
333
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
334
+ ErrorSnackbarFixedList,
335
+ {
336
+ errorSnackbarObjects,
337
+ removeErrorSnackbarObjectById,
338
+ disablePositionFixed
339
+ }
340
+ );
341
+ }
342
+
343
+ // src/parseUnknownError.ts
344
+ function parseUnknownError(unknownError) {
345
+ if (typeof unknownError !== "object" || unknownError === null || unknownError === void 0) {
346
+ return {
347
+ status: -1,
348
+ title: "Unkonwn Error",
349
+ type: "unknown",
350
+ detail: `Received ${typeof unknownError}: ${String(unknownError)}`
351
+ };
352
+ }
353
+ const innerError = parseInnerError(getTypedPropertyIfExists(unknownError, "error", "object"));
354
+ return {
355
+ type: getTypedPropertyIfExists(unknownError, "type", "string") || "unknown",
356
+ title: getTypedPropertyIfExists(unknownError, "title", "string") || "Unkown Error",
357
+ status: getTypedPropertyIfExists(unknownError, "status", "number") || -1,
358
+ detail: getTypedPropertyIfExists(unknownError, "detail", "string"),
359
+ error: innerError != null ? innerError : {
360
+ code: "Forbidden",
361
+ message: "You do not meet any of the requirements to access the underlying data.",
362
+ accessRequirements: [
363
+ {
364
+ code: "TrustedApplication",
365
+ description: "Application user (Azure AD Application registration) with established trust.",
366
+ outcome: "User is not application user.",
367
+ wasEvaluated: true
368
+ },
369
+ {
370
+ code: "AccountClassification",
371
+ description: "User must be of type Employee.",
372
+ outcome: "Your account classification is Consultant.",
373
+ wasEvaluated: true
374
+ }
375
+ ]
376
+ },
377
+ traceId: "00-32714e8408ffd5ef675807bfe44f3190-c21117102fa5ac81-00",
378
+ timestamp: "2024-06-27T11:13:22.0185894+00:00"
379
+ };
380
+ }
381
+ function parseInnerError(rawInnerError) {
382
+ var _a;
383
+ if (typeof rawInnerError !== "object" || rawInnerError === null || rawInnerError === void 0) {
384
+ return void 0;
385
+ }
386
+ const accessRequirements = (_a = getTypedPropertyIfExists(rawInnerError, "accessRequirements", "array")) == null ? void 0 : _a.map(parseAccessRequirement).filter(itemIsDefined);
387
+ return {
388
+ code: getTypedPropertyIfExists(rawInnerError, "code", "string"),
389
+ attemptedValue: getTypedPropertyIfExists(rawInnerError, "attemptedValue", "string"),
390
+ possibleAction: getTypedPropertyIfExists(rawInnerError, "possibleAction", "string"),
391
+ message: getTypedPropertyIfExists(rawInnerError, "message", "string"),
392
+ property: getTypedPropertyIfExists(rawInnerError, "property", "string"),
393
+ resourceIdentifier: getTypedPropertyIfExists(rawInnerError, "resourceIdentifier", "string"),
394
+ accessRequirements
395
+ };
396
+ }
397
+ function parseAccessRequirement(rawAccessRequirement) {
398
+ var _a, _b, _c, _d;
399
+ if (typeof rawAccessRequirement !== "object" || !rawAccessRequirement) {
400
+ return void 0;
401
+ }
402
+ return {
403
+ code: (_a = getTypedPropertyIfExists(rawAccessRequirement, "code", "string")) != null ? _a : "",
404
+ description: (_b = getTypedPropertyIfExists(rawAccessRequirement, "description", "string")) != null ? _b : "",
405
+ outcome: (_c = getTypedPropertyIfExists(rawAccessRequirement, "outcome", "string")) != null ? _c : "",
406
+ wasEvaluated: (_d = getTypedPropertyIfExists(rawAccessRequirement, "wasEvaluated", "boolean")) != null ? _d : false
407
+ };
408
+ }
409
+ function getTypedPropertyIfExists(object, key, ...acceptedTypes) {
410
+ const arrayIsAcceptedTypeAndObjectIsArray = acceptedTypes.includes("array") && Array.isArray(object[key]);
411
+ if (acceptedTypes.includes(typeof object[key]) || arrayIsAcceptedTypeAndObjectIsArray) {
412
+ return object[key];
413
+ }
414
+ return void 0;
415
+ }
416
+ function itemIsDefined(e) {
417
+ return Boolean(e);
418
+ }
419
+ // Annotate the CommonJS export names for ESM import in node:
420
+ 0 && (module.exports = {
421
+ CopyToClipboardButton,
422
+ ErrorSnackbar,
423
+ ErrorSnackbarContext,
424
+ ErrorSnackbarContextProvider,
425
+ ErrorSnackbarListContainer,
426
+ parseUnknownError,
427
+ useErrorSnackbarContext
428
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,386 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+
22
+ // src/CopyToClipboardButton.tsx
23
+ import { Button, Icon } from "@equinor/eds-core-react";
24
+ import { check, copy } from "@equinor/eds-icons";
25
+ import { useEffect, useState } from "react";
26
+ import styled from "styled-components";
27
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
28
+ function CopyToClipboardButton({ value }) {
29
+ const [showPopover, setShowPopover] = useState(false);
30
+ useEffect(() => {
31
+ let timer;
32
+ if (showPopover) {
33
+ timer = setTimeout(() => {
34
+ setShowPopover(false);
35
+ }, 2e3);
36
+ }
37
+ return () => {
38
+ if (timer) clearTimeout(timer);
39
+ };
40
+ }, [showPopover]);
41
+ const handleCopy = () => __async(this, null, function* () {
42
+ try {
43
+ yield navigator.clipboard.writeText(value);
44
+ setShowPopover(true);
45
+ } catch (error) {
46
+ console.error("Failed to copy text: ", error);
47
+ }
48
+ });
49
+ return /* @__PURE__ */ jsx(StyledButton, { onClick: handleCopy, title: "Copy to Clipboard", variant: "ghost", color: "secondary", children: showPopover ? /* @__PURE__ */ jsxs(Fragment, { children: [
50
+ /* @__PURE__ */ jsx(Icon, { data: check, size: 16 }),
51
+ "Copied"
52
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
53
+ /* @__PURE__ */ jsx(Icon, { data: copy, size: 16 }),
54
+ "Copy"
55
+ ] }) });
56
+ }
57
+ var StyledButton = styled(Button)`
58
+ color: inherit;
59
+ `;
60
+
61
+ // src/ErrorSnackbar.tsx
62
+ import { Button as Button2, Icon as Icon2, List, Typography } from "@equinor/eds-core-react";
63
+ import { close, error_filled } from "@equinor/eds-icons";
64
+ import { tokens } from "@equinor/eds-tokens";
65
+ import styled2 from "styled-components";
66
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
67
+ function ErrorSnackbar({
68
+ error,
69
+ icon,
70
+ onClose,
71
+ hideCopyToClipboardButton = false
72
+ }) {
73
+ var _a;
74
+ return /* @__PURE__ */ jsxs2(ErrorSnackbarWrapper, { tabIndex: 0, children: [
75
+ /* @__PURE__ */ jsx2(IconWrapper, { children: icon || /* @__PURE__ */ jsx2(
76
+ Icon2,
77
+ {
78
+ size: 24,
79
+ data: error_filled,
80
+ color: tokens.colors.interactive.danger__resting.rgba
81
+ }
82
+ ) }),
83
+ /* @__PURE__ */ jsxs2(MainColumn, { children: [
84
+ /* @__PURE__ */ jsxs2(HeaderWrapper, { children: [
85
+ /* @__PURE__ */ jsxs2("div", { children: [
86
+ /* @__PURE__ */ jsx2(Typography, { variant: "h6", children: error.title }),
87
+ error.detail && /* @__PURE__ */ jsx2(BodyTypography, { children: error.detail })
88
+ ] }),
89
+ /* @__PURE__ */ jsx2(
90
+ CloseButton,
91
+ {
92
+ variant: "ghost_icon",
93
+ onClick: onClose,
94
+ title: "Close error snackbar",
95
+ color: "secondary",
96
+ children: /* @__PURE__ */ jsx2(Icon2, { data: close, size: 24 })
97
+ }
98
+ )
99
+ ] }),
100
+ error.error && /* @__PURE__ */ jsxs2("div", { children: [
101
+ /* @__PURE__ */ jsx2(Typography, { variant: "h6", children: "Error details:" }),
102
+ error.error.message && /* @__PURE__ */ jsx2(BodyTypography, { children: error.error.message }),
103
+ error.error.possibleAction && /* @__PURE__ */ jsx2(BodyTypography, { children: error.error.possibleAction }),
104
+ ((_a = error.error.accessRequirements) == null ? void 0 : _a.length) && /* @__PURE__ */ jsx2(StyledList, { style: { color: "inherit" }, children: error.error.accessRequirements.map((accessRequirement) => /* @__PURE__ */ jsx2(StyledList.Item, { children: /* @__PURE__ */ jsxs2(BodyTypography, { children: [
105
+ accessRequirement.description,
106
+ /* @__PURE__ */ jsx2("br", {}),
107
+ "Outcome: ",
108
+ accessRequirement.outcome
109
+ ] }) }, accessRequirement.code + accessRequirement.description)) })
110
+ ] }),
111
+ (error.timestamp || error.traceId) && /* @__PURE__ */ jsxs2(MetadataWrapper, { children: [
112
+ error.timestamp && /* @__PURE__ */ jsxs2(MetadataTypography, { children: [
113
+ "Timestamp: ",
114
+ error.timestamp,
115
+ /* @__PURE__ */ jsx2("br", {})
116
+ ] }),
117
+ error.traceId && /* @__PURE__ */ jsxs2(MetadataTypography, { children: [
118
+ "Trace ID: ",
119
+ error.traceId
120
+ ] })
121
+ ] }),
122
+ !hideCopyToClipboardButton && /* @__PURE__ */ jsx2(CopyWrapper, { children: /* @__PURE__ */ jsx2(CopyToClipboardButton, { value: JSON.stringify(error, null, 2) }) })
123
+ ] })
124
+ ] });
125
+ }
126
+ var IconWrapper = styled2.div`
127
+ padding: 0.25rem 0;
128
+ `;
129
+ var CopyWrapper = styled2.div`
130
+ margin: -0.5rem -1rem;
131
+ color: inherit;
132
+ `;
133
+ var MainColumn = styled2.div`
134
+ flex: 1;
135
+
136
+ display: flex;
137
+ flex-direction: column;
138
+ gap: 1rem;
139
+ `;
140
+ var HeaderWrapper = styled2.div`
141
+ display: flex;
142
+ justify-content: space-between;
143
+ `;
144
+ var BodyTypography = styled2(Typography)`
145
+ font-size: 0.857rem; // 14px
146
+ `;
147
+ var MetadataWrapper = styled2.div`
148
+ display: flex;
149
+ flex-direction: column;
150
+ gap: 0.25rem;
151
+ `;
152
+ var MetadataTypography = styled2(Typography)`
153
+ font-size: 0.625rem; // 10px
154
+ `;
155
+ var CloseButton = styled2(Button2)`
156
+ margin: -0.5rem;
157
+ color: inherit;
158
+ flex-shrink: 0;
159
+ `;
160
+ var ErrorSnackbarWrapper = styled2.div`
161
+ background-color: ${tokens.colors.ui.background__default.rgba};
162
+ border: 2px solid ${tokens.colors.ui.background__medium.rgba};
163
+ border-radius: ${tokens.shape.button.borderRadius};
164
+ padding: 0.75rem 1rem 1rem 1rem;
165
+
166
+ display: flex;
167
+ color: ${tokens.colors.text.static_icons__default.rgba};
168
+ gap: 0.5rem;
169
+
170
+ // Focus border copied from EDS button
171
+ &:focus-visible {
172
+ outline: 2px dashed ${tokens.colors.interactive.primary__resting.hex};
173
+ outline-offset: 3px;
174
+ }
175
+ `;
176
+ var StyledList = styled2(List)`
177
+ color: inherit;
178
+ `;
179
+
180
+ // src/ErrorSnackbarContext.tsx
181
+ import { createContext, useCallback, useContext, useMemo, useState as useState2 } from "react";
182
+ import { jsx as jsx3 } from "react/jsx-runtime";
183
+ var defaultState = {
184
+ errorSnackbarObjects: [],
185
+ addError: () => "",
186
+ removeAllErrorSnackbarObjects: () => null,
187
+ removeErrorSnackbarObjectById: () => null
188
+ };
189
+ var ErrorSnackbarContext = createContext(defaultState);
190
+ function useErrorSnackbarContext() {
191
+ return useContext(ErrorSnackbarContext);
192
+ }
193
+ function ErrorSnackbarContextProvider({
194
+ children,
195
+ errorSnackbarObjects: initialErrorSnackbarObjects = []
196
+ }) {
197
+ const [errorSnackbarObjects, setErrorSnackbarObjects] = useState2(
198
+ initialErrorSnackbarObjects
199
+ );
200
+ const addError = useCallback(
201
+ (error) => {
202
+ const id = crypto.randomUUID();
203
+ setErrorSnackbarObjects([{ id, error }, ...errorSnackbarObjects]);
204
+ return id;
205
+ },
206
+ [errorSnackbarObjects]
207
+ );
208
+ const removeAllErrorSnackbarObjects = useCallback(() => {
209
+ setErrorSnackbarObjects([]);
210
+ }, []);
211
+ const removeErrorSnackbarObjectById = useCallback((errorSnackbarId) => {
212
+ setErrorSnackbarObjects(
213
+ (old) => old.filter((errorSnackbar) => errorSnackbar.id !== errorSnackbarId)
214
+ );
215
+ }, []);
216
+ const value = useMemo(
217
+ () => ({
218
+ errorSnackbarObjects,
219
+ addError,
220
+ removeAllErrorSnackbarObjects,
221
+ removeErrorSnackbarObjectById
222
+ }),
223
+ [addError, errorSnackbarObjects, removeAllErrorSnackbarObjects, removeErrorSnackbarObjectById]
224
+ );
225
+ return /* @__PURE__ */ jsx3(ErrorSnackbarContext.Provider, { value, children });
226
+ }
227
+
228
+ // src/ErrorSnackbarFixedList.tsx
229
+ import styled3 from "styled-components";
230
+ import { jsx as jsx4 } from "react/jsx-runtime";
231
+ var ERROR_SNACKBARS_FIXED_WRAPPER_TESTID = "error-snackbars-fixed-wrapper";
232
+ function ErrorSnackbarFixedList({
233
+ disablePositionFixed = false,
234
+ errorSnackbarObjects,
235
+ removeErrorSnackbarObjectById
236
+ }) {
237
+ return /* @__PURE__ */ jsx4(
238
+ FixedWrapper,
239
+ {
240
+ $disablePositionFixed: disablePositionFixed,
241
+ "data-testid": ERROR_SNACKBARS_FIXED_WRAPPER_TESTID,
242
+ children: /* @__PURE__ */ jsx4(SnackbarList, { children: errorSnackbarObjects.map((errorSnackbarObject) => /* @__PURE__ */ jsx4("li", { children: /* @__PURE__ */ jsx4(
243
+ ErrorSnackbar,
244
+ {
245
+ error: errorSnackbarObject.error,
246
+ onClose: () => removeErrorSnackbarObjectById(errorSnackbarObject.id)
247
+ }
248
+ ) }, errorSnackbarObject.id)) })
249
+ }
250
+ );
251
+ }
252
+ var SnackbarList = styled3.ul`
253
+ list-style: none;
254
+ padding: 1rem;
255
+ margin: 0;
256
+
257
+ width: 50rem;
258
+ max-width: calc(100dvw - 4rem);
259
+
260
+ // Add gap between list items
261
+ li + li {
262
+ margin-top: 0.5rem;
263
+ }
264
+ `;
265
+ var FixedWrapper = styled3.div`
266
+ display: flex;
267
+ gap: 0.5rem;
268
+ flex: 1;
269
+ flex-direction: column;
270
+
271
+ ${({ $disablePositionFixed }) => {
272
+ if ($disablePositionFixed) {
273
+ return "";
274
+ }
275
+ return `
276
+ position: fixed;
277
+ bottom: 0;
278
+ left: 0;
279
+ width: 100%;
280
+ max-height: 90%;
281
+ overflow: auto;
282
+ `;
283
+ }};
284
+ `;
285
+
286
+ // src/ErrorSnackbarListContainer.tsx
287
+ import { jsx as jsx5 } from "react/jsx-runtime";
288
+ function ErrorSnackbarListContainer({
289
+ disablePositionFixed = false
290
+ }) {
291
+ const { errorSnackbarObjects, removeErrorSnackbarObjectById } = useErrorSnackbarContext();
292
+ return /* @__PURE__ */ jsx5(
293
+ ErrorSnackbarFixedList,
294
+ {
295
+ errorSnackbarObjects,
296
+ removeErrorSnackbarObjectById,
297
+ disablePositionFixed
298
+ }
299
+ );
300
+ }
301
+
302
+ // src/parseUnknownError.ts
303
+ function parseUnknownError(unknownError) {
304
+ if (typeof unknownError !== "object" || unknownError === null || unknownError === void 0) {
305
+ return {
306
+ status: -1,
307
+ title: "Unkonwn Error",
308
+ type: "unknown",
309
+ detail: `Received ${typeof unknownError}: ${String(unknownError)}`
310
+ };
311
+ }
312
+ const innerError = parseInnerError(getTypedPropertyIfExists(unknownError, "error", "object"));
313
+ return {
314
+ type: getTypedPropertyIfExists(unknownError, "type", "string") || "unknown",
315
+ title: getTypedPropertyIfExists(unknownError, "title", "string") || "Unkown Error",
316
+ status: getTypedPropertyIfExists(unknownError, "status", "number") || -1,
317
+ detail: getTypedPropertyIfExists(unknownError, "detail", "string"),
318
+ error: innerError != null ? innerError : {
319
+ code: "Forbidden",
320
+ message: "You do not meet any of the requirements to access the underlying data.",
321
+ accessRequirements: [
322
+ {
323
+ code: "TrustedApplication",
324
+ description: "Application user (Azure AD Application registration) with established trust.",
325
+ outcome: "User is not application user.",
326
+ wasEvaluated: true
327
+ },
328
+ {
329
+ code: "AccountClassification",
330
+ description: "User must be of type Employee.",
331
+ outcome: "Your account classification is Consultant.",
332
+ wasEvaluated: true
333
+ }
334
+ ]
335
+ },
336
+ traceId: "00-32714e8408ffd5ef675807bfe44f3190-c21117102fa5ac81-00",
337
+ timestamp: "2024-06-27T11:13:22.0185894+00:00"
338
+ };
339
+ }
340
+ function parseInnerError(rawInnerError) {
341
+ var _a;
342
+ if (typeof rawInnerError !== "object" || rawInnerError === null || rawInnerError === void 0) {
343
+ return void 0;
344
+ }
345
+ const accessRequirements = (_a = getTypedPropertyIfExists(rawInnerError, "accessRequirements", "array")) == null ? void 0 : _a.map(parseAccessRequirement).filter(itemIsDefined);
346
+ return {
347
+ code: getTypedPropertyIfExists(rawInnerError, "code", "string"),
348
+ attemptedValue: getTypedPropertyIfExists(rawInnerError, "attemptedValue", "string"),
349
+ possibleAction: getTypedPropertyIfExists(rawInnerError, "possibleAction", "string"),
350
+ message: getTypedPropertyIfExists(rawInnerError, "message", "string"),
351
+ property: getTypedPropertyIfExists(rawInnerError, "property", "string"),
352
+ resourceIdentifier: getTypedPropertyIfExists(rawInnerError, "resourceIdentifier", "string"),
353
+ accessRequirements
354
+ };
355
+ }
356
+ function parseAccessRequirement(rawAccessRequirement) {
357
+ var _a, _b, _c, _d;
358
+ if (typeof rawAccessRequirement !== "object" || !rawAccessRequirement) {
359
+ return void 0;
360
+ }
361
+ return {
362
+ code: (_a = getTypedPropertyIfExists(rawAccessRequirement, "code", "string")) != null ? _a : "",
363
+ description: (_b = getTypedPropertyIfExists(rawAccessRequirement, "description", "string")) != null ? _b : "",
364
+ outcome: (_c = getTypedPropertyIfExists(rawAccessRequirement, "outcome", "string")) != null ? _c : "",
365
+ wasEvaluated: (_d = getTypedPropertyIfExists(rawAccessRequirement, "wasEvaluated", "boolean")) != null ? _d : false
366
+ };
367
+ }
368
+ function getTypedPropertyIfExists(object, key, ...acceptedTypes) {
369
+ const arrayIsAcceptedTypeAndObjectIsArray = acceptedTypes.includes("array") && Array.isArray(object[key]);
370
+ if (acceptedTypes.includes(typeof object[key]) || arrayIsAcceptedTypeAndObjectIsArray) {
371
+ return object[key];
372
+ }
373
+ return void 0;
374
+ }
375
+ function itemIsDefined(e) {
376
+ return Boolean(e);
377
+ }
378
+ export {
379
+ CopyToClipboardButton,
380
+ ErrorSnackbar,
381
+ ErrorSnackbarContext,
382
+ ErrorSnackbarContextProvider,
383
+ ErrorSnackbarListContainer,
384
+ parseUnknownError,
385
+ useErrorSnackbarContext
386
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@equinor/cpl-error-snackbar-react",
3
+ "version": "0.0.0",
4
+ "license": "MIT",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist/**"
10
+ ],
11
+ "dependencies": {
12
+ "@equinor/eds-icons": "^0.21.0",
13
+ "@equinor/eds-tokens": "^0.9.2"
14
+ },
15
+ "devDependencies": {
16
+ "@equinor/eds-core-react": "^0.40.0",
17
+ "@storybook/react": "^8.1.11",
18
+ "@storybook/test": "^8.1.11",
19
+ "@types/react": "^18.3.3",
20
+ "@types/react-dom": "^18.3.0",
21
+ "@types/styled-components": "^5.1.34",
22
+ "eslint": "^8.56.0",
23
+ "react": "^18.2.0",
24
+ "react-dom": "^18.2.0",
25
+ "styled-components": "^6.1.11",
26
+ "tsup": "^8.1.0",
27
+ "eslint-config-custom": "0.0.5",
28
+ "tsconfig": "0.0.1"
29
+ },
30
+ "peerDependencies": {
31
+ "@equinor/eds-core-react": ">=0.35.1",
32
+ "react": ">=18.2.0",
33
+ "react-dom": ">=18.2.0",
34
+ "styled-components": ">=5.3.11"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup src/index.ts --format esm,cjs --dts --external react",
41
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
42
+ "dev": "tsup src/index.ts --format esm,cjs --watch --dts --external react",
43
+ "lint": "TIMING=1 eslint . --fix"
44
+ }
45
+ }