Skip to content

Commit

Permalink
Merge pull request #2 from lara-zeus/blade-component
Browse files Browse the repository at this point in the history
adding Accordion Blade Component and update the docs
  • Loading branch information
atmonshi authored Jan 17, 2024
2 parents 206caac + ac93fe1 commit 9a337de
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 47 deletions.
36 changes: 36 additions & 0 deletions docs/getting-started/blade-component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Blade Component
weight: 4
---

## Accordion Blade Component

you can use accordion as a blade component in any view you want

```html
<x-zeus-accordion::accordion activeAccordion="3">
<x-zeus-accordion::accordion.item
:isIsolated="true"
:label="__('title')"
icon="heroicon-o-chevron-right"
>
<div class="bg-white p-4 *:py-2">
<p>title</p>
<p>title</p>
</div>
</x-zeus-accordion::accordion.item>

<x-zeus-accordion::accordion.item
:isIsolated="true"
:label="__('info')"
icon="heroicon-o-chevron-right"
>
<div class="bg-white p-4 *:py-2">
<p>info</p>
<p>info</p>
<p>info</p>
</div>
</x-zeus-accordion::accordion.item>

</x-zeus-accordion::accordion>
```
13 changes: 13 additions & 0 deletions resources/views/components/accordion/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@props([
'activeAccordion' => 1,
])
<div x-data="{
activeAccordion: 'accordion-{{ $activeAccordion }}',
setActiveAccordion(id) {
this.activeAccordion = (this.activeAccordion == id) ? '' : id
}
}"
class="fi-accordion rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 dark:bg-gray-900 dark:ring-white/10 relative w-full mx-auto overflow-hidden divide-y divide-gray-200 dark:divide-white/5"
>
{{ $slot }}
</div>
45 changes: 45 additions & 0 deletions resources/views/components/accordion/item.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@props([
'activeAccordion' => 1,
'isIsolated' => false,
'icon' => null,
'label' => '',
])
<div
x-data="{
id: $id('accordion'),
@if($isIsolated) activeAccordion: 'accordion-{{ $activeAccordion }}', @endif
}"
class="fi-accordion-item group"
>
<button
type="button"
@click="setActiveAccordion(id)"
class="flex items-center justify-between w-full p-4 text-start select-none"
:class="{
'bg-gray-100 dark:bg-gray-800': activeAccordion == id,
'bg-white': activeAccordion != id,
}"
>
<span
:class="{
'text-primary-600': activeAccordion == id ,
'text-gray-500': activeAccordion != id
}"
class="flex gap-2 font-medium items-center justify-center text-gray-500 group-hover:text-primary-600"
>
@if ($icon !== null)
<x-filament::icon
:icon="$icon"
class="fi-accordion-item-icon h-6 w-6 shrink-0 transition duration-75"
/>
@endif
{{ $label }}
</span>
<span :class="{ 'rotate-180': activeAccordion == id }">
@svg('heroicon-c-chevron-down','w-4 h-4 duration-200 ease-out')
</span>
</button>
<div class="p-4" x-show="activeAccordion == id" x-collapse x-cloak>
{{ $slot }}
</div>
</div>
4 changes: 1 addition & 3 deletions resources/views/forms/accordion.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<div
class="fi-fo-accordions-accordion outline-none p-6"
>
<div>
{{ $getChildComponentContainer() }}
</div>
54 changes: 10 additions & 44 deletions resources/views/forms/accordions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
->merge($getExtraAttributes(), escape: false)
->merge($getExtraAlpineAttributes(), escape: false)
->class([
'fi-fo-accordions rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 dark:bg-gray-900 dark:ring-white/10',
'rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 dark:bg-gray-900 dark:ring-white/10',
])
}}
>
Expand All @@ -20,49 +20,15 @@
$getActiveAccordion = $getActiveAccordion();
@endphp

<div x-data="{
activeAccordion: 'accordion-{{ $getActiveAccordion }}',
setActiveAccordion(id) {
this.activeAccordion = (this.activeAccordion == id) ? '' : id
}
}"
class="relative w-full mx-auto overflow-hidden text-sm divide-y divide-gray-200 dark:divide-white/5 rounded-xl"
>
<x-zeus-accordion::accordion :activeAccordion="$getActiveAccordion">
@foreach ($getChildComponentContainer()->getComponents() as $accordion)
<div
x-data="{
id: $id('accordion'),
@if($isIsolated) activeAccordion: 'accordion-{{ $getActiveAccordion }}', @endif
}"
class="cursor-pointer group">
<button
type="button"
@click="setActiveAccordion(id)"
:class="{ 'bg-gray-100 dark:bg-gray-800': activeAccordion == id }"
class="flex items-center justify-between w-full p-4 text-start select-none"
>
<span
:class="{
'text-primary-600': activeAccordion == id ,
'text-gray-500': activeAccordion != id
}"
class="flex gap-2 font-medium items-center justify-center text-gray-500 group-hover:text-primary-600">
@if ($accordion->getIcon())
<x-filament::icon
:icon="$accordion->getIcon()"
class="fi-accordion-item-icon h-6 w-6 shrink-0 transition duration-75"
/>
@endif
{{ $accordion->getLabel() }}
</span>
<span :class="{ 'rotate-180': activeAccordion == id }">
@svg('heroicon-c-chevron-down','w-4 h-4 duration-200 ease-out')
</span>
</button>
<div x-show="activeAccordion == id" x-collapse x-cloak>
{{ $accordion }}
</div>
</div>
<x-zeus-accordion::accordion.item
:label="$accordion->getLabel()"
:icon="$accordion->getIcon()"
:isIsolated="$isIsolated"
:activeAccordion="$getActiveAccordion">
{{ $accordion }}
</x-zeus-accordion::accordion.item>
@endforeach
</div>
</x-zeus-accordion::accordion>
</div>

0 comments on commit 9a337de

Please sign in to comment.