builder block: add search

This commit is contained in:
Simon Vieille 2024-05-26 21:36:42 +02:00
parent d4ba8dc619
commit 1120c20f05
Signed by: deblan
GPG key ID: 579388D585F70417

View file

@ -39,6 +39,10 @@
background: #eee; background: #eee;
border: 1px solid #1e2430; border: 1px solid #1e2430;
} }
.search {
max-width: 300px;
}
</style> </style>
<template> <template>
@ -72,9 +76,13 @@
:class="{'d-none': activeCategory !== key}" :class="{'d-none': activeCategory !== key}"
> >
<div class="row"> <div class="row">
<div class="col-12 mb-4">
<input v-model="search" placeholder="Type to search..." class="form-control search">
</div>
<div <div
v-for="(widget, name) in category.widgets" v-for="(widget, name) in category.widgets"
v-on:click="add(name, widget)" v-on:click="add(name, widget)"
v-if="matchSearch(name)"
class="widget col-auto" class="widget col-auto"
> >
<span class="widget-icon" v-if="widget.icon" v-html="widget.icon"></span> <span class="widget-icon" v-if="widget.icon" v-html="widget.icon"></span>
@ -116,6 +124,7 @@ export default {
return { return {
showPicker: false, showPicker: false,
activeCategory: 'all', activeCategory: 'all',
search: '',
} }
}, },
methods: { methods: {
@ -154,6 +163,13 @@ export default {
return `block-${result}` return `block-${result}`
}, },
matchSearch(name) {
if (!this.search.trim().length) {
return true
}
return name.toLowerCase().includes(this.search.toLowerCase())
},
togglePicker() { togglePicker() {
this.showPicker = !this.showPicker this.showPicker = !this.showPicker
}, },