@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,178 +1,175 @@
|
|
|
1
|
-
<script lang="ts" generics="E extends HtmlElementTagName, B extends Base = Base">
|
|
2
|
-
import { animate as motion } from 'motion';
|
|
3
|
-
import { PortalBond, PortalsBond, Teleport } from '../portal';
|
|
4
|
-
import { HtmlAtom, type Base } from '../atom';
|
|
5
|
-
import type { HtmlElementTagName, HtmlElementType } from '../element';
|
|
6
|
-
import { DURATION } from '../../shared';
|
|
7
|
-
import { PopoverBond } from './bond.svelte';
|
|
8
|
-
import type { AnimateParams, PopoverContentProps } from './types';
|
|
9
|
-
|
|
10
|
-
type Element = HtmlElementType<E>;
|
|
11
|
-
|
|
12
|
-
const bond = PopoverBond.get();
|
|
13
|
-
const activePortalBond = (() => {
|
|
14
|
-
const key = bond.state.props.portal;
|
|
15
|
-
if (key instanceof PortalBond) {
|
|
16
|
-
return key;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
let portal: PortalBond | undefined | null = undefined;
|
|
20
|
-
|
|
21
|
-
if (typeof key === 'string') {
|
|
22
|
-
portal = PortalsBond.get()?.state.get(key);
|
|
23
|
-
console.error('portal was not found');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return portal ?? PortalBond.get();
|
|
27
|
-
})();
|
|
28
|
-
|
|
29
|
-
if (!bond) {
|
|
30
|
-
throw new Error('<PopoverOverlay /> must be used within a <Popover />');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let {
|
|
34
|
-
class: klass = '',
|
|
35
|
-
children = undefined,
|
|
36
|
-
onmount = undefined,
|
|
37
|
-
ondestroy = undefined,
|
|
38
|
-
animate = _animate,
|
|
39
|
-
enter = undefined,
|
|
40
|
-
exit = undefined,
|
|
41
|
-
initial = undefined,
|
|
42
|
-
...restProps
|
|
43
|
-
}: PopoverContentProps<E, B> = $props();
|
|
44
|
-
|
|
45
|
-
const isOpen = $derived(bond.state.isOpen && !!bond.elements.trigger);
|
|
46
|
-
const portalId = $derived(activePortalBond?.id);
|
|
47
|
-
|
|
48
|
-
const position = $derived(bond.position);
|
|
49
|
-
const placement = $derived(position?.placement);
|
|
50
|
-
|
|
51
|
-
const x = $derived(position?.x ?? 0);
|
|
52
|
-
const y = $derived(position?.y ?? 0);
|
|
53
|
-
|
|
54
|
-
const dy = $derived(placement?.startsWith('top') ? -1 : placement?.startsWith('bottom') ? 1 : 0);
|
|
55
|
-
const dx = $derived(placement?.startsWith('left') ? -1 : placement?.startsWith('right') ? 1 : 0);
|
|
56
|
-
|
|
57
|
-
const offset = $derived(bond.state.props.offset);
|
|
58
|
-
|
|
59
|
-
const xOffset = $derived(dx * offset);
|
|
60
|
-
const yOffset = $derived(dy * offset);
|
|
61
|
-
|
|
62
|
-
const openAsNumber = $derived(+isOpen);
|
|
63
|
-
const deltaArrow = $derived(position?.middlewareData?.arrow ? 1 : 0);
|
|
64
|
-
|
|
65
|
-
let isInitialized = false;
|
|
66
|
-
|
|
67
|
-
function _containerInitial(this: typeof bond.state, node: Element) {
|
|
68
|
-
const arrowClientWidth = bond?.elements.arrow?.clientWidth ?? 0;
|
|
69
|
-
const arrowClientHeight = bond?.elements.arrow?.clientHeight ?? 0;
|
|
70
|
-
|
|
71
|
-
const _x = x + xOffset * openAsNumber + deltaArrow * dx * arrowClientWidth;
|
|
72
|
-
const _y = y + yOffset * openAsNumber + deltaArrow * dy * arrowClientHeight;
|
|
73
|
-
|
|
74
|
-
node.style.transform = `translate3d(${_x}px, ${_y}px, 1px)`;
|
|
75
|
-
|
|
76
|
-
isInitialized = true;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function _containerAnimate(this: typeof bond.state, node: Element, _?: AnimateParams) {
|
|
80
|
-
if (!isInitialized) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const deltaArrow = position?.middlewareData?.arrow ? 1 : 0;
|
|
85
|
-
const arrowClientWidth = bond?.elements.arrow?.clientWidth ?? 0;
|
|
86
|
-
const arrowClientHeight = bond?.elements.arrow?.clientHeight ?? 0;
|
|
87
|
-
|
|
88
|
-
const _x = x + xOffset * openAsNumber + deltaArrow * dx * arrowClientWidth;
|
|
89
|
-
const _y = y + yOffset * openAsNumber + deltaArrow * dy * arrowClientHeight;
|
|
90
|
-
|
|
91
|
-
node.style.transform = `translate3d(${_x}px, ${_y}px, 1px)`;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
let isOpened = false;
|
|
95
|
-
|
|
96
|
-
function _animate(this: typeof bond.state, node: Element) {
|
|
97
|
-
const isOpen = this.isOpen;
|
|
98
|
-
|
|
99
|
-
const arrowClientWidth = bond?.elements.arrow?.clientWidth ?? 0;
|
|
100
|
-
const arrowClientHeight = bond?.elements.arrow?.clientHeight ?? 0;
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
case '
|
|
109
|
-
case '
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
case '
|
|
113
|
-
case '
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
case '
|
|
117
|
-
case '
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
{@render children?.({ popover: bond })}
|
|
177
|
-
</HtmlAtom>
|
|
178
|
-
</Teleport>
|
|
1
|
+
<script lang="ts" generics="E extends HtmlElementTagName, B extends Base = Base">
|
|
2
|
+
import { animate as motion } from 'motion';
|
|
3
|
+
import { PortalBond, PortalsBond, Teleport } from '../portal';
|
|
4
|
+
import { HtmlAtom, type Base } from '../atom';
|
|
5
|
+
import type { HtmlElementTagName, HtmlElementType } from '../element';
|
|
6
|
+
import { DURATION } from '../../shared';
|
|
7
|
+
import { PopoverBond } from './bond.svelte';
|
|
8
|
+
import type { AnimateParams, PopoverContentProps } from './types';
|
|
9
|
+
|
|
10
|
+
type Element = HtmlElementType<E>;
|
|
11
|
+
|
|
12
|
+
const bond = PopoverBond.get();
|
|
13
|
+
const activePortalBond = (() => {
|
|
14
|
+
const key = bond.state.props.portal;
|
|
15
|
+
if (key instanceof PortalBond) {
|
|
16
|
+
return key;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let portal: PortalBond | undefined | null = undefined;
|
|
20
|
+
|
|
21
|
+
if (typeof key === 'string') {
|
|
22
|
+
portal = PortalsBond.get()?.state.get(key);
|
|
23
|
+
console.error('portal was not found');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return portal ?? PortalBond.get();
|
|
27
|
+
})();
|
|
28
|
+
|
|
29
|
+
if (!bond) {
|
|
30
|
+
throw new Error('<PopoverOverlay /> must be used within a <Popover />');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let {
|
|
34
|
+
class: klass = '',
|
|
35
|
+
children = undefined,
|
|
36
|
+
onmount = undefined,
|
|
37
|
+
ondestroy = undefined,
|
|
38
|
+
animate = _animate,
|
|
39
|
+
enter = undefined,
|
|
40
|
+
exit = undefined,
|
|
41
|
+
initial = undefined,
|
|
42
|
+
...restProps
|
|
43
|
+
}: PopoverContentProps<E, B> = $props();
|
|
44
|
+
|
|
45
|
+
const isOpen = $derived(bond.state.isOpen && !!bond.elements.trigger);
|
|
46
|
+
const portalId = $derived(activePortalBond?.id);
|
|
47
|
+
|
|
48
|
+
const position = $derived(bond.position);
|
|
49
|
+
const placement = $derived(position?.placement);
|
|
50
|
+
|
|
51
|
+
const x = $derived(position?.x ?? 0);
|
|
52
|
+
const y = $derived(position?.y ?? 0);
|
|
53
|
+
|
|
54
|
+
const dy = $derived(placement?.startsWith('top') ? -1 : placement?.startsWith('bottom') ? 1 : 0);
|
|
55
|
+
const dx = $derived(placement?.startsWith('left') ? -1 : placement?.startsWith('right') ? 1 : 0);
|
|
56
|
+
|
|
57
|
+
const offset = $derived(bond.state.props.offset);
|
|
58
|
+
|
|
59
|
+
const xOffset = $derived(dx * offset);
|
|
60
|
+
const yOffset = $derived(dy * offset);
|
|
61
|
+
|
|
62
|
+
const openAsNumber = $derived(+isOpen);
|
|
63
|
+
const deltaArrow = $derived(position?.middlewareData?.arrow ? 1 : 0);
|
|
64
|
+
|
|
65
|
+
let isInitialized = false;
|
|
66
|
+
|
|
67
|
+
function _containerInitial(this: typeof bond.state, node: Element) {
|
|
68
|
+
const arrowClientWidth = bond?.elements.arrow?.clientWidth ?? 0;
|
|
69
|
+
const arrowClientHeight = bond?.elements.arrow?.clientHeight ?? 0;
|
|
70
|
+
|
|
71
|
+
const _x = x + xOffset * openAsNumber + deltaArrow * dx * arrowClientWidth;
|
|
72
|
+
const _y = y + yOffset * openAsNumber + deltaArrow * dy * arrowClientHeight;
|
|
73
|
+
|
|
74
|
+
node.style.transform = `translate3d(${_x}px, ${_y}px, 1px)`;
|
|
75
|
+
|
|
76
|
+
isInitialized = true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function _containerAnimate(this: typeof bond.state, node: Element, _?: AnimateParams) {
|
|
80
|
+
if (!isInitialized) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const deltaArrow = position?.middlewareData?.arrow ? 1 : 0;
|
|
85
|
+
const arrowClientWidth = bond?.elements.arrow?.clientWidth ?? 0;
|
|
86
|
+
const arrowClientHeight = bond?.elements.arrow?.clientHeight ?? 0;
|
|
87
|
+
|
|
88
|
+
const _x = x + xOffset * openAsNumber + deltaArrow * dx * arrowClientWidth;
|
|
89
|
+
const _y = y + yOffset * openAsNumber + deltaArrow * dy * arrowClientHeight;
|
|
90
|
+
|
|
91
|
+
node.style.transform = `translate3d(${_x}px, ${_y}px, 1px)`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let isOpened = false;
|
|
95
|
+
|
|
96
|
+
function _animate(this: typeof bond.state, node: Element) {
|
|
97
|
+
const isOpen = this.isOpen;
|
|
98
|
+
|
|
99
|
+
const arrowClientWidth = bond?.elements.arrow?.clientWidth ?? 0;
|
|
100
|
+
const arrowClientHeight = bond?.elements.arrow?.clientHeight ?? 0;
|
|
101
|
+
|
|
102
|
+
const getTransformOrigin = () => {
|
|
103
|
+
switch (placement) {
|
|
104
|
+
case 'top':
|
|
105
|
+
case 'top-start':
|
|
106
|
+
case 'top-end':
|
|
107
|
+
return 'bottom';
|
|
108
|
+
case 'bottom':
|
|
109
|
+
case 'bottom-start':
|
|
110
|
+
case 'bottom-end':
|
|
111
|
+
return 'top';
|
|
112
|
+
case 'left':
|
|
113
|
+
case 'left-start':
|
|
114
|
+
case 'left-end':
|
|
115
|
+
return 'right';
|
|
116
|
+
case 'right':
|
|
117
|
+
case 'right-start':
|
|
118
|
+
case 'right-end':
|
|
119
|
+
return 'left';
|
|
120
|
+
default:
|
|
121
|
+
return 'center';
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const transformOrigin = getTransformOrigin();
|
|
126
|
+
|
|
127
|
+
const from = isOpened ? 1 : 0.95;
|
|
128
|
+
|
|
129
|
+
motion(
|
|
130
|
+
node,
|
|
131
|
+
{
|
|
132
|
+
opacity: openAsNumber,
|
|
133
|
+
y: dy * (!isOpen ? -1 : 0) * (arrowClientHeight + yOffset),
|
|
134
|
+
x: dx * (!isOpen ? -1 : 0) * (arrowClientWidth + xOffset),
|
|
135
|
+
scaleY: dy ? (isOpen ? [from, 1] : [1, 0.8]) : undefined,
|
|
136
|
+
scaleX: dx ? (isOpen ? [from, 1] : [1, 0.8]) : undefined,
|
|
137
|
+
transformOrigin
|
|
138
|
+
},
|
|
139
|
+
{ duration: DURATION.fast / 1000 }
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
isOpened = isOpen;
|
|
143
|
+
}
|
|
144
|
+
</script>
|
|
145
|
+
|
|
146
|
+
<Teleport
|
|
147
|
+
portal={portalId ?? 'root.l0'}
|
|
148
|
+
as="div"
|
|
149
|
+
class={[
|
|
150
|
+
'pointer-events-auto absolute top-0 left-0 h-min w-fit',
|
|
151
|
+
!isOpen && 'pointer-events-none'
|
|
152
|
+
]}
|
|
153
|
+
initial={_containerInitial?.bind(bond.state)}
|
|
154
|
+
animate={_containerAnimate?.bind(bond.state)}
|
|
155
|
+
{...bond.content({ onchange: _containerInitial })}
|
|
156
|
+
>
|
|
157
|
+
<HtmlAtom
|
|
158
|
+
{bond}
|
|
159
|
+
preset="popover.content"
|
|
160
|
+
class={[
|
|
161
|
+
'popover-content bg-popover text-popover-foreground border-border rounded-md border p-2 opacity-0 shadow-lg',
|
|
162
|
+
'$preset',
|
|
163
|
+
klass
|
|
164
|
+
]}
|
|
165
|
+
enter={enter?.bind(bond.state)}
|
|
166
|
+
exit={exit?.bind(bond.state)}
|
|
167
|
+
initial={initial?.bind(bond.state)}
|
|
168
|
+
animate={animate?.bind(bond.state)}
|
|
169
|
+
onmount={onmount?.bind(bond.state)}
|
|
170
|
+
ondestroy={ondestroy?.bind(bond.state)}
|
|
171
|
+
{...restProps}
|
|
172
|
+
>
|
|
173
|
+
{@render children?.({ popover: bond })}
|
|
174
|
+
</HtmlAtom>
|
|
175
|
+
</Teleport>
|
|
@@ -1,43 +1,44 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { animate as motion } from 'motion';
|
|
3
|
-
import { Icon } from '../icon';
|
|
4
|
-
import IconArrowDown from '../../icons/icon-arrow-down.svelte';
|
|
5
|
-
import { HtmlAtom } from '../atom';
|
|
6
|
-
import { PopoverBond } from './bond.svelte';
|
|
7
|
-
|
|
8
|
-
const bond = PopoverBond.get();
|
|
9
|
-
|
|
10
|
-
let {
|
|
11
|
-
class: klass = '',
|
|
12
|
-
children = undefined,
|
|
13
|
-
onmount = undefined,
|
|
14
|
-
ondestroy = undefined,
|
|
15
|
-
animate = undefined,
|
|
16
|
-
enter = undefined,
|
|
17
|
-
exit = undefined,
|
|
18
|
-
initial = undefined
|
|
19
|
-
} = $props();
|
|
20
|
-
|
|
21
|
-
const isOpen = $derived(bond?.state.props.open ?? false);
|
|
22
|
-
</script>
|
|
23
|
-
|
|
24
|
-
<HtmlAtom
|
|
25
|
-
{bond}
|
|
26
|
-
preset="popover.indicator"
|
|
27
|
-
class={['border-border flex items-center justify-center', '$preset', klass]}
|
|
28
|
-
onmount={onmount?.bind(bond.state)}
|
|
29
|
-
ondestroy={ondestroy?.bind(bond.state)}
|
|
30
|
-
animate={animate?.bind(bond.state)}
|
|
31
|
-
enter={enter?.bind(bond.state)}
|
|
32
|
-
exit={exit?.bind(bond.state)}
|
|
33
|
-
initial={initial?.bind(bond.state)}
|
|
34
|
-
>
|
|
35
|
-
{#if children}
|
|
36
|
-
{@render children?.({ popover: bond })}
|
|
37
|
-
{:else}
|
|
38
|
-
<Icon
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { animate as motion } from 'motion';
|
|
3
|
+
import { Icon } from '../icon';
|
|
4
|
+
import IconArrowDown from '../../icons/icon-arrow-down.svelte';
|
|
5
|
+
import { HtmlAtom } from '../atom';
|
|
6
|
+
import { PopoverBond } from './bond.svelte';
|
|
7
|
+
|
|
8
|
+
const bond = PopoverBond.get();
|
|
9
|
+
|
|
10
|
+
let {
|
|
11
|
+
class: klass = '',
|
|
12
|
+
children = undefined,
|
|
13
|
+
onmount = undefined,
|
|
14
|
+
ondestroy = undefined,
|
|
15
|
+
animate = undefined,
|
|
16
|
+
enter = undefined,
|
|
17
|
+
exit = undefined,
|
|
18
|
+
initial = undefined
|
|
19
|
+
} = $props();
|
|
20
|
+
|
|
21
|
+
const isOpen = $derived(bond?.state.props.open ?? false);
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<HtmlAtom
|
|
25
|
+
{bond}
|
|
26
|
+
preset="popover.indicator"
|
|
27
|
+
class={['border-border flex h-5 items-center justify-center', '$preset', klass]}
|
|
28
|
+
onmount={onmount?.bind(bond.state)}
|
|
29
|
+
ondestroy={ondestroy?.bind(bond.state)}
|
|
30
|
+
animate={animate?.bind(bond.state)}
|
|
31
|
+
enter={enter?.bind(bond.state)}
|
|
32
|
+
exit={exit?.bind(bond.state)}
|
|
33
|
+
initial={initial?.bind(bond.state)}
|
|
34
|
+
>
|
|
35
|
+
{#if children}
|
|
36
|
+
{@render children?.({ popover: bond })}
|
|
37
|
+
{:else}
|
|
38
|
+
<Icon
|
|
39
|
+
class="h-full"
|
|
40
|
+
src={IconArrowDown}
|
|
41
|
+
animate={(node) => motion(node, { rotate: 180 * +isOpen }, { duration: 0.2 })}
|
|
42
|
+
/>
|
|
43
|
+
{/if}
|
|
44
|
+
</HtmlAtom>
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { PopoverState, PopoverBond, type PopoverStateProps } from './bond.svelte';
|
|
3
|
-
import { defineProperty, defineState } from '../../utils';
|
|
4
|
-
import type { PopoverRootProps } from './types';
|
|
5
|
-
|
|
6
|
-
let {
|
|
7
|
-
open = $bindable(false),
|
|
8
|
-
disabled = false,
|
|
9
|
-
placements = ['bottom-start', 'bottom-end', 'top-start', 'top-end'],
|
|
10
|
-
placement = 'bottom-start',
|
|
11
|
-
offset =
|
|
12
|
-
portal = undefined,
|
|
13
|
-
extend = {},
|
|
14
|
-
factory = _factory,
|
|
15
|
-
children = undefined
|
|
16
|
-
}: PopoverRootProps = $props();
|
|
17
|
-
|
|
18
|
-
const bondProps = defineState<PopoverStateProps>([
|
|
19
|
-
defineProperty(
|
|
20
|
-
'open',
|
|
21
|
-
() => open,
|
|
22
|
-
(v) => {
|
|
23
|
-
open = v;
|
|
24
|
-
}
|
|
25
|
-
),
|
|
26
|
-
defineProperty('disabled', () => disabled),
|
|
27
|
-
defineProperty('placement', () => placement),
|
|
28
|
-
defineProperty('offset', () => offset),
|
|
29
|
-
defineProperty('placements', () => placements ?? []),
|
|
30
|
-
defineProperty('portal', () => portal),
|
|
31
|
-
defineProperty('extend', () => extend)
|
|
32
|
-
]);
|
|
33
|
-
|
|
34
|
-
const bond = factory(bondProps).share();
|
|
35
|
-
|
|
36
|
-
function _factory(props: typeof bondProps) {
|
|
37
|
-
const popoverState = new PopoverState(() => props);
|
|
38
|
-
const popoverBond = new PopoverBond(popoverState);
|
|
39
|
-
|
|
40
|
-
return popoverBond;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function getBond() {
|
|
44
|
-
return bond;
|
|
45
|
-
}
|
|
46
|
-
</script>
|
|
47
|
-
|
|
48
|
-
{@render children?.({ popover: bond })}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { PopoverState, PopoverBond, type PopoverStateProps } from './bond.svelte';
|
|
3
|
+
import { defineProperty, defineState } from '../../utils';
|
|
4
|
+
import type { PopoverRootProps } from './types';
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
open = $bindable(false),
|
|
8
|
+
disabled = false,
|
|
9
|
+
placements = ['bottom-start', 'bottom-end', 'top-start', 'top-end'],
|
|
10
|
+
placement = 'bottom-start',
|
|
11
|
+
offset = 1,
|
|
12
|
+
portal = undefined,
|
|
13
|
+
extend = {},
|
|
14
|
+
factory = _factory,
|
|
15
|
+
children = undefined
|
|
16
|
+
}: PopoverRootProps = $props();
|
|
17
|
+
|
|
18
|
+
const bondProps = defineState<PopoverStateProps>([
|
|
19
|
+
defineProperty(
|
|
20
|
+
'open',
|
|
21
|
+
() => open,
|
|
22
|
+
(v) => {
|
|
23
|
+
open = v;
|
|
24
|
+
}
|
|
25
|
+
),
|
|
26
|
+
defineProperty('disabled', () => disabled),
|
|
27
|
+
defineProperty('placement', () => placement),
|
|
28
|
+
defineProperty('offset', () => offset),
|
|
29
|
+
defineProperty('placements', () => placements ?? []),
|
|
30
|
+
defineProperty('portal', () => portal),
|
|
31
|
+
defineProperty('extend', () => extend)
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
const bond = factory(bondProps).share();
|
|
35
|
+
|
|
36
|
+
function _factory(props: typeof bondProps) {
|
|
37
|
+
const popoverState = new PopoverState(() => props);
|
|
38
|
+
const popoverBond = new PopoverBond(popoverState);
|
|
39
|
+
|
|
40
|
+
return popoverBond;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getBond() {
|
|
44
|
+
return bond;
|
|
45
|
+
}
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
{@render children?.({ popover: bond })}
|
|
@@ -1,52 +1,49 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import { Popover as Popover_ } from '.';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<Popover_.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
</Root>
|
|
51
|
-
{/snippet}
|
|
52
|
-
</Story>
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import { Popover as Popover_ } from '.';
|
|
4
|
+
import { clickoutPopover } from './attachments.svelte';
|
|
5
|
+
import { Button } from '../button';
|
|
6
|
+
|
|
7
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
8
|
+
const { Story } = defineMeta({
|
|
9
|
+
title: 'Atoms/Popover',
|
|
10
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
11
|
+
|
|
12
|
+
parameters: {
|
|
13
|
+
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
|
14
|
+
layout: 'fullscreen'
|
|
15
|
+
},
|
|
16
|
+
args: {}
|
|
17
|
+
});
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
let open = $state(false);
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<Story name="Popover" args={{}}>
|
|
25
|
+
{#snippet children(args)}
|
|
26
|
+
<Popover_.Root bind:open offset={0} {...args}>
|
|
27
|
+
{#snippet children({ popover })}
|
|
28
|
+
<!-- {#if dev}
|
|
29
|
+
<RenderScan duration={400} />
|
|
30
|
+
{/if} -->
|
|
31
|
+
|
|
32
|
+
<Popover_.Trigger base={Button} class="items-center gap-4">
|
|
33
|
+
<div>Open Popover</div>
|
|
34
|
+
<Popover_.Indicator />
|
|
35
|
+
</Popover_.Trigger>
|
|
36
|
+
|
|
37
|
+
<Popover_.Content
|
|
38
|
+
{@attach clickoutPopover((ev, atom) => {
|
|
39
|
+
atom.state.close();
|
|
40
|
+
})}
|
|
41
|
+
class="bg-card"
|
|
42
|
+
>
|
|
43
|
+
<div>Hello World !</div>
|
|
44
|
+
<Popover_.Arrow />
|
|
45
|
+
</Popover_.Content>
|
|
46
|
+
{/snippet}
|
|
47
|
+
</Popover_.Root>
|
|
48
|
+
{/snippet}
|
|
49
|
+
</Story>
|