@equinor/cpl-error-snackbar-react 0.1.1 → 0.1.3

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/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
- import { ReactNode, SetStateAction } from 'react';
3
+ import { ReactNode, SetStateAction, HTMLAttributes } from 'react';
4
4
 
5
5
  interface CopyToClipboardButtonProps {
6
6
  value: string;
@@ -159,7 +159,7 @@ interface Toast {
159
159
  interface BuildToasterOptions {
160
160
  timeoutOverrides?: Partial<Record<ToastType, ToastTimeout>>;
161
161
  }
162
- declare function buildToaster(options: BuildToasterOptions): {
162
+ declare function buildToaster(options?: BuildToasterOptions): {
163
163
  useState: () => readonly [Toast[], (data: SetStateAction<Toast[]>) => void];
164
164
  create: (toast: Omit<Toast, "id" | "timeout">) => `${string}-${string}-${string}-${string}-${string}`;
165
165
  update: (id: string, toast: Partial<Omit<Toast, "id" | "timeout">>) => void;
@@ -174,7 +174,25 @@ declare const DEFAULT_TIMEOUT_MS_BY_TYPE: {
174
174
  };
175
175
  type Toaster = ReturnType<typeof buildToaster>;
176
176
 
177
- interface ToastContainerProps {
177
+ type Placement = 'top-right';
178
+ interface ToastContainerInnerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
179
+ toasts: Toast[];
180
+ /**
181
+ * The z-index of the toast container.
182
+ *
183
+ * @see {@link DEFAULT_TOAST_CONTAINER_Z_INDEX}
184
+ *
185
+ * @default 1000
186
+ */
187
+ zIndex?: number;
188
+ deleteToastById: (id: string) => void;
189
+ /**
190
+ * @default "top-right"
191
+ */
192
+ placement?: Placement;
193
+ }
194
+
195
+ interface ToastContainerProps extends Omit<ToastContainerInnerProps, 'toasts' | 'deleteToastById'> {
178
196
  toaster: Toaster;
179
197
  }
180
198
  declare function ToastContainer({ toaster }: ToastContainerProps): react_jsx_runtime.JSX.Element;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
- import { ReactNode, SetStateAction } from 'react';
3
+ import { ReactNode, SetStateAction, HTMLAttributes } from 'react';
4
4
 
5
5
  interface CopyToClipboardButtonProps {
6
6
  value: string;
@@ -159,7 +159,7 @@ interface Toast {
159
159
  interface BuildToasterOptions {
160
160
  timeoutOverrides?: Partial<Record<ToastType, ToastTimeout>>;
161
161
  }
162
- declare function buildToaster(options: BuildToasterOptions): {
162
+ declare function buildToaster(options?: BuildToasterOptions): {
163
163
  useState: () => readonly [Toast[], (data: SetStateAction<Toast[]>) => void];
164
164
  create: (toast: Omit<Toast, "id" | "timeout">) => `${string}-${string}-${string}-${string}-${string}`;
165
165
  update: (id: string, toast: Partial<Omit<Toast, "id" | "timeout">>) => void;
@@ -174,7 +174,25 @@ declare const DEFAULT_TIMEOUT_MS_BY_TYPE: {
174
174
  };
175
175
  type Toaster = ReturnType<typeof buildToaster>;
176
176
 
177
- interface ToastContainerProps {
177
+ type Placement = 'top-right';
178
+ interface ToastContainerInnerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
179
+ toasts: Toast[];
180
+ /**
181
+ * The z-index of the toast container.
182
+ *
183
+ * @see {@link DEFAULT_TOAST_CONTAINER_Z_INDEX}
184
+ *
185
+ * @default 1000
186
+ */
187
+ zIndex?: number;
188
+ deleteToastById: (id: string) => void;
189
+ /**
190
+ * @default "top-right"
191
+ */
192
+ placement?: Placement;
193
+ }
194
+
195
+ interface ToastContainerProps extends Omit<ToastContainerInnerProps, 'toasts' | 'deleteToastById'> {
178
196
  toaster: Toaster;
179
197
  }
180
198
  declare function ToastContainer({ toaster }: ToastContainerProps): react_jsx_runtime.JSX.Element;
package/dist/index.js CHANGED
@@ -22,6 +22,18 @@ var __spreadValues = (a, b) => {
22
22
  return a;
23
23
  };
24
24
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
25
37
  var __export = (target, all) => {
26
38
  for (var name in all)
27
39
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -428,7 +440,7 @@ function itemIsDefined(e) {
428
440
 
429
441
  // src/toast/createToaster.ts
430
442
  var import_react3 = require("react");
431
- function buildToaster(options) {
443
+ function buildToaster(options = {}) {
432
444
  const { timeoutOverrides = {} } = options;
433
445
  const KEY = "toasts";
434
446
  const state = { [KEY]: [] };
@@ -497,8 +509,8 @@ var DEFAULT_TIMEOUT_MS_BY_TYPE = {
497
509
  danger: "persistent"
498
510
  };
499
511
 
500
- // src/toast/ToastContainerInner.module.css
501
- var ToastContainerInner_default = {};
512
+ // src/toast/ToastContainerInner.tsx
513
+ var import_styled_components5 = __toESM(require("styled-components"));
502
514
 
503
515
  // src/toast/ToastItem.tsx
504
516
  var import_eds_core_react3 = require("@equinor/eds-core-react");
@@ -506,11 +518,6 @@ var import_eds_icons3 = require("@equinor/eds-icons");
506
518
  var import_eds_tokens2 = require("@equinor/eds-tokens");
507
519
  var import_react4 = require("react");
508
520
  var import_styled_components4 = __toESM(require("styled-components"));
509
-
510
- // src/toast/ToastItem.module.css
511
- var ToastItem_default = {};
512
-
513
- // src/toast/ToastItem.tsx
514
521
  var import_jsx_runtime6 = require("react/jsx-runtime");
515
522
  function ToastItem({ toast, onDelete }) {
516
523
  const [isHovered, setIsHovered] = (0, import_react4.useState)(false);
@@ -530,7 +537,6 @@ function ToastItem({ toast, onDelete }) {
530
537
  {
531
538
  elevation: "raised",
532
539
  $toastType: toast.type,
533
- className: `${ToastItem_default.toast} ${ToastItem_default.slideIn}`,
534
540
  onMouseOver: () => setIsHovered(true),
535
541
  onMouseOut: () => setIsHovered(false),
536
542
  children: [
@@ -568,7 +574,39 @@ var StyledPaper = (0, import_styled_components4.default)(import_eds_core_react3.
568
574
  }
569
575
 
570
576
  border: 0;
571
- padding: 12px 16px;
577
+
578
+ transition: 50ms ease-out;
579
+
580
+ border-radius: 4px;
581
+
582
+ padding: 4px 8px 4px 16px;
583
+ display: flex;
584
+ align-items: center;
585
+ justify-content: stretch;
586
+
587
+ border: 2px solid var(--eds_ui_background__medium, rgba(220, 220, 220, 1));
588
+
589
+ @keyframes toast-in-right {
590
+ from {
591
+ opacity: 0;
592
+ transform: translateX(20%);
593
+ }
594
+ to {
595
+ opacity: 1;
596
+ transform: translateX(0);
597
+ }
598
+ }
599
+
600
+ @keyframes toast-out-collapse {
601
+ from {
602
+ height: auto;
603
+ }
604
+ to {
605
+ max-height: 0;
606
+ }
607
+ }
608
+
609
+ animation: toast-in-right 150ms ease-out;
572
610
 
573
611
  ${({ $toastType }) => {
574
612
  switch ($toastType) {
@@ -615,27 +653,54 @@ var StyledPaper = (0, import_styled_components4.default)(import_eds_core_react3.
615
653
 
616
654
  // src/toast/ToastContainerInner.tsx
617
655
  var import_jsx_runtime7 = require("react/jsx-runtime");
618
- function ToastContainerInner({
619
- deleteToastById,
620
- toasts,
621
- placement = "top-right",
622
- toastContainerClassName = ""
623
- }) {
624
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
625
- "div",
626
- {
627
- className: `${ToastContainerInner_default.wrapper} ${getClassNameByPlacement(placement)} ${toastContainerClassName}`,
628
- children: toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ToastItem, { toast, onDelete: deleteToastById }, toast.id))
629
- }
630
- );
656
+ var DEFAULT_TOAST_CONTAINER_Z_INDEX = 1e3;
657
+ function ToastContainerInner(_a) {
658
+ var _b = _a, {
659
+ deleteToastById,
660
+ toasts,
661
+ placement = "top-right",
662
+ zIndex = DEFAULT_TOAST_CONTAINER_Z_INDEX
663
+ } = _b, containerProps = __objRest(_b, [
664
+ "deleteToastById",
665
+ "toasts",
666
+ "placement",
667
+ "zIndex"
668
+ ]);
669
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Container, __spreadProps(__spreadValues({ $placement: placement, $zIndex: zIndex }, containerProps), { children: toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ToastItem, { toast, onDelete: deleteToastById }, toast.id)) }));
631
670
  }
632
- function getClassNameByPlacement(placement) {
633
- switch (placement) {
671
+ var Container = import_styled_components5.default.div`
672
+ position: fixed;
673
+ z-index: ${({ $zIndex }) => $zIndex};
674
+
675
+ padding: 16px;
676
+ margin: -16px;
677
+
678
+ display: flex;
679
+ flex-direction: column;
680
+ gap: 8px;
681
+
682
+ max-height: min(600px, 70dvh);
683
+ width: 24rem;
684
+
685
+ overflow-y: auto;
686
+ overflow-x: hidden;
687
+
688
+ /* Hide when no toasts */
689
+ &:empty {
690
+ display: none;
691
+ }
692
+
693
+ ${({ $placement }) => {
694
+ switch ($placement) {
634
695
  case "top-right": {
635
- return ToastContainerInner_default["top-right"];
696
+ return import_styled_components5.css`
697
+ top: 16px;
698
+ right: 16px;
699
+ `;
636
700
  }
637
701
  }
638
- }
702
+ }}
703
+ `;
639
704
 
640
705
  // src/toast/ToastContainer.tsx
641
706
  var import_jsx_runtime8 = require("react/jsx-runtime");
package/dist/index.mjs CHANGED
@@ -17,6 +17,18 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
20
32
  var __async = (__this, __arguments, generator) => {
21
33
  return new Promise((resolve, reject) => {
22
34
  var fulfilled = (value) => {
@@ -384,7 +396,7 @@ function itemIsDefined(e) {
384
396
 
385
397
  // src/toast/createToaster.ts
386
398
  import { useEffect as useEffect2, useState as useReactState } from "react";
387
- function buildToaster(options) {
399
+ function buildToaster(options = {}) {
388
400
  const { timeoutOverrides = {} } = options;
389
401
  const KEY = "toasts";
390
402
  const state = { [KEY]: [] };
@@ -453,8 +465,8 @@ var DEFAULT_TIMEOUT_MS_BY_TYPE = {
453
465
  danger: "persistent"
454
466
  };
455
467
 
456
- // src/toast/ToastContainerInner.module.css
457
- var ToastContainerInner_default = {};
468
+ // src/toast/ToastContainerInner.tsx
469
+ import styled5, { css as css2 } from "styled-components";
458
470
 
459
471
  // src/toast/ToastItem.tsx
460
472
  import { Button as Button3, Icon as Icon3, Paper, Typography as Typography2 } from "@equinor/eds-core-react";
@@ -462,11 +474,6 @@ import { check as check2, clear, error_filled as error_filled2, info_circle, war
462
474
  import { tokens as tokens2 } from "@equinor/eds-tokens";
463
475
  import { useEffect as useEffect3, useState as useState3 } from "react";
464
476
  import styled4, { css } from "styled-components";
465
-
466
- // src/toast/ToastItem.module.css
467
- var ToastItem_default = {};
468
-
469
- // src/toast/ToastItem.tsx
470
477
  import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
471
478
  function ToastItem({ toast, onDelete }) {
472
479
  const [isHovered, setIsHovered] = useState3(false);
@@ -486,7 +493,6 @@ function ToastItem({ toast, onDelete }) {
486
493
  {
487
494
  elevation: "raised",
488
495
  $toastType: toast.type,
489
- className: `${ToastItem_default.toast} ${ToastItem_default.slideIn}`,
490
496
  onMouseOver: () => setIsHovered(true),
491
497
  onMouseOut: () => setIsHovered(false),
492
498
  children: [
@@ -524,7 +530,39 @@ var StyledPaper = styled4(Paper)`
524
530
  }
525
531
 
526
532
  border: 0;
527
- padding: 12px 16px;
533
+
534
+ transition: 50ms ease-out;
535
+
536
+ border-radius: 4px;
537
+
538
+ padding: 4px 8px 4px 16px;
539
+ display: flex;
540
+ align-items: center;
541
+ justify-content: stretch;
542
+
543
+ border: 2px solid var(--eds_ui_background__medium, rgba(220, 220, 220, 1));
544
+
545
+ @keyframes toast-in-right {
546
+ from {
547
+ opacity: 0;
548
+ transform: translateX(20%);
549
+ }
550
+ to {
551
+ opacity: 1;
552
+ transform: translateX(0);
553
+ }
554
+ }
555
+
556
+ @keyframes toast-out-collapse {
557
+ from {
558
+ height: auto;
559
+ }
560
+ to {
561
+ max-height: 0;
562
+ }
563
+ }
564
+
565
+ animation: toast-in-right 150ms ease-out;
528
566
 
529
567
  ${({ $toastType }) => {
530
568
  switch ($toastType) {
@@ -571,27 +609,54 @@ var StyledPaper = styled4(Paper)`
571
609
 
572
610
  // src/toast/ToastContainerInner.tsx
573
611
  import { jsx as jsx7 } from "react/jsx-runtime";
574
- function ToastContainerInner({
575
- deleteToastById,
576
- toasts,
577
- placement = "top-right",
578
- toastContainerClassName = ""
579
- }) {
580
- return /* @__PURE__ */ jsx7(
581
- "div",
582
- {
583
- className: `${ToastContainerInner_default.wrapper} ${getClassNameByPlacement(placement)} ${toastContainerClassName}`,
584
- children: toasts.map((toast) => /* @__PURE__ */ jsx7(ToastItem, { toast, onDelete: deleteToastById }, toast.id))
585
- }
586
- );
612
+ var DEFAULT_TOAST_CONTAINER_Z_INDEX = 1e3;
613
+ function ToastContainerInner(_a) {
614
+ var _b = _a, {
615
+ deleteToastById,
616
+ toasts,
617
+ placement = "top-right",
618
+ zIndex = DEFAULT_TOAST_CONTAINER_Z_INDEX
619
+ } = _b, containerProps = __objRest(_b, [
620
+ "deleteToastById",
621
+ "toasts",
622
+ "placement",
623
+ "zIndex"
624
+ ]);
625
+ return /* @__PURE__ */ jsx7(Container, __spreadProps(__spreadValues({ $placement: placement, $zIndex: zIndex }, containerProps), { children: toasts.map((toast) => /* @__PURE__ */ jsx7(ToastItem, { toast, onDelete: deleteToastById }, toast.id)) }));
587
626
  }
588
- function getClassNameByPlacement(placement) {
589
- switch (placement) {
627
+ var Container = styled5.div`
628
+ position: fixed;
629
+ z-index: ${({ $zIndex }) => $zIndex};
630
+
631
+ padding: 16px;
632
+ margin: -16px;
633
+
634
+ display: flex;
635
+ flex-direction: column;
636
+ gap: 8px;
637
+
638
+ max-height: min(600px, 70dvh);
639
+ width: 24rem;
640
+
641
+ overflow-y: auto;
642
+ overflow-x: hidden;
643
+
644
+ /* Hide when no toasts */
645
+ &:empty {
646
+ display: none;
647
+ }
648
+
649
+ ${({ $placement }) => {
650
+ switch ($placement) {
590
651
  case "top-right": {
591
- return ToastContainerInner_default["top-right"];
652
+ return css2`
653
+ top: 16px;
654
+ right: 16px;
655
+ `;
592
656
  }
593
657
  }
594
- }
658
+ }}
659
+ `;
595
660
 
596
661
  // src/toast/ToastContainer.tsx
597
662
  import { jsx as jsx8 } from "react/jsx-runtime";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/cpl-error-snackbar-react",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
package/dist/index.css DELETED
@@ -1,52 +0,0 @@
1
- /* src/toast/ToastContainerInner.module.css */
2
- .wrapper {
3
- position: fixed;
4
- padding: 16px;
5
- margin: -16px;
6
- display: flex;
7
- flex-direction: column;
8
- gap: 8px;
9
- max-height: min(600px, 70dvh);
10
- width: 24rem;
11
- overflow-y: auto;
12
- overflow-x: hidden;
13
- &:empty {
14
- display: none;
15
- }
16
- }
17
- .top-right {
18
- top: 16px;
19
- right: 16px;
20
- }
21
-
22
- /* src/toast/ToastItem.module.css */
23
- .slideIn {
24
- animation: toast-in-right 150ms ease-out;
25
- }
26
- .toast {
27
- transition: 50ms ease-out;
28
- border-radius: 4px;
29
- padding: 4px 8px 4px 16px;
30
- display: flex;
31
- align-items: center;
32
- justify-content: stretch;
33
- border: 2px solid var(--eds_ui_background__medium, rgba(220, 220, 220, 1));
34
- }
35
- @keyframes toast-in-right {
36
- from {
37
- opacity: 0;
38
- transform: translateX(20%);
39
- }
40
- to {
41
- opacity: 1;
42
- transform: translateX(0);
43
- }
44
- }
45
- @keyframes toast-out-collapse {
46
- from {
47
- height: auto;
48
- }
49
- to {
50
- max-height: 0;
51
- }
52
- }