cista-storage/cista-front/src/components/HeaderMain.vue

101 lines
2.6 KiB
Vue
Raw Normal View History

<template>
<nav class="headermain">
2023-11-04 00:21:35 +00:00
<div class="buttons">
2023-11-07 18:01:34 +00:00
<template v-if="documentStore.error">
<div class="error-message" @click="documentStore.error = ''">{{ documentStore.error }}</div>
<div class="smallgap"></div>
</template>
<UploadButton />
2023-11-04 20:54:14 +00:00
<SvgButton
name="create-folder"
data-tooltip="New folder"
2023-11-04 20:54:14 +00:00
@click="() => documentStore.fileExplorer.newFolder()"
/>
<slot></slot>
<div class="spacer smallgap"></div>
2023-10-27 16:32:21 +01:00
<template v-if="showSearchInput">
2023-11-04 00:21:35 +00:00
<input
ref="search"
type="search"
v-model="documentStore.search"
placeholder="Search words"
2023-11-04 00:21:35 +00:00
class="margin-input"
@keyup.escape="closeSearch"
2023-11-04 00:21:35 +00:00
/>
2023-10-27 16:32:21 +01:00
</template>
<SvgButton ref="searchButton" name="find" @click.prevent="toggleSearchInput" />
<SvgButton name="cog" @click="settingsMenu" />
</div>
2023-11-04 00:21:35 +00:00
</nav>
</template>
<script setup lang="ts">
import { useDocumentStore } from '@/stores/documents'
import { ref, nextTick } from 'vue'
import ContextMenu from '@imengyu/vue3-context-menu'
const documentStore = useDocumentStore()
const showSearchInput = ref<boolean>(false)
const search = ref<HTMLInputElement | null>()
const searchButton = ref<HTMLButtonElement | null>()
const closeSearch = () => {
if (!showSearchInput.value) return // Already closing
showSearchInput.value = false
documentStore.search = ''
const breadcrumb = document.querySelector('.breadcrumb') as HTMLElement
breadcrumb.focus()
}
const toggleSearchInput = () => {
showSearchInput.value = !showSearchInput.value
if (!showSearchInput.value) return closeSearch()
nextTick(() => {
const input = search.value
if (input) input.focus()
})
}
const settingsMenu = (e: Event) => {
// show the context menu
2023-11-07 18:01:34 +00:00
const items = []
if (documentStore.user.isLoggedIn) {
items.push({ label: `Logout ${documentStore.user.username ?? ''}`, onClick: () => documentStore.logout() })
} else {
items.push({ label: 'Login', onClick: () => documentStore.loginDialog() })
}
ContextMenu.showContextMenu({
// @ts-ignore
x: e.target.getBoundingClientRect().right, y: e.target.getBoundingClientRect().bottom,
2023-11-07 18:01:34 +00:00
items,
})
}
defineExpose({
toggleSearchInput,
closeSearch,
})
</script>
2023-11-04 00:21:35 +00:00
<style scoped>
.buttons {
padding: 0;
display: flex;
2023-11-04 00:21:35 +00:00
align-items: center;
height: 3.5em;
z-index: 10;
}
.buttons > * {
flex-shrink: 1;
}
2023-11-04 00:21:35 +00:00
input[type='search'] {
2023-11-07 19:05:21 +00:00
background: var(--input-background);
color: var(--input-color);
2023-11-04 00:21:35 +00:00
border: 0;
border-radius: 0.1em;
padding: 0.5em;
2023-11-04 00:21:35 +00:00
outline: none;
font-size: 1.5em;
max-width: 30vw;
}
</style>