-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
right click menu for channels and messages
- Loading branch information
Showing
10 changed files
with
231 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<script> | ||
import { writable } from 'svelte/store'; | ||
import Menu from './Menu.svelte'; | ||
export let visible = writable(true); | ||
async function onRightClick(e) { | ||
if ($visible) { | ||
$visible = false; | ||
await new Promise(res => setTimeout(res, 100)); | ||
} | ||
$visible = true; | ||
} | ||
function closeMenu() { | ||
$visible = false; | ||
} | ||
</script> | ||
|
||
{#if $visible} | ||
<Menu on:click={closeMenu} on:clickoutside={closeMenu} {visible}> | ||
<slot /> | ||
</Menu> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<script> | ||
import { onMount, setContext, createEventDispatcher } from 'svelte'; | ||
import { fade } from 'svelte/transition'; | ||
import { position } from './menuStore'; | ||
const key = {}; | ||
export let visible | ||
$: x = $position.x; | ||
$: y = $position.y; | ||
// whenever x and y is changed, restrict box to be within bounds | ||
$: (() => { | ||
if (!menuEl) return; | ||
const rect = menuEl.getBoundingClientRect(); | ||
x = Math.min(window.innerWidth - rect.width, x); | ||
if (y > window.innerHeight - rect.height) y -= rect.height; | ||
})(x, y); | ||
const dispatch = createEventDispatcher(); | ||
setContext(key, { | ||
dispatchClick: () => dispatch('click') | ||
}); | ||
let menuEl; | ||
function onPageClick(e) { | ||
if (e.target.classList.contains("menu-option")) { | ||
$visible = false; | ||
} | ||
else { | ||
$visible = true; | ||
dispatch('clickoutside'); | ||
} | ||
} | ||
// $: console.log("isRightClickMenuVisible", $visible); | ||
</script> | ||
|
||
<style> | ||
div { | ||
position: absolute; | ||
display: grid; | ||
border: 1px solid #0003; | ||
box-shadow: 2px 2px 5px 0px #0002; | ||
background: #18191C; | ||
} | ||
</style> | ||
|
||
<svelte:body on:click={onPageClick} /> | ||
|
||
{#if $visible} | ||
<div transition:fade={{ duration: 100 }} bind:this={menuEl} style="top: {y}px; left: {x}px;"> | ||
<slot /> | ||
</div> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<script> | ||
import { onMount, getContext } from 'svelte'; | ||
import { createEventDispatcher } from 'svelte'; | ||
import { isMenuVisible } from './menuStore'; | ||
const key = {}; | ||
export let text = ''; | ||
export let visible; | ||
const dispatch = createEventDispatcher(); | ||
// const { dispatchClick } = getContext(key); | ||
const handleClick = e => { | ||
dispatch('click'); | ||
visible.set(false); | ||
} | ||
</script> | ||
|
||
<style> | ||
div { | ||
padding: 10px 20px; | ||
cursor: default; | ||
font-size: 14px; | ||
display: flex; | ||
align-items: center; | ||
grid-gap: 5px; | ||
color: #787A7E ; | ||
} | ||
div:hover { | ||
background: #4752C4; | ||
color: white; | ||
} | ||
/* div.disabled { | ||
color: #0006; | ||
} | ||
div.disabled:hover { | ||
background: white; | ||
} */ | ||
</style> | ||
|
||
<div on:click={handleClick} class="menu-option"> | ||
{#if text} | ||
{text} | ||
{:else} | ||
<slot /> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { writable } from "svelte/store"; | ||
|
||
export const isMenuVisible = writable(false); | ||
export const position = writable({ x: 0, y: 0 }); | ||
|
||
export const setMenuVisible = (e) => { | ||
position.set({ x: e.clientX, y: e.clientY }); | ||
isMenuVisible.set(true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters