Skip to content

Commit 861d8fa

Browse files
committed
refactor!: Create Accordion.astro component and implement in Faq.astro
Replace plain text cards in `Faq.astro` with a collapsible accordion component built with Alpine.js and Tailwind. `Accordion.astro` is rendered iteratively from `common-questions.json` content
1 parent 6e81c41 commit 861d8fa

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

src/components/Accordion.astro

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
const {title, description, id} = Astro.props;
3+
console.log("index", id)
4+
---
5+
<div x-data="{
6+
visible: false,
7+
toggle() {
8+
this.visible = !this.visible
9+
}
10+
}"
11+
12+
class:list={[
13+
"bg-white py-6 transition-all duration-300 ease-in-out overflow-hidden",
14+
{ "border-b-0" : id === null },
15+
{ "border-b-2" : id },
16+
]}>
17+
18+
<div @click="toggle()" class="text-lg font-semibold cursor-pointer">
19+
{title}
20+
</div>
21+
22+
<div
23+
x-transition
24+
class="transition-all duration-300 ease-in-out overflow-hidden"
25+
:class="visible ? 'max-h-40 opacity-100' : 'max-h-0 opacity-0'"
26+
27+
>
28+
<p class="text-gray-600 mt-2 overflow-hidden">
29+
{description}
30+
</p>
31+
</div>
32+
</div>

src/components/Faq.astro

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
---
22
import commonQuestions from "../assets/common-questions.json";
3+
import Accordion from "./Accordion.astro";
34
---
45

56
<section class="py-16 bg-gray-50">
67
<div class="container mx-auto px-4">
78
<h2 class="text-3xl font-bold text-center mb-12">Preguntas frecuentes</h2>
8-
<div class="container mx-auto space-y-6">
9+
<div class="container faqs-container mx-auto shadow-md p-6 pt-0">
910
{
10-
commonQuestions.map((question) => (
11-
<div class="bg-white p-6 rounded-lg shadow-md">
12-
<h3 class="text-lg font-semibold mb-2">{question.title}</h3>
13-
<p class="text-gray-600">{question.description}</p>
14-
</div>
11+
commonQuestions.map((question, index) => (
12+
<Accordion {...question} id={index++ < commonQuestions.length - 1? index++ : null}/>
1513
))
1614
}
1715
</div>

src/styles/globals.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,13 @@
3636
svg {
3737
@apply text-sm;
3838
}
39+
40+
/* FAQ collapsibles style */
41+
summary {
42+
list-style: none; /* Elimina el marcador predeterminado */
43+
}
44+
45+
summary::-webkit-details-marker {
46+
display: none; /* Para navegadores basados en Webkit (Chrome, Safari) */
47+
}
3948
}

0 commit comments

Comments
 (0)