-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(NcAppNavigation): Provide consistent in-app search
`NcAppNaviation` now provides an optional in-app search when `show-search` is set. This allows apps which have in app filtering / search to use a consistent layout. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
- Loading branch information
Showing
4 changed files
with
248 additions
and
1 deletion.
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
110 changes: 110 additions & 0 deletions
110
src/components/NcAppNavigation/NcAppNavigationSearch.vue
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,110 @@ | ||
<!-- | ||
- SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors | ||
- SPDX-License-Identifier: AGPL-3.0-or-later | ||
--> | ||
<template> | ||
<div class="app-navigation-search" | ||
:class="{ | ||
'app-navigation-search--has-actions': hasActions, | ||
}"> | ||
<NcInputField ref="inputElement" | ||
:aria-label="label" | ||
class="app-navigation-search__input" | ||
label-outside | ||
:pill="isLegacyVersion" | ||
:placeholder="label" | ||
show-trailing-button | ||
:trailing-button-label="t('Clear search')" | ||
type="search" | ||
:value="value" | ||
@update:value="$emit('update:value', $event)" | ||
@trailing-button-click="onCloseSearch"> | ||
<template #trailing-button-icon> | ||
<IconClose :size="20" /> | ||
</template> | ||
</NcInputField> | ||
<Transition name="slide-fade"> | ||
<NcActions v-if="hasActions" | ||
v-show="showActions" | ||
ref="actions" | ||
class="app-navigation-search__actions" | ||
:inline="1"> | ||
<slot name="actions" /> | ||
</NcActions> | ||
</Transition> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { useFocusWithin } from '@vueuse/core' | ||
import { computed, ref, nextTick, useSlots, watch } from 'vue' | ||
import { t } from '../../l10n.js' | ||
import IconClose from 'vue-material-design-icons/Close.vue' | ||
import NcInputField from '../NcInputField/NcInputField.vue' | ||
defineProps({ | ||
value: { | ||
type: String, | ||
default: '', | ||
}, | ||
label: { | ||
type: String, | ||
default: t('Search in app…'), | ||
}, | ||
}) | ||
const emit = defineEmits(['update:value']) | ||
const slots = useSlots() | ||
const isLegacyVersion = (window.OC?.config?.version?.split('.')[0] ?? 30) < 30 | ||
const inputElement = ref() | ||
const { focused: inputHasFocus } = useFocusWithin(inputElement) | ||
/** | ||
* @type {import('vue').Ref<import('vue').ComponentPublicInstance>} | ||
*/ | ||
const actions = ref() | ||
const hasActions = computed(() => !!slots.actions) | ||
const showActions = ref(true) | ||
watch([inputHasFocus], () => { showActions.value = !inputHasFocus.value }) | ||
/** | ||
* Handle close the search | ||
*/ | ||
function onCloseSearch() { | ||
emit('update:value', '') | ||
if (hasActions.value) { | ||
showActions.value = true | ||
nextTick(() => actions.value.$el.querySelector('button').focus()) | ||
} | ||
} | ||
</script> | ||
<style scoped lang="scss"> | ||
.app-navigation-search { | ||
display: flex; | ||
gap: var(--app-navigation-padding); | ||
padding: var(--app-navigation-padding); | ||
&--has-actions &__input { | ||
flex-grow: 1; | ||
z-index: 3; | ||
} | ||
&__actions { | ||
margin-inline-start: 0; | ||
} | ||
} | ||
.slide-fade-enter-active, | ||
.slide-fade-leave-active { | ||
transition: margin-inline-start var(--animation-quick); | ||
} | ||
.slide-fade-enter, | ||
.slide-fade-leave-to { | ||
margin-inline-start: calc(-1 * var(--default-clickable-area)); | ||
} | ||
</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