-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathDropdownMenu.svelte
47 lines (40 loc) · 1.02 KB
/
DropdownMenu.svelte
1
2
3
4
5
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
35
36
37
38
39
40
41
42
43
44
45
46
47
<script>
import { getContext } from 'svelte';
import classnames from './utils';
const context = getContext('dropdownContext');
let className = '';
export { className as class };
export let end = false;
export let right = false;
const popperPlacement = (direction, end) => {
let prefix = direction;
if (direction === 'up') prefix = 'top';
else if (direction === 'down') prefix = 'bottom';
let suffix = end ? 'end' : 'start';
return `${prefix}-${suffix}`;
};
$: popperOptions = {
modifiers: [
{ name: 'flip' },
{
name: 'offset',
options: {
offset: [0, 2]
}
}
],
placement: popperPlacement($context.direction, end || right)
};
$: classes = classnames(className, 'dropdown-menu', {
'dropdown-menu-end': end || right,
show: $context.isOpen
});
</script>
<div
{...$$restProps}
class={classes}
data-bs-popper={$context.inNavbar ? 'static' : undefined}
use:$context.popperContent={popperOptions}
>
<slot />
</div>