@softwareone/spi-sv5-library 0.0.3 → 0.0.5

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/README.md CHANGED
@@ -14,10 +14,11 @@ npm install @softwareone/swo-spi-svelte5-library
14
14
  Import the components you need into your Svelte application:
15
15
 
16
16
  ```javascript
17
- import { Button, Modal, Spinner } from '@softwareone/swo-spi-svelte5-library';
17
+ import { Button, Modal, Spinner, Toaster, addToast, type Toast } from '@softwareone/swo-spi-svelte5-library';
18
18
  ```
19
19
 
20
20
  # List of components
21
21
  - Button
22
22
  - Modal
23
23
  - Spinner
24
+ - Toaster
@@ -4,18 +4,20 @@
4
4
  variant?: 'primary' | 'danger';
5
5
  disabled?: boolean
6
6
  onClick?: () => void;
7
+ name?: any;
7
8
  }
8
9
 
9
- let { type, variant, disabled, onClick }: ButtonProps = $props();
10
+ let { type, variant, disabled, onClick, name }: ButtonProps = $props();
10
11
 
11
12
  type = type || 'primary';
12
13
  variant = variant || 'primary';
13
14
  disabled = disabled || false;
15
+ name = name || 'Button';
14
16
 
15
17
  let className = `btn-${type}-${variant}`;
16
18
  </script>
17
19
 
18
- <button class={className} disabled={disabled} onclick={onClick}>Button</button>
20
+ <button class={className} disabled={disabled} onclick={onClick}>{name}</button>
19
21
 
20
22
  <style>
21
23
  .btn-primary-primary,
@@ -3,6 +3,7 @@ interface ButtonProps {
3
3
  variant?: 'primary' | 'danger';
4
4
  disabled?: boolean;
5
5
  onClick?: () => void;
6
+ name?: any;
6
7
  }
7
8
  declare const Button: import("svelte").Component<ButtonProps, {}, "">;
8
9
  type Button = ReturnType<typeof Button>;
