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,360 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { onDestroy, onMount } from 'svelte';
|
|
3
|
+
|
|
4
|
+
export let style = '';
|
|
5
|
+
export let additionalStyle = '';
|
|
6
|
+
export let className = '';
|
|
7
|
+
export let proximity = 20;
|
|
8
|
+
export let isReverse = false
|
|
9
|
+
|
|
10
|
+
let isVisible = false;
|
|
11
|
+
let lastMove = 0;
|
|
12
|
+
|
|
13
|
+
let focusVerticalTrack = false;
|
|
14
|
+
let focusHorizontalTrack = false;
|
|
15
|
+
|
|
16
|
+
let overflowX = true;
|
|
17
|
+
let overflowY = true;
|
|
18
|
+
|
|
19
|
+
let overflowXY = true;
|
|
20
|
+
|
|
21
|
+
let topTrack = 0;
|
|
22
|
+
let leftTrack = 0;
|
|
23
|
+
|
|
24
|
+
let heightTrack = 0;
|
|
25
|
+
let widthTrack = 0;
|
|
26
|
+
|
|
27
|
+
let scrollContainer;
|
|
28
|
+
let offsetHeight;
|
|
29
|
+
let offsetWidth;
|
|
30
|
+
|
|
31
|
+
let scrollArea;
|
|
32
|
+
let scrollHeight;
|
|
33
|
+
let scrollWidth;
|
|
34
|
+
let startscrollTop;
|
|
35
|
+
let startscrollLeft;
|
|
36
|
+
|
|
37
|
+
let startDragX;
|
|
38
|
+
let startDragY;
|
|
39
|
+
|
|
40
|
+
let mousemoveEvent = null;
|
|
41
|
+
let mouseupEvent = null;
|
|
42
|
+
|
|
43
|
+
onMount(mount);
|
|
44
|
+
|
|
45
|
+
let scrollEvent = null
|
|
46
|
+
|
|
47
|
+
function scrollEventEmmiter() {
|
|
48
|
+
const monEvenement = new CustomEvent("userScroll",{});
|
|
49
|
+
document.dispatchEvent(monEvenement);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function mount() {
|
|
53
|
+
scrollEvent = scrollArea.addEventListener('scroll', scrollEventEmmiter)
|
|
54
|
+
|
|
55
|
+
// calculer la height de la track
|
|
56
|
+
scrollHeight = scrollArea.scrollHeight;
|
|
57
|
+
offsetHeight = scrollContainer.offsetHeight;
|
|
58
|
+
|
|
59
|
+
scrollWidth = scrollArea.scrollWidth;
|
|
60
|
+
offsetWidth = scrollContainer.offsetWidth;
|
|
61
|
+
|
|
62
|
+
const verticalTrackSize = (offsetHeight / scrollHeight) * 100;
|
|
63
|
+
const horizontalTrackSize = (offsetWidth / scrollWidth) * 100;
|
|
64
|
+
|
|
65
|
+
overflowX = scrollWidth != offsetWidth;
|
|
66
|
+
overflowY = scrollHeight != offsetHeight;
|
|
67
|
+
|
|
68
|
+
overflowXY = overflowX && overflowY;
|
|
69
|
+
|
|
70
|
+
heightTrack = verticalTrackSize;
|
|
71
|
+
widthTrack = horizontalTrackSize;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
onDestroy(()=>{
|
|
75
|
+
if (scrollEvent) {
|
|
76
|
+
scrollArea.removeEventListener('scroll', scrollEventEmmiter)
|
|
77
|
+
scrollEvent = null
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
function handleStartScrollVertical(event) {
|
|
82
|
+
startDragX = null;
|
|
83
|
+
startDragY = event.clientY;
|
|
84
|
+
|
|
85
|
+
// verifier sa position relativement a la scroll bar
|
|
86
|
+
let scrollAreaTop = scrollContainer.getBoundingClientRect()[isReverse ? "bottom" : "top"];
|
|
87
|
+
let relativePosFromTop = startDragY - scrollAreaTop;
|
|
88
|
+
let topRatio = relativePosFromTop / scrollContainer.getBoundingClientRect().height;
|
|
89
|
+
|
|
90
|
+
// recuperer en ratio la taille de la demi de la scrolltrack
|
|
91
|
+
let scrollTrackHeightRatio = heightTrack / 100;
|
|
92
|
+
if (isReverse) {
|
|
93
|
+
scrollTrackHeightRatio = - scrollTrackHeightRatio
|
|
94
|
+
}
|
|
95
|
+
scrollArea.scrollTo(
|
|
96
|
+
scrollArea.scrollLeft,
|
|
97
|
+
scrollArea.scrollHeight * (topRatio - scrollTrackHeightRatio / 2)
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// let percentTop = relativePosFromTop / scrollContainer.offsetHeight
|
|
101
|
+
|
|
102
|
+
// let initialProgress = scrollArea.scrollHeight * percentTop
|
|
103
|
+
// console.log(scrollArea.scrollHeight);
|
|
104
|
+
// console.log(initialProgress);
|
|
105
|
+
// scrollArea.scrollTo(scrollArea.scrollLeft, initialProgress)
|
|
106
|
+
|
|
107
|
+
focusVerticalTrack = true;
|
|
108
|
+
|
|
109
|
+
startscrollTop = scrollArea.scrollTop;
|
|
110
|
+
|
|
111
|
+
// calculer le deplacement
|
|
112
|
+
mousemoveEvent = document.addEventListener('mousemove', handleMouseMove);
|
|
113
|
+
|
|
114
|
+
mouseupEvent = document.addEventListener('mouseup', handleStopScroll);
|
|
115
|
+
}
|
|
116
|
+
function handleStartScrollHorizontal(event) {
|
|
117
|
+
startDragX = event.clientX;
|
|
118
|
+
startDragY = null;
|
|
119
|
+
|
|
120
|
+
// verifier sa position relativement a la scroll bar
|
|
121
|
+
let scrollAreaLeft = scrollContainer.getBoundingClientRect().left;
|
|
122
|
+
let relativePosFromLeft = startDragX - scrollAreaLeft;
|
|
123
|
+
let leftRatio = relativePosFromLeft / scrollContainer.getBoundingClientRect().width;
|
|
124
|
+
|
|
125
|
+
// recuperer en ratio la taille de la demi de la scrolltrack
|
|
126
|
+
let scrollTrackWidthRatio = widthTrack / 100;
|
|
127
|
+
|
|
128
|
+
scrollArea.scrollTo(
|
|
129
|
+
scrollArea.scrollWidth * (leftRatio - scrollTrackWidthRatio / 2),
|
|
130
|
+
scrollArea.scrollTop
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
focusHorizontalTrack = true;
|
|
134
|
+
|
|
135
|
+
startscrollLeft = scrollArea.scrollLeft;
|
|
136
|
+
// calculer le deplacement
|
|
137
|
+
mousemoveEvent = document.addEventListener('mousemove', handleMouseMove);
|
|
138
|
+
|
|
139
|
+
mouseupEvent = document.addEventListener('mouseup', handleStopScroll);
|
|
140
|
+
}
|
|
141
|
+
function handleMouseMove(event) {
|
|
142
|
+
// calculer la pose et scroll
|
|
143
|
+
if (startDragX) {
|
|
144
|
+
// scroll horizontal
|
|
145
|
+
const deltaX = event.clientX - startDragX;
|
|
146
|
+
const cursorToScroll = (deltaX / offsetWidth) * scrollWidth;
|
|
147
|
+
scrollArea.scrollTo(startscrollLeft + cursorToScroll, scrollArea.scrollTop);
|
|
148
|
+
} else {
|
|
149
|
+
// scroll vertical
|
|
150
|
+
const deltaY = event.clientY - startDragY;
|
|
151
|
+
const cursorToScroll = (deltaY / offsetHeight) * scrollHeight;
|
|
152
|
+
scrollArea.scrollTo(scrollArea.scrollLeft, startscrollTop + cursorToScroll);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function handleStopScroll(event) {
|
|
157
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
158
|
+
mousemoveEvent = null;
|
|
159
|
+
|
|
160
|
+
document.removeEventListener('mouseup', handleStopScroll);
|
|
161
|
+
mouseupEvent = null;
|
|
162
|
+
|
|
163
|
+
// calculer la pose et scroll
|
|
164
|
+
if (startDragX) {
|
|
165
|
+
// scroll horizontal
|
|
166
|
+
const deltaX = event.clientX - startDragX;
|
|
167
|
+
const cursorToScroll = (deltaX / offsetWidth) * scrollWidth;
|
|
168
|
+
scrollArea.scrollTo(startscrollLeft + cursorToScroll, scrollArea.scrollTop);
|
|
169
|
+
focusHorizontalTrack = false;
|
|
170
|
+
} else {
|
|
171
|
+
// scroll vertical
|
|
172
|
+
const deltaY = event.clientY - startDragY;
|
|
173
|
+
const cursorToScroll = (deltaY / offsetHeight) * scrollHeight;
|
|
174
|
+
scrollArea.scrollTo(scrollArea.scrollLeft, startscrollTop + cursorToScroll);
|
|
175
|
+
focusVerticalTrack = false;
|
|
176
|
+
}
|
|
177
|
+
startDragX = null
|
|
178
|
+
startDragY = null
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function handleScroll() {
|
|
182
|
+
let calcTop = (scrollArea.scrollTop / scrollHeight) * 100;
|
|
183
|
+
leftTrack = (scrollArea.scrollLeft / scrollWidth) * 100;
|
|
184
|
+
|
|
185
|
+
topTrack = isReverse ? -calcTop : calcTop
|
|
186
|
+
|
|
187
|
+
}
|
|
188
|
+
function handleDisplayScrollBar() {
|
|
189
|
+
|
|
190
|
+
if (lastMove + 800 < Date.now()) {
|
|
191
|
+
mount();
|
|
192
|
+
}
|
|
193
|
+
isVisible = true;
|
|
194
|
+
lastMove = Date.now();
|
|
195
|
+
setTimeout(() => {
|
|
196
|
+
if (lastMove + 750 < Date.now()) {
|
|
197
|
+
isVisible = false;
|
|
198
|
+
}
|
|
199
|
+
}, 800);
|
|
200
|
+
}
|
|
201
|
+
</script>
|
|
202
|
+
|
|
203
|
+
<scrollarea-container
|
|
204
|
+
role="scrollbar"
|
|
205
|
+
tabindex="-1"
|
|
206
|
+
bind:this={scrollContainer}
|
|
207
|
+
on:resize={mount}
|
|
208
|
+
class="scrollarea-container"
|
|
209
|
+
{style}
|
|
210
|
+
on:mousemove={handleDisplayScrollBar}
|
|
211
|
+
>
|
|
212
|
+
<scrollarea
|
|
213
|
+
on:scroll={handleScroll}
|
|
214
|
+
bind:this={scrollArea}
|
|
215
|
+
style="{style + additionalStyle}"
|
|
216
|
+
class="scrollarea {className} {startDragY ? "is-scrolling" : ""}"
|
|
217
|
+
>
|
|
218
|
+
<slot />
|
|
219
|
+
</scrollarea>
|
|
220
|
+
{#if overflowY && (isVisible || startDragY)}
|
|
221
|
+
<div
|
|
222
|
+
role="button"
|
|
223
|
+
tabindex="-1"
|
|
224
|
+
class="vertical-sb {overflowXY ? 'global-overflow' : ''}"
|
|
225
|
+
on:mousedown|preventDefault={handleStartScrollVertical}
|
|
226
|
+
>
|
|
227
|
+
<span
|
|
228
|
+
class="vertical-track {proximity ? 'proxy' : ''} {focusVerticalTrack ? 'focus' : ''}"
|
|
229
|
+
style="--proximity:{proximity}px;height:{heightTrack}%;{isReverse ? "bottom" : "top"}:{topTrack}%;"
|
|
230
|
+
></span>
|
|
231
|
+
</div>
|
|
232
|
+
{/if}
|
|
233
|
+
{#if overflowX && (isVisible || startDragY)}
|
|
234
|
+
<div
|
|
235
|
+
role="button"
|
|
236
|
+
tabindex="-1"
|
|
237
|
+
class="horizontal-sb {overflowXY ? 'global-overflow' : ''}"
|
|
238
|
+
on:mousedown|preventDefault={handleStartScrollHorizontal}
|
|
239
|
+
>
|
|
240
|
+
<span
|
|
241
|
+
class="horizontal-track {proximity ? 'proxy' : ''} {focusHorizontalTrack ? 'focus' : ''}"
|
|
242
|
+
style="--proximity:{proximity}px;width:{widthTrack}%;left:{leftTrack}%;"
|
|
243
|
+
></span>
|
|
244
|
+
</div>
|
|
245
|
+
{/if}
|
|
246
|
+
{#if overflowXY}
|
|
247
|
+
<div class="overflow-xy-corner"></div>
|
|
248
|
+
{/if}
|
|
249
|
+
</scrollarea-container>
|
|
250
|
+
|
|
251
|
+
<style>
|
|
252
|
+
.scrollarea-container {
|
|
253
|
+
position: relative;
|
|
254
|
+
display: flex;
|
|
255
|
+
overflow: hidden;
|
|
256
|
+
width: 100%;
|
|
257
|
+
height: 100%;
|
|
258
|
+
flex: 1;
|
|
259
|
+
}
|
|
260
|
+
.scrollarea {
|
|
261
|
+
overflow: scroll;
|
|
262
|
+
width: 100%;
|
|
263
|
+
height: 100%;
|
|
264
|
+
flex: 1;
|
|
265
|
+
display: flex;
|
|
266
|
+
flex-direction: column;
|
|
267
|
+
/* Pour Firefox plus ancien */
|
|
268
|
+
overflow: -moz-scrollbars-none;
|
|
269
|
+
/* Pour Internet Explorer et Edge */
|
|
270
|
+
-ms-overflow-style: none;
|
|
271
|
+
scrollbar-width: none;
|
|
272
|
+
/* display: contents; */
|
|
273
|
+
}
|
|
274
|
+
.scrollarea:not(.is-scrolling){
|
|
275
|
+
/* scroll-behavior: smooth; */
|
|
276
|
+
}
|
|
277
|
+
.scrollarea::-webkit-scrollbar {
|
|
278
|
+
display: none;
|
|
279
|
+
/* Chrome, Safari, Edge */
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.vertical-sb {
|
|
283
|
+
position: absolute;
|
|
284
|
+
top: 0;
|
|
285
|
+
right: 0;
|
|
286
|
+
height: 100%;
|
|
287
|
+
width: 12px;
|
|
288
|
+
background-color: rgba(143, 143, 143, 0.082);
|
|
289
|
+
z-index: 10;
|
|
290
|
+
}
|
|
291
|
+
.vertical-sb.global-overflow {
|
|
292
|
+
height: calc(100% - 12px);
|
|
293
|
+
}
|
|
294
|
+
.vertical-track {
|
|
295
|
+
--size: 7px;
|
|
296
|
+
position: absolute;
|
|
297
|
+
right: 0px;
|
|
298
|
+
width: var(--size);
|
|
299
|
+
background-color: rgba(122, 122, 122, 0.336);
|
|
300
|
+
border-radius: calc(var(--size) / 2);
|
|
301
|
+
border-top-right-radius: 0px;
|
|
302
|
+
border-bottom-right-radius: 0px;
|
|
303
|
+
transition: width 0.2s ease-out;
|
|
304
|
+
}
|
|
305
|
+
.vertical-track.proxy::after {
|
|
306
|
+
content: '';
|
|
307
|
+
position: absolute;
|
|
308
|
+
top: 0;
|
|
309
|
+
right: 0;
|
|
310
|
+
width: calc(12px + var(--proximity));
|
|
311
|
+
height: 100%;
|
|
312
|
+
}
|
|
313
|
+
.vertical-track.proxy:hover,
|
|
314
|
+
.vertical-track.proxy.focus {
|
|
315
|
+
width: calc(100% + var(--proximity));
|
|
316
|
+
}
|
|
317
|
+
.horizontal-sb {
|
|
318
|
+
position: absolute;
|
|
319
|
+
bottom: 0;
|
|
320
|
+
left: 0;
|
|
321
|
+
height: 12px;
|
|
322
|
+
width: 100%;
|
|
323
|
+
background-color: rgba(143, 143, 143, 0.082);
|
|
324
|
+
z-index: 10;
|
|
325
|
+
}
|
|
326
|
+
.horizontal-sb.global-overflow {
|
|
327
|
+
width: calc(100% - 12px);
|
|
328
|
+
}
|
|
329
|
+
.horizontal-track {
|
|
330
|
+
--size: 7px;
|
|
331
|
+
position: absolute;
|
|
332
|
+
bottom: 0;
|
|
333
|
+
height: var(--size);
|
|
334
|
+
background-color: rgba(122, 122, 122, 0.336);
|
|
335
|
+
border-radius: calc(var(--size) / 2);
|
|
336
|
+
border-bottom-left-radius: 0px;
|
|
337
|
+
border-bottom-right-radius: 0px;
|
|
338
|
+
transition: height 0.2s ease-out;
|
|
339
|
+
}
|
|
340
|
+
.horizontal-track.proxy::after {
|
|
341
|
+
content: '';
|
|
342
|
+
position: absolute;
|
|
343
|
+
bottom: 0;
|
|
344
|
+
right: 0;
|
|
345
|
+
height: calc(12px + var(--proximity));
|
|
346
|
+
width: 100%;
|
|
347
|
+
}
|
|
348
|
+
.horizontal-track.proxy:hover,
|
|
349
|
+
.horizontal-track.proxy.focus {
|
|
350
|
+
height: calc(100% + var(--proximity));
|
|
351
|
+
}
|
|
352
|
+
.overflow-xy-corner {
|
|
353
|
+
position: absolute;
|
|
354
|
+
bottom: 0;
|
|
355
|
+
right: 0;
|
|
356
|
+
width: 12px;
|
|
357
|
+
height: 12px;
|
|
358
|
+
background-color: rgba(143, 143, 143, 0.082);
|
|
359
|
+
}
|
|
360
|
+
</style>
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
export let style;
|
|
3
|
+
export let size = 24;
|
|
4
|
+
export let checked = false;
|
|
5
|
+
export let disabled = false;
|
|
6
|
+
export let disabledIcon = false;
|
|
7
|
+
export let onChange = undefined;
|
|
8
|
+
export let label;
|
|
9
|
+
|
|
10
|
+
import './index.css';
|
|
11
|
+
|
|
12
|
+
function handleChange() {
|
|
13
|
+
|
|
14
|
+
if (disabled) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
checked = !checked;
|
|
19
|
+
if (onChange && typeof onChange === 'function') {
|
|
20
|
+
onChange(checked)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<label class="label-switch">
|
|
26
|
+
{#if label}
|
|
27
|
+
<h4>{label}</h4>
|
|
28
|
+
{/if}
|
|
29
|
+
<div
|
|
30
|
+
style="width:{size * 2 + 4}px;height:{size + 4}px;--size:{size + 4}px; {style ? style : ''}"
|
|
31
|
+
class="switch {checked ? 'active' : ''} {disabled ? 'disabled' : ''}"
|
|
32
|
+
>
|
|
33
|
+
<input type="checkbox" {checked} style="display:none;" on:change={handleChange}/>
|
|
34
|
+
<div
|
|
35
|
+
style="width:{size}px;height:{size}px;transform:{checked
|
|
36
|
+
? `translateX(${size + 2}px) translateY(2px)`
|
|
37
|
+
: 'translateX(2px) translateY(2px)'};"
|
|
38
|
+
class="head"
|
|
39
|
+
>
|
|
40
|
+
{#if disabledIcon}
|
|
41
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
42
|
+
<path d="M18 10.75C17.59 10.75 17.25 10.41 17.25 10V8C17.25 4.85 16.36 2.75 12 2.75C7.64 2.75 6.75 4.85 6.75 8V10C6.75 10.41 6.41 10.75 6 10.75C5.59 10.75 5.25 10.41 5.25 10V8C5.25 5.1 5.95 1.25 12 1.25C18.05 1.25 18.75 5.1 18.75 8V10C18.75 10.41 18.41 10.75 18 10.75Z" fill="#292D32"/>
|
|
43
|
+
<path d="M12 19.25C10.21 19.25 8.75 17.79 8.75 16C8.75 14.21 10.21 12.75 12 12.75C13.79 12.75 15.25 14.21 15.25 16C15.25 17.79 13.79 19.25 12 19.25ZM12 14.25C11.04 14.25 10.25 15.04 10.25 16C10.25 16.96 11.04 17.75 12 17.75C12.96 17.75 13.75 16.96 13.75 16C13.75 15.04 12.96 14.25 12 14.25Z" fill="#292D32"/>
|
|
44
|
+
<path d="M17 22.75H7C2.59 22.75 1.25 21.41 1.25 17V15C1.25 10.59 2.59 9.25 7 9.25H17C21.41 9.25 22.75 10.59 22.75 15V17C22.75 21.41 21.41 22.75 17 22.75ZM7 10.75C3.42 10.75 2.75 11.43 2.75 15V17C2.75 20.57 3.42 21.25 7 21.25H17C20.58 21.25 21.25 20.57 21.25 17V15C21.25 11.43 20.58 10.75 17 10.75H7Z" fill="#292D32"/>
|
|
45
|
+
</svg>
|
|
46
|
+
{/if}
|
|
47
|
+
|
|
48
|
+
</div>
|
|
49
|
+
<div class="state">
|
|
50
|
+
<div class="active">
|
|
51
|
+
<svg
|
|
52
|
+
width="31"
|
|
53
|
+
height="31"
|
|
54
|
+
viewBox="0 0 31 31"
|
|
55
|
+
fill="none"
|
|
56
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
57
|
+
>
|
|
58
|
+
<path
|
|
59
|
+
fill-rule="evenodd"
|
|
60
|
+
clip-rule="evenodd"
|
|
61
|
+
d="M15.5 5.97668C16.0523 5.97668 16.5 6.4244 16.5 6.97668L16.5 24.0233C16.5 24.5756 16.0523 25.0233 15.5 25.0233C14.9477 25.0233 14.5 24.5756 14.5 24.0233L14.5 6.97668C14.5 6.4244 14.9477 5.97668 15.5 5.97668Z"
|
|
62
|
+
fill="black"
|
|
63
|
+
/>
|
|
64
|
+
</svg>
|
|
65
|
+
</div>
|
|
66
|
+
<div class="not-active">
|
|
67
|
+
<svg
|
|
68
|
+
width="31"
|
|
69
|
+
height="31"
|
|
70
|
+
viewBox="0 0 31 31"
|
|
71
|
+
fill="none"
|
|
72
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
73
|
+
>
|
|
74
|
+
<path
|
|
75
|
+
fill-rule="evenodd"
|
|
76
|
+
clip-rule="evenodd"
|
|
77
|
+
d="M15.5 5.58868C10.0261 5.58868 5.58868 10.0261 5.58868 15.5C5.58868 20.9739 10.0261 25.4113 15.5 25.4113C20.9739 25.4113 25.4113 20.9739 25.4113 15.5C25.4113 10.0261 20.9739 5.58868 15.5 5.58868ZM3.58868 15.5C3.58868 8.92156 8.92156 3.58868 15.5 3.58868C22.0784 3.58868 27.4113 8.92156 27.4113 15.5C27.4113 22.0784 22.0784 27.4113 15.5 27.4113C8.92156 27.4113 3.58868 22.0784 3.58868 15.5Z"
|
|
78
|
+
fill="black"
|
|
79
|
+
/>
|
|
80
|
+
</svg>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
</label>
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
.label-switch{
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
column-gap: 7px;
|
|
5
|
+
cursor: pointer;
|
|
6
|
+
}
|
|
7
|
+
.switch{
|
|
8
|
+
position: relative;
|
|
9
|
+
border-radius: var(--radius-xxl);
|
|
10
|
+
background-color: var(--bg-2);
|
|
11
|
+
transition: background-color .2s ease-out;
|
|
12
|
+
cursor: pointer;
|
|
13
|
+
transition-property:transform, opacity, background-color ;
|
|
14
|
+
transition-duration: .2s;
|
|
15
|
+
transition-timing-function: ease-out;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.switch:active{
|
|
19
|
+
transform: scale(.95);
|
|
20
|
+
opacity: .8;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.switch:hover:not(.disabled){
|
|
24
|
+
background-color: var(--bg-3);
|
|
25
|
+
}
|
|
26
|
+
.switch .head{
|
|
27
|
+
border-radius: var(--radius-xl);
|
|
28
|
+
background-color: var(--white);
|
|
29
|
+
transform: translateX(2px) translateY(2px);
|
|
30
|
+
transition: transform .2s ease-out;
|
|
31
|
+
z-index: 2;
|
|
32
|
+
position: relative;
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: center;
|
|
36
|
+
padding: 5px;
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
.switch .head svg{
|
|
40
|
+
width: 100%;
|
|
41
|
+
height: 100%;
|
|
42
|
+
flex-shrink: 0;
|
|
43
|
+
}
|
|
44
|
+
.switch .head svg path{
|
|
45
|
+
fill: var(--red);
|
|
46
|
+
}
|
|
47
|
+
.switch.active{
|
|
48
|
+
background-color: var(--accent) !important;
|
|
49
|
+
}
|
|
50
|
+
.switch .state{
|
|
51
|
+
position: absolute;
|
|
52
|
+
top: 0;
|
|
53
|
+
left: 0;
|
|
54
|
+
width: 100%;
|
|
55
|
+
height: 100%;
|
|
56
|
+
display: flex;
|
|
57
|
+
justify-content: space-between;
|
|
58
|
+
user-select: none;
|
|
59
|
+
pointer-events: none;
|
|
60
|
+
z-index: 1;
|
|
61
|
+
}
|
|
62
|
+
.switch .state .active{
|
|
63
|
+
width: var(--size);
|
|
64
|
+
height: var(--size);
|
|
65
|
+
padding: 4px;
|
|
66
|
+
display:flex;
|
|
67
|
+
align-items:center;
|
|
68
|
+
justify-content:center;
|
|
69
|
+
color: var(--font-t);
|
|
70
|
+
transform: scale(.6) translateX(5px);
|
|
71
|
+
opacity: 0;
|
|
72
|
+
transition-property:transform, opacity ;
|
|
73
|
+
transition-duration: .2s;
|
|
74
|
+
transition-timing-function: ease-out;
|
|
75
|
+
}
|
|
76
|
+
.switch .state .active svg {
|
|
77
|
+
width: 100%;
|
|
78
|
+
height: 100%;
|
|
79
|
+
flex-shrink: 0;
|
|
80
|
+
}
|
|
81
|
+
.switch.active .state .active{
|
|
82
|
+
transform: scale(1);
|
|
83
|
+
opacity: 1;
|
|
84
|
+
}
|
|
85
|
+
.switch.active .state .active *{
|
|
86
|
+
color: var(--white);
|
|
87
|
+
fill: var(--white);
|
|
88
|
+
}
|
|
89
|
+
.switch .state .not-active{
|
|
90
|
+
width: var(--size);
|
|
91
|
+
height: var(--size);
|
|
92
|
+
padding: 4px;
|
|
93
|
+
display:flex;
|
|
94
|
+
align-items:center;
|
|
95
|
+
justify-content:center;
|
|
96
|
+
color: var(--font-t);
|
|
97
|
+
transform: scale(.6) translateX(-5px);
|
|
98
|
+
opacity: 0;
|
|
99
|
+
transition-property:transform, opacity ;
|
|
100
|
+
transition-duration: .2s;
|
|
101
|
+
transition-timing-function: ease-out;
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
.switch .state .not-active svg {
|
|
105
|
+
width: 100%;
|
|
106
|
+
height: 100%;
|
|
107
|
+
flex-shrink: 0;
|
|
108
|
+
}
|
|
109
|
+
.switch:not(.active) .state .not-active{
|
|
110
|
+
transform: scale(1);
|
|
111
|
+
opacity: 1;
|
|
112
|
+
}
|
|
113
|
+
.switch:not(.active) .state .not-active *{
|
|
114
|
+
color: var(--font-u);
|
|
115
|
+
fill: var(--font-u);
|
|
116
|
+
}
|
|
117
|
+
.label-switch:has(.switch.disabled), .switch.disabled{
|
|
118
|
+
opacity: .9;
|
|
119
|
+
cursor: not-allowed;
|
|
120
|
+
}
|