hamzus-ui 0.0.48 → 0.0.50
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/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { default as Link } from "./src/components/hamzus-ui/Link/Link.svelte"
|
|
|
12
12
|
export { default as Kbd } from "./src/components/hamzus-ui/Kbd/Kbd.svelte"
|
|
13
13
|
|
|
14
14
|
// dialog
|
|
15
|
+
export { toast as toast } from "./src/components/hamzus-ui/Toast/toast.js"
|
|
15
16
|
export { default as Dialog } from "./src/components/hamzus-ui/Dialog/Dialog.svelte"
|
|
16
17
|
|
|
17
18
|
// form
|
package/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export { default as AlertCard } from "./src/components/hamzus-ui/AlertCard/Alert
|
|
|
9
9
|
export { default as Link } from "./src/components/hamzus-ui/Link/Link.svelte"
|
|
10
10
|
export { default as Kbd } from "./src/components/hamzus-ui/KBD/KBD.svelte"
|
|
11
11
|
// dialog
|
|
12
|
+
export { toast as toast } from "./src/components/hamzus-ui/Toast/toast.js"
|
|
12
13
|
export { default as Dialog } from "./src/components/hamzus-ui/Dialog/Dialog.svelte"
|
|
13
14
|
// form
|
|
14
15
|
export { default as Form } from "./src/components/hamzus-ui/Form/Form.svelte"
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { allNotification } from "./toast";
|
|
3
|
+
import Toast from "./Toast.svelte";
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<div class="toast-container">
|
|
7
|
+
{#each $allNotification as toast}
|
|
8
|
+
<Toast
|
|
9
|
+
title={toast.title}
|
|
10
|
+
description={toast.description ?? ""}
|
|
11
|
+
variant={toast.variant ?? "default"}
|
|
12
|
+
onClick={toast.onClick ?? undefined}
|
|
13
|
+
href={toast.href ?? undefined}
|
|
14
|
+
buttonLabel={toast.buttonLabel ?? ""}
|
|
15
|
+
isExiting={toast.isExiting ?? false}
|
|
16
|
+
></Toast>
|
|
17
|
+
{/each}
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
<style>
|
|
21
|
+
.toast-container {
|
|
22
|
+
width: min(100%, 350px);
|
|
23
|
+
position: fixed;
|
|
24
|
+
bottom: var(--pad-s);
|
|
25
|
+
right: var(--pad-s);
|
|
26
|
+
padding: var(--pad-m);
|
|
27
|
+
row-gap: var(--pad-s);
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-direction: column-reverse;
|
|
30
|
+
}
|
|
31
|
+
</style>
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Button from '../Button/Button.svelte';
|
|
3
|
+
import { onMount } from 'svelte';
|
|
4
|
+
import { writable } from 'svelte/store';
|
|
5
|
+
import { tick } from 'svelte';
|
|
6
|
+
|
|
7
|
+
export let variant = 'default'; // "default" | "success" | "error"
|
|
8
|
+
export let title = '';
|
|
9
|
+
export let description = '';
|
|
10
|
+
export let buttonLabel = 'buttonLabel';
|
|
11
|
+
export let onClick = undefined; // function
|
|
12
|
+
export let href = undefined; // link
|
|
13
|
+
export let isExiting = false;
|
|
14
|
+
|
|
15
|
+
let entry = "entry"
|
|
16
|
+
let toast;
|
|
17
|
+
let toastSize = 0
|
|
18
|
+
|
|
19
|
+
onMount(()=>{
|
|
20
|
+
if (!toast) return;
|
|
21
|
+
|
|
22
|
+
const resizeObserver = new ResizeObserver(entries => {
|
|
23
|
+
for (const entry of entries) {
|
|
24
|
+
console.log(entry);
|
|
25
|
+
|
|
26
|
+
toastSize = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
resizeObserver.observe(toast);
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
setTimeout(()=>{
|
|
34
|
+
entry = ""
|
|
35
|
+
}, 200)
|
|
36
|
+
|
|
37
|
+
return () => {
|
|
38
|
+
resizeObserver.disconnect();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
})
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<div class="parent-container {entry}" style="--toast-height:{toastSize}px;">
|
|
45
|
+
<div class="toast {variant} {isExiting ? "exiting" : ""} {entry}" bind:this={toast}>
|
|
46
|
+
<div class="description">
|
|
47
|
+
<h4>{title}</h4>
|
|
48
|
+
{#if description}
|
|
49
|
+
<p>{description}</p>
|
|
50
|
+
{/if}
|
|
51
|
+
</div>
|
|
52
|
+
{#if onClick !== undefined || href !== undefined}
|
|
53
|
+
<Button style="flex-shrink:0;" {href} {onClick} label={buttonLabel} variant="secondary"></Button>
|
|
54
|
+
{/if}
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
|
|
58
|
+
<style>
|
|
59
|
+
.parent-container {
|
|
60
|
+
width: 100%;
|
|
61
|
+
overflow: hidden;
|
|
62
|
+
height: calc(var(--toast-height) + 4px);
|
|
63
|
+
padding: 2px;
|
|
64
|
+
}
|
|
65
|
+
.parent-container.entry {
|
|
66
|
+
animation: entry-parent .2s ease-out ;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@keyframes entry-parent {
|
|
70
|
+
from {
|
|
71
|
+
height: 0px;
|
|
72
|
+
}
|
|
73
|
+
to {
|
|
74
|
+
height: calc(var(--toast-height) + 4px);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
.parent-container:has( .exiting) {
|
|
78
|
+
height: 0px;
|
|
79
|
+
animation: exit-parent .2s ease-out;
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
@keyframes exit-parent {
|
|
83
|
+
from {
|
|
84
|
+
height: calc(var(--toast-height) + 4px);
|
|
85
|
+
}
|
|
86
|
+
to {
|
|
87
|
+
height: 0px;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.toast {
|
|
92
|
+
width: 100%;
|
|
93
|
+
display: flex;
|
|
94
|
+
flex-shrink: 0;
|
|
95
|
+
align-items: center;
|
|
96
|
+
column-gap: var(--pad-m);
|
|
97
|
+
padding: var(--pad-m) var(--pad-xxl);
|
|
98
|
+
border-radius: var(--radius-m);
|
|
99
|
+
border: 1px solid var(--stroke);
|
|
100
|
+
background-color: var(--bg-1);
|
|
101
|
+
outline: 2px solid var(--bg-blur);
|
|
102
|
+
overflow: hidden;
|
|
103
|
+
}
|
|
104
|
+
.toast.entry {
|
|
105
|
+
|
|
106
|
+
animation: entry .2s ease-out ;
|
|
107
|
+
}
|
|
108
|
+
.toast h4 {
|
|
109
|
+
color: var(--font-1);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.exiting {
|
|
113
|
+
animation: exiting .2s ease-out ;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@keyframes entry {
|
|
117
|
+
from {
|
|
118
|
+
opacity: 0;
|
|
119
|
+
transform: scale(0);
|
|
120
|
+
}
|
|
121
|
+
to {
|
|
122
|
+
opacity: 100;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
@keyframes exiting {
|
|
126
|
+
from {
|
|
127
|
+
opacity: 100;
|
|
128
|
+
}
|
|
129
|
+
to {
|
|
130
|
+
opacity: 0;
|
|
131
|
+
transform: scale(0);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
.description {
|
|
137
|
+
display: flex;
|
|
138
|
+
flex-direction: column;
|
|
139
|
+
align-items: baseline;
|
|
140
|
+
text-align: left;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
.success h4{
|
|
147
|
+
color: var(--green);
|
|
148
|
+
}
|
|
149
|
+
.error h4{
|
|
150
|
+
color: var(--red);
|
|
151
|
+
}
|
|
152
|
+
</style>
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { mount, unmount } from 'svelte';
|
|
2
|
+
import ParentToast from "./ParentToast.svelte"
|
|
3
|
+
import { writable } from 'svelte/store';
|
|
4
|
+
|
|
5
|
+
export const allNotification = writable([])
|
|
6
|
+
|
|
7
|
+
const target = "body"
|
|
8
|
+
|
|
9
|
+
let numberOfNotification = 0
|
|
10
|
+
let app;
|
|
11
|
+
let id = 0
|
|
12
|
+
|
|
13
|
+
allNotification.subscribe((value)=>{
|
|
14
|
+
numberOfNotification = value.length
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const toast = {
|
|
18
|
+
success : (options) => {
|
|
19
|
+
addNotification(options, "success")
|
|
20
|
+
},
|
|
21
|
+
error : (options) => {
|
|
22
|
+
addNotification(options, "error")
|
|
23
|
+
},
|
|
24
|
+
default : (options) => {
|
|
25
|
+
addNotification(options, "default")
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
function addNotification(options, variant) {
|
|
31
|
+
let element;
|
|
32
|
+
|
|
33
|
+
if (!target) {
|
|
34
|
+
console.warn(`[svelte-portal] Invalid Portal target: ${target}`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (typeof target === 'string') {
|
|
39
|
+
element = document.querySelector(target);
|
|
40
|
+
} else {
|
|
41
|
+
element = target;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (element && numberOfNotification === 0) {
|
|
45
|
+
|
|
46
|
+
app = mount(ParentToast, {
|
|
47
|
+
target: element,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
allNotification.update(((actualValue)=>{
|
|
54
|
+
return [
|
|
55
|
+
...actualValue,
|
|
56
|
+
{
|
|
57
|
+
...options,
|
|
58
|
+
variant:variant
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
setTimeout(()=>{
|
|
65
|
+
// retirer le dernier toast
|
|
66
|
+
allNotification.update(actualValue=>{
|
|
67
|
+
// mettre le toast en mode disparition
|
|
68
|
+
actualValue[0].isExiting = true
|
|
69
|
+
|
|
70
|
+
return actualValue
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
allNotification.update(actualValue=>{
|
|
75
|
+
// retirer le composant parent si il n ya plus de toast
|
|
76
|
+
|
|
77
|
+
if (actualValue.length === 1 && app) {
|
|
78
|
+
unmount(app);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return actualValue.slice(1)
|
|
82
|
+
})
|
|
83
|
+
}, 200);
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
}, 5000)
|
|
87
|
+
}
|