@hyvor/design 0.0.12 → 0.0.14

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,8 +1,10 @@
1
1
  <script>import DarkProvider from "./../Dark/DarkProvider.svelte";
2
2
  import "../../index.js";
3
+ import ToastProvider from "../Toast/ToastProvider.svelte";
3
4
  </script>
4
5
 
5
6
  <DarkProvider />
7
+ <ToastProvider />
6
8
 
7
9
  <div id="base">
8
10
  <slot />
@@ -2,7 +2,7 @@ import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
4
  [x: string]: any;
5
- type?: "danger" | "soft" | "info" | "success" | "warning" | undefined;
5
+ type?: "danger" | "success" | "warning" | "info" | "soft" | undefined;
6
6
  };
7
7
  events: {
8
8
  [evt: string]: CustomEvent<any>;
@@ -0,0 +1,27 @@
1
+ <script>export let color = "var(--accent-lightest)";
2
+ export let height = 1;
3
+ export let width = 100;
4
+ export let margin = 0;
5
+ export let align = "center";
6
+ </script>
7
+
8
+
9
+ <div
10
+ class="line"
11
+ style="
12
+ background-color: {color};
13
+ height: {height}px;
14
+ width: {width}%;
15
+ margin-top: {margin}px;
16
+ margin-bottom: {margin}px;
17
+ margin-left: {align === 'center' || align === 'end' ? 'auto' : 0};
18
+ margin-right: {align === 'center' ? 'auto' : 0};
19
+ display: flex;
20
+ "
21
+ />
22
+
23
+ <style>
24
+ .line {
25
+ display: block;
26
+ }
27
+ </style>
@@ -0,0 +1,20 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ color?: string | undefined;
5
+ height?: number | undefined;
6
+ width?: number | undefined;
7
+ margin?: number | undefined;
8
+ align?: "start" | "end" | "center" | undefined;
9
+ };
10
+ events: {
11
+ [evt: string]: CustomEvent<any>;
12
+ };
13
+ slots: {};
14
+ };
15
+ export type DividerProps = typeof __propDef.props;
16
+ export type DividerEvents = typeof __propDef.events;
17
+ export type DividerSlots = typeof __propDef.slots;
18
+ export default class Divider extends SvelteComponent<DividerProps, DividerEvents, DividerSlots> {
19
+ }
20
+ export {};
@@ -5,11 +5,12 @@ export let width = 225;
5
5
  export let relative = false;
6
6
  export let closeOnOutsideClick = true;
7
7
  export let align = "start";
8
+ export let position = "bottom";
8
9
  </script>
9
10
 
10
11
  <span
11
- class="dropdown"
12
- class:relative
12
+ class="dropdown"
13
+ class:relative
13
14
  >
14
15
 
15
16
  <span
@@ -28,7 +29,7 @@ export let align = "start";
28
29
 
