@rainlanguage/ui-components 0.0.1-alpha.93 → 0.0.1-alpha.95

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.
@@ -0,0 +1,16 @@
1
+ <script>import { Toast } from "flowbite-svelte";
2
+ import { slide } from "svelte/transition";
3
+ import { CheckCircleSolid, CloseCircleSolid } from "flowbite-svelte-icons";
4
+ export let toast;
5
+ </script>
6
+
7
+ <Toast dismissable={true} transition={slide} color={toast.color} class="mb-2">
8
+ <svelte:fragment slot="icon">
9
+ {#if toast.type === 'success'}
10
+ <CheckCircleSolid class="h-5 w-5" />
11
+ {:else if toast.type === 'error'}
12
+ <CloseCircleSolid class="h-5 w-5" />
13
+ {/if}
14
+ </svelte:fragment>
15
+ {toast.message}
16
+ </Toast>
@@ -0,0 +1,19 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { ToastProps } from '../types/toast';
3
+ declare const __propDef: {
4
+ props: {
5
+ toast: ToastProps;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ exports?: {} | undefined;
12
+ bindings?: string | undefined;
13
+ };
14
+ export type ToastDetailProps = typeof __propDef.props;
15
+ export type ToastDetailEvents = typeof __propDef.events;
16
+ export type ToastDetailSlots = typeof __propDef.slots;
17
+ export default class ToastDetail extends SvelteComponent<ToastDetailProps, ToastDetailEvents, ToastDetailSlots> {
18
+ }
19
+ export {};
package/dist/index.d.ts CHANGED
@@ -70,6 +70,7 @@ export { TransactionStatus, TransactionErrorMessage, type TransactionState, type
70
70
  export type { DeploymentArgs, DepositOrWithdrawArgs, OrderRemoveArgs } from './types/transaction';
71
71
  export type { DepositOrWithdrawModalProps, OrderRemoveModalProps, QuoteDebugModalHandler, DebugTradeModalHandler, DeployModalProps, DisclaimerModalProps } from './types/modal';
72
72
  export type { ValidStrategyDetail, InvalidStrategyDetail } from './types/strategy';
73
+ export type { ToastProps } from './types/toast';
73
74
  export { createResolvableQuery, createResolvableInfiniteQuery } from './__mocks__/queries';
74
75
  export { formatTimestampSecondsAsLocal, timestampSecondsToUTCTimestamp, promiseTimeout } from './services/time';
75
76
  export { bigintStringToHex, HEX_INPUT_REGEX } from './utils/hex';
@@ -88,9 +89,11 @@ export { default as logoDark } from './assets/logo-dark.svg';
88
89
  export { default as GuiProvider } from './providers/GuiProvider.svelte';
89
90
  export { default as WalletProvider } from './providers/wallet/WalletProvider.svelte';
90
91
  export { default as RegistryProvider } from './providers/registry/RegistryProvider.svelte';
92
+ export { default as ToastProvider } from './providers/toasts/ToastProvider.svelte';
91
93
  export { useGui } from './hooks/useGui';
92
94
  export { useAccount } from './providers/wallet/useAccount';
93
95
  export { useRegistry } from './providers/registry/useRegistry';
96
+ export { useToasts } from './providers/toasts/useToasts';
94
97
  export { RegistryManager } from './providers/registry/RegistryManager';
95
98
  export { mockPageStore } from './__mocks__/stores';
96
99
  export { mockConfigSource } from './__mocks__/settings';
package/dist/index.js CHANGED
@@ -89,10 +89,12 @@ export { default as logoDark } from './assets/logo-dark.svg';
89
89
  export { default as GuiProvider } from './providers/GuiProvider.svelte';
90
90
  export { default as WalletProvider } from './providers/wallet/WalletProvider.svelte';
91
91
  export { default as RegistryProvider } from './providers/registry/RegistryProvider.svelte';
92
+ export { default as ToastProvider } from './providers/toasts/ToastProvider.svelte';
92
93
  // Hooks
93
94
  export { useGui } from './hooks/useGui';
94
95
  export { useAccount } from './providers/wallet/useAccount';
95
96
  export { useRegistry } from './providers/registry/useRegistry';
97
+ export { useToasts } from './providers/toasts/useToasts';
96
98
  // Classes
97
99
  export { RegistryManager } from './providers/registry/RegistryManager';
98
100
  // Mocks
@@ -0,0 +1,17 @@
1
+ <script>import ToastDetail from "../../components/ToastDetail.svelte";
2
+ import { setToastsContext } from "./context";
3
+ import { writable } from "svelte/store";
4
+ import { fade } from "svelte/transition";
5
+ export let toasts = writable([]);
6
+ setToastsContext(toasts);
7
+ </script>
8
+
9
+ <div class="fixed right-4 top-4 z-[100]">
10
+ {#each $toasts as toast}
11
+ <div out:fade data-testid="toast">
12
+ <ToastDetail {toast} />
13
+ </div>
14
+ {/each}
15
+ </div>
16
+
17
+ <slot />
@@ -0,0 +1,22 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import { type Writable } from 'svelte/store';
3
+ import type { ToastProps } from '../../types/toast';
4
+ declare const __propDef: {
5
+ props: {
6
+ toasts?: Writable<ToastProps[]>;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {
12
+ default: {};
13
+ };
14
+ exports?: {} | undefined;
15
+ bindings?: string | undefined;
16
+ };
17
+ export type ToastProviderProps = typeof __propDef.props;
18
+ export type ToastProviderEvents = typeof __propDef.events;
19
+ export type ToastProviderSlots = typeof __propDef.slots;
20
+ export default class ToastProvider extends SvelteComponent<ToastProviderProps, ToastProviderEvents, ToastProviderSlots> {
21
+ }
22
+ export {};
@@ -0,0 +1,11 @@
1
+ import { type Writable } from 'svelte/store';
2
+ import type { ToastProps } from '../../types/toast';
3
+ export declare const TOASTS_KEY = "rain:ui-components:toasts";
4
+ /**
5
+ * Retrieves the toasts store from Svelte's context
6
+ */
7
+ export declare function getToastsContext(): Writable<ToastProps[]>;
8
+ /**
9
+ * Sets the toasts store in Svelte's context
10
+ */
11
+ export declare function setToastsContext(toasts: Writable<ToastProps[]>): void;
@@ -0,0 +1,19 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ import {} from 'svelte/store';
3
+ export const TOASTS_KEY = 'rain:ui-components:toasts';
4
+ /**
5
+ * Retrieves the toasts store from Svelte's context
6
+ */
7
+ export function getToastsContext() {
8
+ const toasts = getContext(TOASTS_KEY);
9
+ if (!toasts) {
10
+ throw new Error('No toasts context found. Did you forget to wrap your component with ToastProvider?');
11
+ }
12
+ return toasts;
13
+ }
14
+ /**
15
+ * Sets the toasts store in Svelte's context
16
+ */
17
+ export function setToastsContext(toasts) {
18
+ setContext(TOASTS_KEY, toasts);
19
+ }
@@ -0,0 +1,12 @@
1
+ import type { ToastProps } from '../../types/toast';
2
+ /**
3
+ * Hook for managing toast notifications in the application.
4
+ * Provides functionality to add, remove, and access toast notifications.
5
+ *
6
+ * @returns An object containing the toast store and methods to manipulate toasts
7
+ */
8
+ export declare function useToasts(): {
9
+ toasts: import("svelte/store").Writable<ToastProps[]>;
10
+ addToast: (toast: ToastProps) => void;
11
+ removeToast: (index: number) => void;
12
+ };
@@ -0,0 +1,54 @@
1
+ import { getToastsContext } from './context';
2
+ import { get } from 'svelte/store';
3
+ import { v4 as uuidv4 } from 'uuid';
4
+ /**
5
+ * Hook for managing toast notifications in the application.
6
+ * Provides functionality to add, remove, and access toast notifications.
7
+ *
8
+ * @returns An object containing the toast store and methods to manipulate toasts
9
+ */
10
+ export function useToasts() {
11
+ const toasts = getToastsContext();
12
+ /**
13
+ * Removes a toast notification by its index
14
+ *
15
+ * @param index - The index of the toast to remove
16
+ */
17
+ const removeToast = (index) => {
18
+ toasts.update((toasts) => {
19
+ if (index < 0 || index >= toasts.length) {
20
+ return toasts;
21
+ }
22
+ return toasts.filter((_, i) => i !== index);
23
+ });
24
+ };
25
+ /**
26
+ * Adds a new toast notification and automatically removes it after 3 seconds
27
+ *
28
+ * @param toast - The toast properties (message and type)
29
+ */
30
+ const addToast = (toast) => {
31
+ const newToast = { ...toast, id: uuidv4() };
32
+ let addedToastIndex = -1;
33
+ toasts.update((toasts) => {
34
+ const updatedToasts = [...toasts, newToast];
35
+ addedToastIndex = updatedToasts.length - 1;
36
+ return updatedToasts;
37
+ });
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
+ };
49
+ return {
50
+ toasts,
51
+ addToast,
52
+ removeToast
53
+ };
54
+ }
@@ -1,8 +1,10 @@
1
1
  import dayjs from 'dayjs';
2
2
  import bigIntSupport from 'dayjs/plugin/bigIntSupport';
3
3
  import localizedFormat from 'dayjs/plugin/localizedFormat';
4
+ import utc from 'dayjs/plugin/utc';
4
5
  dayjs.extend(bigIntSupport);
5
6
  dayjs.extend(localizedFormat);
7
+ dayjs.extend(utc);
6
8
  export const TIME_DELTA_24_HOURS = 60 * 60 * 24;
7
9
  export const TIME_DELTA_48_HOURS = TIME_DELTA_24_HOURS * 2;
8
10
  export const TIME_DELTA_7_DAYS = TIME_DELTA_24_HOURS * 7;
@@ -12,7 +14,9 @@ export function dateTimestamp(date) {
12
14
  return Math.floor(date.getTime() / 1000);
13
15
  }
14
16
  export function formatTimestampSecondsAsLocal(timestampSeconds) {
15
- return dayjs(timestampSeconds * BigInt('1000')).format('L LT');
17
+ return dayjs(timestampSeconds * BigInt('1000'))
18
+ .utc()
19
+ .format('L LT');
16
20
  }
17
21
  export function timestampSecondsToUTCTimestamp(timestampSeconds) {
18
22
  return dayjs(timestampSeconds * BigInt('1000')).unix();
@@ -38,7 +42,7 @@ if (import.meta.vitest) {
38
42
  describe('Date and timestamp utilities', () => {
39
43
  describe('formatTimestampSecondsAsLocal', () => {
40
44
  it('converts timestamp to local format', () => {
41
- const result = formatTimestampSecondsAsLocal(BigInt('1672531200')); // Jan 1, 2023 01:00 AM
45
+ const result = formatTimestampSecondsAsLocal(BigInt('1672531200')); // Jan 1, 2023 12:00 AM
42
46
  expect(result).toBe('01/01/2023 12:00 AM');
43
47
  });
44
48
  });
@@ -0,0 +1,6 @@
1
+ export interface ToastProps {
2
+ message: string;
3
+ type: 'success' | 'error' | 'warning' | 'info';
4
+ color: 'green' | 'red' | 'yellow' | 'blue';
5
+ id?: string;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainlanguage/ui-components",
3
- "version": "0.0.1-alpha.93",
3
+ "version": "0.0.1-alpha.95",
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.93",
56
+ "@rainlanguage/orderbook": "0.0.1-alpha.95",
57
57
  "@reown/appkit": "1.6.4",
58
58
  "@reown/appkit-adapter-wagmi": "1.6.4",
59
59
  "@sentry/sveltekit": "7.120.0",