generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from mehedijaman/main
Feature: Sidebar Menu Items Search Functionality
- Loading branch information
Showing
4 changed files
with
170 additions
and
4 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
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 |
---|---|---|
@@ -1,16 +1,87 @@ | ||
<template> | ||
<div> | ||
<ul v-for="(item, index) in items" :key="index"> | ||
<li class="mb-2 block"> | ||
<div class="rounded-tl rounded-tr"> | ||
<label for="search" class="sr-only">Search</label> | ||
<div class="flex items-center align-middle"> | ||
<div | ||
class="pointer-events-none absolute flex items-center pl-3" | ||
> | ||
<i class="ri-search-line"></i> | ||
</div> | ||
<AppInputText | ||
id="search" | ||
v-model="searchTerm" | ||
:placeholder="__('Search...')" | ||
class="w-full pl-9" | ||
></AppInputText> | ||
|
||
<AppButton | ||
v-if="searchTerm" | ||
class="btn ml-1 border border-skin-neutral-8 bg-skin-neutral-5 hover:bg-skin-neutral-8" | ||
@click="searchTerm = ''" | ||
> | ||
<i class="ri-close-line"></i> | ||
</AppButton> | ||
</div> | ||
</div> | ||
</li> | ||
|
||
<ul v-for="(item, index) in filteredItems" :key="index"> | ||
<AppMenuSection :item="item" /> | ||
</ul> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
defineProps({ | ||
import { ref, computed } from 'vue' | ||
const props = defineProps({ | ||
items: { | ||
type: Array, | ||
default: () => [] | ||
} | ||
}) | ||
const searchTerm = ref('') | ||
// Computed property to filter items based on search term | ||
const filteredItems = computed(() => { | ||
if (!searchTerm.value) return props.items | ||
const term = searchTerm.value.toLowerCase() | ||
// Recursive function to filter items and their children | ||
const filterItems = (items) => { | ||
return items.reduce((acc, item) => { | ||
const isParentMatch = item.label.toLowerCase().includes(term) | ||
let filteredChildren = [] | ||
if (item.children) { | ||
if (isParentMatch) { | ||
// If parent matches, include all children | ||
filteredChildren = item.children | ||
} else { | ||
// Else, filter children based on search term | ||
filteredChildren = filterItems(item.children) | ||
} | ||
} | ||
// Include the item if the parent matches or any of its children match | ||
if ( | ||
isParentMatch || | ||
(filteredChildren && filteredChildren.length) | ||
) { | ||
acc.push({ | ||
...item, | ||
// If parent matches, include all children; else, include filtered children | ||
children: isParentMatch ? item.children : filteredChildren | ||
}) | ||
} | ||
return acc | ||
}, []) | ||
} | ||
return filterItems(props.items) | ||
}) | ||
</script> |
45 changes: 45 additions & 0 deletions
45
stubs/resources/js/Pages/Dashboard/Components/DashboardCard.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,45 @@ | ||
<template> | ||
<div | ||
class="shadow-xs flex items-center rounded-lg border border-skin-neutral-4 bg-skin-neutral-2 p-4 hover:cursor-pointer hover:bg-skin-neutral-1" | ||
@click="$inertia.visit(route(link))" | ||
> | ||
<div | ||
class="mr-4 rounded-full bg-green-100 px-3 py-2 text-green-500 dark:bg-green-500 dark:text-green-100" | ||
> | ||
<i :class="icon" class="text-2xl"></i> | ||
</div> | ||
<div> | ||
<p class="mb-2 text-sm font-medium"> | ||
{{ label }} | ||
</p> | ||
<p class="text-lg font-semibold"> | ||
{{ count }} | ||
</p> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import useAuthCan from '@/Composables/useAuthCan' | ||
defineProps({ | ||
link: { | ||
type: String, | ||
default: null | ||
}, | ||
count: { | ||
type: String, | ||
default: null | ||
}, | ||
label: { | ||
type: String, | ||
default: null | ||
}, | ||
icon: { | ||
type: String, | ||
default: null | ||
} | ||
}) | ||
const { can } = useAuthCan() | ||
</script> |
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