-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and introduce
BuilderSidebarTitleSearch
- Loading branch information
Showing
3 changed files
with
109 additions
and
48 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<template> | ||
<div v-if="!isSearchActive" class="sectionTitle"> | ||
<i class="material-symbols-outlined">{{ icon }}</i> | ||
<h3>{{ title }}</h3> | ||
<i | ||
title="Search" | ||
class="searchIcon material-symbols-outlined" | ||
tabindex="0" | ||
@keydown.enter="toggleSearch" | ||
@click="toggleSearch" | ||
> | ||
search | ||
</i> | ||
</div> | ||
<div v-if="isSearchActive" class="sectionTitle"> | ||
<input | ||
ref="searchInput" | ||
v-model="searchQuery" | ||
type="text" | ||
placeholder="Search..." | ||
/> | ||
<slot /> | ||
<i | ||
:class="{ disabled: disabled }" | ||
class="searchIcon material-symbols-outlined" | ||
title="Close" | ||
tabindex="0" | ||
@keydown.enter="toggleSearch" | ||
@click="toggleSearch" | ||
> | ||
close | ||
</i> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { nextTick, ref, Ref } from "vue"; | ||
defineProps({ | ||
icon: { type: String, required: true }, | ||
title: { type: String, required: true }, | ||
disabled: { type: Boolean, required: false }, | ||
}); | ||
const searchQuery = defineModel({ type: String, default: "" }); | ||
defineEmits({}); | ||
const searchInput: Ref<HTMLInputElement> = ref(null); | ||
const isSearchActive: Ref<boolean> = ref(false); | ||
async function toggleSearch() { | ||
isSearchActive.value = !isSearchActive.value; | ||
if (isSearchActive.value) { | ||
await nextTick(); | ||
searchInput.value.focus(); | ||
} else { | ||
searchQuery.value = ""; | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
@import "./sharedStyles.css"; | ||
.sectionTitle { | ||
background: var(--builderBackgroundColor); | ||
padding: 16px; | ||
top: 0; | ||
position: sticky; | ||
font-size: 1rem; | ||
} | ||
.sectionTitle h3 { | ||
font-weight: 500; | ||
font-size: 0.875rem; | ||
flex-grow: 1; | ||
} | ||
.sectionTitle .searchIcon { | ||
cursor: pointer; | ||
} | ||
.sectionTitle .searchIcon.disabled { | ||
color: var(--builderDisabledColor); | ||
} | ||
.sectionTitle input { | ||
outline: 0; | ||
border: 0; | ||
flex-grow: 1; | ||
width: 50%; | ||
} | ||
</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
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