|
| 1 | +<!-- |
| 2 | + - SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + - SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | +--> |
| 5 | +<template> |
| 6 | + <search class="unified-search-input" :class="[{ 'unified-search-input--mobile': isSmallMobile }]"> |
| 7 | + <NcHeaderButton |
| 8 | + v-if="isSmallMobile" |
| 9 | + :aria-label="placeholderText" |
| 10 | + aria-haspopup="dialog" |
| 11 | + :aria-expanded="expanded ? 'true' : 'false'" |
| 12 | + @click="$emit('click', $event)"> |
| 13 | + <template #icon> |
| 14 | + <IconMagnify :size="20" /> |
| 15 | + </template> |
| 16 | + </NcHeaderButton> |
| 17 | + <button |
| 18 | + v-else |
| 19 | + type="button" |
| 20 | + class="unified-search-input__button" |
| 21 | + aria-haspopup="dialog" |
| 22 | + :aria-expanded="expanded ? 'true' : 'false'" |
| 23 | + @click="$emit('click', $event)"> |
| 24 | + <IconMagnify |
| 25 | + class="unified-search-input__icon" |
| 26 | + :size="20" |
| 27 | + aria-hidden="true" /> |
| 28 | + <span class="unified-search-input__label"> |
| 29 | + {{ placeholderText }} |
| 30 | + </span> |
| 31 | + </button> |
| 32 | + </search> |
| 33 | +</template> |
| 34 | + |
| 35 | +<script setup lang="ts"> |
| 36 | +import { t } from '@nextcloud/l10n' |
| 37 | +import { useIsSmallMobile } from '@nextcloud/vue/composables/useIsMobile' |
| 38 | +import NcHeaderButton from '@nextcloud/vue/components/NcHeaderButton' |
| 39 | +import IconMagnify from 'vue-material-design-icons/Magnify.vue' |
| 40 | +
|
| 41 | +/** |
| 42 | + * First phase of the unified-search input: a button styled to look like an |
| 43 | + * input field that opens the unified-search modal on click. A later phase |
| 44 | + * will replace the button with a real input that filters results inline. |
| 45 | + * |
| 46 | + * Implemented as a custom component because no `@nextcloud/vue` component |
| 47 | + * fits the design role here: NcInputField is a real input whose styling |
| 48 | + * assumes a light page background and clashes with the themed header, |
| 49 | + * and NcTextField has the same issue. On narrow viewports the trigger |
| 50 | + * collapses to a standard NcHeaderButton so it matches the visual |
| 51 | + * language of the other header items. |
| 52 | + */ |
| 53 | +
|
| 54 | +defineProps<{ |
| 55 | + /** Whether the popup the input controls is currently open. Bound to aria-expanded. */ |
| 56 | + expanded?: boolean |
| 57 | +}>() |
| 58 | +
|
| 59 | +defineEmits<{ |
| 60 | + click: [mouseEvent: MouseEvent] |
| 61 | +}>() |
| 62 | +
|
| 63 | +const isSmallMobile = useIsSmallMobile() |
| 64 | +const placeholderText = t('core', 'Search apps, files, tags, messages …') |
| 65 | +</script> |
| 66 | + |
| 67 | +<style lang="scss" scoped> |
| 68 | +.unified-search-input { |
| 69 | + &:not(.unified-search-input--mobile) { |
| 70 | + position: absolute; |
| 71 | + top: 0; |
| 72 | + bottom: 0; |
| 73 | + inset-inline: 0; |
| 74 | + margin-inline: auto; |
| 75 | + display: flex; |
| 76 | + align-items: center; |
| 77 | + width: clamp(200px, 35vw, 600px); |
| 78 | + max-width: calc(100% - 32px); |
| 79 | + pointer-events: none; |
| 80 | + } |
| 81 | +
|
| 82 | + &--mobile { |
| 83 | + display: contents; |
| 84 | + } |
| 85 | +
|
| 86 | + &__button { |
| 87 | + pointer-events: auto; |
| 88 | + display: flex; |
| 89 | + align-items: center; |
| 90 | + justify-content: center; |
| 91 | + gap: 8px; |
| 92 | + width: 100%; |
| 93 | + height: calc(var(--default-clickable-area) - 8px); |
| 94 | + padding: 0 12px; |
| 95 | + border: none; |
| 96 | + border-radius: var(--border-radius-element, 8px); |
| 97 | + background-color: rgba(0, 0, 0, 0.15); |
| 98 | + -webkit-backdrop-filter: var(--filter-background-blur); |
| 99 | + backdrop-filter: var(--filter-background-blur); |
| 100 | + box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.12); |
| 101 | + color: var(--color-background-plain-text); |
| 102 | + cursor: pointer; |
| 103 | + text-align: center; |
| 104 | + font: inherit; |
| 105 | + transition: background-color var(--animation-quick) ease-in-out; |
| 106 | +
|
| 107 | + &:hover { |
| 108 | + background-color: rgba(0, 0, 0, 0.22); |
| 109 | + } |
| 110 | +
|
| 111 | + &:focus-visible { |
| 112 | + background-color: rgba(0, 0, 0, 0.22); |
| 113 | + outline: 2px solid var(--color-background-plain-text); |
| 114 | + outline-offset: 2px; |
| 115 | + } |
| 116 | +
|
| 117 | + &:active { |
| 118 | + background-color: rgba(0, 0, 0, 0.28) !important; |
| 119 | + color: var(--color-background-plain-text) !important; |
| 120 | + outline: none; |
| 121 | + } |
| 122 | + } |
| 123 | +
|
| 124 | + &__icon { |
| 125 | + flex-shrink: 0; |
| 126 | + display: flex; |
| 127 | + align-items: center; |
| 128 | + } |
| 129 | +
|
| 130 | + &__label { |
| 131 | + min-width: 0; |
| 132 | + overflow: hidden; |
| 133 | + text-overflow: ellipsis; |
| 134 | + white-space: nowrap; |
| 135 | + } |
| 136 | +} |
| 137 | +
|
| 138 | +.unified-search-input--mobile :deep(.header-menu) { |
| 139 | + height: var(--default-clickable-area); |
| 140 | +} |
| 141 | +
|
| 142 | +.unified-search-input--mobile :deep(.header-menu__trigger) { |
| 143 | + --button-size: var(--default-clickable-area) !important; |
| 144 | + height: var(--default-clickable-area) !important; |
| 145 | +} |
| 146 | +
|
| 147 | +.unified-search-input--mobile :deep(.button-vue) { |
| 148 | + --color-main-text: var(--color-background-plain-text); |
| 149 | + color: var(--color-background-plain-text); |
| 150 | + border-radius: var(--border-radius-element) !important; |
| 151 | +
|
| 152 | + &:hover:not(:disabled) { |
| 153 | + background-color: rgba(0, 0, 0, 0.1) !important; |
| 154 | + } |
| 155 | +
|
| 156 | + &:active:not(:disabled) { |
| 157 | + background-color: rgba(0, 0, 0, 0.15) !important; |
| 158 | + } |
| 159 | +
|
| 160 | + &:focus-visible { |
| 161 | + background-color: rgba(0, 0, 0, 0.1) !important; |
| 162 | + outline: none !important; |
| 163 | + box-shadow: inset 0 0 0 2px var(--color-background-plain-text) !important; |
| 164 | + } |
| 165 | +} |
| 166 | +
|
| 167 | +[data-theme-dark] .unified-search-input__button, |
| 168 | +[data-theme-dark-highcontrast] .unified-search-input__button { |
| 169 | + background-color: color-mix(in srgb, var(--color-primary-element) 16%, transparent); |
| 170 | +
|
| 171 | + &:hover { |
| 172 | + background-color: color-mix(in srgb, var(--color-primary-element) 22%, transparent); |
| 173 | + } |
| 174 | +
|
| 175 | + &:focus-visible { |
| 176 | + background-color: color-mix(in srgb, var(--color-primary-element) 22%, transparent); |
| 177 | + } |
| 178 | +
|
| 179 | + &:active { |
| 180 | + background-color: color-mix(in srgb, var(--color-primary-element) 28%, transparent) !important; |
| 181 | + color: var(--color-background-plain-text) !important; |
| 182 | + outline: none; |
| 183 | + } |
| 184 | +} |
| 185 | +</style> |
0 commit comments