| 1 |
{{- /* |
| 2 |
Renders an HTML details element. |
| 3 |
|
| 4 |
@param {string} [class] The value of the element's class attribute. |
| 5 |
@param {string} [name] The value of the element's name attribute. |
| 6 |
@param {string} [summary] The content of the child summary element. |
| 7 |
@param {string} [title] The value of the element's title attribute. |
| 8 |
@param {bool} [open=false] Whether to initially display the content of the details element. |
| 9 |
|
| 10 |
@reference https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details |
| 11 |
|
| 12 |
@examples |
| 13 |
|
| 14 |
{{< details >}} |
| 15 |
A basic collapsible section. |
| 16 |
{{< /details >}} |
| 17 |
|
| 18 |
{{< details summary="Custom Summary Text" >}} |
| 19 |
Showing custom `summary` text. |
| 20 |
{{< /details >}} |
| 21 |
|
| 22 |
{{< details summary="Open Details" open=true >}} |
| 23 |
Contents displayed initially by using `open`. |
| 24 |
{{< /details >}} |
| 25 |
|
| 26 |
{{< details summary="Styled Content" class="my-custom-class" >}} |
| 27 |
Content can be styled with CSS by specifying a `class`. |
| 28 |
|
| 29 |
Target details element: |
| 30 |
|
| 31 |
```css |
| 32 |
details.my-custom-class { } |
| 33 |
``` |
| 34 |
|
| 35 |
Target summary element: |
| 36 |
|
| 37 |
```css |
| 38 |
details.my-custom-class > summary > * { } |
| 39 |
``` |
| 40 |
|
| 41 |
Target inner content: |
| 42 |
|
| 43 |
```css |
| 44 |
details.my-custom-class > :not(summary) { } |
| 45 |
``` |
| 46 |
{{< /details >}} |
| 47 |
|
| 48 |
{{< details summary="Grouped Details" name="my-details" >}} |
| 49 |
Specifying a `name` allows elements to be connected, with only one able to be open at a time. |
| 50 |
{{< /details >}} |
| 51 |
|
| 52 |
*/}} |
| 53 |
|
| 54 |
{{- /* Get arguments. */}} |
| 55 |
{{- $class := or (.Get "class") "" }} |
| 56 |
{{- $name := or (.Get "name") "" }} |
| 57 |
{{- $summary := or (.Get "summary") "Details" }} |
| 58 |
{{- $title := or (.Get "title") "" }} |
| 59 |
{{- $open := false }} |
| 60 |
{{- if in (slice "false" false 0) (.Get "open") }} |
| 61 |
{{- $open = false }} |
| 62 |
{{- else if in (slice "true" true 1) (.Get "open") }} |
| 63 |
{{- $open = true }} |
| 64 |
{{- end }} |
| 65 |
|
| 66 |
{{- /* Render. */}} |
| 67 |
<details |
| 68 |
{{- with $class }} class="{{ . }}" {{- end }} |
| 69 |
{{- with $name }} name="{{ . }}" {{- end }} |
| 70 |
{{- with $open }} open {{- end }} |
| 71 |
{{- with $title }} title="{{ . }}" {{- end -}}> |
| 72 |
<summary>{{ $summary | .Page.RenderString }}</summary> |
| 73 |
{{ .Inner | .Page.RenderString (dict "display" "block") -}} |
| 74 |
</details> |