lapikit 0.1.1 → 0.1.3
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/dist/assets/icons/loading-fill.svelte +29 -0
- package/dist/assets/icons/loading-fill.svelte.d.ts +26 -0
- package/dist/components/button/button.css +44 -8
- package/dist/components/button/button.svelte +14 -1
- package/dist/components/button/types.d.ts +3 -0
- package/dist/components/dropdown/dropdown.css +22 -0
- package/dist/components/dropdown/dropdown.svelte +116 -0
- package/dist/components/dropdown/dropdown.svelte.d.ts +4 -0
- package/dist/components/dropdown/dropdown.svelte.js +148 -0
- package/dist/components/dropdown/types.d.ts +26 -0
- package/dist/components/dropdown/types.js +1 -0
- package/dist/components/icon/icon.css +76 -0
- package/dist/components/icon/icon.svelte +49 -0
- package/dist/components/icon/icon.svelte.d.ts +4 -0
- package/dist/components/icon/types.d.ts +16 -0
- package/dist/components/icon/types.js +1 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +4 -0
- package/dist/components/popover/popover.css +22 -0
- package/dist/components/popover/popover.svelte +73 -0
- package/dist/components/popover/popover.svelte.d.ts +4 -0
- package/dist/components/popover/popover.svelte.js +134 -0
- package/dist/components/popover/types.d.ts +20 -0
- package/dist/components/popover/types.js +1 -0
- package/dist/components/tooltip/tooltip.css +124 -0
- package/dist/components/tooltip/tooltip.svelte +113 -0
- package/dist/components/tooltip/tooltip.svelte.d.ts +4 -0
- package/dist/components/tooltip/tooltip.svelte.js +131 -0
- package/dist/components/tooltip/types.d.ts +23 -0
- package/dist/components/tooltip/types.js +1 -0
- package/dist/internal/clickOutside.d.ts +9 -0
- package/dist/internal/clickOutside.js +34 -0
- package/dist/style/animation.css +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
|
|
2
|
+
><defs
|
|
3
|
+
><linearGradient id="a" x1="50%" x2="50%" y1="5.271%" y2="91.793%"
|
|
4
|
+
><stop offset="0%" stop-color="currentColor" /><stop
|
|
5
|
+
offset="100%"
|
|
6
|
+
stop-color="currentColor"
|
|
7
|
+
stop-opacity=".55"
|
|
8
|
+
/></linearGradient
|
|
9
|
+
><linearGradient id="b" x1="50%" x2="50%" y1="15.24%" y2="87.15%"
|
|
10
|
+
><stop offset="0%" stop-color="currentColor" stop-opacity="0" /><stop
|
|
11
|
+
offset="100%"
|
|
12
|
+
stop-color="currentColor"
|
|
13
|
+
stop-opacity=".55"
|
|
14
|
+
/></linearGradient
|
|
15
|
+
></defs
|
|
16
|
+
><g fill="none"
|
|
17
|
+
><path
|
|
18
|
+
d="M24 0v24H0V0zM12.593 23.258l-.011.002-.071.035-.02.004-.014-.004-.071-.035c-.01-.004-.019-.001-.024.005l-.004.01-.017.428.005.02.01.013.104.074.015.004.012-.004.104-.074.012-.016.004-.017-.017-.427c-.002-.01-.009-.017-.017-.018m.265-.113-.013.002-.185.093-.01.01-.003.011.018.43.005.012.008.007.201.093c.012.004.023 0 .029-.008l.004-.014-.034-.614c-.003-.012-.01-.02-.02-.022m-.715.002a.023.023 0 0 0-.027.006l-.006.014-.034.614c0 .012.007.02.017.024l.015-.002.201-.093.01-.008.004-.011.017-.43-.003-.012-.01-.01z"
|
|
19
|
+
/><path
|
|
20
|
+
fill="url(#a)"
|
|
21
|
+
d="M8.749.021a1.5 1.5 0 0 1 .497 2.958A7.502 7.502 0 0 0 3 10.375a7.5 7.5 0 0 0 7.5 7.5v3c-5.799 0-10.5-4.7-10.5-10.5C0 5.23 3.726.865 8.749.021"
|
|
22
|
+
transform="translate(1.5 1.625)"
|
|
23
|
+
/><path
|
|
24
|
+
fill="url(#b)"
|
|
25
|
+
d="M15.392 2.673a1.5 1.5 0 0 1 2.119-.115A10.475 10.475 0 0 1 21 10.375c0 5.8-4.701 10.5-10.5 10.5v-3a7.5 7.5 0 0 0 5.007-13.084 1.5 1.5 0 0 1-.115-2.118"
|
|
26
|
+
transform="translate(1.5 1.625)"
|
|
27
|
+
/></g
|
|
28
|
+
></svg
|
|
29
|
+
>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default LoadingFill;
|
|
2
|
+
type LoadingFill = SvelteComponent<{
|
|
3
|
+
[x: string]: never;
|
|
4
|
+
}, {
|
|
5
|
+
[evt: string]: CustomEvent<any>;
|
|
6
|
+
}, {}> & {
|
|
7
|
+
$$bindings?: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
declare const LoadingFill: $$__sveltets_2_IsomorphicComponent<{
|
|
10
|
+
[x: string]: never;
|
|
11
|
+
}, {
|
|
12
|
+
[evt: string]: CustomEvent<any>;
|
|
13
|
+
}, {}, {}, string>;
|
|
14
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
15
|
+
new (options: import("svelte").ComponentConstructorOptions<Props>): import("svelte").SvelteComponent<Props, Events, Slots> & {
|
|
16
|
+
$$bindings?: Bindings;
|
|
17
|
+
} & Exports;
|
|
18
|
+
(internal: unknown, props: {
|
|
19
|
+
$$events?: Events;
|
|
20
|
+
$$slots?: Slots;
|
|
21
|
+
}): Exports & {
|
|
22
|
+
$set?: any;
|
|
23
|
+
$on?: any;
|
|
24
|
+
};
|
|
25
|
+
z_$$bindings?: Bindings;
|
|
26
|
+
}
|
|
@@ -23,6 +23,15 @@
|
|
|
23
23
|
border-color: var(--btn-background);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
.kit-btn .kit-btn-content,
|
|
27
|
+
.kit-btn .kit-btn-loading {
|
|
28
|
+
display: inline-flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
justify-content: center;
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
gap: var(--btn-gap);
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
.kit-btn:active:hover,
|
|
27
36
|
.kit-btn:active:focus {
|
|
28
37
|
animation: button-click 0s ease-out;
|
|
@@ -33,59 +42,82 @@
|
|
|
33
42
|
.kit-btn[breakpoint]kit-btn--size-xs {
|
|
34
43
|
--btn-height: 1.75rem;
|
|
35
44
|
--btn-multiplier-y: 2;
|
|
45
|
+
--btn-gap: 0.25rem;
|
|
36
46
|
font-size: 0.75rem;
|
|
37
|
-
gap:
|
|
47
|
+
gap: var(--btn-gap);
|
|
38
48
|
}
|
|
39
49
|
|
|
40
50
|
.kit-btn[breakpoint]kit-btn--size-sm {
|
|
41
51
|
--btn-height: 2rem;
|
|
42
52
|
--btn-multiplier-y: 3;
|
|
53
|
+
--btn-gap: 0.5rem;
|
|
43
54
|
font-size: 0.875rem;
|
|
44
|
-
gap:
|
|
55
|
+
gap: var(--btn-gap);
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
.kit-btn[breakpoint]kit-btn--size-md {
|
|
48
59
|
--btn-height: 2.25rem;
|
|
49
60
|
--btn-multiplier-y: 4;
|
|
61
|
+
--btn-gap: 0.5rem;
|
|
50
62
|
font-size: 0.875rem;
|
|
51
|
-
gap:
|
|
63
|
+
gap: var(--btn-gap);
|
|
52
64
|
}
|
|
53
65
|
|
|
54
66
|
.kit-btn[breakpoint]kit-btn--size-lg {
|
|
55
67
|
--btn-height: 2.5rem;
|
|
56
68
|
--btn-multiplier-y: 5;
|
|
69
|
+
--btn-gap: 0.5rem;
|
|
57
70
|
font-size: 1rem;
|
|
58
|
-
gap:
|
|
71
|
+
gap: var(--btn-gap);
|
|
59
72
|
}
|
|
60
73
|
|
|
61
74
|
.kit-btn[breakpoint]kit-btn--size-xl {
|
|
62
75
|
--btn-height: 2.75rem;
|
|
63
76
|
--btn-multiplier-y: 6;
|
|
77
|
+
--btn-gap: 0.675rem;
|
|
64
78
|
font-size: 1.125rem;
|
|
65
|
-
gap:
|
|
79
|
+
gap: var(--btn-gap);
|
|
66
80
|
}
|
|
67
81
|
|
|
68
82
|
/* density */
|
|
69
|
-
.kit-btn[breakpoint]kit-btn--density-default {
|
|
83
|
+
.kit-btn:not(.kit-btn--icon)[breakpoint]kit-btn--density-default {
|
|
70
84
|
height: calc(var(--btn-height));
|
|
71
85
|
min-width: calc(var(--btn-height));
|
|
72
86
|
--btn-spacing-x: 0;
|
|
73
87
|
--btn-spacing-y: calc(var(--kit-spacing) * var(--btn-multiplier-y));
|
|
74
88
|
}
|
|
89
|
+
.kit-btn.kit-btn--icon[breakpoint]kit-btn--density-default {
|
|
90
|
+
height: calc(var(--btn-height));
|
|
91
|
+
width: calc(var(--btn-height));
|
|
92
|
+
--btn-spacing-x: 0;
|
|
93
|
+
--btn-spacing-y: 0;
|
|
94
|
+
}
|
|
75
95
|
|
|
76
|
-
.kit-btn[breakpoint]kit-btn--density-compact {
|
|
96
|
+
.kit-btn:not(.kit-btn--icon)[breakpoint]kit-btn--density-compact {
|
|
77
97
|
height: calc(var(--btn-height) - 0.25rem);
|
|
78
98
|
min-width: calc(var(--btn-height - 0.25rem));
|
|
79
99
|
--btn-spacing-x: 0;
|
|
80
100
|
--btn-spacing-y: calc(var(--kit-spacing) * var(--btn-multiplier-y) - 0.25rem);
|
|
81
101
|
}
|
|
102
|
+
.kit-btn.kit-btn--icon[breakpoint]kit-btn--density-compact {
|
|
103
|
+
height: calc(var(--btn-height) - 0.25rem);
|
|
104
|
+
width: calc(var(--btn-height) - 0.25rem);
|
|
105
|
+
--btn-spacing-x: 0;
|
|
106
|
+
--btn-spacing-y: 0;
|
|
107
|
+
}
|
|
82
108
|
|
|
83
|
-
.kit-btn[breakpoint]kit-btn--density-comfortable {
|
|
109
|
+
.kit-btn:not(.kit-btn--icon)[breakpoint]kit-btn--density-comfortable {
|
|
84
110
|
height: calc(var(--btn-height) + 0.25rem);
|
|
85
111
|
min-width: calc(var(--btn-height) + 0.25rem);
|
|
86
112
|
--btn-spacing-x: 0;
|
|
87
113
|
--btn-spacing-y: calc(var(--kit-spacing) * var(--btn-multiplier-y) + 0.25rem);
|
|
88
114
|
}
|
|
115
|
+
.kit-btn.kit-btn--icon[breakpoint]kit-btn--density-comfortable {
|
|
116
|
+
height: calc(var(--btn-height) + 0.25rem);
|
|
117
|
+
width: calc(var(--btn-height) + 0.25rem);
|
|
118
|
+
--btn-spacing-x: 0;
|
|
119
|
+
--btn-spacing-y: 0;
|
|
120
|
+
}
|
|
89
121
|
|
|
90
122
|
/* variant */
|
|
91
123
|
.kit-btn[breakpoint]kit-btn--variant-outline {
|
|
@@ -233,8 +265,12 @@ input.kit-btn[disabled] {
|
|
|
233
265
|
}
|
|
234
266
|
.kit-btn.kit-btn--loading > .kit-btn-content {
|
|
235
267
|
color: transparent;
|
|
268
|
+
opacity: 0;
|
|
236
269
|
}
|
|
237
270
|
.kit-btn.kit-btn--loading > .kit-btn-loading {
|
|
238
271
|
position: absolute;
|
|
239
272
|
min-width: fit-content;
|
|
240
273
|
}
|
|
274
|
+
.kit-btn.kit-btn--loading > .kit-btn-loading .kit-icon-load {
|
|
275
|
+
animation: icon-rotate 1s ease-out infinite;
|
|
276
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { getAssets } from '../../internal/index.js';
|
|
3
|
+
import Icon from '../icon/icon.svelte';
|
|
3
4
|
import type { BtnProps } from './types.js';
|
|
4
5
|
|
|
6
|
+
// external
|
|
7
|
+
import LoadingFill from '../../assets/icons/loading-fill.svelte';
|
|
8
|
+
|
|
5
9
|
let {
|
|
6
10
|
children,
|
|
7
11
|
ref = $bindable(),
|
|
@@ -24,6 +28,8 @@
|
|
|
24
28
|
label,
|
|
25
29
|
loading,
|
|
26
30
|
rounded,
|
|
31
|
+
icon,
|
|
32
|
+
load,
|
|
27
33
|
...rest
|
|
28
34
|
}: BtnProps = $props();
|
|
29
35
|
|
|
@@ -56,6 +62,7 @@
|
|
|
56
62
|
disabled && 'kit-btn--disabled',
|
|
57
63
|
active && 'kit-btn--active',
|
|
58
64
|
loading && 'kit-btn--loading',
|
|
65
|
+
icon && 'kit-btn--icon',
|
|
59
66
|
rest.class
|
|
60
67
|
]}
|
|
61
68
|
tabindex={href && disabled ? -1 : 0}
|
|
@@ -69,7 +76,13 @@
|
|
|
69
76
|
>
|
|
70
77
|
{#if loading}
|
|
71
78
|
<div class="kit-btn-loading">
|
|
72
|
-
|
|
79
|
+
{#if load}
|
|
80
|
+
{@render load?.()}
|
|
81
|
+
{:else}
|
|
82
|
+
<Icon class="kit-icon-load">
|
|
83
|
+
<LoadingFill />
|
|
84
|
+
</Icon>
|
|
85
|
+
{/if}
|
|
73
86
|
</div>
|
|
74
87
|
{/if}
|
|
75
88
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Component } from '../../internal/types.js';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
2
3
|
export interface BtnProps extends Component {
|
|
3
4
|
ref?: HTMLElement | null;
|
|
4
5
|
is?: 'button' | 'a' | 'input';
|
|
@@ -21,4 +22,6 @@ export interface BtnProps extends Component {
|
|
|
21
22
|
};
|
|
22
23
|
type?: 'button' | 'submit' | 'reset' | 'radio' | 'checkbox';
|
|
23
24
|
label?: string;
|
|
25
|
+
icon?: boolean;
|
|
26
|
+
load?: Snippet;
|
|
24
27
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
.kit-dropdown-content {
|
|
2
|
+
--dropdown-color: var(--on, var(--kit-on-neutral));
|
|
3
|
+
--dropdown-background: var(--base, var(--kit-neutral));
|
|
4
|
+
--dropdown-radius: var(--shape, var(--kit-radius-md));
|
|
5
|
+
|
|
6
|
+
inset: 0px auto auto 0px;
|
|
7
|
+
margin: 0px;
|
|
8
|
+
position: fixed;
|
|
9
|
+
z-index: 9999;
|
|
10
|
+
display: inline-block;
|
|
11
|
+
width: auto;
|
|
12
|
+
opacity: 1;
|
|
13
|
+
transition-property: opacity, transform;
|
|
14
|
+
transition:
|
|
15
|
+
color 0.5s,
|
|
16
|
+
background-color 0.5s;
|
|
17
|
+
|
|
18
|
+
/* theme */
|
|
19
|
+
background-color: var(--dropdown-background);
|
|
20
|
+
color: var(--dropdown-color);
|
|
21
|
+
border-radius: var(--dropdown-radius);
|
|
22
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getAssets } from '../../internal/assets.svelte.js';
|
|
3
|
+
import { clickOutside } from '../../internal/clickOutside.js';
|
|
4
|
+
import { getPositions } from './dropdown.svelte.js';
|
|
5
|
+
import type { DropdownProps, ModelDropdownProps } from './types.js';
|
|
6
|
+
|
|
7
|
+
let {
|
|
8
|
+
children,
|
|
9
|
+
activator,
|
|
10
|
+
dark,
|
|
11
|
+
light,
|
|
12
|
+
rounded,
|
|
13
|
+
position,
|
|
14
|
+
closeOnClick,
|
|
15
|
+
openOnHover,
|
|
16
|
+
color,
|
|
17
|
+
background,
|
|
18
|
+
...rest
|
|
19
|
+
}: DropdownProps = $props();
|
|
20
|
+
|
|
21
|
+
const positionAxis = getPositions();
|
|
22
|
+
const assets = getAssets();
|
|
23
|
+
|
|
24
|
+
let ref: HTMLElement | null = $state(null);
|
|
25
|
+
let refActivator: HTMLElement | PointerEvent | null = $state(null);
|
|
26
|
+
let open = $state(false);
|
|
27
|
+
let axis = $state({ x: 0, y: 0 });
|
|
28
|
+
let innerHeight = $state(0);
|
|
29
|
+
let innerWidth = $state(0);
|
|
30
|
+
let scrollX = $state(0);
|
|
31
|
+
let scrollY = $state(0);
|
|
32
|
+
let timeoutId: ReturnType<typeof setTimeout> | null = $state(null);
|
|
33
|
+
|
|
34
|
+
axis = positionAxis?.values;
|
|
35
|
+
|
|
36
|
+
let model: ModelDropdownProps = {
|
|
37
|
+
get open() {
|
|
38
|
+
return open;
|
|
39
|
+
},
|
|
40
|
+
close: () => (open = false),
|
|
41
|
+
toggle: (element) => handleToggle(element)
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const handleToggle = (element: HTMLElement | PointerEvent | null) => {
|
|
45
|
+
if (element === null) return;
|
|
46
|
+
refActivator = element;
|
|
47
|
+
open = !open;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const handleClose = () => {
|
|
51
|
+
if (closeOnClick && open) open = false;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const handleMouseEvent = (
|
|
55
|
+
state: 'open' | 'close',
|
|
56
|
+
element: HTMLElement | PointerEvent | null
|
|
57
|
+
) => {
|
|
58
|
+
console.log();
|
|
59
|
+
if (openOnHover && state === 'open') {
|
|
60
|
+
if (timeoutId) {
|
|
61
|
+
clearTimeout(timeoutId);
|
|
62
|
+
timeoutId = null;
|
|
63
|
+
}
|
|
64
|
+
refActivator = element;
|
|
65
|
+
open = true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (openOnHover && state === 'close') {
|
|
69
|
+
timeoutId = setTimeout(() => {
|
|
70
|
+
open = false;
|
|
71
|
+
timeoutId = null;
|
|
72
|
+
}, 150);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
$effect(() => {
|
|
77
|
+
if (
|
|
78
|
+
open &&
|
|
79
|
+
ref &&
|
|
80
|
+
refActivator &&
|
|
81
|
+
(scrollX > 0 || scrollY > 0 || innerHeight > 0 || innerWidth > 0)
|
|
82
|
+
) {
|
|
83
|
+
positionAxis.update(refActivator, ref, position);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
$effect(() => {
|
|
88
|
+
if (scrollX || scrollY) open = false;
|
|
89
|
+
});
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
<svelte:window bind:innerHeight bind:innerWidth bind:scrollX bind:scrollY />
|
|
93
|
+
|
|
94
|
+
{@render activator?.(model, (state, element) => handleMouseEvent(state, element))}
|
|
95
|
+
|
|
96
|
+
{#if open}
|
|
97
|
+
<div
|
|
98
|
+
bind:this={ref}
|
|
99
|
+
{...rest}
|
|
100
|
+
role="menu"
|
|
101
|
+
class={['kit-dropdown-content', light && 'light', dark && 'dark', rest.class]}
|
|
102
|
+
style={`transform: translate(${axis.x}px, ${axis.y}px);`}
|
|
103
|
+
onmouseover={() => handleMouseEvent('open', refActivator)}
|
|
104
|
+
onmouseleave={() => handleMouseEvent('close', refActivator)}
|
|
105
|
+
onclick={(e) => {
|
|
106
|
+
e.stopPropagation();
|
|
107
|
+
handleClose();
|
|
108
|
+
}}
|
|
109
|
+
style:--base={assets.color(background)}
|
|
110
|
+
style:--on={assets.color(color)}
|
|
111
|
+
style:--shape={assets.shape(rounded)}
|
|
112
|
+
use:clickOutside={{ exclude: [ref, refActivator], onClose: () => (open = false) }}
|
|
113
|
+
>
|
|
114
|
+
{@render children?.()}
|
|
115
|
+
</div>
|
|
116
|
+
{/if}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { innerWidth, innerHeight } from 'svelte/reactivity/window';
|
|
2
|
+
export function getPositions() {
|
|
3
|
+
// state
|
|
4
|
+
const axis = $state({
|
|
5
|
+
x: 0,
|
|
6
|
+
y: 0,
|
|
7
|
+
location: null
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
get values() {
|
|
11
|
+
return axis;
|
|
12
|
+
},
|
|
13
|
+
update(activator, element, location, centered, avoidCollisions) {
|
|
14
|
+
if (!activator || !element)
|
|
15
|
+
return;
|
|
16
|
+
const elementRect = element.getBoundingClientRect();
|
|
17
|
+
if (!(activator instanceof HTMLElement)) {
|
|
18
|
+
if (activator.clientX + elementRect.width > innerWidth.current) {
|
|
19
|
+
axis.x = activator.clientX - elementRect.width;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
axis.x = activator.clientX;
|
|
23
|
+
}
|
|
24
|
+
if (activator.clientY + elementRect.height > innerHeight.current) {
|
|
25
|
+
axis.y = activator.clientY - elementRect.height;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
axis.y = activator.clientY;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (activator instanceof HTMLElement) {
|
|
32
|
+
const activatorRect = activator.getBoundingClientRect();
|
|
33
|
+
const spacing = 0;
|
|
34
|
+
const _activator = activatorRect.y + activatorRect.height;
|
|
35
|
+
const _element = elementRect.height + spacing;
|
|
36
|
+
if (location === 'top' || location === 'bottom') {
|
|
37
|
+
if (avoidCollisions) {
|
|
38
|
+
if (location === 'top') {
|
|
39
|
+
if (activatorRect.y - _element < 0) {
|
|
40
|
+
axis.y = activatorRect.bottom + spacing;
|
|
41
|
+
axis.location = 'bottom';
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
axis.y = activatorRect.top - _element;
|
|
45
|
+
axis.location = 'top';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
if (_activator + _element > innerHeight.current) {
|
|
50
|
+
axis.y = activatorRect.top - _element;
|
|
51
|
+
axis.location = 'top';
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
axis.y = activatorRect.bottom + spacing;
|
|
55
|
+
axis.location = 'bottom';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
if (location === 'top') {
|
|
61
|
+
axis.y = activatorRect.top - _element;
|
|
62
|
+
axis.location = 'top';
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
axis.y = activatorRect.bottom + spacing;
|
|
66
|
+
axis.location = 'bottom';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (centered &&
|
|
70
|
+
activatorRect.left - (elementRect.width - activatorRect.width) / 2 > 0 &&
|
|
71
|
+
activatorRect.left + elementRect.width < innerWidth.current) {
|
|
72
|
+
axis.x = activatorRect.left - (elementRect.width - activatorRect.width) / 2;
|
|
73
|
+
}
|
|
74
|
+
else if (activatorRect.left + elementRect.width > innerWidth.current) {
|
|
75
|
+
axis.x = activatorRect.left - (elementRect.width - activatorRect.width);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
axis.x = activatorRect.left;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (location === 'left' || location === 'right') {
|
|
82
|
+
if (avoidCollisions) {
|
|
83
|
+
if (location === 'left' && !(activatorRect.left - elementRect.width < 0)) {
|
|
84
|
+
axis.x = activatorRect.left - (elementRect.width + spacing);
|
|
85
|
+
axis.location = 'left';
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (activatorRect.left + activatorRect.width + elementRect.width + spacing >
|
|
89
|
+
innerWidth.current) {
|
|
90
|
+
axis.x = activatorRect.left - (elementRect.width + spacing);
|
|
91
|
+
axis.location = 'left';
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
axis.x = activatorRect.left + activatorRect.width + spacing;
|
|
95
|
+
axis.location = 'right';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
if (location === 'left') {
|
|
101
|
+
axis.x = activatorRect.left - (elementRect.width + spacing);
|
|
102
|
+
axis.location = 'left';
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
axis.x = activatorRect.left + activatorRect.width + spacing;
|
|
106
|
+
axis.location = 'right';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (centered &&
|
|
110
|
+
activatorRect.top - (elementRect.height - activatorRect.height) / 2 > 0 &&
|
|
111
|
+
activatorRect.top + elementRect.height < innerHeight.current) {
|
|
112
|
+
axis.y = activatorRect.top - (elementRect.height - activatorRect.height) / 2;
|
|
113
|
+
}
|
|
114
|
+
else if (activatorRect.y + elementRect.height > innerHeight.current) {
|
|
115
|
+
axis.y = activatorRect.y - elementRect.height + activatorRect.height;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
axis.y = activatorRect.y;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
if (centered &&
|
|
123
|
+
activatorRect.left - (elementRect.width - activatorRect.width) / 2 > 0 &&
|
|
124
|
+
activatorRect.left + elementRect.width < innerWidth.current) {
|
|
125
|
+
axis.x = activatorRect.left - (elementRect.width - activatorRect.width) / 2;
|
|
126
|
+
}
|
|
127
|
+
else if (activatorRect.left + elementRect.width > innerWidth.current) {
|
|
128
|
+
axis.x = activatorRect.left - (elementRect.width - activatorRect.width);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
axis.x = activatorRect.left;
|
|
132
|
+
}
|
|
133
|
+
if (centered &&
|
|
134
|
+
activatorRect.top - (elementRect.height - activatorRect.height) / 2 > 0 &&
|
|
135
|
+
activatorRect.top + elementRect.height < innerHeight.current) {
|
|
136
|
+
axis.y = activatorRect.top - (elementRect.height - activatorRect.height) / 2;
|
|
137
|
+
}
|
|
138
|
+
else if (activatorRect.bottom + elementRect.height > innerHeight.current) {
|
|
139
|
+
axis.y = activatorRect.top - elementRect.height;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
axis.y = activatorRect.bottom;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Component } from '../../internal/types.js';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
export type PositionElement = {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
location: string | null;
|
|
7
|
+
};
|
|
8
|
+
export interface DropdownProps extends Component {
|
|
9
|
+
dark?: boolean;
|
|
10
|
+
light?: boolean;
|
|
11
|
+
rounded?: string;
|
|
12
|
+
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
13
|
+
openOnHover?: boolean;
|
|
14
|
+
closeOnClick?: boolean;
|
|
15
|
+
color?: string;
|
|
16
|
+
background?: string;
|
|
17
|
+
activator?: Snippet<[
|
|
18
|
+
ModelDropdownProps,
|
|
19
|
+
(state: 'open' | 'close', element: HTMLElement | PointerEvent | null) => void
|
|
20
|
+
]>;
|
|
21
|
+
}
|
|
22
|
+
export type ModelDropdownProps = {
|
|
23
|
+
open: boolean;
|
|
24
|
+
close: () => void;
|
|
25
|
+
toggle: (element: HTMLElement | PointerEvent | null) => void;
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
.kit-icon {
|
|
2
|
+
--icon-size: 1rem;
|
|
3
|
+
--icon-color: var(--base, var(--kit-on-neutral));
|
|
4
|
+
|
|
5
|
+
display: inline-flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
transition: color 0.5s;
|
|
9
|
+
text-indent: 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.kit-icon:before {
|
|
13
|
+
font-size: calc(var(--icon-size-multiplier) * var(--icon-size));
|
|
14
|
+
color: var(--icon-color);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.kit-icon svg {
|
|
18
|
+
color: var(--icon-color);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.kit-icon svg,
|
|
22
|
+
.kit-icon img {
|
|
23
|
+
width: calc(var(--icon-size-multiplier) * var(--icon-size));
|
|
24
|
+
height: calc(var(--icon-size-multiplier) * var(--icon-size));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* size */
|
|
28
|
+
.kit-icon[breakpoint]kit-icon--size-xs {
|
|
29
|
+
--icon-size-multiplier: 0.875;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.kit-icon[breakpoint]kit-icon--size-sm {
|
|
33
|
+
--icon-size-multiplier: 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.kit-icon[breakpoint]kit-icon--size-md {
|
|
37
|
+
--icon-size-multiplier: 1.125;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.kit-icon[breakpoint]kit-icon--size-lg {
|
|
41
|
+
--icon-size-multiplier: 1.25;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.kit-icon[breakpoint]kit-icon--size-xl {
|
|
45
|
+
--icon-size-multiplier: 1.5;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* state */
|
|
49
|
+
.kit-icon.kit-icon--info {
|
|
50
|
+
--base: var(--kit-info);
|
|
51
|
+
}
|
|
52
|
+
.kit-icon.kit-icon--success {
|
|
53
|
+
--base: var(--kit-success);
|
|
54
|
+
}
|
|
55
|
+
.kit-icon.kit-icon--warning {
|
|
56
|
+
--base: var(--kit-warning);
|
|
57
|
+
}
|
|
58
|
+
.kit-icon.kit-icon--error {
|
|
59
|
+
--base: var(--kit-error);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* disabled */
|
|
63
|
+
.kit-icon.kit-icon--disabled {
|
|
64
|
+
-webkit-user-select: none;
|
|
65
|
+
user-select: none;
|
|
66
|
+
pointer-events: none;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.kit-icon.kit-icon--disabled img {
|
|
70
|
+
opacity: 0.38;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.kit-icon.kit-icon--disabled svg,
|
|
74
|
+
.kit-icon.kit-icon--disabled:before {
|
|
75
|
+
color: color-mix(in oklab, var(--icon-color) 40%, transparent) !important;
|
|
76
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getAssets } from '../../internal/assets.svelte.js';
|
|
3
|
+
import type { IconProps } from './types.js';
|
|
4
|
+
let {
|
|
5
|
+
children,
|
|
6
|
+
ref = $bindable(),
|
|
7
|
+
is = 'i',
|
|
8
|
+
light,
|
|
9
|
+
dark,
|
|
10
|
+
icon,
|
|
11
|
+
size = 'md',
|
|
12
|
+
error,
|
|
13
|
+
info,
|
|
14
|
+
success,
|
|
15
|
+
warning,
|
|
16
|
+
disabled,
|
|
17
|
+
alt,
|
|
18
|
+
color,
|
|
19
|
+
...rest
|
|
20
|
+
}: IconProps = $props();
|
|
21
|
+
|
|
22
|
+
const assets = getAssets();
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<svelte:element
|
|
26
|
+
this={icon && icon.includes('/') ? 'div' : is}
|
|
27
|
+
bind:this={ref}
|
|
28
|
+
{...rest}
|
|
29
|
+
class={[
|
|
30
|
+
'kit-icon',
|
|
31
|
+
icon && !icon.includes('/') && icon,
|
|
32
|
+
light && 'light',
|
|
33
|
+
dark && 'dark',
|
|
34
|
+
info && 'kit-icon--info',
|
|
35
|
+
success && 'kit-icon--success',
|
|
36
|
+
warning && 'kit-icon--warning',
|
|
37
|
+
error && 'kit-icon--error',
|
|
38
|
+
disabled && 'kit-icon--disabled',
|
|
39
|
+
size && assets.className('icon', 'size', size),
|
|
40
|
+
rest.class
|
|
41
|
+
]}
|
|
42
|
+
style:--base={assets.color(color)}
|
|
43
|
+
>
|
|
44
|
+
{#if icon && icon.includes('/')}
|
|
45
|
+
<img src={icon} {alt} />
|
|
46
|
+
{:else}
|
|
47
|
+
{@render children?.()}
|
|
48
|
+
{/if}
|
|
49
|
+
</svelte:element>
|