-
Notifications
You must be signed in to change notification settings - Fork 85
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
273 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
126 changes: 126 additions & 0 deletions
126
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,126 @@ | ||
<!-- | ||
- SPDX-FileCopyrightText: 2024 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 | ||
: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 v-if="hasActions()" name="slide-fade"> | ||
<NcActions v-show="showActions" | ||
ref="actions" | ||
class="app-navigation-search__actions" | ||
:inline="noInlineActions ? 0 : 1"> | ||
<slot name="actions" /> | ||
</NcActions> | ||
</Transition> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { useFocusWithin } from '@vueuse/core' | ||
import { 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({ | ||
/** | ||
* Current search input | ||
*/ | ||
value: { | ||
type: String, | ||
default: '', | ||
}, | ||
/** | ||
* Text used to label the search input | ||
*/ | ||
label: { | ||
type: String, | ||
default: t('Search in app…'), | ||
}, | ||
/** | ||
* Disable inline actions forcing a menu if more than one action is provided | ||
*/ | ||
noInlineActions: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}) | ||
const emit = defineEmits(['update:value']) | ||
const slots = useSlots() | ||
const inputElement = ref() | ||
const { focused: inputHasFocus } = useFocusWithin(inputElement) | ||
/** | ||
* @type {import('vue').Ref<import('vue').ComponentPublicInstance>} | ||
*/ | ||
const actions = ref() | ||
const hasActions = () => !!slots.actions | ||
const showActions = ref(true) | ||
watch(inputHasFocus, () => { | ||
showActions.value = !inputHasFocus.value | ||
}) | ||
/** | ||
* Handle close the search | ||
*/ | ||
function onCloseSearch() { | ||
emit('update:value', '') | ||
if (hasActions()) { | ||
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; | ||
} | ||
&__input { | ||
// This is a fallback for legacy version (Nextcloud 29 and older) so that we keep the pill like design there | ||
--input-border-radius: var(--borer-radius-element, var(--border-radius-pill)) !important; | ||
} | ||
} | ||
.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