29
30
  {#if show}
30
31
  <div
31
- class="content-wrap {align}"
32
+ class="content-wrap {align} {position}"
32
33
  use:clickOutside={{
33
34
  enabled: closeOnOutsideClick,
34
35
  callback: () => show = false
@@ -42,36 +43,82 @@ export let align = "start";
42
43
 
43
44
  </span>
44
45
 
45
- <style>
46
- .dropdown {
47
- position: relative;
48
- display: inline-block;
49
- }
50
-
51
- .dropdown .content-wrap {
52
- position: absolute;
53
- top: 100%;
54
- margin-top: 5px;
55
- left: 0;
56
- z-index: 1;
57
- }
58
-
59
- .content-wrap.end {
60
- left: auto;
61
- right: 0;
62
- }
63
-
64
- .content-wrap.center {
65
- left: 50%;
66
- transform: translateX(-50%);
67
- }
68
-
69
- .content-wrap > :global(.content) {
70
- padding: 10px;
71
- }
72
-
73
- .dropdown.relative > .content-wrap {
74
- position: relative;
75
- }
76
-
77
- </style>
46
+ <style>.dropdown {
47
+ position: relative;
48
+ display: inline-block;
49
+ }
50
+
51
+ .dropdown .content-wrap {
52
+ position: absolute;
53
+ left: 0;
54
+ z-index: 1;
55
+ }
56
+
57
+ .content-wrap.bottom {
58
+ top: 100%;
59
+ margin-top: 5px;
60
+ }
61
+ .content-wrap.bottom.end {
62
+ left: auto;
63
+ right: 0;
64
+ }
65
+ .content-wrap.bottom.center {
66
+ left: 50%;
67
+ transform: translateX(-50%);
68
+ }
69
+
70
+ .content-wrap.top {
71
+ bottom: 100%;
72
+ margin-bottom: 5px;
73
+ }
74
+ .content-wrap.top.end {
75
+ left: auto;
76
+ right: 0;
77
+ }
78
+ .content-wrap.top.center {
79
+ left: 50%;
80
+ transform: translateX(-50%);
81
+ }
82
+
83
+ .content-wrap.left {
84
+ right: 100%;
85
+ left: auto;
86
+ margin-right: 5px;
87
+ top: 0;
88
+ bottom: auto;
89
+ }
90
+ .content-wrap.left.end {
91
+ top: auto;
92
+ bottom: 0;
93
+ }
94
+ .content-wrap.left.center {
95
+ top: 50%;
96
+ transform: translateY(-50%);
97
+ }
98
+
99
+ .content-wrap.right {
100
+ left: 100%;
101
+ margin-left: 5px;
102
+ top: 0;
103
+ bottom: auto;
104
+ }
105
+ .content-wrap.right.end {
106
+ bottom: 0;
107
+ top: auto;
108
+ }
109
+ .content-wrap.right.center {
110
+ top: 50%;
111
+ transform: translateY(-50%);
112
+ }
113
+
114
+ .content-wrap > :global(.content) {
115
+ padding: 10px;
116
+ }
117
+
118
+ .dropdown.relative > .content-wrap {
119
+ position: relative;
120
+ }</style>
121
+
122
+
123
+
124
+
@@ -6,6 +6,7 @@ declare const __propDef: {
6
6
  relative?: boolean | undefined;
7
7
  closeOnOutsideClick?: boolean | undefined;
8
8
  align?: "start" | "end" | "center" | undefined;
9
+ position?: "left" | "right" | "bottom" | "top" | undefined;
9
10
  };
10
11
  events: {
11
12
  [evt: string]: CustomEvent<any>;
@@ -27,6 +27,17 @@ let input;
27
27
  <input
28
28
  {...$$restProps}
29
29
  bind:this={input}
30
+
31
+ on:keyup
32
+ on:keydown
33
+ on:keypress
34
+ on:focus
35
+ on:blur
36
+ on:click
37
+ on:mouseover
38
+ on:mouseenter
39
+ on:mouseleave
40
+ on:change
30
41
  />
31
42
 
32
43
  {#if $$slots.end}
@@ -7,6 +7,17 @@ declare const __propDef: {
7
7
  block?: boolean | undefined;
8
8
  };
9
9
  events: {
10
+ keyup: KeyboardEvent;
11
+ keydown: KeyboardEvent;
12
+ keypress: KeyboardEvent;
13
+ focus: FocusEvent;
14
+ blur: FocusEvent;
15
+ click: MouseEvent;
16
+ mouseover: MouseEvent;
17
+ mouseenter: MouseEvent;
18
+ mouseleave: MouseEvent;
19
+ change: Event;
20
+ } & {
10
21
  [evt: string]: CustomEvent<any>;
11
22
  };
12
23
  slots: {
@@ -0,0 +1,52 @@
1
+ <script>import Loader from "../Loader/Loader.svelte";
2
+ import {
3
+ IconCheckCircleFill,
4
+ IconXCircleFill,
5
+ IconExclamationCircleFill,
6
+ IconInfoCircleFill
7
+ } from "@hyvor/icons";
8
+ export let toast;
9
+ $:
10
+ color = {
11
+ success: "var(--green)",
12
+ error: "var(--red)",
13
+ warning: "var(--orange)",
14
+ info: "var(--blue)"
15
+ }[toast.type] || "inherit";
16
+ </script>
17
+
18
+ <span
19
+ style:color={color}
20
+ >
21
+ {#if toast.type === 'success'}
22
+ <IconCheckCircleFill />
23
+ {:else if toast.type === 'error'}
24
+ <IconXCircleFill />
25
+ {:else if toast.type === 'warning'}
26
+ <IconExclamationCircleFill />
27
+ {:else if toast.type === 'info'}
28
+ <IconInfoCircleFill />
29
+ {:else if toast.type === 'loading'}
30
+ <Loader size="small" />
31
+ {/if}
32
+ </span>
33
+
34
+ <style>
35
+ span {
36
+ display: inline-flex;
37
+ align-items: center;
38
+ justify-content: center;
39
+ animation: scale 0.2s ease-in-out;
40
+ }
41
+
42
+ @keyframes scale {
43
+ 0% {
44
+ transform: scale(0.5);
45
+ opacity: 0.4;
46
+ }
47
+ 100% {
48
+ transform: scale(1);
49
+ opacity: 1;
50
+ }
51
+ }
52
+ </style>
@@ -0,0 +1,17 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { Toast } from './toast.ts';
3
+ declare const __propDef: {
4
+ props: {
5
+ toast: Toast;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ };
12
+ export type ToastIconProps = typeof __propDef.props;
13
+ export type ToastIconEvents = typeof __propDef.events;
14
+ export type ToastIconSlots = typeof __propDef.slots;
15
+ export default class ToastIcon extends SvelteComponent<ToastIconProps, ToastIconEvents, ToastIconSlots> {
16
+ }
17
+ export {};
@@ -0,0 +1,47 @@
1
+ <script>import ToastIcon from "./ToastIcon.svelte";
2
+ import { fade } from "svelte/transition";
3
+ export let toast;
4
+ </script>
5
+
6
+ <div
7
+ class="toast"
8
+ out:fade={{ duration: 200 }}
9
+ in:fade={{duration: 50}}
10
+ >
11
+
12
+ {#if toast.type !== 'blank'}
13
+ <div class="icon-wrap">
14
+ <ToastIcon {toast} />
15
+ </div>
16
+ {/if}
17
+
18
+ <div class="message-wrap">
19
+ {#if typeof toast.message === 'string' || toast.message === null}
20
+ {@html toast.message }
21
+ {:else}
22
+ <svelte:component this={toast.message} {toast} />
23
+ {/if}
24
+ </div>
25
+
26
+ </div>
27
+
28
+ <style>
29
+ .toast {
30
+ margin-bottom: 10px;
31
+ box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.1);
32
+ border-radius: var(--box-radius);
33
+ background-color: var(--box-background);
34
+ padding: 8px 20px;
35
+ display: flex;
36
+ align-items: center;
37
+ max-width: 350px;
38
+ }
39
+ .toast:first-child {
40
+ margin-top: 10px;
41
+ }
42
+ .icon-wrap {
43
+ margin-right: 8px;
44
+ display: inline-flex;
45
+ align-items: center;
46
+ }
47
+ </style>
@@ -0,0 +1,17 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { Toast } from './toast.ts';
3
+ declare const __propDef: {
4
+ props: {
5
+ toast: Toast;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ };
12
+ export type ToastMessageProps = typeof __propDef.props;
13
+ export type ToastMessageEvents = typeof __propDef.events;
14
+ export type ToastMessageSlots = typeof __propDef.slots;
15
+ export default class ToastMessage extends SvelteComponent<ToastMessageProps, ToastMessageEvents, ToastMessageSlots> {
16
+ }
17
+ export {};
@@ -0,0 +1,25 @@
1
+ <script>import ToastMessage from "./ToastMessage.svelte";
2
+ import { toastStore } from "./toast.js";
3
+ import { useCleaner } from "./cleaner.js";
4
+ useCleaner();
5
+ </script>
6
+
7
+ <div id="toasts-wrap">
8
+ {#each $toastStore as toast (toast.id)}
9
+ <ToastMessage {toast} />
10
+ {/each}
11
+ </div>
12
+
13
+ <style>
14
+ #toasts-wrap {
15
+ position: fixed;
16
+ top: 0;
17
+ left: 0;
18
+ width: 100%;
19
+ z-index: 9999;
20
+ display: flex;
21
+ flex-direction: column;
22
+ align-items: center;
23
+ justify-content: center;
24
+ }
25
+ </style>
@@ -0,0 +1,14 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: Record<string, never>;
4
+ events: {
5
+ [evt: string]: CustomEvent<any>;
6
+ };
7
+ slots: {};
8
+ };
9
+ export type ToastProviderProps = typeof __propDef.props;
10
+ export type ToastProviderEvents = typeof __propDef.events;
11
+ export type ToastProviderSlots = typeof __propDef.slots;
12
+ export default class ToastProvider extends SvelteComponent<ToastProviderProps, ToastProviderEvents, ToastProviderSlots> {
13
+ }
14
+ export {};
@@ -0,0 +1 @@
1
+ export declare function useCleaner(): void;
@@ -0,0 +1,28 @@
1
+ import { onDestroy } from "svelte";
2
+ import { default as toastService, toastStore } from "./toast.js";
3
+ const DEFAULT_DURATIONS = {
4
+ success: 2000,
5
+ loading: Infinity,
6
+ };
7
+ export function useCleaner() {
8
+ const timeouts = new Map();
9
+ const unsubscribe = toastStore.subscribe(toasts => {
10
+ toasts.forEach(toast => {
11
+ if (timeouts.has(toast.id)) {
12
+ return;
13
+ }
14
+ const duration = toast.duration || DEFAULT_DURATIONS[toast.type] || 5000;
15
+ if (duration === Infinity) {
16
+ return;
17
+ }
18
+ const timeout = setTimeout(() => {
19
+ toastService.close(toast.id);
20
+ timeouts.delete(toast.id);
21
+ }, duration);
22
+ timeouts.set(toast.id, timeout);
23
+ });
24
+ });
25
+ onDestroy(() => {
26
+ unsubscribe();
27
+ });
28
+ }
@@ -0,0 +1,23 @@
1
+ import type { SvelteComponent } from "svelte";
2
+ export interface Toast {
3
+ id: number;
4
+ type: ToastType;
5
+ message: ToastMessageType;
6
+ duration?: number;
7
+ }
8
+ export declare const toastStore: import("svelte/store").Writable<Toast[]>;
9
+ export type ToastType = "success" | "error" | "warning" | "info" | "loading" | "blank";
10
+ export type ToastMessageType = typeof SvelteComponent<Record<string, any>> | string | null;
11
+ declare function createHandler(type: ToastType): (message: ToastMessageType, options?: Partial<Toast>) => number;
12
+ type ToastFunctionSignature = ReturnType<typeof createHandler>;
13
+ interface ToastSignature {
14
+ (message: ToastMessageType, options?: Partial<Toast>): number;
15
+ success: ToastFunctionSignature;
16
+ error: ToastFunctionSignature;
17
+ warning: ToastFunctionSignature;
18
+ info: ToastFunctionSignature;
19
+ loading: ToastFunctionSignature;
20
+ close: (id: number) => void;
21
+ }
22
+ declare const toast: ToastSignature;
23
+ export default toast;
@@ -0,0 +1,43 @@
1
+ import { get, writable } from "svelte/store";
2
+ const MAX_TOASTS = 10;
3
+ export const toastStore = writable([]);
4
+ const storeHelper = {
5
+ add: (toast) => {
6
+ toastStore.update((toasts) => [toast, ...toasts].slice(0, MAX_TOASTS));
7
+ },
8
+ update: (toast) => {
9
+ toastStore.update((toasts) => toasts.map(t => t.id === toast.id ? { ...t, ...toast } : t));
10
+ },
11
+ upsert: (toast) => {
12
+ if (get(toastStore).find(t => t.id === toast.id)) {
13
+ storeHelper.update(toast);
14
+ }
15
+ else {
16
+ storeHelper.add(toast);
17
+ }
18
+ },
19
+ remove: (id) => {
20
+ toastStore.update((toasts) => toasts.filter(t => t.id !== id));
21
+ }
22
+ };
23
+ let id = 0;
24
+ function createHandler(type) {
25
+ return (message, options = {}) => {
26
+ const newId = options.id || id++;
27
+ storeHelper.upsert({
28
+ id: newId,
29
+ type,
30
+ message,
31
+ ...options
32
+ });
33
+ return newId;
34
+ };
35
+ }
36
+ const toast = createHandler("blank");
37
+ toast.success = createHandler("success");
38
+ toast.error = createHandler("error");
39
+ toast.warning = createHandler("warning");
40
+ toast.info = createHandler("info");
41
+ toast.loading = createHandler("loading");
42
+ toast.close = (id) => storeHelper.remove(id);
43
+ export default toast;
@@ -77,7 +77,7 @@ onMount(() => {
77
77
 
78
78
  <style>
79
79
  .tooltip-wrap {
80
- display: inline-block;
80
+ display: inline-flex;
81
81
  position: relative;
82
82
 
83
83
  --local-bg: #24292f;
@@ -2,7 +2,7 @@ import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
4
  text?: string | undefined;
5
- position?: "left" | "right" | "top" | "bottom" | undefined;
5
+ position?: "left" | "right" | "bottom" | "top" | undefined;
6
6
  color?: "danger" | "accent" | "soft" | "black" | undefined;
7
7
  show?: boolean | undefined;
8
8
  maxWidth?: number | undefined;
@@ -12,6 +12,7 @@ export { default as Checkbox } from './Checkbox/Checkbox.svelte';
12
12
  export { default as CodeBlock } from './CodeBlock/CodeBlock.svelte';
13
13
  export { default as DarkToggle } from './Dark/DarkToggle.svelte';
14
14
  export { default as Dropdown } from './Dropdown/Dropdown.svelte';
15
+ export { default as Divider } from './Divider/Divider.svelte';
15
16
  export { default as Caption } from './FormControl/Caption.svelte';
16
17
  export { default as FormControl } from './FormControl/FormControl.svelte';
17
18
  export { default as InputGroup } from './FormControl/InputGroup.svelte';
@@ -29,4 +30,5 @@ export { default as TableRow } from './Table/TableRow.svelte';
29
30
  export { default as Textarea } from './Textarea/Textarea.svelte';
30
31
  export { default as Text } from './Text/Text.svelte';
31
32
  export { default as TextInput } from './TextInput/TextInput.svelte';
33
+ export { default as toast } from './Toast/toast.js';
32
34
  export { default as Tooltip } from './Tooltip/Tooltip.svelte';
@@ -12,6 +12,7 @@ export { default as Checkbox } from './Checkbox/Checkbox.svelte';
12
12
  export { default as CodeBlock } from './CodeBlock/CodeBlock.svelte';
13
13
  export { default as DarkToggle } from './Dark/DarkToggle.svelte';
14
14
  export { default as Dropdown } from './Dropdown/Dropdown.svelte';
15
+ export { default as Divider } from './Divider/Divider.svelte';
15
16
  export { default as Caption } from './FormControl/Caption.svelte';
16
17
  export { default as FormControl } from './FormControl/FormControl.svelte';
17
18
  export { default as InputGroup } from './FormControl/InputGroup.svelte';
@@ -29,4 +30,5 @@ export { default as TableRow } from './Table/TableRow.svelte';
29
30
  export { default as Textarea } from './Textarea/Textarea.svelte';
30
31
  export { default as Text } from './Text/Text.svelte';
31
32
  export { default as TextInput } from './TextInput/TextInput.svelte';
33
+ export { default as toast } from './Toast/toast.js';
32
34
  export { default as Tooltip } from './Tooltip/Tooltip.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyvor/design",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "scripts": {