Skip to content

Commit 625c7d8

Browse files
authored
feat: add attribute support to CTA section (#5723)
* feat: add attribute support to CTA section * chore: bump to v4.39.0
1 parent 786f5ea commit 625c7d8

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vanilla-framework",
3-
"version": "4.38.0",
3+
"version": "4.39.0",
44
"author": {
55
"email": "[email protected]",
66
"name": "Canonical Webteam"

releases.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
- version: 4.39.0
2+
features:
3+
- component: CTA section
4+
url: /docs/patterns/cta-section
5+
status: Updated
6+
notes: Added <code>attrs</code> parameter to the section element.
17
- version: 4.38.0
28
features:
39
- component: Basic section

templates/_macros/vf_cta-section.jinja

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# title_text: H2 title text - optional
1414
# variant: default
1515
# layout: 100
16+
# attrs: A dictionary of attributes to apply to the section element
1617

1718
# Slots:
1819
# cta: The cta link - required
@@ -46,7 +47,7 @@
4647
# description: Paragraph-style (one or more) content below the title - Optional
4748
# cta: Call-to-action block (required)
4849

49-
{%- macro vf_cta_section(title_text, variant='default', layout='100', caller=None) -%}
50+
{%- macro vf_cta_section(title_text, variant='default', layout='100', caller=None, attrs={}) -%}
5051
{% set description_content = caller('description') %}
5152
{% set has_description = description_content|trim|length > 0 %}
5253
{% set cta_content = caller('cta') %}
@@ -88,7 +89,13 @@
8889
{%- endif -%}
8990
{%- endmacro -%}
9091
<hr class="p-rule is-fixed-width u-no-margin--bottom" />
91-
<section class="p-strip is-deep">
92+
<section class="p-strip is-deep {{ attrs.get("class", "") -}}"
93+
{%- for attr, value in attrs.items() -%}
94+
{% if attr != "class" %}
95+
{{ attr }}="{{ value }}"
96+
{%- endif -%}
97+
{%- endfor -%}
98+
>
9299
{%- if layout == "25-75" -%}
93100
<div class="grid-row">
94101
<div class="grid-col-start-large-3 grid-col-9">{{ _cta_variant() }}</div>

templates/docs/examples/patterns/cta-section/default-full-width.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
title_text='The quick brown fox jumps over the lazy dog',
99
variant='default',
1010
layout='100',
11+
attrs={'id': 'full-width-default'}
1112
) -%}
1213
{%- if slot == 'cta' -%}
1314
<a href="#">The quick brown fox jumps over the lazy dog &rsaquo;</a>

templates/docs/patterns/cta-section/index.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,23 @@ The `vf_cta_section` Jinja macro can be used to generate a CTA section pattern.
149149
<code>h2</code> title text
150150
</td>
151151
</tr>
152+
<tr>
153+
<td>
154+
<code>attrs</code>
155+
</td>
156+
<td>
157+
No
158+
</td>
159+
<td>
160+
<code>&lt;Object&gt;</code>
161+
</td>
162+
<td>
163+
<code>N/A</code>
164+
</td>
165+
<td>
166+
Attributes to apply to the CTA section. See <a href="/docs/building-vanilla#attribute-forwarding">attribute forwarding docs</a> for more info.
167+
</td>
168+
</tr>
152169
</tbody>
153170
</table>
154171
</div>

0 commit comments

Comments
 (0)