forked from simonwep/ocular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add dropdown to select a different year
add new state version add separate utils module for state management
- Loading branch information
Showing
18 changed files
with
284 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,107 @@ | ||
<template> | ||
<div :class="$style.contextMenu"> | ||
<button ref="reference" :class="$style.reference" @click="open = !open"> | ||
<slot /> | ||
</button> | ||
<div ref="popper" :class="$style.popper"> | ||
<ul :class="[$style.list, { [$style.visible]: open }]"> | ||
<li :class="$style.item" v-for="option of options" :key="option.id"> | ||
<button :class="$style.btn" @click="select(option)"> | ||
{{ option.label ?? option.id }} | ||
</button> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { ref, watch } from 'vue'; | ||
import { createPopper, Instance } from '@popperjs/core'; | ||
import { ContextMenuOption } from '.'; | ||
const emit = defineEmits<{ | ||
(e: 'select', option: ContextMenuOption): void; | ||
}>(); | ||
defineProps<{ | ||
options: ContextMenuOption[]; | ||
}>(); | ||
const reference = ref<HTMLButtonElement>(); | ||
const popper = ref<HTMLDivElement>(); | ||
const open = ref(false); | ||
let instance: Instance | undefined; | ||
watch([reference, popper], () => { | ||
instance?.destroy(); | ||
if (reference.value && popper.value) { | ||
instance = createPopper(reference.value, popper.value, { | ||
placement: 'right-end', | ||
modifiers: [{ name: 'offset', options: { offset: [10, 10] } }] | ||
}); | ||
} | ||
}); | ||
const select = (option: ContextMenuOption): void => { | ||
emit('select', option); | ||
open.value = false; | ||
}; | ||
</script> | ||
|
||
<style lang="scss" module> | ||
.contextMenu { | ||
display: flex; | ||
} | ||
.reference { | ||
all: unset; | ||
display: flex; | ||
} | ||
.popper { | ||
display: flex; | ||
position: absolute; | ||
z-index: 1; | ||
} | ||
.list { | ||
list-style: none outside none; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-end; | ||
backdrop-filter: var(--context-menu-backdrop); | ||
box-shadow: var(--context-menu-shadow); | ||
border-radius: var(--border-radius-m); | ||
padding: 5px 2px; | ||
max-height: 130px; | ||
overflow: auto; | ||
visibility: hidden; | ||
opacity: 0; | ||
transform: translateX(-10px); | ||
transition: all var(--transition-m); | ||
&.visible { | ||
visibility: visible; | ||
opacity: 1; | ||
transform: none; | ||
} | ||
.item .btn { | ||
all: unset; | ||
display: flex; | ||
align-items: center; | ||
cursor: pointer; | ||
font-size: var(--font-size-xs); | ||
border-radius: 10px; | ||
padding: 6px 8px; | ||
color: var(--context-menu-item-color); | ||
position: relative; | ||
&:hover { | ||
color: var(--context-menu-item-color-hover); | ||
} | ||
} | ||
} | ||
</style> |
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,4 @@ | ||
export interface ContextMenuOption { | ||
id: number; | ||
label?: string; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<template> | ||
<ContextMenu :options="options" @select="changeYear($event.id)"> | ||
<Button icon="calendar-line" textual color="dimmed" /> | ||
</ContextMenu> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { computed } from 'vue'; | ||
import Button from '@components/base/button/Button.vue'; | ||
import ContextMenu from '@components/base/context-menu/ContextMenu.vue'; | ||
import { ContextMenuOption } from '@components/base/context-menu'; | ||
import { useDataStore } from '@store/state'; | ||
const { changeYear, state } = useDataStore(); | ||
const options = computed((): ContextMenuOption[] => { | ||
const yearsStored = state.years.map((v) => v.year); | ||
const offset = Math.min(new Date().getFullYear(), ...yearsStored); | ||
const list: ContextMenuOption[] = []; | ||
for (let i = 0; i < 3; i++) { | ||
list.push({ id: offset + i }); | ||
} | ||
return list; | ||
}); | ||
</script> |
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,12 @@ | ||
import { onMounted, onUnmounted, Ref } from 'vue'; | ||
|
||
export const useOutOfElementClick = (el: Ref<HTMLElement | undefined>, cb: (evt: MouseEvent) => void) => { | ||
const click = (evt: MouseEvent) => { | ||
if (el.value && !evt.composedPath().includes(el.value)) { | ||
cb(evt); | ||
} | ||
}; | ||
|
||
onMounted(() => window.addEventListener('click', click)); | ||
onUnmounted(() => window.removeEventListener('click', click)); | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.