@@ -0,0 +1,98 @@
1
+ <script lang="ts">
2
+ import { getToast } from './toastState.svelte';
3
+
4
+ let { duration }:{duration?: number | undefined} = $props();
5
+
6
+ const toast = getToast(duration);
7
+
8
+ const getToastColor = (type: string): string => {
9
+ const colors: Record<string, string> = {
10
+ info: '#472AFF',
11
+ warning: '#E87D1E',
12
+ danger: '#DC182C',
13
+ neutral: '#6B7180',
14
+ success: '#008556'
15
+ };
16
+ return colors[type] || '#6B7180'; // Default to neutral if type is unknown
17
+ };
18
+
19
+ </script>
20
+
21
+ {#if toast.msg.length > 0}
22
+ <div class="toast-container">
23
+ {#each toast.msg as msg}
24
+ <div class="toast">
25
+ <div>
26
+ <svg
27
+ xmlns="http://www.w3.org/2000/svg"
28
+ width="8"
29
+ height="36"
30
+ viewBox="0 0 8 36"
31
+ fill="none"
32
+ >
33
+ <rect width="8" height="36" rx="4" fill={getToastColor(msg.type)} />
34
+ </svg>
35
+ </div>
36
+ <div class="toast-content">
37
+ <div>{msg.message}</div>
38
+ <div class="toast-content-link">View details</div>
39
+ </div>
40
+ </div>
41
+ {/each}
42
+ </div>
43
+ {/if}
44
+
45
+ <style>
46
+ .toast-container {
47
+ position: fixed;
48
+ top: 16px;
49
+ right: 16px;
50
+ z-index: 9999;
51
+ display: flex;
52
+ flex-direction: column;
53
+ gap: 16px;
54
+ }
55
+ .toast {
56
+ display: inline-flex;
57
+ padding: 8px;
58
+ justify-content: flex-start;
59
+ align-items: center;
60
+ gap: 16px;
61
+ border-radius: 8px;
62
+ border: 1px solid var(--gray-2, #e0e5e8);
63
+ background: var(--brand-white, #fff);
64
+ /* shadow/dropdown */
65
+ box-shadow:
66
+ 0px 4px 5px 0px rgba(51, 56, 64, 0.15),
67
+ 0px 1px 3px 0px rgba(51, 56, 64, 0.2),
68
+ 0px 1px 16px 0px rgba(51, 56, 64, 0.1);
69
+ }
70
+ .toast-content {
71
+ display: flex;
72
+ padding: 8px 0px;
73
+ align-items: flex-start;
74
+ gap: 8px;
75
+ color: var(--brand-type, #000);
76
+
77
+ /* regular/2 */
78
+ font-family: 'Neue Haas Grotesk Display Pro', sans-serif;
79
+ font-size: 14px;
80
+ font-style: normal;
81
+ font-weight: 400;
82
+ line-height: 20px; /* 142.857% */
83
+ }
84
+ .toast-content-link {
85
+ display: flex;
86
+ align-items: flex-start;
87
+ color: var(--alerts-info-4, #2b1999);
88
+ font-family: 'Neue Haas Grotesk Display Pro', sans-serif;
89
+ font-size: 14px;
90
+ font-style: normal;
91
+ font-weight: 400;
92
+ line-height: 20px; /* 142.857% */
93
+ }
94
+ .toast-content-link:hover {
95
+ color: var(--brand-primary, #472aff);
96
+ text-decoration: underline;
97
+ }
98
+ </style>
@@ -0,0 +1,6 @@
1
+ type $$ComponentProps = {
2
+ duration?: number | undefined;
3
+ };
4
+ declare const Toast: import("svelte").Component<$$ComponentProps, {}, "">;
5
+ type Toast = ReturnType<typeof Toast>;
6
+ export default Toast;
@@ -0,0 +1,14 @@
1
+ type ToastType = 'info' | 'success' | 'warning' | 'danger' | 'neutral';
2
+ export interface Toast {
3
+ type: ToastType;
4
+ message: string;
5
+ }
6
+ interface ToastState extends Toast {
7
+ id: string;
8
+ }
9
+ export declare function getToast(duration?: number): {
10
+ msg: ToastState[];
11
+ duration: number;
12
+ };
13
+ export declare function addToast(toast: Toast): void;
14
+ export {};
@@ -0,0 +1,20 @@
1
+ const toastState = $state({
2
+ msg: [],
3
+ duration: 5000,
4
+ });
5
+ export function getToast(duration) {
6
+ if (duration) {
7
+ toastState.duration = duration;
8
+ }
9
+ return toastState;
10
+ }
11
+ export function addToast(toast) {
12
+ const newToast = { ...toast, id: crypto.randomUUID() };
13
+ toastState.msg.push(newToast);
14
+ scheduleToastRemoval(newToast.id);
15
+ }
16
+ function scheduleToastRemoval(id) {
17
+ setTimeout(() => {
18
+ toastState.msg = toastState.msg.filter((toast) => toast.id !== id);
19
+ }, toastState.duration);
20
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import Button from "./Button/Button.svelte";
2
2
  import Modal from "./Modal/Modal.svelte";
3
3
  import Spinner from "./Spinner/Spinner.svelte";
4
- export { Button, Modal, Spinner };
4
+ import Toaster from "./Toast/Toast.svelte";
5
+ import { addToast, type Toast } from "./Toast/toastState.svelte";
6
+ export { Button, Modal, Spinner, Toaster, addToast, type Toast };
package/dist/index.js CHANGED
@@ -2,4 +2,6 @@
2
2
  import Button from "./Button/Button.svelte";
3
3
  import Modal from "./Modal/Modal.svelte";
4
4
  import Spinner from "./Spinner/Spinner.svelte";
5
- export { Button, Modal, Spinner };
5
+ import Toaster from "./Toast/Toast.svelte";
6
+ import { addToast } from "./Toast/toastState.svelte";
7
+ export { Button, Modal, Spinner, Toaster, addToast };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwareone/spi-sv5-library",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Svelte components",
5
5
  "keywords": [
6
6
  "svelte",