hamzus-ui 0.0.1
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/README.md +38 -0
- package/index.js +6 -0
- package/package.json +48 -0
- package/src/components/hamzus-ui/AdvancedTooltip/Content.svelte +22 -0
- package/src/components/hamzus-ui/AdvancedTooltip/Label.svelte +1 -0
- package/src/components/hamzus-ui/AdvancedTooltip/Root.svelte +336 -0
- package/src/components/hamzus-ui/AdvancedTooltip/Separator.svelte +12 -0
- package/src/components/hamzus-ui/AdvancedTooltip/Trigger.svelte +5 -0
- package/src/components/hamzus-ui/AdvancedTooltip/index.js +5 -0
- package/src/components/hamzus-ui/AlertCard/AlertCard.svelte +32 -0
- package/src/components/hamzus-ui/Avatar/Avatar.svelte +32 -0
- package/src/components/hamzus-ui/Button/Button.svelte +79 -0
- package/src/components/hamzus-ui/Button/Button_default.svelte +142 -0
- package/src/components/hamzus-ui/Button/Button_link.svelte +138 -0
- package/src/components/hamzus-ui/Checkboxes/Checkbox/Checkbox.svelte +41 -0
- package/src/components/hamzus-ui/Checkboxes/Checkbox/index.css +68 -0
- package/src/components/hamzus-ui/Checkboxes/CheckboxCard/CheckboxCard.svelte +27 -0
- package/src/components/hamzus-ui/Checkboxes/CheckboxCard/index.css +54 -0
- package/src/components/hamzus-ui/Code/Code.svelte +192 -0
- package/src/components/hamzus-ui/CopyCode/CopyCode.svelte +55 -0
- package/src/components/hamzus-ui/CopyLabel/CopyLabel.svelte +43 -0
- package/src/components/hamzus-ui/DataList/DataList.svelte +82 -0
- package/src/components/hamzus-ui/DatePicker/DatePicker.svelte +326 -0
- package/src/components/hamzus-ui/Dialog/Dialog.svelte +61 -0
- package/src/components/hamzus-ui/DropdownMenu/Button.svelte +46 -0
- package/src/components/hamzus-ui/DropdownMenu/Content.svelte +22 -0
- package/src/components/hamzus-ui/DropdownMenu/Label.svelte +1 -0
- package/src/components/hamzus-ui/DropdownMenu/Root.svelte +340 -0
- package/src/components/hamzus-ui/DropdownMenu/Separator.svelte +12 -0
- package/src/components/hamzus-ui/DropdownMenu/Trigger.svelte +1 -0
- package/src/components/hamzus-ui/DropdownMenu/index.js +6 -0
- package/src/components/hamzus-ui/IconButton/IconButton.svelte +80 -0
- package/src/components/hamzus-ui/IconButton/IconButton_default.svelte +140 -0
- package/src/components/hamzus-ui/IconButton/IconButton_link.svelte +141 -0
- package/src/components/hamzus-ui/InfoCard/InfoCard.svelte +32 -0
- package/src/components/hamzus-ui/Input/Input.svelte +304 -0
- package/src/components/hamzus-ui/KBD/KBD.svelte +24 -0
- package/src/components/hamzus-ui/Link/Link.svelte +36 -0
- package/src/components/hamzus-ui/List/List.svelte +30 -0
- package/src/components/hamzus-ui/LoaderCircle/Loader.svelte +25 -0
- package/src/components/hamzus-ui/LoaderCircle/index.js +1 -0
- package/src/components/hamzus-ui/Popover/Button.svelte +46 -0
- package/src/components/hamzus-ui/Popover/Content.svelte +21 -0
- package/src/components/hamzus-ui/Popover/Label.svelte +1 -0
- package/src/components/hamzus-ui/Popover/Root.svelte +374 -0
- package/src/components/hamzus-ui/Popover/Separator.svelte +12 -0
- package/src/components/hamzus-ui/Popover/Trigger.svelte +1 -0
- package/src/components/hamzus-ui/Popover/index.js +6 -0
- package/src/components/hamzus-ui/Portal/Portal.svelte +46 -0
- package/src/components/hamzus-ui/Portal/Wormhole.svelte +7 -0
- package/src/components/hamzus-ui/Radios/Radio/Radio.svelte +43 -0
- package/src/components/hamzus-ui/Radios/Radio/index.css +68 -0
- package/src/components/hamzus-ui/Radios/RadioCard/RadioCard.svelte +32 -0
- package/src/components/hamzus-ui/Radios/RadioCard/index.css +50 -0
- package/src/components/hamzus-ui/Radios/RadioGroup/RadioGroup.svelte +46 -0
- package/src/components/hamzus-ui/Radios/RadioGroup/index.css +8 -0
- package/src/components/hamzus-ui/ScrollArea/ScrollArea.svelte +360 -0
- package/src/components/hamzus-ui/Swicth/Swicth.svelte +84 -0
- package/src/components/hamzus-ui/Swicth/index.css +120 -0
- package/src/components/hamzus-ui/Table/ActionsBar.svelte +174 -0
- package/src/components/hamzus-ui/Table/Content.svelte +68 -0
- package/src/components/hamzus-ui/Table/Header.svelte +268 -0
- package/src/components/hamzus-ui/Table/NavigationBar.svelte +10 -0
- package/src/components/hamzus-ui/Table/Root.svelte +128 -0
- package/src/components/hamzus-ui/Table/index.js +5 -0
- package/src/components/hamzus-ui/Table/table.js +48 -0
- package/src/components/hamzus-ui/Tabs/Tabs.svelte +87 -0
- package/src/components/hamzus-ui/TabsLink/Tabs.svelte +80 -0
- package/src/components/hamzus-ui/Tag/Tag.svelte +43 -0
- package/src/components/hamzus-ui/TinyScrollArea/TinyScrollArea.svelte +350 -0
- package/src/styles/font.css +71 -0
- package/src/styles/global.css +37 -0
- package/src/styles/variables.css +81 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Portal from '@hamzus-ui/Portal/Portal.svelte';
|
|
3
|
+
import { onDestroy, onMount } from 'svelte';
|
|
4
|
+
|
|
5
|
+
// import
|
|
6
|
+
|
|
7
|
+
// props
|
|
8
|
+
export let triggerFullWidth = false;
|
|
9
|
+
export let direction = 'bottom';
|
|
10
|
+
export let onOpen = undefined;
|
|
11
|
+
// locale var
|
|
12
|
+
let display = false;
|
|
13
|
+
let exit = false;
|
|
14
|
+
|
|
15
|
+
let originalParent;
|
|
16
|
+
let trigger;
|
|
17
|
+
let content;
|
|
18
|
+
let contentContainer;
|
|
19
|
+
|
|
20
|
+
let top = 0;
|
|
21
|
+
let left = 0;
|
|
22
|
+
|
|
23
|
+
const padding = 7;
|
|
24
|
+
|
|
25
|
+
const entryPosition = {
|
|
26
|
+
bottom: ['-12px', '0px'],
|
|
27
|
+
top: ['12px', '0px'],
|
|
28
|
+
left: ['0px', '12px'],
|
|
29
|
+
right: ['0px', '-12px']
|
|
30
|
+
};
|
|
31
|
+
// function
|
|
32
|
+
function handleDisplay(e) {
|
|
33
|
+
if (!calc[direction]) {
|
|
34
|
+
console.error('Error : direction props not found !');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!display) {
|
|
38
|
+
[top, left] = calc[direction]();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
toggleDisplay();
|
|
42
|
+
|
|
43
|
+
if (onOpen !== undefined && typeof onOpen === 'function') {
|
|
44
|
+
onOpen(e)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function toggleDisplay() {
|
|
49
|
+
if (display) {
|
|
50
|
+
// appliquer une animation
|
|
51
|
+
exit = true;
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
exit = false;
|
|
54
|
+
}, 200);
|
|
55
|
+
|
|
56
|
+
disableExitEvent();
|
|
57
|
+
enableScroll();
|
|
58
|
+
} else {
|
|
59
|
+
enableExitEvent();
|
|
60
|
+
disableScroll();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
display = !display;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const calc = {
|
|
67
|
+
bottom: () => {
|
|
68
|
+
// recuperer la taille du content
|
|
69
|
+
const contentWidth = content.offsetWidth;
|
|
70
|
+
const contentHeight = content.offsetHeight;
|
|
71
|
+
// recuperer la taille du trigger
|
|
72
|
+
const triggerWidth = trigger.offsetWidth;
|
|
73
|
+
const triggerHeight = trigger.offsetHeight;
|
|
74
|
+
// recuperer la position du trigger par rapport a la fenetre
|
|
75
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
76
|
+
const triggerTop = triggerRect.top;
|
|
77
|
+
const triggerLeft = triggerRect.left;
|
|
78
|
+
const triggerBottom = window.innerHeight - triggerTop - triggerHeight;
|
|
79
|
+
const triggerRight = window.innerWidth - triggerLeft - triggerWidth;
|
|
80
|
+
|
|
81
|
+
// return values
|
|
82
|
+
let topCalc = triggerTop + triggerHeight + padding;
|
|
83
|
+
let leftCalc = triggerLeft - (contentWidth - triggerWidth) / 2;
|
|
84
|
+
|
|
85
|
+
// verifier si il y a assez de la place en bas
|
|
86
|
+
if (triggerBottom < contentHeight) {
|
|
87
|
+
topCalc = window.innerHeight - contentHeight - padding;
|
|
88
|
+
}
|
|
89
|
+
// verifier si il y a assez de place a droite
|
|
90
|
+
if (triggerRight < (contentWidth - triggerWidth) / 2) {
|
|
91
|
+
leftCalc = window.innerWidth - contentWidth - padding;
|
|
92
|
+
}
|
|
93
|
+
// verifier si il y a assez de place a gauche
|
|
94
|
+
|
|
95
|
+
if (triggerLeft < (contentWidth - triggerWidth) / 2) {
|
|
96
|
+
leftCalc = padding;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return [topCalc, leftCalc];
|
|
100
|
+
},
|
|
101
|
+
top: () => {
|
|
102
|
+
// recuperer la taille du content
|
|
103
|
+
const contentWidth = content.offsetWidth;
|
|
104
|
+
const contentHeight = content.offsetHeight;
|
|
105
|
+
// recuperer la taille du trigger
|
|
106
|
+
const triggerWidth = trigger.offsetWidth;
|
|
107
|
+
const triggerHeight = trigger.offsetHeight;
|
|
108
|
+
// recuperer la position du trigger par rapport a la fenetre
|
|
109
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
110
|
+
const triggerTop = triggerRect.top;
|
|
111
|
+
const triggerBottom = window.innerHeight - triggerTop - triggerHeight;
|
|
112
|
+
const triggerLeft = triggerRect.left;
|
|
113
|
+
const triggerRight = window.innerWidth - triggerLeft - triggerWidth;
|
|
114
|
+
|
|
115
|
+
// return values
|
|
116
|
+
let topCalc = triggerTop - contentHeight - padding;
|
|
117
|
+
let leftCalc = triggerLeft - (contentWidth - triggerWidth) / 2;
|
|
118
|
+
|
|
119
|
+
// verifier si il y a assez de la place en haut
|
|
120
|
+
if (triggerTop < contentHeight) {
|
|
121
|
+
topCalc = padding;
|
|
122
|
+
}
|
|
123
|
+
// verifier si il y a assez de la place en bas
|
|
124
|
+
if (triggerBottom + triggerHeight < contentHeight) {
|
|
125
|
+
topCalc = padding;
|
|
126
|
+
}
|
|
127
|
+
// verifier si il y a assez de place a gauche
|
|
128
|
+
if (triggerLeft < (contentWidth - triggerWidth) / 2) {
|
|
129
|
+
leftCalc = padding;
|
|
130
|
+
}
|
|
131
|
+
// verifier si il y a assez de place a droite
|
|
132
|
+
if (triggerRight < (contentWidth - triggerWidth) / 2) {
|
|
133
|
+
leftCalc = window.innerWidth - contentWidth - padding;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return [topCalc, leftCalc];
|
|
137
|
+
},
|
|
138
|
+
left: () => {
|
|
139
|
+
// recuperer la taille du content
|
|
140
|
+
const contentWidth = content.offsetWidth;
|
|
141
|
+
const contentHeight = content.offsetHeight;
|
|
142
|
+
// recuperer la taille du trigger
|
|
143
|
+
const triggerWidth = trigger.offsetWidth;
|
|
144
|
+
const triggerHeight = trigger.offsetHeight;
|
|
145
|
+
// recuperer la position du trigger par rapport a la fenetre
|
|
146
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
147
|
+
const triggerTop = triggerRect.top;
|
|
148
|
+
const triggerBottom = window.innerHeight - triggerTop - triggerHeight;
|
|
149
|
+
const triggerLeft = triggerRect.left;
|
|
150
|
+
const triggerRight = window.innerWidth - triggerLeft - triggerWidth;
|
|
151
|
+
|
|
152
|
+
// return values
|
|
153
|
+
let topCalc = triggerTop;
|
|
154
|
+
let leftCalc = triggerLeft - contentWidth - padding;
|
|
155
|
+
|
|
156
|
+
// verifier si il y a assez de la place en haut
|
|
157
|
+
if (triggerTop < 0) {
|
|
158
|
+
topCalc = padding;
|
|
159
|
+
}
|
|
160
|
+
// verifier si il y a assez de la place en bas
|
|
161
|
+
if (triggerBottom < (contentHeight - triggerHeight)) {
|
|
162
|
+
topCalc = window.innerHeight - contentHeight - padding;
|
|
163
|
+
}
|
|
164
|
+
// verifier si il y a assez de place a gauche
|
|
165
|
+
if (triggerLeft < contentWidth + padding) {
|
|
166
|
+
leftCalc = padding;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return [topCalc, leftCalc];
|
|
170
|
+
},
|
|
171
|
+
right: () => {
|
|
172
|
+
// recuperer la taille du content
|
|
173
|
+
const contentWidth = content.offsetWidth;
|
|
174
|
+
const contentHeight = content.offsetHeight;
|
|
175
|
+
// recuperer la taille du trigger
|
|
176
|
+
const triggerWidth = trigger.offsetWidth;
|
|
177
|
+
const triggerHeight = trigger.offsetHeight;
|
|
178
|
+
// recuperer la position du trigger par rapport a la fenetre
|
|
179
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
180
|
+
const triggerTop = triggerRect.top;
|
|
181
|
+
const triggerBottom = window.innerHeight - triggerTop - triggerHeight;
|
|
182
|
+
const triggerLeft = triggerRect.left;
|
|
183
|
+
const triggerRight = window.innerWidth - triggerLeft - triggerWidth;
|
|
184
|
+
|
|
185
|
+
// return values
|
|
186
|
+
let topCalc = triggerTop;
|
|
187
|
+
let leftCalc = triggerLeft + triggerWidth + padding;
|
|
188
|
+
|
|
189
|
+
// verifier si il y a assez de la place en haut
|
|
190
|
+
if (triggerTop < 0) {
|
|
191
|
+
topCalc = padding;
|
|
192
|
+
}
|
|
193
|
+
// verifier si il y a assez de la place en bas
|
|
194
|
+
if (triggerBottom < (contentHeight - triggerHeight)) {
|
|
195
|
+
topCalc = window.innerHeight - contentHeight - padding;
|
|
196
|
+
}
|
|
197
|
+
// verifier si il y a assez de place a droite
|
|
198
|
+
if (triggerRight < contentWidth + padding) {
|
|
199
|
+
leftCalc = window.innerWidth - contentWidth - padding - triggerWidth;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return [topCalc, leftCalc];
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// Bloquer le scroll
|
|
207
|
+
function disableScroll() {
|
|
208
|
+
document.addEventListener('userScroll', updatePos);
|
|
209
|
+
window.addEventListener('scroll', updatePos);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Réactiver le scroll
|
|
213
|
+
function enableScroll() {
|
|
214
|
+
document.removeEventListener('userScroll', updatePos);
|
|
215
|
+
window.removeEventListener('scroll', updatePos);
|
|
216
|
+
}
|
|
217
|
+
function updatePos(e) {
|
|
218
|
+
// recalculer la position
|
|
219
|
+
if (!display) {
|
|
220
|
+
return
|
|
221
|
+
}
|
|
222
|
+
[top, left] = calc[direction]();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function enableExitEvent() {
|
|
226
|
+
document.addEventListener('click', checkClick);
|
|
227
|
+
}
|
|
228
|
+
function disableExitEvent() {
|
|
229
|
+
document.removeEventListener('click', checkClick);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function checkClick(event) {
|
|
233
|
+
|
|
234
|
+
if (event.target.closest('.parent-popover-hamzus') && event.target.closest('.parent-popover-hamzus') === originalParent) {
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
if (event.target.closest('.content-popover-hamzus') && event.target.closest('.content-popover-hamzus') === content) {
|
|
238
|
+
return
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
handleDisplay();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
onMount(() => {
|
|
245
|
+
return () => {
|
|
246
|
+
document.removeEventListener('userScroll', updatePos);
|
|
247
|
+
window.removeEventListener('scroll', updatePos);
|
|
248
|
+
document.removeEventListener('click', checkClick);
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
</script>
|
|
252
|
+
|
|
253
|
+
<dropdown bind:this={originalParent} style="{triggerFullWidth ? "width:100%;" : ""}" class="parent-popover-hamzus">
|
|
254
|
+
<div bind:this={trigger} class="trigger" style="{triggerFullWidth ? "width:100%;" : ""}" on:click={handleDisplay}>
|
|
255
|
+
<slot name="trigger" />
|
|
256
|
+
</div>
|
|
257
|
+
<Portal disabled={!display} target="body">
|
|
258
|
+
<content-container bind:this={contentContainer}>
|
|
259
|
+
<content
|
|
260
|
+
bind:this={content}
|
|
261
|
+
class="content content-popover-hamzus"
|
|
262
|
+
class:display
|
|
263
|
+
class:exit
|
|
264
|
+
style="--left:{left}px;--top:{top}px;--transform-x:{entryPosition[
|
|
265
|
+
direction
|
|
266
|
+
][1]};--transform-y:{entryPosition[direction][0]};"
|
|
267
|
+
>
|
|
268
|
+
<slot name="content" />
|
|
269
|
+
</content>
|
|
270
|
+
</content-container>
|
|
271
|
+
</Portal>
|
|
272
|
+
</dropdown>
|
|
273
|
+
|
|
274
|
+
<style>
|
|
275
|
+
.trigger {
|
|
276
|
+
all: unset;
|
|
277
|
+
width: max-content;
|
|
278
|
+
display: inline-block;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.content {
|
|
282
|
+
position: fixed;
|
|
283
|
+
top: var(--top);
|
|
284
|
+
left: var(--left);
|
|
285
|
+
display: block;
|
|
286
|
+
user-select: none;
|
|
287
|
+
pointer-events: none;
|
|
288
|
+
opacity: 0;
|
|
289
|
+
z-index: 2;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.content.exit {
|
|
293
|
+
display: block;
|
|
294
|
+
animation-name: exit;
|
|
295
|
+
animation-duration: 0.2s;
|
|
296
|
+
animation-timing-function: ease-out;
|
|
297
|
+
}
|
|
298
|
+
.content.display {
|
|
299
|
+
display: block;
|
|
300
|
+
animation-name: entry;
|
|
301
|
+
animation-duration: 0.2s;
|
|
302
|
+
animation-timing-function: ease-out;
|
|
303
|
+
user-select: initial;
|
|
304
|
+
pointer-events: initial;
|
|
305
|
+
opacity: 1;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
@keyframes entry {
|
|
309
|
+
from {
|
|
310
|
+
display: block;
|
|
311
|
+
opacity: 0;
|
|
312
|
+
user-select: none;
|
|
313
|
+
pointer-events: none;
|
|
314
|
+
transform: translate(var(--transform-x), var(--transform-y)) scale(0.86);
|
|
315
|
+
}
|
|
316
|
+
to {
|
|
317
|
+
display: block;
|
|
318
|
+
opacity: 1;
|
|
319
|
+
user-select: initial;
|
|
320
|
+
pointer-events: initial;
|
|
321
|
+
transform: translate(0px, 0px) scale(1);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
@keyframes exit {
|
|
325
|
+
from {
|
|
326
|
+
display: block;
|
|
327
|
+
opacity: 1;
|
|
328
|
+
user-select: initial;
|
|
329
|
+
pointer-events: initial;
|
|
330
|
+
transform: translate(0px, 0px) scale(1);
|
|
331
|
+
}
|
|
332
|
+
to {
|
|
333
|
+
display: block;
|
|
334
|
+
opacity: 0;
|
|
335
|
+
user-select: none;
|
|
336
|
+
pointer-events: none;
|
|
337
|
+
transform: translate(var(--transform-x), var(--transform-y)) scale(0.86);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
</style>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<slot/>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as Root } from './Root.svelte';
|
|
2
|
+
export { default as Trigger } from './Trigger.svelte';
|
|
3
|
+
export { default as Content } from './Content.svelte';
|
|
4
|
+
export { default as Label } from './Label.svelte';
|
|
5
|
+
export { default as Separator } from './Separator.svelte';
|
|
6
|
+
export { default as Button } from './Button.svelte';
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
// import
|
|
3
|
+
import ButtonDefault from "./IconButton_default.svelte";
|
|
4
|
+
import ButtonLink from "./IconButton_link.svelte";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// props
|
|
8
|
+
export let variant = 'primary';
|
|
9
|
+
export let loading = false;
|
|
10
|
+
export let desabled = false;
|
|
11
|
+
export let href = "";
|
|
12
|
+
export let onClick = undefined;
|
|
13
|
+
export let avoidRipple = false;
|
|
14
|
+
// local var
|
|
15
|
+
const colorConfig = {
|
|
16
|
+
primary: {
|
|
17
|
+
defaultBg: '--accent',
|
|
18
|
+
defaultBorder:'',
|
|
19
|
+
defaultColor: '--white',
|
|
20
|
+
hoverBg: '--accent-b',
|
|
21
|
+
hoverBorder:'',
|
|
22
|
+
hoverColor: '--white-d'
|
|
23
|
+
},
|
|
24
|
+
secondary: {
|
|
25
|
+
defaultBg: '--bg-2',
|
|
26
|
+
defaultBorder:'',
|
|
27
|
+
defaultColor: '--font-u',
|
|
28
|
+
hoverBg: '--bg-3',
|
|
29
|
+
hoverBorder:'',
|
|
30
|
+
hoverColor: '--font-d'
|
|
31
|
+
},
|
|
32
|
+
ghost: {
|
|
33
|
+
defaultBg: '',
|
|
34
|
+
defaultBorder:'',
|
|
35
|
+
defaultColor: '--font-d',
|
|
36
|
+
hoverBg: '--bg-3',
|
|
37
|
+
hoverBorder:'',
|
|
38
|
+
hoverColor: '--font-u'
|
|
39
|
+
},
|
|
40
|
+
outline: {
|
|
41
|
+
defaultBg: '',
|
|
42
|
+
defaultBorder:'--stroke',
|
|
43
|
+
defaultColor: '--font-d',
|
|
44
|
+
hoverBg: '--bg-2',
|
|
45
|
+
hoverBorder:'--stroke',
|
|
46
|
+
hoverColor: '--font-u'
|
|
47
|
+
},
|
|
48
|
+
destructive: {
|
|
49
|
+
defaultBg: '--red-b',
|
|
50
|
+
defaultBorder:'--red',
|
|
51
|
+
defaultColor: '--red',
|
|
52
|
+
hoverBg: '--red',
|
|
53
|
+
hoverBorder:'--red-b',
|
|
54
|
+
hoverColor: '--white'
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
// functions
|
|
58
|
+
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<div
|
|
62
|
+
style="
|
|
63
|
+
--button-default-bg:var({colorConfig[variant].defaultBg});
|
|
64
|
+
--button-default-border:var({colorConfig[variant].defaultBorder});
|
|
65
|
+
--button-default-color:var({colorConfig[variant].defaultColor});
|
|
66
|
+
--button-hover-bg:var({colorConfig[variant].hoverBg});
|
|
67
|
+
--button-hover-border:var({colorConfig[variant].hoverBorder});
|
|
68
|
+
--button-hover-color:var({colorConfig[variant].hoverColor});
|
|
69
|
+
"
|
|
70
|
+
>
|
|
71
|
+
{#if href}
|
|
72
|
+
<ButtonLink {href} {onClick} {...$$restProps} {loading} {desabled} {avoidRipple}>
|
|
73
|
+
<slot/>
|
|
74
|
+
</ButtonLink>
|
|
75
|
+
{:else}
|
|
76
|
+
<ButtonDefault {onClick} {...$$restProps} {loading} {desabled} {avoidRipple}>
|
|
77
|
+
<slot/>
|
|
78
|
+
</ButtonDefault>
|
|
79
|
+
{/if}
|
|
80
|
+
</div>
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
// import
|
|
3
|
+
import Loader from '@hamzus-ui/LoaderCircle/Loader.svelte';
|
|
4
|
+
// props
|
|
5
|
+
export let loading = false
|
|
6
|
+
export let desabled = false
|
|
7
|
+
export let onClick = undefined
|
|
8
|
+
export let avoidRipple = false;
|
|
9
|
+
// local var
|
|
10
|
+
let button
|
|
11
|
+
// functions
|
|
12
|
+
function handleClick(event) {
|
|
13
|
+
if (!desabled && !loading) {
|
|
14
|
+
createRipple(event)
|
|
15
|
+
if (onClick && typeof onClick === "function") {
|
|
16
|
+
onClick()
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function createRipple(event) {
|
|
21
|
+
if (avoidRipple) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const ripple = document.createElement('span');
|
|
26
|
+
|
|
27
|
+
const rect = button.getBoundingClientRect();
|
|
28
|
+
const x = event.clientX - rect.left;
|
|
29
|
+
const y = event.clientY - rect.top;
|
|
30
|
+
|
|
31
|
+
ripple.style.left = `${x}px`;
|
|
32
|
+
ripple.style.top = `${y}px`;
|
|
33
|
+
ripple.classList.add('ripple');
|
|
34
|
+
|
|
35
|
+
button.appendChild(ripple);
|
|
36
|
+
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
ripple.remove();
|
|
39
|
+
}, 1000);
|
|
40
|
+
}
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<button bind:this={button} on:click={handleClick} class="button h4" class:desabled class:loading {...$$restProps}>
|
|
44
|
+
<slot/>
|
|
45
|
+
{#if loading}
|
|
46
|
+
<div class="loader">
|
|
47
|
+
<Loader size="16px" color="var(--button-default-color)"></Loader>
|
|
48
|
+
</div>
|
|
49
|
+
{/if}
|
|
50
|
+
</button>
|
|
51
|
+
<style>
|
|
52
|
+
.button{
|
|
53
|
+
display: flex;
|
|
54
|
+
align-items: center;
|
|
55
|
+
justify-content: center;
|
|
56
|
+
padding:var(--pad-s);
|
|
57
|
+
border-radius: var(--radius-m);
|
|
58
|
+
background-color: var(--button-default-bg);
|
|
59
|
+
color: var(--button-default-color);
|
|
60
|
+
transition-property: background-color, transform, color;
|
|
61
|
+
transition-duration: .2s;
|
|
62
|
+
transition-timing-function: ease-out;
|
|
63
|
+
cursor: pointer;
|
|
64
|
+
border: 1px solid var(--button-default-border);
|
|
65
|
+
width: max-content;
|
|
66
|
+
white-space: nowrap;
|
|
67
|
+
text-overflow: ellipsis;
|
|
68
|
+
overflow: hidden;
|
|
69
|
+
width: 30px;
|
|
70
|
+
height: 30px;
|
|
71
|
+
flex-shrink: 0;
|
|
72
|
+
position: relative;
|
|
73
|
+
}
|
|
74
|
+
.button :global(*) {
|
|
75
|
+
color: var(--button-default-color);
|
|
76
|
+
}
|
|
77
|
+
.button :global(svg){
|
|
78
|
+
height: 100%;
|
|
79
|
+
width: 100%;
|
|
80
|
+
flex-shrink: 0;
|
|
81
|
+
}
|
|
82
|
+
.button :global(svg > path) {
|
|
83
|
+
fill: var(--button-default-color);
|
|
84
|
+
}
|
|
85
|
+
/* states */
|
|
86
|
+
.button:not(.desabled):not(.loading):hover{
|
|
87
|
+
background-color: var(--button-hover-bg);
|
|
88
|
+
border: 1px solid var(--button-hover-border);
|
|
89
|
+
color: var(--button-hover-color);
|
|
90
|
+
}
|
|
91
|
+
.button:not(.desabled):not(.loading):hover :global(*) {
|
|
92
|
+
color: var(--button-hover-color);
|
|
93
|
+
}
|
|
94
|
+
.button:not(.desabled):not(.loading):hover :global(svg > path) {
|
|
95
|
+
fill: var(--button-hover-color);
|
|
96
|
+
}
|
|
97
|
+
.button:active{
|
|
98
|
+
transform: scale(.95);
|
|
99
|
+
}
|
|
100
|
+
.button.loading {
|
|
101
|
+
cursor: not-allowed;
|
|
102
|
+
}
|
|
103
|
+
.button.desabled {
|
|
104
|
+
opacity: .8;
|
|
105
|
+
cursor: not-allowed;
|
|
106
|
+
transform: scale(.9);
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
.button.loading :global(> *:not(.loader)){
|
|
110
|
+
opacity: 0;
|
|
111
|
+
user-select: none;
|
|
112
|
+
pointer-events: none;
|
|
113
|
+
}
|
|
114
|
+
.loader{
|
|
115
|
+
position: absolute;
|
|
116
|
+
top: 50%;
|
|
117
|
+
left: 50%;
|
|
118
|
+
transform: translate(-50%, -50%);
|
|
119
|
+
}
|
|
120
|
+
/* ripple */
|
|
121
|
+
.button :global(.ripple) {
|
|
122
|
+
width: 0px;
|
|
123
|
+
aspect-ratio: 1/1;
|
|
124
|
+
background: var(--ripple-gradient);
|
|
125
|
+
position: absolute;
|
|
126
|
+
transform: translate(-50%, -50%);
|
|
127
|
+
border-radius: 100%;
|
|
128
|
+
animation: grow 1s ease-out;
|
|
129
|
+
}
|
|
130
|
+
@keyframes grow {
|
|
131
|
+
from {
|
|
132
|
+
width: 0px;
|
|
133
|
+
opacity: 1;
|
|
134
|
+
}
|
|
135
|
+
to {
|
|
136
|
+
width: 500%;
|
|
137
|
+
opacity: 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
</style>
|