|
2 | 2 |
|
3 | 3 | An accordion component is an element that organizes content into collapsible sections, enabling users to expand or collapse them for efficient information presentation and navigation. |
4 | 4 |
|
5 | | -`<Accordion::Accordion />` can be used in any design system. |
| 5 | +<Callout> |
| 6 | + |
| 7 | +Before reaching for this component, consider if the [native `<details>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details) is sufficient for your use case. |
| 8 | + |
| 9 | + |
| 10 | +<details><summary>example of <code>details</code></summary> |
| 11 | + |
| 12 | +Like with the component, `<details>` and `<summary>` can be styled with CSS. |
| 13 | + |
| 14 | +```gjs live preview |
| 15 | +// No imports needed! |
| 16 | +// Though, as a TODO: for this component, we'll soon have a multi-details |
| 17 | +// management wrapper in case you want only one `<details>` open at a time. |
| 18 | +
|
| 19 | +<template> |
| 20 | + <div class="demo"> |
| 21 | + <details> |
| 22 | + <summary>the header</summary> |
| 23 | +
|
| 24 | + <span> |
| 25 | + Ember.js is a productive, battle-tested JavaScript framework for building modern web |
| 26 | + applications. It includes everything you need to build rich UIs that work on any device. |
| 27 | + </span> |
| 28 | + </details> |
| 29 | +
|
| 30 | + <details> |
| 31 | + <summary>another header</summary> |
| 32 | +
|
| 33 | + <span> |
| 34 | + Ember.js is a productive, battle-tested JavaScript framework for building modern web |
| 35 | + applications. It includes everything you need to build rich UIs that work on any device. |
| 36 | + </span> |
| 37 | + </details> |
| 38 | +
|
| 39 | + <details> |
| 40 | + <summary>a third header</summary> |
| 41 | +
|
| 42 | + <span> |
| 43 | + Ember.js is a productive, battle-tested JavaScript framework for building modern web |
| 44 | + applications. It includes everything you need to build rich UIs that work on any device. |
| 45 | + </span> |
| 46 | + </details> |
| 47 | + </div> |
| 48 | +
|
| 49 | + <style> |
| 50 | + details { |
| 51 | + position: relative; |
| 52 | + padding-bottom: 1rem; |
| 53 | + } |
| 54 | + summary { |
| 55 | + cursor: pointer; |
| 56 | + margin-bottom: -1rem; |
| 57 | + transition-property: all; |
| 58 | + transition-duration: 150ms; |
| 59 | + transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); |
| 60 | +
|
| 61 | + background: white; |
| 62 | + padding: 0.5rem; |
| 63 | + color: black; |
| 64 | + border: 1px solid; |
| 65 | + border-radius: 0.25rem; |
| 66 | + position: relative; |
| 67 | + z-index: 2; |
| 68 | + } |
| 69 | + details[open] > summary { |
| 70 | + background: #dcdcff; |
| 71 | + font-weight: bold; |
| 72 | + margin-bottom: 1rem; |
| 73 | + } |
| 74 | +
|
| 75 | + details > span { |
| 76 | + position: relative; |
| 77 | + z-index: 1; |
| 78 | + } |
| 79 | +
|
| 80 | + .demo { |
| 81 | + margin: 1rem; |
| 82 | + padding: 1rem; |
| 83 | + display: grid; |
| 84 | + gap: 1rem; |
| 85 | + } |
| 86 | + </style> |
| 87 | +</template> |
| 88 | +``` |
| 89 | + |
| 90 | +</details> |
| 91 | + |
| 92 | +</Callout> |
6 | 93 |
|
7 | 94 | ## Examples |
8 | 95 |
|
|
0 commit comments