@makolabs/ripple 0.0.1-dev.3 → 0.0.1-dev.5
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 +229 -96
- package/dist/button/Button.svelte +46 -0
- package/dist/button/Button.svelte.d.ts +4 -0
- package/dist/button/button.d.ts +136 -0
- package/dist/button/button.js +167 -0
- package/dist/button/index.d.ts +1 -0
- package/dist/button/index.js +1 -0
- package/dist/drawer/Drawer.svelte +213 -0
- package/dist/drawer/Drawer.svelte.d.ts +4 -0
- package/dist/drawer/drawer.d.ts +177 -0
- package/dist/drawer/drawer.js +80 -0
- package/dist/drawer/index.d.ts +2 -0
- package/dist/drawer/index.js +1 -0
- package/dist/elements/badge/Badge.svelte +35 -0
- package/dist/elements/badge/Badge.svelte.d.ts +4 -0
- package/dist/elements/badge/badge.d.ts +193 -0
- package/dist/elements/badge/badge.js +65 -0
- package/dist/elements/badge/index.d.ts +2 -0
- package/dist/elements/badge/index.js +2 -0
- package/dist/elements/dropdown/Dropdown.svelte +272 -0
- package/dist/elements/dropdown/Dropdown.svelte.d.ts +4 -0
- package/dist/elements/dropdown/Select.svelte +230 -0
- package/dist/elements/dropdown/Select.svelte.d.ts +4 -0
- package/dist/elements/dropdown/dropdown.d.ts +274 -0
- package/dist/elements/dropdown/dropdown.js +89 -0
- package/dist/elements/dropdown/index.d.ts +3 -0
- package/dist/elements/dropdown/index.js +2 -0
- package/dist/elements/dropdown/select.d.ts +220 -0
- package/dist/elements/dropdown/select.js +74 -0
- package/dist/header/Breadcrumbs.svelte +72 -0
- package/dist/header/Breadcrumbs.svelte.d.ts +4 -0
- package/dist/header/PageHeader.svelte +30 -0
- package/dist/header/PageHeader.svelte.d.ts +4 -0
- package/dist/header/breadcrumbs.d.ts +220 -0
- package/dist/header/breadcrumbs.js +81 -0
- package/dist/header/index.d.ts +4 -0
- package/dist/header/index.js +2 -0
- package/dist/header/pageheaders.d.ts +10 -0
- package/dist/header/pageheaders.js +1 -0
- package/dist/helper/cls.d.ts +1 -0
- package/dist/helper/cls.js +4 -0
- package/dist/helper/nav.svelte.d.ts +6 -0
- package/dist/helper/nav.svelte.js +23 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +18 -1
- package/dist/layout/card/Card.svelte +44 -0
- package/dist/layout/card/Card.svelte.d.ts +4 -0
- package/dist/layout/card/StatsCard.svelte +236 -0
- package/dist/layout/card/StatsCard.svelte.d.ts +4 -0
- package/dist/layout/card/card.d.ts +139 -0
- package/dist/layout/card/card.js +50 -0
- package/dist/layout/card/index.d.ts +4 -0
- package/dist/layout/card/index.js +2 -0
- package/dist/layout/card/stats-card.d.ts +208 -0
- package/dist/layout/card/stats-card.js +73 -0
- package/dist/layout/index.d.ts +5 -1
- package/dist/layout/index.js +5 -1
- package/dist/layout/navbar/Navbar.svelte +206 -0
- package/dist/layout/navbar/Navbar.svelte.d.ts +4 -0
- package/dist/layout/navbar/index.d.ts +2 -0
- package/dist/layout/navbar/index.js +2 -0
- package/dist/layout/navbar/navbar.d.ts +228 -0
- package/dist/layout/navbar/navbar.js +98 -0
- package/dist/layout/sidebar/NavGroup.svelte +101 -0
- package/dist/layout/sidebar/NavGroup.svelte.d.ts +4 -0
- package/dist/layout/sidebar/NavItem.svelte +29 -0
- package/dist/layout/sidebar/NavItem.svelte.d.ts +4 -0
- package/dist/layout/sidebar/Sidebar.svelte +145 -0
- package/dist/layout/sidebar/Sidebar.svelte.d.ts +4 -0
- package/dist/layout/sidebar/index.d.ts +2 -0
- package/dist/layout/sidebar/index.js +1 -0
- package/dist/layout/sidebar/sidebar.d.ts +46 -0
- package/dist/layout/sidebar/sidebar.js +1 -0
- package/dist/layout/table/Cells.svelte +111 -0
- package/dist/layout/table/Cells.svelte.d.ts +27 -0
- package/dist/layout/table/Table.svelte +413 -0
- package/dist/layout/table/Table.svelte.d.ts +4 -0
- package/dist/layout/table/index.d.ts +3 -0
- package/dist/layout/table/index.js +2 -0
- package/dist/layout/table/table.d.ts +303 -0
- package/dist/layout/table/table.js +149 -0
- package/dist/layout/tabs/Tab.svelte +57 -0
- package/dist/layout/tabs/Tab.svelte.d.ts +4 -0
- package/dist/layout/tabs/TabContent.svelte +31 -0
- package/dist/layout/tabs/TabContent.svelte.d.ts +4 -0
- package/dist/layout/tabs/TabGroup.svelte +57 -0
- package/dist/layout/tabs/TabGroup.svelte.d.ts +4 -0
- package/dist/layout/tabs/index.d.ts +3 -0
- package/dist/layout/tabs/index.js +3 -0
- package/dist/layout/tabs/tabs.d.ts +155 -0
- package/dist/layout/tabs/tabs.js +156 -0
- package/dist/modal/Modal.svelte +206 -0
- package/dist/modal/Modal.svelte.d.ts +4 -0
- package/dist/modal/index.d.ts +1 -0
- package/dist/modal/index.js +1 -0
- package/dist/modal/modal.d.ts +234 -0
- package/dist/modal/modal.js +81 -0
- package/dist/types/variants.d.ts +21 -0
- package/dist/types/variants.js +19 -0
- package/package.json +100 -102
- package/dist/layout/Card.svelte +0 -179
- package/dist/layout/Card.svelte.d.ts +0 -208
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type { ClassValue } from 'tailwind-variants';
|
|
2
|
+
import type { VariantColors, VariantSizes } from '../../types/variants.js';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
export declare const badge: import("tailwind-variants").TVReturnType<{
|
|
5
|
+
size: {
|
|
6
|
+
xs: {
|
|
7
|
+
base: string;
|
|
8
|
+
icon: string;
|
|
9
|
+
};
|
|
10
|
+
sm: {
|
|
11
|
+
base: string;
|
|
12
|
+
icon: string;
|
|
13
|
+
};
|
|
14
|
+
base: {
|
|
15
|
+
base: string;
|
|
16
|
+
icon: string;
|
|
17
|
+
};
|
|
18
|
+
lg: {
|
|
19
|
+
base: string;
|
|
20
|
+
icon: string;
|
|
21
|
+
};
|
|
22
|
+
xl: {
|
|
23
|
+
base: string;
|
|
24
|
+
icon: string;
|
|
25
|
+
};
|
|
26
|
+
'2xl': {
|
|
27
|
+
base: string;
|
|
28
|
+
icon: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
color: {
|
|
32
|
+
default: {
|
|
33
|
+
base: string;
|
|
34
|
+
icon: string;
|
|
35
|
+
};
|
|
36
|
+
primary: {
|
|
37
|
+
base: string;
|
|
38
|
+
icon: string;
|
|
39
|
+
};
|
|
40
|
+
secondary: {
|
|
41
|
+
base: string;
|
|
42
|
+
icon: string;
|
|
43
|
+
};
|
|
44
|
+
success: {
|
|
45
|
+
base: string;
|
|
46
|
+
icon: string;
|
|
47
|
+
};
|
|
48
|
+
warning: {
|
|
49
|
+
base: string;
|
|
50
|
+
icon: string;
|
|
51
|
+
};
|
|
52
|
+
danger: {
|
|
53
|
+
base: string;
|
|
54
|
+
icon: string;
|
|
55
|
+
};
|
|
56
|
+
info: {
|
|
57
|
+
base: string;
|
|
58
|
+
icon: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
}, {
|
|
62
|
+
base: string;
|
|
63
|
+
icon: string;
|
|
64
|
+
}, undefined, {
|
|
65
|
+
size: {
|
|
66
|
+
xs: {
|
|
67
|
+
base: string;
|
|
68
|
+
icon: string;
|
|
69
|
+
};
|
|
70
|
+
sm: {
|
|
71
|
+
base: string;
|
|
72
|
+
icon: string;
|
|
73
|
+
};
|
|
74
|
+
base: {
|
|
75
|
+
base: string;
|
|
76
|
+
icon: string;
|
|
77
|
+
};
|
|
78
|
+
lg: {
|
|
79
|
+
base: string;
|
|
80
|
+
icon: string;
|
|
81
|
+
};
|
|
82
|
+
xl: {
|
|
83
|
+
base: string;
|
|
84
|
+
icon: string;
|
|
85
|
+
};
|
|
86
|
+
'2xl': {
|
|
87
|
+
base: string;
|
|
88
|
+
icon: string;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
color: {
|
|
92
|
+
default: {
|
|
93
|
+
base: string;
|
|
94
|
+
icon: string;
|
|
95
|
+
};
|
|
96
|
+
primary: {
|
|
97
|
+
base: string;
|
|
98
|
+
icon: string;
|
|
99
|
+
};
|
|
100
|
+
secondary: {
|
|
101
|
+
base: string;
|
|
102
|
+
icon: string;
|
|
103
|
+
};
|
|
104
|
+
success: {
|
|
105
|
+
base: string;
|
|
106
|
+
icon: string;
|
|
107
|
+
};
|
|
108
|
+
warning: {
|
|
109
|
+
base: string;
|
|
110
|
+
icon: string;
|
|
111
|
+
};
|
|
112
|
+
danger: {
|
|
113
|
+
base: string;
|
|
114
|
+
icon: string;
|
|
115
|
+
};
|
|
116
|
+
info: {
|
|
117
|
+
base: string;
|
|
118
|
+
icon: string;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
}, {
|
|
122
|
+
base: string;
|
|
123
|
+
icon: string;
|
|
124
|
+
}, import("tailwind-variants").TVReturnType<{
|
|
125
|
+
size: {
|
|
126
|
+
xs: {
|
|
127
|
+
base: string;
|
|
128
|
+
icon: string;
|
|
129
|
+
};
|
|
130
|
+
sm: {
|
|
131
|
+
base: string;
|
|
132
|
+
icon: string;
|
|
133
|
+
};
|
|
134
|
+
base: {
|
|
135
|
+
base: string;
|
|
136
|
+
icon: string;
|
|
137
|
+
};
|
|
138
|
+
lg: {
|
|
139
|
+
base: string;
|
|
140
|
+
icon: string;
|
|
141
|
+
};
|
|
142
|
+
xl: {
|
|
143
|
+
base: string;
|
|
144
|
+
icon: string;
|
|
145
|
+
};
|
|
146
|
+
'2xl': {
|
|
147
|
+
base: string;
|
|
148
|
+
icon: string;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
color: {
|
|
152
|
+
default: {
|
|
153
|
+
base: string;
|
|
154
|
+
icon: string;
|
|
155
|
+
};
|
|
156
|
+
primary: {
|
|
157
|
+
base: string;
|
|
158
|
+
icon: string;
|
|
159
|
+
};
|
|
160
|
+
secondary: {
|
|
161
|
+
base: string;
|
|
162
|
+
icon: string;
|
|
163
|
+
};
|
|
164
|
+
success: {
|
|
165
|
+
base: string;
|
|
166
|
+
icon: string;
|
|
167
|
+
};
|
|
168
|
+
warning: {
|
|
169
|
+
base: string;
|
|
170
|
+
icon: string;
|
|
171
|
+
};
|
|
172
|
+
danger: {
|
|
173
|
+
base: string;
|
|
174
|
+
icon: string;
|
|
175
|
+
};
|
|
176
|
+
info: {
|
|
177
|
+
base: string;
|
|
178
|
+
icon: string;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
}, {
|
|
182
|
+
base: string;
|
|
183
|
+
icon: string;
|
|
184
|
+
}, undefined, unknown, unknown, undefined>>;
|
|
185
|
+
export type BadgeProps = {
|
|
186
|
+
label?: string;
|
|
187
|
+
size?: VariantSizes;
|
|
188
|
+
color?: VariantColors;
|
|
189
|
+
class?: ClassValue;
|
|
190
|
+
contentClass?: ClassValue;
|
|
191
|
+
children: Snippet;
|
|
192
|
+
onclose?: (event: MouseEvent) => void;
|
|
193
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { tv } from 'tailwind-variants';
|
|
2
|
+
export const badge = tv({
|
|
3
|
+
slots: {
|
|
4
|
+
base: 'w-min inline-flex items-center justify-center whitespace-nowrap',
|
|
5
|
+
icon: 'h-4 w-4'
|
|
6
|
+
},
|
|
7
|
+
variants: {
|
|
8
|
+
size: {
|
|
9
|
+
xs: {
|
|
10
|
+
base: 'h-4 px-1.5 text-xs rounded gap-0.5',
|
|
11
|
+
icon: 'h-2.5 w-2.5'
|
|
12
|
+
},
|
|
13
|
+
sm: {
|
|
14
|
+
base: 'h-5 px-2 text-xs rounded gap-1',
|
|
15
|
+
icon: 'h-3 w-3'
|
|
16
|
+
},
|
|
17
|
+
base: {
|
|
18
|
+
base: 'h-6 px-2.5 text-sm rounded-md gap-1.5',
|
|
19
|
+
icon: 'h-3.5 w-3.5'
|
|
20
|
+
},
|
|
21
|
+
lg: {
|
|
22
|
+
base: 'h-7 px-3 text-base rounded-lg gap-2',
|
|
23
|
+
icon: 'h-4 w-4'
|
|
24
|
+
},
|
|
25
|
+
xl: {
|
|
26
|
+
base: 'h-8 px-3.5 text-lg rounded-xl gap-2.5',
|
|
27
|
+
icon: 'h-5 w-5'
|
|
28
|
+
},
|
|
29
|
+
'2xl': {
|
|
30
|
+
base: 'h-10 px-4 text-xl rounded-2xl gap-3',
|
|
31
|
+
icon: 'h-6 w-6'
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
color: {
|
|
35
|
+
default: {
|
|
36
|
+
base: 'bg-default-50 text-default-700',
|
|
37
|
+
icon: 'text-default-700'
|
|
38
|
+
},
|
|
39
|
+
primary: {
|
|
40
|
+
base: 'bg-primary-50 text-primary-700',
|
|
41
|
+
icon: 'text-primary-700'
|
|
42
|
+
},
|
|
43
|
+
secondary: {
|
|
44
|
+
base: 'bg-secondary-50 text-secondary-700',
|
|
45
|
+
icon: 'text-secondary-700'
|
|
46
|
+
},
|
|
47
|
+
success: {
|
|
48
|
+
base: 'bg-success-50 text-success-700',
|
|
49
|
+
icon: 'text-success-700'
|
|
50
|
+
},
|
|
51
|
+
warning: {
|
|
52
|
+
base: 'bg-warning-50 text-warning-700',
|
|
53
|
+
icon: 'text-warning-700'
|
|
54
|
+
},
|
|
55
|
+
danger: {
|
|
56
|
+
base: 'bg-danger-50 text-danger-700',
|
|
57
|
+
icon: 'text-danger-700'
|
|
58
|
+
},
|
|
59
|
+
info: {
|
|
60
|
+
base: 'bg-info-50 text-info-700',
|
|
61
|
+
icon: 'text-info-700'
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '../../helper/cls.js';
|
|
3
|
+
import { fly } from 'svelte/transition';
|
|
4
|
+
import { dropdownMenu, type DropdownMenuProps, type DropdownItem } from './dropdown.js';
|
|
5
|
+
import { onMount, onDestroy } from 'svelte';
|
|
6
|
+
import { Size } from '../../types/variants.js';
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
sections = [],
|
|
10
|
+
open: isOpen = $bindable(false),
|
|
11
|
+
label = 'Options',
|
|
12
|
+
icon: Icon,
|
|
13
|
+
triggerContent,
|
|
14
|
+
triggerClass = '',
|
|
15
|
+
containerClass = '',
|
|
16
|
+
itemClass = '',
|
|
17
|
+
class: className = '',
|
|
18
|
+
size = Size.BASE,
|
|
19
|
+
disabled = false,
|
|
20
|
+
position = 'bottom-left',
|
|
21
|
+
width = 'w-56',
|
|
22
|
+
header
|
|
23
|
+
}: DropdownMenuProps = $props();
|
|
24
|
+
|
|
25
|
+
let dropdownRef = $state<HTMLDivElement | undefined>();
|
|
26
|
+
let triggerRef = $state<HTMLDivElement | undefined>();
|
|
27
|
+
let portalEl = $state<HTMLDivElement | undefined>();
|
|
28
|
+
let triggerRect = $state<DOMRect | null>(null);
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
base,
|
|
32
|
+
trigger,
|
|
33
|
+
container,
|
|
34
|
+
section,
|
|
35
|
+
item,
|
|
36
|
+
itemIcon,
|
|
37
|
+
header: headerClass,
|
|
38
|
+
headerTitle,
|
|
39
|
+
headerSubtitle
|
|
40
|
+
} = $derived(
|
|
41
|
+
dropdownMenu({
|
|
42
|
+
position,
|
|
43
|
+
size,
|
|
44
|
+
isOpen
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const baseClass = $derived(cn(base(), className));
|
|
49
|
+
const triggerClass_ = $derived(cn(trigger(), triggerClass));
|
|
50
|
+
const containerClass_ = $derived(cn(container(), width, containerClass, 'shadow-lg'));
|
|
51
|
+
const sectionClass = $derived(cn(section()));
|
|
52
|
+
const itemClass_ = $derived(cn(item(), itemClass));
|
|
53
|
+
const iconClass = $derived(cn(itemIcon()));
|
|
54
|
+
const headerClass_ = $derived(cn(headerClass(), header?.class ?? ''));
|
|
55
|
+
const headerTitleClass = $derived(cn(headerTitle(), header?.titleClass ?? ''));
|
|
56
|
+
const headerSubtitleClass = $derived(cn(headerSubtitle(), header?.subtitleClass ?? ''));
|
|
57
|
+
|
|
58
|
+
const dropdownStyles = $derived.by(() => {
|
|
59
|
+
if (!triggerRect) return '';
|
|
60
|
+
|
|
61
|
+
const { top, left, bottom, right, width: triggerWidth, height: triggerHeight } = triggerRect;
|
|
62
|
+
const viewportWidth = window.innerWidth;
|
|
63
|
+
const viewportHeight = window.innerHeight;
|
|
64
|
+
|
|
65
|
+
// Default to 14rem (w-56) if not specified
|
|
66
|
+
const dropdownWidth = width ? parseInt(width.replace(/[^\d]/g, '')) * 0.25 : 14; // Convert Tailwind widths to rem
|
|
67
|
+
const dropdownWidthPx = dropdownWidth * 16;
|
|
68
|
+
|
|
69
|
+
let posStyles = `position: fixed; z-index: 9999;`;
|
|
70
|
+
|
|
71
|
+
if (position.includes('bottom')) {
|
|
72
|
+
posStyles += `top: ${bottom}px;`;
|
|
73
|
+
} else if (position.includes('top')) {
|
|
74
|
+
posStyles += `top: ${top - triggerHeight}px; transform: translateY(-100%);`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (position.includes('left')) {
|
|
78
|
+
if (left + dropdownWidthPx > viewportWidth - 20) {
|
|
79
|
+
posStyles += `left: auto; right: ${viewportWidth - right}px;`;
|
|
80
|
+
} else {
|
|
81
|
+
posStyles += `left: ${left}px;`;
|
|
82
|
+
}
|
|
83
|
+
} else if (position.includes('right')) {
|
|
84
|
+
if (right - dropdownWidthPx < 20) {
|
|
85
|
+
posStyles += `left: ${left}px; right: auto;`;
|
|
86
|
+
} else {
|
|
87
|
+
posStyles += `left: ${right - triggerWidth}px;`;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
const centeredLeft = left + (triggerWidth / 2);
|
|
91
|
+
if (centeredLeft + (dropdownWidthPx / 2) > viewportWidth - 20) {
|
|
92
|
+
posStyles += `right: 20px; left: auto;`;
|
|
93
|
+
} else if (centeredLeft - (dropdownWidthPx / 2) < 20) {
|
|
94
|
+
posStyles += `left: 20px; right: auto;`;
|
|
95
|
+
} else {
|
|
96
|
+
posStyles += `left: ${centeredLeft}px; transform: translateX(-50%);`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const maxHeight = viewportHeight - bottom - 20; // 20px padding from bottom
|
|
101
|
+
if (position.includes('bottom')) {
|
|
102
|
+
posStyles += `max-height: ${maxHeight}px; overflow-y: auto;`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return posStyles;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
function handleToggle() {
|
|
109
|
+
if (disabled) return;
|
|
110
|
+
isOpen = !isOpen;
|
|
111
|
+
|
|
112
|
+
if (isOpen) {
|
|
113
|
+
setTimeout(updatePosition, 0); // Use setTimeout to ensure DOM is updated
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function handleClickOutside(event: MouseEvent) {
|
|
118
|
+
if (isOpen &&
|
|
119
|
+
dropdownRef &&
|
|
120
|
+
!dropdownRef.contains(event.target as Node) &&
|
|
121
|
+
triggerRef &&
|
|
122
|
+
!triggerRef.contains(event.target as Node)) {
|
|
123
|
+
isOpen = false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function handleItemClick(item: DropdownItem) {
|
|
128
|
+
if (item.disabled) return;
|
|
129
|
+
if (item.onclick) item.onclick();
|
|
130
|
+
isOpen = false;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function updatePosition() {
|
|
134
|
+
if (triggerRef) {
|
|
135
|
+
triggerRect = triggerRef.getBoundingClientRect();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function renderPortalDropdown() {
|
|
140
|
+
if (!portalEl || !document.body.contains(portalEl)) {
|
|
141
|
+
portalEl = document.createElement('div');
|
|
142
|
+
portalEl.id = 'dropdown-portal';
|
|
143
|
+
portalEl.style.position = 'fixed';
|
|
144
|
+
portalEl.style.top = '0';
|
|
145
|
+
portalEl.style.left = '0';
|
|
146
|
+
portalEl.style.width = '100%';
|
|
147
|
+
portalEl.style.height = '100%';
|
|
148
|
+
portalEl.style.pointerEvents = 'none';
|
|
149
|
+
portalEl.style.zIndex = '9999';
|
|
150
|
+
document.body.appendChild(portalEl);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
onMount(() => {
|
|
155
|
+
renderPortalDropdown();
|
|
156
|
+
window.addEventListener('scroll', updatePosition, true);
|
|
157
|
+
window.addEventListener('resize', updatePosition);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
onDestroy(() => {
|
|
161
|
+
if (!triggerRef) return;
|
|
162
|
+
window.removeEventListener('scroll', updatePosition, true);
|
|
163
|
+
window.removeEventListener('resize', updatePosition);
|
|
164
|
+
if (portalEl && document.body.contains(portalEl)) {
|
|
165
|
+
document.body.removeChild(portalEl);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
$effect(() => {
|
|
170
|
+
if (isOpen) {
|
|
171
|
+
renderPortalDropdown();
|
|
172
|
+
updatePosition();
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
</script>
|
|
176
|
+
|
|
177
|
+
<svelte:window onclick={handleClickOutside} />
|
|
178
|
+
|
|
179
|
+
<div class={baseClass}>
|
|
180
|
+
<div bind:this={triggerRef}>
|
|
181
|
+
{#if triggerContent}
|
|
182
|
+
{@render triggerContent()}
|
|
183
|
+
{:else}
|
|
184
|
+
<button
|
|
185
|
+
type="button"
|
|
186
|
+
id="menu-button"
|
|
187
|
+
aria-expanded={isOpen}
|
|
188
|
+
aria-haspopup="true"
|
|
189
|
+
class={triggerClass_}
|
|
190
|
+
onclick={handleToggle}
|
|
191
|
+
{disabled}
|
|
192
|
+
>
|
|
193
|
+
{label}
|
|
194
|
+
{#if Icon}
|
|
195
|
+
<Icon class="-mr-1 size-5 text-default-400" />
|
|
196
|
+
{:else}
|
|
197
|
+
<svg
|
|
198
|
+
class="-mr-1 size-5 text-default-400"
|
|
199
|
+
viewBox="0 0 16 16"
|
|
200
|
+
fill="currentColor"
|
|
201
|
+
aria-hidden="true"
|
|
202
|
+
>
|
|
203
|
+
<path
|
|
204
|
+
d="M6.62 12.7c.31.27.77.27 1.08 0l5-4.5A.76.76 0 0 0 12.16 7c0-.2-.08-.38-.21-.52a.76.76 0 0 0-1.09.02L7 10l-3.85-3.5a.76.76 0 0 0-1.07-.02.74.74 0 0 0-.02 1.07l4.56 5.15Z"
|
|
205
|
+
/>
|
|
206
|
+
</svg>
|
|
207
|
+
{/if}
|
|
208
|
+
</button>
|
|
209
|
+
{/if}
|
|
210
|
+
</div>
|
|
211
|
+
</div>
|
|
212
|
+
|
|
213
|
+
{#if isOpen && portalEl}
|
|
214
|
+
<div
|
|
215
|
+
bind:this={dropdownRef}
|
|
216
|
+
class={containerClass_}
|
|
217
|
+
role="menu"
|
|
218
|
+
aria-orientation="vertical"
|
|
219
|
+
aria-labelledby="menu-button"
|
|
220
|
+
style={dropdownStyles}
|
|
221
|
+
transition:fly={{ duration: 150, y: 5, opacity: 0 }}
|
|
222
|
+
>
|
|
223
|
+
{#if header}
|
|
224
|
+
<button class={headerClass_} onclick={header.onclick} aria-label="Header Actions">
|
|
225
|
+
{#if header.content}
|
|
226
|
+
{@render header.content()}
|
|
227
|
+
{:else}
|
|
228
|
+
{#if header.title}
|
|
229
|
+
<span class={headerTitleClass}>{header.title}</span>
|
|
230
|
+
{/if}
|
|
231
|
+
{#if header.subtitle}
|
|
232
|
+
<span class={headerSubtitleClass}>{header.subtitle}</span>
|
|
233
|
+
{/if}
|
|
234
|
+
{/if}
|
|
235
|
+
</button>
|
|
236
|
+
{/if}
|
|
237
|
+
|
|
238
|
+
{#each sections as section_, sectionIndex (sectionIndex)}
|
|
239
|
+
<div class={sectionClass}>
|
|
240
|
+
{#each section_.items as menuItem, itemIndex (itemIndex)}
|
|
241
|
+
{@const itemProps = {
|
|
242
|
+
class: itemClass_,
|
|
243
|
+
role: 'menuitem',
|
|
244
|
+
tabindex: -1,
|
|
245
|
+
id: `menu-item-${sectionIndex}-${itemIndex}`,
|
|
246
|
+
'data-active': menuItem.active
|
|
247
|
+
}}
|
|
248
|
+
{#if menuItem.href}
|
|
249
|
+
<a href={menuItem.href} {...itemProps}>
|
|
250
|
+
{@render DropItemContent(menuItem)}
|
|
251
|
+
</a>
|
|
252
|
+
{:else}
|
|
253
|
+
<button
|
|
254
|
+
type="button"
|
|
255
|
+
onclick={() => handleItemClick(menuItem)}
|
|
256
|
+
disabled={menuItem.disabled} {...itemProps}>
|
|
257
|
+
{@render DropItemContent(menuItem)}
|
|
258
|
+
</button>
|
|
259
|
+
{/if}
|
|
260
|
+
{/each}
|
|
261
|
+
</div>
|
|
262
|
+
{/each}
|
|
263
|
+
</div>
|
|
264
|
+
{/if}
|
|
265
|
+
|
|
266
|
+
{#snippet DropItemContent(menuItem: DropdownItem)}
|
|
267
|
+
{#if menuItem.icon}
|
|
268
|
+
{@const ItemIcon = menuItem.icon}
|
|
269
|
+
<ItemIcon class={iconClass} />
|
|
270
|
+
{/if}
|
|
271
|
+
<span class="truncate">{menuItem.label}</span>
|
|
272
|
+
{/snippet}
|