@svelte-atoms/core 1.0.0-alpha.29 → 1.0.0-alpha.30
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 +852 -852
- package/dist/attachments/clickout.svelte.d.ts +1 -1
- package/dist/attachments/clickout.svelte.js +2 -2
- package/dist/components/accordion/accordion-root.svelte +61 -61
- package/dist/components/accordion/accordion-root.svelte.d.ts +1 -1
- package/dist/components/accordion/accordion.stories.svelte +145 -134
- package/dist/components/alert/alert.stories.svelte +400 -401
- package/dist/components/atom/html-atom.svelte +71 -17
- package/dist/components/avatar/avatar.stories.svelte +22 -27
- package/dist/components/badge/badge.stories.svelte +12 -17
- package/dist/components/badge/badge.svelte +19 -19
- package/dist/components/breadcrumb/breadcrumb.stories.svelte +16 -21
- package/dist/components/button/button.stories.svelte +27 -60
- package/dist/components/calendar/calendar-day.svelte +96 -96
- package/dist/components/calendar/calendar-header.svelte +29 -29
- package/dist/components/calendar/calendar-root.svelte +206 -206
- package/dist/components/calendar/calendar.stories.svelte +10 -15
- package/dist/components/card/card-body.svelte +39 -39
- package/dist/components/card/card-footer.svelte +41 -41
- package/dist/components/card/card-root.svelte +91 -91
- package/dist/components/card/card.stories.svelte +133 -145
- package/dist/components/checkbox/checkbox.stories.svelte +22 -27
- package/dist/components/checkbox/checkbox.svelte +155 -157
- package/dist/components/collapsible/collapsible.stories.svelte +172 -173
- package/dist/components/combobox/combobox-root.svelte +65 -65
- package/dist/components/combobox/compobox.stories.svelte +51 -54
- package/dist/components/container/container.stories.svelte +20 -23
- package/dist/components/datagrid/datagrid-root.svelte +59 -59
- package/dist/components/datagrid/datagrid.css +5 -5
- package/dist/components/datagrid/datagrid.stories.svelte +72 -75
- package/dist/components/date-picker/date-picker-calendar.svelte +67 -67
- package/dist/components/date-picker/date-picker-header.svelte +100 -100
- package/dist/components/date-picker/date-picker-months.svelte +142 -142
- package/dist/components/date-picker/date-picker-root.svelte +1 -1
- package/dist/components/date-picker/date-picker-years.svelte +205 -205
- package/dist/components/date-picker/date-picker.stories.svelte +11 -18
- package/dist/components/dialog/dialog-content.svelte +62 -62
- package/dist/components/dialog/dialog.stories.svelte +64 -67
- package/dist/components/drawer/attachments.svelte.js +8 -9
- package/dist/components/drawer/drawer-content.svelte +57 -42
- package/dist/components/drawer/drawer.stories.svelte +212 -224
- package/dist/components/dropdown/dropdown-root.svelte +59 -59
- package/dist/components/dropdown/dropdown.stories.svelte +80 -83
- package/dist/components/form/form.stories.svelte +96 -99
- package/dist/components/image/image.stories.svelte +20 -23
- package/dist/components/input/input.stories.svelte +35 -38
- package/dist/components/label/label.stories.svelte +15 -26
- package/dist/components/label/label.stories.svelte.d.ts +24 -4
- package/dist/components/lazy/lazy.stories.svelte +9 -16
- package/dist/components/lazy/lazy.svelte +28 -28
- package/dist/components/link/link.stories.svelte +15 -26
- package/dist/components/link/link.stories.svelte.d.ts +24 -4
- package/dist/components/menu/menu-list.svelte +40 -40
- package/dist/components/menu/menu.stories.svelte +33 -36
- package/dist/components/popover/bond.svelte.js +31 -25
- package/dist/components/popover/popover-arrow.svelte +111 -111
- package/dist/components/popover/popover-content.svelte +175 -178
- package/dist/components/popover/popover-indicator.svelte +44 -43
- package/dist/components/popover/popover-root.svelte +48 -48
- package/dist/components/popover/popover.stories.svelte +49 -52
- package/dist/components/qr-code/qr-code.stories.svelte +4 -13
- package/dist/components/qr-code/qr-code.svelte +75 -75
- package/dist/components/radio/radio-group.stories.svelte +41 -50
- package/dist/components/radio/radio.stories.svelte +17 -26
- package/dist/components/radio/radio.svelte +109 -109
- package/dist/components/root/root.svelte +121 -121
- package/dist/components/root/root.svelte.d.ts +1 -1
- package/dist/components/scrollable/scrollable.stories.svelte +116 -126
- package/dist/components/sidebar/sidebar-content.svelte +13 -2
- package/dist/components/sidebar/sidebar-root.svelte +10 -12
- package/dist/components/sidebar/sidebar.stories.svelte +8 -19
- package/dist/components/sidebar/types.d.ts +1 -0
- package/dist/components/tabs/tab/bond.svelte.d.ts +4 -1
- package/dist/components/tabs/tab/bond.svelte.js +4 -1
- package/dist/components/tabs/tabs.stories.svelte +56 -59
- package/dist/components/tooltip/tooltip-trigger.svelte +39 -37
- package/dist/components/tooltip/tooltip.stories.svelte +32 -35
- package/dist/components/tree/tree.stories.svelte +142 -134
- package/dist/context/preset.svelte.d.ts +3 -3
- package/dist/utils/function.d.ts +2 -0
- package/dist/utils/function.js +6 -0
- package/package.json +6 -9
- package/dist/actions/animation.svelte.d.ts +0 -6
- package/dist/actions/animation.svelte.js +0 -14
- package/dist/actions/clickout.svelte.d.ts +0 -2
- package/dist/actions/clickout.svelte.js +0 -15
- package/dist/actions/popover.svelte.d.ts +0 -19
- package/dist/actions/popover.svelte.js +0 -81
- package/dist/actions/portal.svelte.d.ts +0 -8
- package/dist/actions/portal.svelte.js +0 -32
- package/dist/attachments/gsap.svelte.d.ts +0 -2
- package/dist/attachments/gsap.svelte.js +0 -26
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import type { Component } from 'svelte';
|
|
3
|
-
import type { LazyProps } from './types';
|
|
4
|
-
|
|
5
|
-
let { promise, children, loading, error, ...restProps }: LazyProps = $props();
|
|
6
|
-
|
|
7
|
-
let Lazy: Component | null = $state(null);
|
|
8
|
-
|
|
9
|
-
let err = $state();
|
|
10
|
-
|
|
11
|
-
promise
|
|
12
|
-
.then((c) => {
|
|
13
|
-
Lazy = c;
|
|
14
|
-
})
|
|
15
|
-
.catch((r) => {
|
|
16
|
-
err = r;
|
|
17
|
-
});
|
|
18
|
-
</script>
|
|
19
|
-
|
|
20
|
-
<Lazy {...restProps}>
|
|
21
|
-
{@render children?.()}
|
|
22
|
-
</Lazy>
|
|
23
|
-
|
|
24
|
-
{#if err && error}
|
|
25
|
-
{@render error?.()}
|
|
26
|
-
{:else if !Lazy}
|
|
27
|
-
{@render loading?.()}
|
|
28
|
-
{/if}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Component } from 'svelte';
|
|
3
|
+
import type { LazyProps } from './types';
|
|
4
|
+
|
|
5
|
+
let { promise, children, loading, error, ...restProps }: LazyProps = $props();
|
|
6
|
+
|
|
7
|
+
let Lazy: Component | null = $state(null);
|
|
8
|
+
|
|
9
|
+
let err = $state();
|
|
10
|
+
|
|
11
|
+
promise
|
|
12
|
+
.then((c) => {
|
|
13
|
+
Lazy = c;
|
|
14
|
+
})
|
|
15
|
+
.catch((r) => {
|
|
16
|
+
err = r;
|
|
17
|
+
});
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<Lazy {...restProps}>
|
|
21
|
+
{@render children?.()}
|
|
22
|
+
</Lazy>
|
|
23
|
+
|
|
24
|
+
{#if err && error}
|
|
25
|
+
{@render error?.()}
|
|
26
|
+
{:else if !Lazy}
|
|
27
|
+
{@render loading?.()}
|
|
28
|
+
{/if}
|
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
</
|
|
15
|
-
|
|
16
|
-
<Story name="Link">
|
|
17
|
-
{#snippet children(args)}
|
|
18
|
-
<Root>
|
|
19
|
-
{#snippet children({})}
|
|
20
|
-
<div class="flex h-full w-full items-center justify-center">
|
|
21
|
-
<LinkComponent>Hello World</LinkComponent>
|
|
22
|
-
</div>
|
|
23
|
-
{/snippet}
|
|
24
|
-
</Root>
|
|
25
|
-
{/snippet}
|
|
26
|
-
</Story>
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import LinkComponent from './link.svelte';
|
|
4
|
+
|
|
5
|
+
const { Story } = defineMeta({
|
|
6
|
+
title: 'ATOMS/Link'
|
|
7
|
+
});
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script>
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<Story name="Link">
|
|
14
|
+
<LinkComponent>Hello World</LinkComponent>
|
|
15
|
+
</Story>
|
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
export default Link;
|
|
2
|
-
type Link = {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
type Link = SvelteComponent<{
|
|
3
|
+
[x: string]: never;
|
|
4
|
+
}, {
|
|
5
|
+
[evt: string]: CustomEvent<any>;
|
|
6
|
+
}, {}> & {
|
|
7
|
+
$$bindings?: string;
|
|
5
8
|
};
|
|
6
|
-
declare const Link:
|
|
9
|
+
declare const Link: $$__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
|
+
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
<script lang="ts" generics="T extends keyof HTMLElementTagNameMap = 'div', B extends Base = Base">
|
|
2
|
-
import { List } from '../list';
|
|
3
|
-
import { Content } from '../popover/atoms';
|
|
4
|
-
import type { Base } from '../atom';
|
|
5
|
-
import { PopoverBond } from '../popover';
|
|
6
|
-
|
|
7
|
-
const bond = PopoverBond.get();
|
|
8
|
-
|
|
9
|
-
let {
|
|
10
|
-
class: klass = '',
|
|
11
|
-
as = 'ul' as T,
|
|
12
|
-
base = List.Root as B,
|
|
13
|
-
preset = 'menu.list',
|
|
14
|
-
children = undefined,
|
|
15
|
-
onmount = undefined,
|
|
16
|
-
ondestroy = undefined,
|
|
17
|
-
animate = undefined,
|
|
18
|
-
enter = undefined,
|
|
19
|
-
exit = undefined,
|
|
20
|
-
initial = undefined,
|
|
21
|
-
...restProps
|
|
22
|
-
} = $props();
|
|
23
|
-
</script>
|
|
24
|
-
|
|
25
|
-
<Content
|
|
26
|
-
{as}
|
|
27
|
-
{base}
|
|
28
|
-
{bond}
|
|
29
|
-
{preset}
|
|
30
|
-
class={['bg-background border-border overflow-hidden p-0', '$preset', klass]}
|
|
31
|
-
onmount={onmount?.bind(bond.state)}
|
|
32
|
-
ondestroy={ondestroy?.bind(bond.state)}
|
|
33
|
-
enter={enter?.bind(bond.state)}
|
|
34
|
-
exit={exit?.bind(bond.state)}
|
|
35
|
-
initial={initial?.bind(bond.state)}
|
|
36
|
-
animate={animate?.bind(bond.state)}
|
|
37
|
-
{...restProps}
|
|
38
|
-
>
|
|
39
|
-
{@render children?.()}
|
|
40
|
-
</Content>
|
|
1
|
+
<script lang="ts" generics="T extends keyof HTMLElementTagNameMap = 'div', B extends Base = Base">
|
|
2
|
+
import { List } from '../list';
|
|
3
|
+
import { Content } from '../popover/atoms';
|
|
4
|
+
import type { Base } from '../atom';
|
|
5
|
+
import { PopoverBond } from '../popover';
|
|
6
|
+
|
|
7
|
+
const bond = PopoverBond.get();
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
class: klass = '',
|
|
11
|
+
as = 'ul' as T,
|
|
12
|
+
base = List.Root as B,
|
|
13
|
+
preset = 'menu.list',
|
|
14
|
+
children = undefined,
|
|
15
|
+
onmount = undefined,
|
|
16
|
+
ondestroy = undefined,
|
|
17
|
+
animate = undefined,
|
|
18
|
+
enter = undefined,
|
|
19
|
+
exit = undefined,
|
|
20
|
+
initial = undefined,
|
|
21
|
+
...restProps
|
|
22
|
+
} = $props();
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<Content
|
|
26
|
+
{as}
|
|
27
|
+
{base}
|
|
28
|
+
{bond}
|
|
29
|
+
{preset}
|
|
30
|
+
class={['bg-background border-border overflow-hidden p-0', '$preset', klass]}
|
|
31
|
+
onmount={onmount?.bind(bond.state)}
|
|
32
|
+
ondestroy={ondestroy?.bind(bond.state)}
|
|
33
|
+
enter={enter?.bind(bond.state)}
|
|
34
|
+
exit={exit?.bind(bond.state)}
|
|
35
|
+
initial={initial?.bind(bond.state)}
|
|
36
|
+
animate={animate?.bind(bond.state)}
|
|
37
|
+
{...restProps}
|
|
38
|
+
>
|
|
39
|
+
{@render children?.()}
|
|
40
|
+
</Content>
|
|
@@ -1,36 +1,33 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import { Menu as AMenu } from '.';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<
|
|
25
|
-
|
|
26
|
-
<AMenu.
|
|
27
|
-
<AMenu.
|
|
28
|
-
<AMenu.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
</AMenu.Root>
|
|
35
|
-
</Root>
|
|
36
|
-
</Story>
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import { Menu as AMenu } from '.';
|
|
4
|
+
import { Button } from '../button';
|
|
5
|
+
|
|
6
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
7
|
+
const { Story } = defineMeta({
|
|
8
|
+
title: 'Atoms/Menu',
|
|
9
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
10
|
+
|
|
11
|
+
parameters: {
|
|
12
|
+
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
|
13
|
+
layout: 'fullscreen'
|
|
14
|
+
},
|
|
15
|
+
args: {}
|
|
16
|
+
});
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script lang="ts">
|
|
20
|
+
let open = $state(false);
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<Story name="Menu" args={{}}>
|
|
24
|
+
<AMenu.Root bind:open offset={4}>
|
|
25
|
+
<AMenu.Trigger base={Button}>Select a language</AMenu.Trigger>
|
|
26
|
+
<AMenu.List>
|
|
27
|
+
<AMenu.Item>Arabic</AMenu.Item>
|
|
28
|
+
<AMenu.Item>English</AMenu.Item>
|
|
29
|
+
<AMenu.Item>Spanish</AMenu.Item>
|
|
30
|
+
<AMenu.Item>Italian</AMenu.Item>
|
|
31
|
+
</AMenu.List>
|
|
32
|
+
</AMenu.Root>
|
|
33
|
+
</Story>
|
|
@@ -52,7 +52,7 @@ export class PopoverBond extends Bond {
|
|
|
52
52
|
const position = untrack(() => this.#position);
|
|
53
53
|
if (!position) {
|
|
54
54
|
const init = async () => {
|
|
55
|
-
popover(this)(
|
|
55
|
+
popover(this)({
|
|
56
56
|
...props,
|
|
57
57
|
onchange: (node, position) => {
|
|
58
58
|
this.#position = position;
|
|
@@ -96,7 +96,7 @@ export class PopoverBond extends Bond {
|
|
|
96
96
|
}
|
|
97
97
|
if (!this.state.isOpen)
|
|
98
98
|
return;
|
|
99
|
-
return popover(this)(
|
|
99
|
+
return popover(this)({
|
|
100
100
|
...props,
|
|
101
101
|
onchange: (node, position) => {
|
|
102
102
|
this.#position = position;
|
|
@@ -160,38 +160,44 @@ export class PopoverState extends BondState {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
function popover(bond) {
|
|
163
|
-
return (
|
|
163
|
+
return (props, updater) => {
|
|
164
164
|
const { offset: ofs, placements, placement } = bond.state.props;
|
|
165
|
-
|
|
165
|
+
// Guard: ensure required elements exist
|
|
166
|
+
if (!bond.elements.content || !bond.elements.trigger) {
|
|
166
167
|
return;
|
|
167
168
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const middleware = [
|
|
173
|
-
|
|
174
|
-
|
|
169
|
+
const { content, trigger, arrow: arrowElement } = bond.elements;
|
|
170
|
+
// Set minimum width to match trigger
|
|
171
|
+
content.style.minWidth = `${trigger.clientWidth}px`;
|
|
172
|
+
// Build middleware stack
|
|
173
|
+
const middleware = [
|
|
174
|
+
offset(ofs),
|
|
175
|
+
flip({
|
|
176
|
+
fallbackPlacements: placements,
|
|
177
|
+
padding: 4
|
|
178
|
+
})
|
|
179
|
+
];
|
|
180
|
+
// Add arrow middleware if element exists
|
|
181
|
+
if (arrowElement) {
|
|
182
|
+
middleware.push(arrow({ element: arrowElement }));
|
|
175
183
|
}
|
|
184
|
+
// Debounce position change callback
|
|
185
|
+
const onchangeCallback = props.onchange;
|
|
176
186
|
const onchangeDebounced = debounce((node, position) => {
|
|
177
|
-
|
|
178
|
-
}, 1000 / 60
|
|
187
|
+
onchangeCallback?.(node, position);
|
|
188
|
+
}, 1000 / 60 // ~16ms for 60fps
|
|
189
|
+
);
|
|
190
|
+
// Compute position and notify listeners
|
|
179
191
|
const compute = async () => {
|
|
180
|
-
const position = await computePosition(
|
|
181
|
-
placement,
|
|
182
|
-
middleware
|
|
183
|
-
offset(ofs),
|
|
184
|
-
flip({
|
|
185
|
-
fallbackPlacements: placements,
|
|
186
|
-
padding: 4
|
|
187
|
-
}),
|
|
188
|
-
...middleware
|
|
189
|
-
]
|
|
192
|
+
const position = await computePosition(trigger, content, {
|
|
193
|
+
placement: placement ?? 'bottom',
|
|
194
|
+
middleware
|
|
190
195
|
});
|
|
191
|
-
onchangeDebounced
|
|
196
|
+
onchangeDebounced(content, position);
|
|
192
197
|
};
|
|
198
|
+
// Use auto-update if provided, otherwise compute once
|
|
193
199
|
if (updater) {
|
|
194
|
-
return updater(
|
|
200
|
+
return updater(trigger, content, compute, {});
|
|
195
201
|
}
|
|
196
202
|
compute();
|
|
197
203
|
};
|
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
<script lang="ts" generics="E extends keyof HTMLElementTagNameMap = 'div', B extends Base = Base">
|
|
2
|
-
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
-
import { animate as motion } from 'motion';
|
|
4
|
-
import { HtmlAtom, type Base } from '../atom';
|
|
5
|
-
import { PopoverBond } from './bond.svelte';
|
|
6
|
-
import type { PopoverArrowProps } from './types';
|
|
7
|
-
|
|
8
|
-
type Element = HTMLElementTagNameMap[E];
|
|
9
|
-
|
|
10
|
-
const bond = PopoverBond.get();
|
|
11
|
-
|
|
12
|
-
if (!bond) {
|
|
13
|
-
throw new Error('');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let {
|
|
17
|
-
class: klass = '',
|
|
18
|
-
children = undefined,
|
|
19
|
-
onmount = undefined,
|
|
20
|
-
ondestroy = undefined,
|
|
21
|
-
animate = _animate,
|
|
22
|
-
enter = undefined,
|
|
23
|
-
exit = undefined,
|
|
24
|
-
initial = undefined,
|
|
25
|
-
...restProps
|
|
26
|
-
}: PopoverArrowProps<E, B> & HTMLAttributes<Element> = $props();
|
|
27
|
-
|
|
28
|
-
const position = $derived(bond.position);
|
|
29
|
-
const middlewareArrowData = $derived(position?.middlewareData?.arrow);
|
|
30
|
-
const isReady = $derived(!!middlewareArrowData);
|
|
31
|
-
const side = $derived(position?.placement?.split('-')[0] ?? 'top');
|
|
32
|
-
|
|
33
|
-
const arrowProps = $derived({
|
|
34
|
-
...bond.arrow(),
|
|
35
|
-
...restProps
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Rotation based on placement side
|
|
39
|
-
const rotation = $derived.by(() => {
|
|
40
|
-
switch (side) {
|
|
41
|
-
case 'top':
|
|
42
|
-
return 180;
|
|
43
|
-
case 'bottom':
|
|
44
|
-
return 0;
|
|
45
|
-
case 'left':
|
|
46
|
-
return 90;
|
|
47
|
-
case 'right':
|
|
48
|
-
return -90;
|
|
49
|
-
default:
|
|
50
|
-
return 0;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
function _animate(node: HTMLElement) {
|
|
55
|
-
if (!middlewareArrowData) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const { x, y } = middlewareArrowData;
|
|
60
|
-
|
|
61
|
-
const isMainAxis = side === 'top' || side === 'bottom';
|
|
62
|
-
|
|
63
|
-
const crossAxisStyle = isMainAxis
|
|
64
|
-
? {
|
|
65
|
-
left: 0
|
|
66
|
-
}
|
|
67
|
-
: {
|
|
68
|
-
top: 0
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
motion(
|
|
72
|
-
node,
|
|
73
|
-
{
|
|
74
|
-
x: x ?? 0,
|
|
75
|
-
y: y ?? 0,
|
|
76
|
-
opacity: 1,
|
|
77
|
-
...crossAxisStyle
|
|
78
|
-
},
|
|
79
|
-
{ duration: 0 }
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
</script>
|
|
83
|
-
|
|
84
|
-
<HtmlAtom
|
|
85
|
-
{bond}
|
|
86
|
-
preset="popover.arrow"
|
|
87
|
-
class={['text-border border-border pointer-events-none absolute opacity-0', '$preset', klass]}
|
|
88
|
-
onmount={onmount?.bind(bond.state)}
|
|
89
|
-
ondestroy={ondestroy?.bind(bond.state)}
|
|
90
|
-
animate={animate?.bind(bond.state)}
|
|
91
|
-
enter={enter?.bind(bond.state)}
|
|
92
|
-
exit={exit?.bind(bond.state)}
|
|
93
|
-
initial={initial?.bind(bond.state)}
|
|
94
|
-
style="{side}: 100%;"
|
|
95
|
-
{...arrowProps}
|
|
96
|
-
>
|
|
97
|
-
{#if children}
|
|
98
|
-
{@render children({ popover: bond })}
|
|
99
|
-
{:else}
|
|
100
|
-
<svg
|
|
101
|
-
width="
|
|
102
|
-
height="
|
|
103
|
-
viewBox="0 0
|
|
104
|
-
fill="none"
|
|
105
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
106
|
-
style="transform: rotate({rotation}deg);"
|
|
107
|
-
>
|
|
108
|
-
<path d="M0
|
|
109
|
-
</svg>
|
|
110
|
-
{/if}
|
|
111
|
-
</HtmlAtom>
|
|
1
|
+
<script lang="ts" generics="E extends keyof HTMLElementTagNameMap = 'div', B extends Base = Base">
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import { animate as motion } from 'motion';
|
|
4
|
+
import { HtmlAtom, type Base } from '../atom';
|
|
5
|
+
import { PopoverBond } from './bond.svelte';
|
|
6
|
+
import type { PopoverArrowProps } from './types';
|
|
7
|
+
|
|
8
|
+
type Element = HTMLElementTagNameMap[E];
|
|
9
|
+
|
|
10
|
+
const bond = PopoverBond.get();
|
|
11
|
+
|
|
12
|
+
if (!bond) {
|
|
13
|
+
throw new Error('');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let {
|
|
17
|
+
class: klass = '',
|
|
18
|
+
children = undefined,
|
|
19
|
+
onmount = undefined,
|
|
20
|
+
ondestroy = undefined,
|
|
21
|
+
animate = _animate,
|
|
22
|
+
enter = undefined,
|
|
23
|
+
exit = undefined,
|
|
24
|
+
initial = undefined,
|
|
25
|
+
...restProps
|
|
26
|
+
}: PopoverArrowProps<E, B> & HTMLAttributes<Element> = $props();
|
|
27
|
+
|
|
28
|
+
const position = $derived(bond.position);
|
|
29
|
+
const middlewareArrowData = $derived(position?.middlewareData?.arrow);
|
|
30
|
+
const isReady = $derived(!!middlewareArrowData);
|
|
31
|
+
const side = $derived(position?.placement?.split('-')[0] ?? 'top');
|
|
32
|
+
|
|
33
|
+
const arrowProps = $derived({
|
|
34
|
+
...bond.arrow(),
|
|
35
|
+
...restProps
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Rotation based on placement side
|
|
39
|
+
const rotation = $derived.by(() => {
|
|
40
|
+
switch (side) {
|
|
41
|
+
case 'top':
|
|
42
|
+
return 180;
|
|
43
|
+
case 'bottom':
|
|
44
|
+
return 0;
|
|
45
|
+
case 'left':
|
|
46
|
+
return 90;
|
|
47
|
+
case 'right':
|
|
48
|
+
return -90;
|
|
49
|
+
default:
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
function _animate(node: HTMLElement) {
|
|
55
|
+
if (!middlewareArrowData) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const { x, y } = middlewareArrowData;
|
|
60
|
+
|
|
61
|
+
const isMainAxis = side === 'top' || side === 'bottom';
|
|
62
|
+
|
|
63
|
+
const crossAxisStyle = isMainAxis
|
|
64
|
+
? {
|
|
65
|
+
left: 0
|
|
66
|
+
}
|
|
67
|
+
: {
|
|
68
|
+
top: 0
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
motion(
|
|
72
|
+
node,
|
|
73
|
+
{
|
|
74
|
+
x: x ?? 0,
|
|
75
|
+
y: y ?? 0,
|
|
76
|
+
opacity: 1,
|
|
77
|
+
...crossAxisStyle
|
|
78
|
+
},
|
|
79
|
+
{ duration: 0 }
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<HtmlAtom
|
|
85
|
+
{bond}
|
|
86
|
+
preset="popover.arrow"
|
|
87
|
+
class={['text-border border-border pointer-events-none absolute opacity-0', '$preset', klass]}
|
|
88
|
+
onmount={onmount?.bind(bond.state)}
|
|
89
|
+
ondestroy={ondestroy?.bind(bond.state)}
|
|
90
|
+
animate={animate?.bind(bond.state)}
|
|
91
|
+
enter={enter?.bind(bond.state)}
|
|
92
|
+
exit={exit?.bind(bond.state)}
|
|
93
|
+
initial={initial?.bind(bond.state)}
|
|
94
|
+
style="{side}: 100%;"
|
|
95
|
+
{...arrowProps}
|
|
96
|
+
>
|
|
97
|
+
{#if children}
|
|
98
|
+
{@render children({ popover: bond })}
|
|
99
|
+
{:else}
|
|
100
|
+
<svg
|
|
101
|
+
width="16"
|
|
102
|
+
height="8"
|
|
103
|
+
viewBox="0 0 16 8"
|
|
104
|
+
fill="none"
|
|
105
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
106
|
+
style="transform: rotate({rotation}deg);"
|
|
107
|
+
>
|
|
108
|
+
<path d="M0 8C2 8 6 4 8 0C10 4 14 8 16 8H0Z" fill="currentColor" />
|
|
109
|
+
</svg>
|
|
110
|
+
{/if}
|
|
111
|
+
</HtmlAtom>
|