@reshape-biotech/design-system 1.2.0 → 1.2.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.
@@ -1,5 +1,5 @@
1
1
  <script module lang="ts">
2
- import { notifications } from '../../../notifications';
2
+ import { notifications } from '../../notifications';
3
3
  import Button from '../button/Button.svelte';
4
4
  import Notifications from '../notifications/Notifications.svelte';
5
5
  import { defineMeta } from '@storybook/addon-svelte-csf';
@@ -1,26 +1,8 @@
1
1
  <script lang="ts">
2
2
  import { flip } from 'svelte/animate';
3
3
  import { fly } from 'svelte/transition';
4
- import { notifications } from '../../../notifications';
5
- import { type IconColor } from '../icons';
6
- import { tokens } from '../../tokens';
4
+ import { notifications } from '../../notifications';
7
5
  import Toast from '../toast/Toast.svelte';
8
-
9
- const color = {
10
- danger: tokens.backgroundColor['danger-inverse'],
11
- success: tokens.backgroundColor['success-inverse-hover'],
12
- warning: tokens.backgroundColor['warning-inverse-hover'],
13
- info: tokens.backgroundColor['blue-inverse'],
14
- default: tokens.backgroundColor.surface
15
- };
16
-
17
- const textColor: Record<string, IconColor | 'inherit'> = {
18
- danger: 'primary-inverse',
19
- success: 'primary-inverse',
20
- warning: 'primary-inverse',
21
- info: 'primary-inverse',
22
- default: 'inherit'
23
- };
24
6
  </script>
25
7
 
26
8
  <div class="fixed left-0 right-0 top-2 z-50 mx-auto flex w-fit flex-col items-center justify-start">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { type Notification, notifications } from '../../../notifications';
2
+ import { type Notification, notifications } from '../../notifications';
3
3
  import Icon from '../icons/Icon.svelte';
4
4
  import { type IconColor } from '../icons';
5
5
  import { tokens } from '../../tokens';
@@ -1,4 +1,4 @@
1
- import { type Notification } from '../../../notifications';
1
+ import { type Notification } from '../../notifications';
2
2
  type $$ComponentProps = {
3
3
  notification: Notification;
4
4
  };
package/dist/index.d.ts CHANGED
@@ -46,5 +46,5 @@ export * from './components/toggle/';
46
46
  export * from './components/checkbox/';
47
47
  export * from './components/sjsf-wrappers/';
48
48
  export { tokens } from './tokens';
49
- export { notifications } from '../notifications';
49
+ export { notifications } from './notifications';
50
50
  import './app.css';
package/dist/index.js CHANGED
@@ -48,5 +48,5 @@ export * from './components/checkbox/';
48
48
  export * from './components/sjsf-wrappers/';
49
49
  // Styles and Tokens
50
50
  export { tokens } from './tokens';
51
- export { notifications } from '../notifications';
51
+ export { notifications } from './notifications';
52
52
  import './app.css';
@@ -0,0 +1,22 @@
1
+ import type { IconName } from './';
2
+ export type NotificationType = 'info' | 'success' | 'warning' | 'danger' | 'default';
3
+ export interface Notification {
4
+ id: string;
5
+ type: NotificationType;
6
+ message: string;
7
+ timeout?: number;
8
+ icon?: IconName;
9
+ dismissable: boolean;
10
+ }
11
+ export declare const notifications: {
12
+ subscribe: {
13
+ (this: void, run: import("svelte/store").Subscriber<Notification[]>, invalidate?: (() => void) | undefined): import("svelte/store").Unsubscriber;
14
+ (this: void, run: import("svelte/store").Subscriber<Notification[]>, invalidate?: (() => void) | undefined): import("svelte/store").Unsubscriber;
15
+ };
16
+ dismiss: (id: string) => void;
17
+ default: (message: string, icon?: IconName, dismissable?: boolean, timeout?: number) => void;
18
+ danger: (message: string, icon?: IconName, dismissable?: boolean, timeout?: number) => void;
19
+ warning: (message: string, icon?: IconName, dismissable?: boolean, timeout?: number) => void;
20
+ info: (message: string, icon?: IconName, dismissable?: boolean, timeout?: number) => void;
21
+ success: (message: string, icon?: IconName, dismissable?: boolean, timeout?: number) => void;
22
+ };
@@ -0,0 +1,27 @@
1
+ import { writable } from 'svelte/store';
2
+ const TIMEOUT = 3000;
3
+ const createNotificationStore = () => {
4
+ const { subscribe, update } = writable([]);
5
+ const send = (message, type = 'default', iconName, dismissable = false, timeout = 3000) => {
6
+ const notification = { id: id(), type, message, timeout, icon: iconName, dismissable };
7
+ update((state) => [...state, notification]);
8
+ setTimeout(() => {
9
+ update((state) => state.filter((n) => n.id !== notification.id));
10
+ }, timeout);
11
+ };
12
+ return {
13
+ subscribe,
14
+ dismiss: (id) => {
15
+ update((state) => state.filter((n) => n.id !== id));
16
+ },
17
+ default: (message, icon, dismissable = false, timeout = TIMEOUT) => send(message, 'default', icon, dismissable, timeout),
18
+ danger: (message, icon, dismissable = false, timeout = TIMEOUT) => send(message, 'danger', icon, dismissable, timeout),
19
+ warning: (message, icon, dismissable = false, timeout = TIMEOUT) => send(message, 'warning', icon, dismissable, timeout),
20
+ info: (message, icon, dismissable = false, timeout = TIMEOUT) => send(message, 'info', icon, dismissable, timeout),
21
+ success: (message, icon, dismissable = false, timeout = TIMEOUT) => send(message, 'success', icon, dismissable, timeout)
22
+ };
23
+ };
24
+ const id = () => {
25
+ return crypto.randomUUID();
26
+ };
27
+ export const notifications = createNotificationStore();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reshape-biotech/design-system",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build",
@@ -28,6 +28,7 @@
28
28
  "default": "./dist/index.js"
29
29
  },
30
30
  "./tokens": "./dist/tokens.js",
31
+ "./notifications": "./dist/notifications.js",
31
32
  "./styles": "./dist/app.css",
32
33
  "./tailwind": "./dist/tailwind.preset.js",
33
34
  "./tailwind-safelist": "./dist/tailwind-safelist.js"