generated from rapidez/package-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaccordion.blade.php
66 lines (60 loc) · 1.96 KB
/
accordion.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{{--
Accordion component using the Tailwind CSS `peer` and `group` utilities.
## Properties
- `id` A unique identifier for each accordion instance, automatically generated if not provided.
- `type` Default `checkbox`, set to `radio` if you want only one accordion to be open at a time.
- `name` Required if you use `radio` to group accordions together.
- `opened` Default `false`, set to `true` to have it open initially.
## Slots
- `label` Defines the clickable label that toggles the accordion.
- `content` The collapsible section that appears when the accordion is opened.
## Examples
Basic usage:
```
<x-rapidez::accordion>
<x-slot:label>
Label
</x-slot:label>
<x-slot:content>
Content
</x-slot:content>
</x-rapidez::accordion>
```
With rotating chevron:
```
<x-rapidez::accordion>
<x-slot:label>
<span>Label</span>
<x-heroicon-o-chevron-down class="transition-transform size-5 group-has-[:checked]:rotate-180" />
</x-slot:label>
<x-slot:content>
Content
</x-slot:content>
</x-rapidez::accordion>
```
--}}
@props(['id' => uniqid('accordion-'), 'type' => 'checkbox', 'name' => '', 'opened' => false])
@slots(['label', 'content'])
<div {{ $attributes->twMerge('flex flex-col group') }}>
<input
id="{{ $id }}"
name="{{ $name }}"
type="{{ $type }}"
@checked($opened)
class="peer hidden"
/>
<label
for="{{ $id }}"
{{ $label->attributes->twMerge('flex items-center gap-2 justify-between cursor-pointer') }}
@if ($type === 'radio')
onclick="event.preventDefault(); document.getElementById('{{ $id }}').checked = !document.getElementById('{{ $id }}').checked;"
@endif
>
{{ $label }}
</label>
<div {{ $content->attributes->twMerge('grid peer-checked:grid-rows-[1fr] grid-rows-[0fr] transition-all') }}>
<div class="overflow-hidden">
{{ $content }}
</div>
</div>
</div>