Skip to content

Commit 99730a0

Browse files
committed
Adding a new Accordion controller/component
1 parent 6ad5150 commit 99730a0

File tree

9 files changed

+411
-106
lines changed

9 files changed

+411
-106
lines changed

index.html

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717

1818
<script type="module">
1919
import { Application } from "@hotwired/stimulus";
20-
import { Alert, ColorPreview, Dropdown, Modal, Popover, Slideover, Tabs, Toggle } from "tailwindcss-stimulus-components";
20+
import { Accordion, Alert, ColorPreview, Dropdown, Modal, Popover, Slideover, Tabs, Toggle } from "tailwindcss-stimulus-components";
2121

2222
(() => {
2323
const application = Application.start();
24+
application.register('accordion', Accordion);
2425
application.register('alert', Alert);
2526
application.register('color-preview', ColorPreview);
2627
application.register('dropdown', Dropdown);
@@ -68,6 +69,63 @@ <h1 class="text-3xl font-semibold mb-2">Tailwind Stimulus Components Examples</h
6869
<a href="https://github.com/excid3/tailwindcss-stimulus-components" target="_blank" class="text-blue-500">View on Github</a>
6970
<p class="my-4">To view examples locally, run <code class="bg-gray-300 text-sm px-2 py-1 rounded">npm install && npm run build && npx serve</code> and then open <code class="bg-gray-300 text-sm px-2 py-1 rounded">localhost:3000</code> in your browser.</p>
7071

72+
<div class="my-12">
73+
<h2 class="text-2xl text-gray-800 font-semibold mb-4">Accordion</h2>
74+
75+
<!-- Accordion -->
76+
<div data-controller="accordion"
77+
class='flex flex-col gap-0.5 max-w-75 border border-gray-400 rounded-lg'>
78+
<div data-index='0' data-action='click->accordion#toggle' data-accordion-target='button'
79+
class='flex justify-between items-center cursor-pointer w-full items-center gap-3 rounded-lg px-2 py-4 text-left text-base/6 font-medium text-zinc-950 sm:py-2 sm:text-sm/5'
80+
>
81+
<span>Button 1</span>
82+
<span data-accordion-target='chevron' class='w-4 h-4 transition-transform'>
83+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
84+
<path stroke-linecap="round" stroke-linejoin="round" d="m8.25 4.5 7.5 7.5-7.5 7.5" />
85+
</svg>
86+
</span>
87+
</div>
88+
<div data-accordion-target='panel' class='pl-4 overflow-hidden h-0'>
89+
<div class="p-4">
90+
This is the first accordion panel.
91+
</div>
92+
</div>
93+
94+
<div data-index='1' data-action='click->accordion#toggle' data-accordion-target='button'
95+
class='flex justify-between items-center cursor-pointer w-full items-center gap-3 rounded-lg px-2 py-4 text-left text-base/6 font-medium text-zinc-950 sm:py-2 sm:text-sm/5'
96+
>
97+
<span>Button 2</span>
98+
<span data-accordion-target='chevron' class='w-4 h-4 transition-transform'>
99+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
100+
<path stroke-linecap="round" stroke-linejoin="round" d="m8.25 4.5 7.5 7.5-7.5 7.5" />
101+
</svg>
102+
</span>
103+
</div>
104+
<div data-accordion-target='panel' class='pl-4 overflow-hidden h-0'>
105+
<div class="p-4">
106+
This is the second accordion panel.
107+
</div>
108+
</div>
109+
110+
<div data-index='2' data-action='click->accordion#toggle' data-accordion-target='button'
111+
class='flex justify-between items-center cursor-pointer w-full items-center gap-3 rounded-lg px-2 py-4 text-left text-base/6 font-medium text-zinc-950 sm:py-2 sm:text-sm/5'
112+
>
113+
<span>Button 3</span>
114+
<span data-accordion-target='chevron' class='w-4 h-4 transition-transform'>
115+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
116+
<path stroke-linecap="round" stroke-linejoin="round" d="m8.25 4.5 7.5 7.5-7.5 7.5" />
117+
</svg>
118+
</span>
119+
</div>
120+
<div data-accordion-target='panel' class='pl-4 overflow-hidden h-0'>
121+
<div class="p-4">
122+
This is the third accordion panel.
123+
</div>
124+
</div>
125+
126+
</div>
127+
</div>
128+
71129
<div class="my-12">
72130
<h2 class="text-2xl text-gray-800 font-semibold mb-4">Alerts</h2>
73131

0 commit comments

Comments
 (0)