lapikit 0.4.11 → 0.4.13
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/labs/compiler/components.js +14 -0
- package/dist/labs/components/appbar/appbar.svelte +196 -0
- package/dist/labs/components/appbar/appbar.svelte.d.ts +4 -0
- package/dist/labs/components/appbar/appbar.types.d.ts +16 -0
- package/dist/labs/components/appbar/appbar.types.js +1 -0
- package/dist/labs/components/dropdown/dropdown.svelte +249 -0
- package/dist/labs/components/dropdown/dropdown.svelte.d.ts +4 -0
- package/dist/labs/components/dropdown/dropdown.svelte.js +148 -0
- package/dist/labs/components/dropdown/dropdown.types.d.ts +28 -0
- package/dist/labs/components/dropdown/dropdown.types.js +1 -0
- package/dist/labs/components/index.d.ts +8 -0
- package/dist/labs/components/index.js +8 -0
- package/dist/labs/components/list/list.svelte +190 -0
- package/dist/labs/components/list/list.svelte.d.ts +4 -0
- package/dist/labs/components/list/list.types.d.ts +30 -0
- package/dist/labs/components/list/list.types.js +1 -0
- package/dist/labs/components/list/modules/list-item.svelte +195 -0
- package/dist/labs/components/list/modules/list-item.svelte.d.ts +4 -0
- package/dist/labs/components/popover/popover.svelte +188 -0
- package/dist/labs/components/popover/popover.svelte.d.ts +4 -0
- package/dist/labs/components/popover/popover.svelte.js +134 -0
- package/dist/labs/components/popover/popover.types.d.ts +22 -0
- package/dist/labs/components/popover/popover.types.js +1 -0
- package/dist/labs/components/textfield/textfield.svelte +587 -0
- package/dist/labs/components/textfield/textfield.svelte.d.ts +4 -0
- package/dist/labs/components/textfield/textfield.types.d.ts +41 -0
- package/dist/labs/components/textfield/textfield.types.js +1 -0
- package/dist/labs/components/toolbar/toolbar.svelte +262 -0
- package/dist/labs/components/toolbar/toolbar.svelte.d.ts +4 -0
- package/dist/labs/components/toolbar/toolbar.types.d.ts +21 -0
- package/dist/labs/components/toolbar/toolbar.types.js +1 -0
- package/dist/labs/components/tooltip/tooltip.svelte +372 -0
- package/dist/labs/components/tooltip/tooltip.svelte.d.ts +4 -0
- package/dist/labs/components/tooltip/tooltip.svelte.js +131 -0
- package/dist/labs/components/tooltip/tooltip.types.d.ts +26 -0
- package/dist/labs/components/tooltip/tooltip.types.js +1 -0
- package/dist/labs/utils/index.d.ts +1 -0
- package/dist/labs/utils/index.js +1 -0
- package/dist/labs/utils/outside.d.ts +5 -0
- package/dist/labs/utils/outside.js +34 -0
- package/dist/labs/utils/types/index.d.ts +4 -0
- package/package.json +1 -1
|
@@ -4,6 +4,20 @@ const lapikitComponents = [
|
|
|
4
4
|
'btn',
|
|
5
5
|
'icon',
|
|
6
6
|
'avatar',
|
|
7
|
+
'dropdown',
|
|
8
|
+
'popover',
|
|
9
|
+
'tooltip',
|
|
10
|
+
'textfield',
|
|
11
|
+
'appbar',
|
|
12
|
+
'btn',
|
|
13
|
+
'icon',
|
|
14
|
+
'avatar',
|
|
15
|
+
'toolbar',
|
|
16
|
+
'btn',
|
|
17
|
+
'icon',
|
|
18
|
+
'avatar',
|
|
19
|
+
'list',
|
|
20
|
+
'list-item',
|
|
7
21
|
'dialog',
|
|
8
22
|
'modal',
|
|
9
23
|
'accordion',
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { useClassName, useStyles } from '../../utils/index.js';
|
|
3
|
+
import { makeComponentProps } from '../../compiler/mapped-code.js';
|
|
4
|
+
import type { AppbarProps } from './appbar.types.js';
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
ref = $bindable(),
|
|
8
|
+
is = 'header',
|
|
9
|
+
children,
|
|
10
|
+
class: className = '',
|
|
11
|
+
style: styleAttr = '',
|
|
12
|
+
's-class': sClass,
|
|
13
|
+
's-style': sStyle,
|
|
14
|
+
classContent,
|
|
15
|
+
light = false,
|
|
16
|
+
dark = false,
|
|
17
|
+
variant = 'outline',
|
|
18
|
+
rounded,
|
|
19
|
+
background,
|
|
20
|
+
color,
|
|
21
|
+
density = 'default',
|
|
22
|
+
...rest
|
|
23
|
+
}: AppbarProps = $props();
|
|
24
|
+
|
|
25
|
+
let safeVariant = $derived(
|
|
26
|
+
typeof variant === 'string' && (variant === 'outline' || variant === 'text')
|
|
27
|
+
? variant
|
|
28
|
+
: 'outline'
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
let safeDensity = $derived(
|
|
32
|
+
typeof density === 'string' &&
|
|
33
|
+
(density === 'compact' || density === 'comfortable' || density === 'default')
|
|
34
|
+
? density
|
|
35
|
+
: 'default'
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
let { classProps, styleProps, restProps } = $derived(
|
|
39
|
+
makeComponentProps(rest as Record<string, unknown>)
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
let componentClass = $derived(
|
|
43
|
+
useClassName({
|
|
44
|
+
baseClass: 'kit-appbar',
|
|
45
|
+
className: `${className ?? ''}`.trim(),
|
|
46
|
+
sClass,
|
|
47
|
+
classProps
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
let normalizedClassContent = $derived(
|
|
52
|
+
Array.isArray(classContent) ? classContent.filter(Boolean).join(' ') : classContent
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
let wrapperClass = $derived(
|
|
56
|
+
useClassName({
|
|
57
|
+
baseClass: 'kit-appbar__wrapper',
|
|
58
|
+
className: normalizedClassContent
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
let componentStyle = $derived(
|
|
63
|
+
useStyles({
|
|
64
|
+
styleAttr,
|
|
65
|
+
sStyle,
|
|
66
|
+
styleProps
|
|
67
|
+
})
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
let mergedStyle = $derived(
|
|
71
|
+
[
|
|
72
|
+
componentStyle,
|
|
73
|
+
background ? `--kit-appbar-background:${background}` : '',
|
|
74
|
+
color ? `--kit-appbar-color:${color}` : '',
|
|
75
|
+
typeof rounded === 'string' && rounded.includes('px') ? `--kit-appbar-radius:${rounded}` : ''
|
|
76
|
+
]
|
|
77
|
+
.filter(Boolean)
|
|
78
|
+
.join('; ')
|
|
79
|
+
);
|
|
80
|
+
</script>
|
|
81
|
+
|
|
82
|
+
<svelte:element
|
|
83
|
+
this={is}
|
|
84
|
+
bind:this={ref}
|
|
85
|
+
class={componentClass}
|
|
86
|
+
style={mergedStyle}
|
|
87
|
+
{...restProps}
|
|
88
|
+
data-variant={safeVariant}
|
|
89
|
+
data-density={safeDensity}
|
|
90
|
+
data-light={light || undefined}
|
|
91
|
+
data-dark={dark || undefined}
|
|
92
|
+
data-rounded={rounded}
|
|
93
|
+
>
|
|
94
|
+
{#if safeVariant === 'outline'}
|
|
95
|
+
<span class="outline"></span>
|
|
96
|
+
{/if}
|
|
97
|
+
|
|
98
|
+
<div class={wrapperClass}>
|
|
99
|
+
{@render children?.()}
|
|
100
|
+
</div>
|
|
101
|
+
</svelte:element>
|
|
102
|
+
|
|
103
|
+
<style>
|
|
104
|
+
.kit-appbar {
|
|
105
|
+
--kit-appbar-background: var(--kit-surface-2);
|
|
106
|
+
--kit-appbar-color: var(--kit-fg);
|
|
107
|
+
--kit-appbar-radius: 1rem;
|
|
108
|
+
--kit-appbar-size: 4rem;
|
|
109
|
+
--kit-appbar-padding-x: 1rem;
|
|
110
|
+
--kit-appbar-padding-wrapper: 0;
|
|
111
|
+
--kit-appbar-border: color-mix(in oklab, var(--kit-appbar-color), transparent 88%);
|
|
112
|
+
|
|
113
|
+
display: flex;
|
|
114
|
+
align-items: center;
|
|
115
|
+
box-sizing: border-box;
|
|
116
|
+
position: relative;
|
|
117
|
+
width: 100%;
|
|
118
|
+
min-height: var(--kit-appbar-size);
|
|
119
|
+
padding-inline: var(--kit-appbar-padding-x);
|
|
120
|
+
border-radius: var(--kit-appbar-radius);
|
|
121
|
+
color: var(--kit-appbar-color);
|
|
122
|
+
background-color: var(--kit-appbar-background);
|
|
123
|
+
overflow: hidden;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.kit-appbar[data-variant='text'] {
|
|
127
|
+
--kit-appbar-border: transparent;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.kit-appbar[data-density='compact'] {
|
|
131
|
+
--kit-appbar-size: 3.5rem;
|
|
132
|
+
--kit-appbar-padding-x: 0.75rem;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.kit-appbar[data-density='default'] {
|
|
136
|
+
--kit-appbar-size: 4rem;
|
|
137
|
+
--kit-appbar-padding-x: 1rem;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.kit-appbar[data-density='comfortable'] {
|
|
141
|
+
--kit-appbar-size: 4.5rem;
|
|
142
|
+
--kit-appbar-padding-x: 1.5rem;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.kit-appbar[data-light='true'] {
|
|
146
|
+
--kit-appbar-background: color-mix(in oklab, white 88%, var(--kit-surface-1));
|
|
147
|
+
--kit-appbar-color: var(--kit-fg);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.kit-appbar[data-dark='true'] {
|
|
151
|
+
--kit-appbar-background: color-mix(in oklab, black 72%, var(--kit-surface-3));
|
|
152
|
+
--kit-appbar-color: white;
|
|
153
|
+
--kit-appbar-border: color-mix(in oklab, white, transparent 78%);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.kit-appbar[data-rounded='0'] {
|
|
157
|
+
--kit-appbar-radius: 0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.kit-appbar[data-rounded='xs'] {
|
|
161
|
+
--kit-appbar-radius: 2px;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.kit-appbar[data-rounded='sm'] {
|
|
165
|
+
--kit-appbar-radius: 4px;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.kit-appbar[data-rounded='md'] {
|
|
169
|
+
--kit-appbar-radius: 8px;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.kit-appbar[data-rounded='lg'] {
|
|
173
|
+
--kit-appbar-radius: 16px;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.kit-appbar[data-rounded='xl'] {
|
|
177
|
+
--kit-appbar-radius: 99999px;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.kit-appbar__wrapper {
|
|
181
|
+
position: relative;
|
|
182
|
+
z-index: 1;
|
|
183
|
+
display: flex;
|
|
184
|
+
align-items: center;
|
|
185
|
+
flex-direction: row;
|
|
186
|
+
gap: 0.75rem;
|
|
187
|
+
width: 100%;
|
|
188
|
+
margin: 0 auto;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.kit-appbar .outline {
|
|
192
|
+
--outline-color: var(--kit-appbar-border);
|
|
193
|
+
|
|
194
|
+
pointer-events: none;
|
|
195
|
+
}
|
|
196
|
+
</style>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Component, RoundedType } from '../../utils/types/index.js';
|
|
2
|
+
type Density = 'compact' | 'comfortable' | 'default';
|
|
3
|
+
type Variant = 'outline' | 'text';
|
|
4
|
+
export interface AppbarProps extends Component {
|
|
5
|
+
ref?: HTMLElement | null;
|
|
6
|
+
is?: 'div' | 'header' | 'nav';
|
|
7
|
+
variant?: Variant;
|
|
8
|
+
rounded?: RoundedType | string;
|
|
9
|
+
density?: Density | Record<string, Density>;
|
|
10
|
+
dark?: boolean;
|
|
11
|
+
light?: boolean;
|
|
12
|
+
color?: string;
|
|
13
|
+
background?: string;
|
|
14
|
+
classContent?: string | string[] | undefined;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onDestroy } from 'svelte';
|
|
3
|
+
import { useClassName, useStyles, clickOutside } from '../../utils/index.js';
|
|
4
|
+
import { makeComponentProps } from '../../compiler/mapped-code.js';
|
|
5
|
+
import { getPositions } from './dropdown.svelte.js';
|
|
6
|
+
import type { DropdownProps, ModelDropdownProps } from './dropdown.types.js';
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
ref = $bindable(),
|
|
10
|
+
children,
|
|
11
|
+
activator,
|
|
12
|
+
dark = false,
|
|
13
|
+
light = false,
|
|
14
|
+
rounded,
|
|
15
|
+
position = 'bottom',
|
|
16
|
+
closeOnClick = false,
|
|
17
|
+
openOnHover = false,
|
|
18
|
+
color,
|
|
19
|
+
background,
|
|
20
|
+
class: className = '',
|
|
21
|
+
style: styleAttr = '',
|
|
22
|
+
's-class': sClass,
|
|
23
|
+
's-style': sStyle,
|
|
24
|
+
...rest
|
|
25
|
+
}: DropdownProps = $props();
|
|
26
|
+
|
|
27
|
+
let safePosition = $derived(
|
|
28
|
+
position === 'top' || position === 'bottom' || position === 'left' || position === 'right'
|
|
29
|
+
? position
|
|
30
|
+
: 'bottom'
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
let { classProps, styleProps, restProps } = $derived(
|
|
34
|
+
makeComponentProps(rest as Record<string, unknown>)
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
let componentClass = $derived(
|
|
38
|
+
useClassName({
|
|
39
|
+
baseClass: 'kit-dropdown-content',
|
|
40
|
+
className: `${className ?? ''}`.trim(),
|
|
41
|
+
sClass,
|
|
42
|
+
classProps
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
let componentStyle = $derived(
|
|
47
|
+
useStyles({
|
|
48
|
+
styleAttr,
|
|
49
|
+
sStyle,
|
|
50
|
+
styleProps
|
|
51
|
+
})
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
let mergedStyle = $derived(
|
|
55
|
+
[
|
|
56
|
+
componentStyle,
|
|
57
|
+
background ? `--kit-dropdown-background:${background}` : '',
|
|
58
|
+
color ? `--kit-dropdown-color:${color}` : '',
|
|
59
|
+
typeof rounded === 'string' && rounded.includes('px')
|
|
60
|
+
? `--kit-dropdown-radius:${rounded}`
|
|
61
|
+
: ''
|
|
62
|
+
]
|
|
63
|
+
.filter(Boolean)
|
|
64
|
+
.join('; ')
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const positioner = getPositions();
|
|
68
|
+
|
|
69
|
+
let contentRef = $state<HTMLElement | null>(null);
|
|
70
|
+
let activatorRef = $state<HTMLElement | PointerEvent | null>(null);
|
|
71
|
+
let open = $state(false);
|
|
72
|
+
let axis = $state(positioner.values);
|
|
73
|
+
let innerHeight = $state(0);
|
|
74
|
+
let innerWidth = $state(0);
|
|
75
|
+
let scrollX = $state(0);
|
|
76
|
+
let scrollY = $state(0);
|
|
77
|
+
let timeoutId = $state<ReturnType<typeof setTimeout> | null>(null);
|
|
78
|
+
|
|
79
|
+
const clearHoverTimeout = () => {
|
|
80
|
+
if (timeoutId) {
|
|
81
|
+
clearTimeout(timeoutId);
|
|
82
|
+
timeoutId = null;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const updatePosition = () => {
|
|
87
|
+
if (!contentRef || !activatorRef) return;
|
|
88
|
+
positioner.update(activatorRef, contentRef, safePosition, false, true);
|
|
89
|
+
axis = positioner.values;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const handleToggle = (element: HTMLElement | PointerEvent | null) => {
|
|
93
|
+
if (element === null) return;
|
|
94
|
+
activatorRef = element;
|
|
95
|
+
open = !open;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const handleClose = () => {
|
|
99
|
+
clearHoverTimeout();
|
|
100
|
+
open = false;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const handleContentClick = () => {
|
|
104
|
+
if (closeOnClick && open) open = false;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const handleMouseEvent = (
|
|
108
|
+
state: 'open' | 'close',
|
|
109
|
+
element: HTMLElement | PointerEvent | null
|
|
110
|
+
) => {
|
|
111
|
+
if (!openOnHover) return;
|
|
112
|
+
|
|
113
|
+
if (state === 'open') {
|
|
114
|
+
clearHoverTimeout();
|
|
115
|
+
if (element) activatorRef = element;
|
|
116
|
+
open = true;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
timeoutId = setTimeout(() => {
|
|
121
|
+
open = false;
|
|
122
|
+
timeoutId = null;
|
|
123
|
+
}, 150);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
let model: ModelDropdownProps = {
|
|
127
|
+
get open() {
|
|
128
|
+
return open;
|
|
129
|
+
},
|
|
130
|
+
close: () => handleClose(),
|
|
131
|
+
toggle: (element) => handleToggle(element)
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
$effect(() => {
|
|
135
|
+
if (open && contentRef && activatorRef) {
|
|
136
|
+
updatePosition();
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
$effect(() => {
|
|
141
|
+
if (
|
|
142
|
+
open &&
|
|
143
|
+
contentRef &&
|
|
144
|
+
activatorRef &&
|
|
145
|
+
(scrollX > 0 || scrollY > 0 || innerHeight > 0 || innerWidth > 0)
|
|
146
|
+
) {
|
|
147
|
+
updatePosition();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
$effect(() => {
|
|
152
|
+
if (scrollX || scrollY) open = false;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
$effect(() => {
|
|
156
|
+
ref = contentRef;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
onDestroy(() => {
|
|
160
|
+
clearHoverTimeout();
|
|
161
|
+
});
|
|
162
|
+
</script>
|
|
163
|
+
|
|
164
|
+
<svelte:window bind:innerHeight bind:innerWidth bind:scrollX bind:scrollY />
|
|
165
|
+
|
|
166
|
+
{@render activator?.(model, (state, element) => handleMouseEvent(state, element))}
|
|
167
|
+
|
|
168
|
+
{#if open}
|
|
169
|
+
<div
|
|
170
|
+
bind:this={contentRef}
|
|
171
|
+
class={componentClass}
|
|
172
|
+
style={`left:${axis.x}px; top:${axis.y}px; ${mergedStyle}`}
|
|
173
|
+
role="menu"
|
|
174
|
+
data-light={light || undefined}
|
|
175
|
+
data-dark={dark || undefined}
|
|
176
|
+
data-rounded={rounded}
|
|
177
|
+
data-position={axis.location ?? safePosition}
|
|
178
|
+
onmouseover={() => handleMouseEvent('open', activatorRef)}
|
|
179
|
+
onmouseleave={() => handleMouseEvent('close', activatorRef)}
|
|
180
|
+
onclick={(event) => {
|
|
181
|
+
event.stopPropagation();
|
|
182
|
+
handleContentClick();
|
|
183
|
+
}}
|
|
184
|
+
use:clickOutside={{ exclude: [contentRef, activatorRef], onClose: handleClose }}
|
|
185
|
+
{...restProps}
|
|
186
|
+
>
|
|
187
|
+
{@render children?.()}
|
|
188
|
+
</div>
|
|
189
|
+
{/if}
|
|
190
|
+
|
|
191
|
+
<style>
|
|
192
|
+
.kit-dropdown-content {
|
|
193
|
+
--kit-dropdown-background: var(--kit-surface-1);
|
|
194
|
+
--kit-dropdown-color: var(--kit-fg);
|
|
195
|
+
--kit-dropdown-radius: 12px;
|
|
196
|
+
--kit-dropdown-border: color-mix(in oklab, var(--kit-fg), transparent 88%);
|
|
197
|
+
--kit-dropdown-shadow: 0 18px 40px -18px color-mix(in oklab, black 24%, transparent);
|
|
198
|
+
|
|
199
|
+
position: fixed;
|
|
200
|
+
z-index: 1800;
|
|
201
|
+
min-width: 12rem;
|
|
202
|
+
max-width: min(22rem, calc(100vw - 1rem));
|
|
203
|
+
padding: 0.375rem;
|
|
204
|
+
border: 1px solid var(--kit-dropdown-border);
|
|
205
|
+
border-radius: var(--kit-dropdown-radius);
|
|
206
|
+
background: var(--kit-dropdown-background);
|
|
207
|
+
color: var(--kit-dropdown-color);
|
|
208
|
+
box-shadow: var(--kit-dropdown-shadow);
|
|
209
|
+
transform-origin: top left;
|
|
210
|
+
animation: kit-dropdown-enter 140ms ease;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.kit-dropdown-content[data-light='true'] {
|
|
214
|
+
--kit-dropdown-background: color-mix(in oklab, white 94%, var(--kit-surface-1));
|
|
215
|
+
--kit-dropdown-color: var(--kit-fg);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.kit-dropdown-content[data-dark='true'] {
|
|
219
|
+
--kit-dropdown-background: color-mix(in oklab, black 78%, var(--kit-surface-3));
|
|
220
|
+
--kit-dropdown-color: white;
|
|
221
|
+
--kit-dropdown-border: color-mix(in oklab, white, transparent 80%);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.kit-dropdown-content[data-rounded='0'] {
|
|
225
|
+
--kit-dropdown-radius: 0;
|
|
226
|
+
}
|
|
227
|
+
.kit-dropdown-content[data-rounded='xs'] {
|
|
228
|
+
--kit-dropdown-radius: 2px;
|
|
229
|
+
}
|
|
230
|
+
.kit-dropdown-content[data-rounded='sm'] {
|
|
231
|
+
--kit-dropdown-radius: 4px;
|
|
232
|
+
}
|
|
233
|
+
.kit-dropdown-content[data-rounded='md'] {
|
|
234
|
+
--kit-dropdown-radius: 8px;
|
|
235
|
+
}
|
|
236
|
+
.kit-dropdown-content[data-rounded='lg'] {
|
|
237
|
+
--kit-dropdown-radius: 16px;
|
|
238
|
+
}
|
|
239
|
+
.kit-dropdown-content[data-rounded='xl'] {
|
|
240
|
+
--kit-dropdown-radius: 99999px;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
@keyframes kit-dropdown-enter {
|
|
244
|
+
from {
|
|
245
|
+
opacity: 0;
|
|
246
|
+
scale: 0.98;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
</style>
|
|
@@ -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,28 @@
|
|
|
1
|
+
import type { Component, PropValue, RoundedType } from '../../utils/types/index.js';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
export type PositionElement = {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
location: 'top' | 'bottom' | 'left' | 'right' | null;
|
|
7
|
+
};
|
|
8
|
+
export type ModelDropdownProps = {
|
|
9
|
+
open: boolean;
|
|
10
|
+
close: () => void;
|
|
11
|
+
toggle: (element: HTMLElement | PointerEvent | null) => void;
|
|
12
|
+
};
|
|
13
|
+
export interface DropdownProps extends Component {
|
|
14
|
+
ref?: HTMLElement | null;
|
|
15
|
+
dark?: boolean;
|
|
16
|
+
light?: boolean;
|
|
17
|
+
rounded?: RoundedType | string;
|
|
18
|
+
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
19
|
+
openOnHover?: boolean;
|
|
20
|
+
closeOnClick?: boolean;
|
|
21
|
+
color?: string;
|
|
22
|
+
background?: string;
|
|
23
|
+
activator?: Snippet<[
|
|
24
|
+
ModelDropdownProps,
|
|
25
|
+
(state: 'open' | 'close', element: HTMLElement | PointerEvent | null) => void
|
|
26
|
+
]>;
|
|
27
|
+
[key: string]: PropValue | Record<string, PropValue> | unknown;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
export { default as KitSheet } from './sheet/sheet.svelte';
|
|
2
2
|
export { default as KitApp } from './app/app.svelte';
|
|
3
|
+
export { default as KitAppbar } from './appbar/appbar.svelte';
|
|
3
4
|
export { default as KitBtn } from './btn/btn.svelte';
|
|
4
5
|
export { default as KitIcon } from './icon/icon.svelte';
|
|
5
6
|
export { default as KitCard } from './card/card.svelte';
|
|
6
7
|
export { default as KitChip } from './chip/chip.svelte';
|
|
7
8
|
export { default as KitAvatar } from './avatar/avatar.svelte';
|
|
9
|
+
export { default as KitDropdown } from './dropdown/dropdown.svelte';
|
|
10
|
+
export { default as KitPopover } from './popover/popover.svelte';
|
|
11
|
+
export { default as KitTooltip } from './tooltip/tooltip.svelte';
|
|
12
|
+
export { default as KitTextfield } from './textfield/textfield.svelte';
|
|
13
|
+
export { default as KitToolbar } from './toolbar/toolbar.svelte';
|
|
14
|
+
export { default as KitList } from './list/list.svelte';
|
|
15
|
+
export { default as KitListItem } from './list/modules/list-item.svelte';
|
|
8
16
|
export { default as KitDialog } from './dialog/dialog.svelte';
|
|
9
17
|
export { default as KitModal } from './modal/modal.svelte';
|
|
10
18
|
export { default as KitAccordion } from './accordion/accordion.svelte';
|