@rainlanguage/ui-components 0.0.1-alpha.100 → 0.0.1-alpha.101

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.
@@ -1,16 +1,39 @@
1
1
  <script>import { Toast } from "flowbite-svelte";
2
2
  import { slide } from "svelte/transition";
3
3
  import { CheckCircleSolid, CloseCircleSolid } from "flowbite-svelte-icons";
4
+ import { useToasts } from "../providers/toasts/useToasts";
4
5
  export let toast;
6
+ export let i;
7
+ const { removeToast } = useToasts();
5
8
  </script>
6
9
 
7
- <Toast dismissable={true} transition={slide} color={toast.color} class="mb-2">
10
+ <Toast
11
+ on:close={() => removeToast(i)}
12
+ dismissable={true}
13
+ transition={slide}
14
+ color={toast.color}
15
+ class="mb-2"
16
+ >
8
17
  <svelte:fragment slot="icon">
9
18
  {#if toast.type === 'success'}
10
- <CheckCircleSolid class="h-5 w-5" />
19
+ <CheckCircleSolid class="h-5 w-5" data-testid="success-icon" />
11
20
  {:else if toast.type === 'error'}
12
- <CloseCircleSolid class="h-5 w-5" />
21
+ <CloseCircleSolid class="h-5 w-5" data-testid="error-icon" />
13
22
  {/if}
14
23
  </svelte:fragment>
15
- {toast.message}
24
+ <p>{toast.message}</p>
25
+ {#if toast.links}
26
+ <div class="flex flex-col">
27
+ {#each toast.links as { link, label }}
28
+ <a
29
+ href={link}
30
+ target="_blank"
31
+ rel="noopener noreferrer"
32
+ class="text-blue-500 hover:underline"
33
+ >
34
+ {label}
35
+ </a>
36
+ {/each}
37
+ </div>
38
+ {/if}
16
39
  </Toast>
@@ -3,6 +3,7 @@ import type { ToastProps } from '../types/toast';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  toast: ToastProps;
6
+ i: number;
6
7
  };
7
8
  events: {
8
9
  [evt: string]: CustomEvent<any>;
@@ -2,14 +2,14 @@
2
2
  import { setToastsContext } from "./context";
3
3
  import { writable } from "svelte/store";
4
4
  import { fade } from "svelte/transition";
5
- export let toasts = writable([]);
5
+ const toasts = writable([]);
6
6
  setToastsContext(toasts);
7
7
  </script>
8
8
 
9
9
  <div class="fixed right-4 top-4 z-[100]">
10
- {#each $toasts as toast}
10
+ {#each $toasts as toast, i}
11
11
  <div out:fade data-testid="toast">
12
- <ToastDetail {toast} />
12
+ <ToastDetail {toast} {i} />
13
13
  </div>
14
14
  {/each}
15
15
  </div>
@@ -1,10 +1,6 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import { type Writable } from 'svelte/store';
3
- import type { ToastProps } from '../../types/toast';
4
2
  declare const __propDef: {
5
- props: {
6
- toasts?: Writable<ToastProps[]>;
7
- };
3
+ props: Record<string, never>;
8
4
  events: {
9
5
  [evt: string]: CustomEvent<any>;
10
6
  };
@@ -7,5 +7,8 @@ export declare const TOASTS_KEY = "rain:ui-components:toasts";
7
7
  export declare function getToastsContext(): Writable<ToastProps[]>;
8
8
  /**
9
9
  * Sets the toasts store in Svelte's context
10
+ *
11
+ * @param {Writable<ToastProps[]>} toasts - The writable store containing all active toast notifications
12
+ * @returns {void}
10
13
  */
11
14
  export declare function setToastsContext(toasts: Writable<ToastProps[]>): void;
@@ -13,6 +13,9 @@ export function getToastsContext() {
13
13
  }
14
14
  /**
15
15
  * Sets the toasts store in Svelte's context
16
+ *
17
+ * @param {Writable<ToastProps[]>} toasts - The writable store containing all active toast notifications
18
+ * @returns {void}
16
19
  */
17
20
  export function setToastsContext(toasts) {
18
21
  setContext(TOASTS_KEY, toasts);
@@ -3,7 +3,10 @@ import type { ToastProps } from '../../types/toast';
3
3
  * Hook for managing toast notifications in the application.
4
4
  * Provides functionality to add, remove, and access toast notifications.
5
5
  *
6
- * @returns An object containing the toast store and methods to manipulate toasts
6
+ * @returns {Object} An object containing:
7
+ * - toasts: Writable store containing all active toast notifications
8
+ * - addToast: Function to add a new toast notification
9
+ * - removeToast: Function to remove a toast notification by index
7
10
  */
8
11
  export declare function useToasts(): {
9
12
  toasts: import("svelte/store").Writable<ToastProps[]>;
@@ -1,18 +1,20 @@
1
1
  import { getToastsContext } from './context';
2
- import { get } from 'svelte/store';
3
- import { v4 as uuidv4 } from 'uuid';
4
2
  /**
5
3
  * Hook for managing toast notifications in the application.
6
4
  * Provides functionality to add, remove, and access toast notifications.
7
5
  *
8
- * @returns An object containing the toast store and methods to manipulate toasts
6
+ * @returns {Object} An object containing:
7
+ * - toasts: Writable store containing all active toast notifications
8
+ * - addToast: Function to add a new toast notification
9
+ * - removeToast: Function to remove a toast notification by index
9
10
  */
10
11
  export function useToasts() {
11
12
  const toasts = getToastsContext();
12
13
  /**
13
- * Removes a toast notification by its index
14
+ * Removes a toast notification by its index from the toasts store
14
15
  *
15
- * @param index - The index of the toast to remove
16
+ * @param {number} index - The index of the toast to remove
17
+ * @returns {void}
16
18
  */
17
19
  const removeToast = (index) => {
18
20
  toasts.update((toasts) => {
@@ -23,28 +25,20 @@ export function useToasts() {
23
25
  });
24
26
  };
25
27
  /**
26
- * Adds a new toast notification and automatically removes it after 3 seconds
28
+ * Adds a new toast notification to the toasts store
27
29
  *
28
- * @param toast - The toast properties (message and type)
30
+ * @param {ToastProps} toast - The toast configuration object containing:
31
+ * - message: The text to display in the toast
32
+ * - type: The type of toast (success, error, warning, info)
33
+ * - color: The color theme of the toast (green, red, yellow, blue)
34
+ * - links: Optional array of links to display in the toast
35
+ * @returns {void}
29
36
  */
30
37
  const addToast = (toast) => {
31
- const newToast = { ...toast, id: uuidv4() };
32
- let addedToastIndex = -1;
33
38
  toasts.update((toasts) => {
34
- const updatedToasts = [...toasts, newToast];
35
- addedToastIndex = updatedToasts.length - 1;
39
+ const updatedToasts = [...toasts, toast];
36
40
  return updatedToasts;
37
41
  });
38
- const toastId = newToast.id;
39
- if (addedToastIndex > -1) {
40
- setTimeout(() => {
41
- const currentToasts = get(toasts);
42
- const currentIndex = currentToasts.findIndex((t) => t.id === toastId);
43
- if (currentIndex > -1) {
44
- removeToast(currentIndex);
45
- }
46
- }, 3000);
47
- }
48
42
  };
49
43
  return {
50
44
  toasts,
@@ -2,5 +2,9 @@ export interface ToastProps {
2
2
  message: string;
3
3
  type: 'success' | 'error' | 'warning' | 'info';
4
4
  color: 'green' | 'red' | 'yellow' | 'blue';
5
- id?: string;
5
+ links?: ToastLink[];
6
6
  }
7
+ export type ToastLink = {
8
+ link: string;
9
+ label: string;
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainlanguage/ui-components",
3
- "version": "0.0.1-alpha.100",
3
+ "version": "0.0.1-alpha.101",
4
4
  "description": "A component library for building Svelte applications to be used with Raindex.",
5
5
  "license": "LicenseRef-DCL-1.0",
6
6
  "author": "Rain Open Source Software Ltd",
@@ -53,7 +53,7 @@
53
53
  "@fontsource/dm-sans": "5.1.0",
54
54
  "@imask/svelte": "7.6.1",
55
55
  "@observablehq/plot": "0.6.16",
56
- "@rainlanguage/orderbook": "0.0.1-alpha.100",
56
+ "@rainlanguage/orderbook": "0.0.1-alpha.101",
57
57
  "@reown/appkit": "1.6.4",
58
58
  "@reown/appkit-adapter-wagmi": "1.6.4",
59
59
  "@sentry/sveltekit": "7.120.0",