Implements ActionMenu component
This commit is contained in:
parent
0b18b55433
commit
cef3437c50
|
@ -0,0 +1,30 @@
|
|||
<script>
|
||||
import DropdownMenu from '../DropdownMenu/DropdownMenu.svelte'
|
||||
import Menu from '../Menu/Menu.svelte'
|
||||
let anchor;
|
||||
let dropdown;
|
||||
|
||||
// This is needed because display: contents is considered "invisible".
|
||||
// It should only ever be an action button, so should be fine.
|
||||
function getAnchor(node) {
|
||||
anchor = node.firstChild
|
||||
}
|
||||
|
||||
export const hide = () => { dropdown.hide() }
|
||||
export const show = () => { dropdown.show() }
|
||||
</script>
|
||||
|
||||
<div class="contents" use:getAnchor on:click={dropdown.show}>
|
||||
<slot name="button" />
|
||||
</div>
|
||||
<DropdownMenu bind:this={dropdown} {anchor} align="left">
|
||||
<Menu>
|
||||
<slot />
|
||||
</Menu>
|
||||
</DropdownMenu>
|
||||
|
||||
<style>
|
||||
div {
|
||||
display: contents;
|
||||
}
|
||||
</style>
|
|
@ -18,10 +18,10 @@ export default function positionDropdown(element, { anchor, align }) {
|
|||
if (spaceAbove > spaceBelow) {
|
||||
positionSide = "bottom"
|
||||
maxHeight = spaceAbove - 20
|
||||
y = window.innerHeight - spaceAbove
|
||||
y = window.innerHeight - spaceAbove + 5
|
||||
} else {
|
||||
positionSide = "top"
|
||||
y = bottom
|
||||
y = bottom + 5
|
||||
maxHeight = spaceBelow - 20
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue