diff --git a/exampleSite/content/docs/shortcodes/index.md b/exampleSite/content/docs/shortcodes/index.md index 7fd16773..d5bf0d60 100644 --- a/exampleSite/content/docs/shortcodes/index.md +++ b/exampleSite/content/docs/shortcodes/index.md @@ -96,6 +96,92 @@ The alert sign (`+` or `-`) is optional to control whether the admonition is fol > [!INFO]- Customize admonition > See the [admonition customization guide](https://github.com/nunocoracao/blowfish/blob/main/layouts/_default/_markup/render-blockquote.html). +## Accordion + +`accordion` creates a collapsible set of panels. Use the `accordionItem` sub-shortcode to define each item. You can control whether multiple items can be open at the same time using the `mode` parameter. + + +| Parameter | Description | +| --------- | ------------------------------------------------------------------------------------------------- | +| `mode` | **Optional.** `collapse` (single open) or `open` (multiple open). Defaults to `collapse`. | +| `separated` | **Optional.** `true` to show each item as a separate card. Defaults to `false` (joined list). | + + +`accordionItem` parameters: + + +| Parameter | Description | +| --------- | --------------------------------------------------------------------------------------------------- | +| `title` | **Required.** Title shown in the item header. | +| `open` | **Optional.** Set to `true` to have the item open by default. | +| `header` | **Optional.** Alias for `title`, kept for compatibility with other shortcodes. | + + +**Example 1: `mode="open"` (multiple items can be open) + `separated=true`** + +```md +{{}} + {{}} + This item demonstrates Markdown rendering: + - **Bold text** + - Lists + - `inline code` + {{}} + + {{}} + This item demonstrates shortcode rendering with md=false: + + {{}}This is an inline alert.{{}} + {{}} +{{}} +``` + +{{< accordion mode="open" separated=true >}} + {{< accordionItem title="Markdown example" open=true >}} + This item demonstrates Markdown rendering: + - **Bold text** + - Lists + - `inline code` + {{< /accordionItem >}} + + {{< accordionItem title="Shortcode example" md=false >}} + This item demonstrates shortcode rendering with md=false: + + {{< alert >}}This is an inline alert.{{< /alert >}} + {{< /accordionItem >}} +{{< /accordion >}} + +**Example 2: `mode="collapse"` (only one item open at a time)** + +```md +{{}} + {{}} + This item uses Markdown with a short list: + 1. One + 2. Two + 3. Three + {{}} + + {{}} + This item includes another shortcode: + {{}}Tip{{}} + {{}} +{{}} +``` + +{{< accordion mode="collapse" >}} + {{< accordionItem title="First item" open=true >}} + This item uses Markdown with a short list: + 1. One + 2. Two + 3. Three + {{< /accordionItem >}} + + {{< accordionItem title="Second item" md=false >}} + This item includes another shortcode: + {{< badge >}}Tip{{< /badge >}} + {{< /accordionItem >}} +{{< /accordion >}}


diff --git a/layouts/shortcodes/accordion.html b/layouts/shortcodes/accordion.html new file mode 100644 index 00000000..14ff2d79 --- /dev/null +++ b/layouts/shortcodes/accordion.html @@ -0,0 +1,46 @@ +{{ $id := delimit (slice "accordion" (partial "functions/uid.html" .)) "-" }} +{{ $mode := .Get "mode" | default "collapse" }} +{{ $separated := .Get "separated" | default false }} +{{ $isSeparated := or (eq $separated true) (eq $separated "true") }} + +
+ {{- .Inner -}} +
+{{ if $isSeparated }} + +{{ else }} + +{{ end }} +{{ if eq $mode "collapse" }} + +{{ end }} diff --git a/layouts/shortcodes/accordionItem.html b/layouts/shortcodes/accordionItem.html new file mode 100644 index 00000000..22a53f28 --- /dev/null +++ b/layouts/shortcodes/accordionItem.html @@ -0,0 +1,31 @@ +{{ $parent := .Parent }} +{{ $separated := false }} +{{ if $parent }} + {{ $separated = $parent.Get "separated" | default false }} +{{ end }} +{{ $isSeparated := or (eq $separated true) (eq $separated "true") }} + +{{ $title := .Get "title" | default (.Get "header") }} +{{ $md := .Get "md" | default true }} +{{ $open := .Get "open" | default false }} +{{ $isOpen := or (eq $open true) (eq $open "true") }} + +
+ + {{ $title }} + + {{ partial "icon" "chevron-down" }} + + +
+ {{ if $md }} + {{- .Inner | markdownify -}} + {{ else }} + {{- .Inner -}} + {{ end }} +
+