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

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
@@ -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;
package/dist/index.d.ts CHANGED
@@ -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;
package/dist/index.js CHANGED
@@ -428,7 +428,7 @@ function itemIsDefined(e) {
428
428
 
429
429
  // src/toast/createToaster.ts
430
430
  var import_react3 = require("react");
431
- function buildToaster(options) {
431
+ function buildToaster(options = {}) {
432
432
  const { timeoutOverrides = {} } = options;
433
433
  const KEY = "toasts";
434
434
  const state = { [KEY]: [] };
@@ -497,8 +497,8 @@ var DEFAULT_TIMEOUT_MS_BY_TYPE = {
497
497
  danger: "persistent"
498
498
  };
499
499
 
500
- // src/toast/ToastContainerInner.module.css
501
- var ToastContainerInner_default = {};
500
+ // src/toast/ToastContainerInner.tsx
501
+ var import_styled_components5 = __toESM(require("styled-components"));
502
502
 
503
503
  // src/toast/ToastItem.tsx
504
504
  var import_eds_core_react3 = require("@equinor/eds-core-react");
@@ -506,11 +506,6 @@ var import_eds_icons3 = require("@equinor/eds-icons");
506
506
  var import_eds_tokens2 = require("@equinor/eds-tokens");
507
507
  var import_react4 = require("react");
508
508
  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
509
  var import_jsx_runtime6 = require("react/jsx-runtime");
515
510
  function ToastItem({ toast, onDelete }) {
516
511
  const [isHovered, setIsHovered] = (0, import_react4.useState)(false);
@@ -530,7 +525,6 @@ function ToastItem({ toast, onDelete }) {
530
525
  {
531
526
  elevation: "raised",
532
527
  $toastType: toast.type,
533
- className: `${ToastItem_default.toast} ${ToastItem_default.slideIn}`,
534
528
  onMouseOver: () => setIsHovered(true),
535
529
  onMouseOut: () => setIsHovered(false),
536
530
  children: [
@@ -568,7 +562,39 @@ var StyledPaper = (0, import_styled_components4.default)(import_eds_core_react3.
568
562
  }
569
563
 
570
564
  border: 0;
571
- padding: 12px 16px;
565
+
566
+ transition: 50ms ease-out;
567
+
568
+ border-radius: 4px;
569
+
570
+ padding: 4px 8px 4px 16px;
571
+ display: flex;
572
+ align-items: center;
573
+ justify-content: stretch;
574
+
575
+ border: 2px solid var(--eds_ui_background__medium, rgba(220, 220, 220, 1));
576
+
577
+ @keyframes toast-in-right {
578
+ from {
579
+ opacity: 0;
580
+ transform: translateX(20%);
581
+ }
582
+ to {
583
+ opacity: 1;
584
+ transform: translateX(0);
585
+ }
586
+ }
587
+
588
+ @keyframes toast-out-collapse {
589
+ from {
590
+ height: auto;
591
+ }
592
+ to {
593
+ max-height: 0;
594
+ }
595
+ }
596
+
597
+ animation: toast-in-right 150ms ease-out;
572
598
 
573
599
  ${({ $toastType }) => {
574
600
  switch ($toastType) {
@@ -621,21 +647,40 @@ function ToastContainerInner({
621
647
  placement = "top-right",
622
648
  toastContainerClassName = ""
623
649
  }) {
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
- );
650
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Container, { $placement: placement, className: toastContainerClassName, children: toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ToastItem, { toast, onDelete: deleteToastById }, toast.id)) });
631
651
  }
632
- function getClassNameByPlacement(placement) {
633
- switch (placement) {
652
+ var Container = import_styled_components5.default.div`
653
+ position: fixed;
654
+
655
+ padding: 16px;
656
+ margin: -16px;
657
+
658
+ display: flex;
659
+ flex-direction: column;
660
+ gap: 8px;
661
+
662
+ max-height: min(600px, 70dvh);
663
+ width: 24rem;
664
+
665
+ overflow-y: auto;
666
+ overflow-x: hidden;
667
+
668
+ /* Hide when no toasts */
669
+ &:empty {
670
+ display: none;
671
+ }
672
+
673
+ ${({ $placement }) => {
674
+ switch ($placement) {
634
675
  case "top-right": {
635
- return ToastContainerInner_default["top-right"];
676
+ return import_styled_components5.css`
677
+ top: 16px;
678
+ right: 16px;
679
+ `;
636
680
  }
637
681
  }
638
- }
682
+ }}
683
+ `;
639
684
 
640
685
  // src/toast/ToastContainer.tsx
641
686
  var import_jsx_runtime8 = require("react/jsx-runtime");
package/dist/index.mjs CHANGED
@@ -384,7 +384,7 @@ function itemIsDefined(e) {
384
384
 
385
385
  // src/toast/createToaster.ts
386
386
  import { useEffect as useEffect2, useState as useReactState } from "react";
387
- function buildToaster(options) {
387
+ function buildToaster(options = {}) {
388
388
  const { timeoutOverrides = {} } = options;
389
389
  const KEY = "toasts";
390
390
  const state = { [KEY]: [] };
@@ -453,8 +453,8 @@ var DEFAULT_TIMEOUT_MS_BY_TYPE = {
453
453
  danger: "persistent"
454
454
  };
455
455
 
456
- // src/toast/ToastContainerInner.module.css
457
- var ToastContainerInner_default = {};
456
+ // src/toast/ToastContainerInner.tsx
457
+ import styled5, { css as css2 } from "styled-components";
458
458
 
459
459
  // src/toast/ToastItem.tsx
460
460
  import { Button as Button3, Icon as Icon3, Paper, Typography as Typography2 } from "@equinor/eds-core-react";
@@ -462,11 +462,6 @@ import { check as check2, clear, error_filled as error_filled2, info_circle, war
462
462
  import { tokens as tokens2 } from "@equinor/eds-tokens";
463
463
  import { useEffect as useEffect3, useState as useState3 } from "react";
464
464
  import styled4, { css } from "styled-components";
465
-
466
- // src/toast/ToastItem.module.css
467
- var ToastItem_default = {};
468
-
469
- // src/toast/ToastItem.tsx
470
465
  import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
471
466
  function ToastItem({ toast, onDelete }) {
472
467
  const [isHovered, setIsHovered] = useState3(false);
@@ -486,7 +481,6 @@ function ToastItem({ toast, onDelete }) {
486
481
  {
487
482
  elevation: "raised",
488
483
  $toastType: toast.type,
489
- className: `${ToastItem_default.toast} ${ToastItem_default.slideIn}`,
490
484
  onMouseOver: () => setIsHovered(true),
491
485
  onMouseOut: () => setIsHovered(false),
492
486
  children: [
@@ -524,7 +518,39 @@ var StyledPaper = styled4(Paper)`
524
518
  }
525
519
 
526
520
  border: 0;
527
- padding: 12px 16px;
521
+
522
+ transition: 50ms ease-out;
523
+
524
+ border-radius: 4px;
525
+
526
+ padding: 4px 8px 4px 16px;
527
+ display: flex;
528
+ align-items: center;
529
+ justify-content: stretch;
530
+
531
+ border: 2px solid var(--eds_ui_background__medium, rgba(220, 220, 220, 1));
532
+
533
+ @keyframes toast-in-right {
534
+ from {
535
+ opacity: 0;
536
+ transform: translateX(20%);
537
+ }
538
+ to {
539
+ opacity: 1;
540
+ transform: translateX(0);
541
+ }
542
+ }
543
+
544
+ @keyframes toast-out-collapse {
545
+ from {
546
+ height: auto;
547
+ }
548
+ to {
549
+ max-height: 0;
550
+ }
551
+ }
552
+
553
+ animation: toast-in-right 150ms ease-out;
528
554
 
529
555
  ${({ $toastType }) => {
530
556
  switch ($toastType) {
@@ -577,21 +603,40 @@ function ToastContainerInner({
577
603
  placement = "top-right",
578
604
  toastContainerClassName = ""
579
605
  }) {
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
- );
606
+ return /* @__PURE__ */ jsx7(Container, { $placement: placement, className: toastContainerClassName, children: toasts.map((toast) => /* @__PURE__ */ jsx7(ToastItem, { toast, onDelete: deleteToastById }, toast.id)) });
587
607
  }
588
- function getClassNameByPlacement(placement) {
589
- switch (placement) {
608
+ var Container = styled5.div`
609
+ position: fixed;
610
+
611
+ padding: 16px;
612
+ margin: -16px;
613
+
614
+ display: flex;
615
+ flex-direction: column;
616
+ gap: 8px;
617
+
618
+ max-height: min(600px, 70dvh);
619
+ width: 24rem;
620
+
621
+ overflow-y: auto;
622
+ overflow-x: hidden;
623
+
624
+ /* Hide when no toasts */
625
+ &:empty {
626
+ display: none;
627
+ }
628
+
629
+ ${({ $placement }) => {
630
+ switch ($placement) {
590
631
  case "top-right": {
591
- return ToastContainerInner_default["top-right"];
632
+ return css2`
633
+ top: 16px;
634
+ right: 16px;
635
+ `;
592
636
  }
593
637
  }
594
- }
638
+ }}
639
+ `;
595
640
 
596
641
  // src/toast/ToastContainer.tsx
597
642
  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.2",
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
- }