Skip to content

Commit 4aaf451

Browse files
authored
feat: add id support to patterns (#5703)
* feat: add title ID to basic section pattern * feat: add title ID to pricing block pattern * feat: add title ID to equal heights pattern * feat: add id support to basic section, pricing block and equal heights patterns * feat: add id to section attrs * feat: add id as pricing block attrs * feat: add id attrs to equal height pattern * Address code comments
1 parent 2929c62 commit 4aaf451

File tree

16 files changed

+104
-7
lines changed

16 files changed

+104
-7
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.37.2",
3+
"version": "4.38.0",
44
"author": {
55
"email": "webteam@canonical.com",
66
"name": "Canonical Webteam"

releases.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
- version: 4.38.0
2+
features:
3+
- component: Basic section
4+
url: /docs/patterns/basic-section
5+
status: Updated
6+
notes: Added <code>attrs</code> parameter to the section element.
7+
- component: Pricing block
8+
url: /docs/patterns/pricing-block
9+
status: Updated
10+
notes: Added <code>attrs</code> parameter to the section element.
11+
- component: Equal heights
12+
url: /docs/patterns/equal-heights
13+
status: Updated
14+
notes: Added <code>attrs</code> parameter to the section element.
115
- version: 4.37.0
216
features:
317
- component: Icon

templates/_macros/vf_basic-section.jinja

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,16 @@
300300
# padding: Type of padding to apply to the pattern - "deep", "shallow", "default" (default is "default").
301301
# is_split_on_medium: Boolean to indicate if the section should be split on medium screens (default is false).
302302
# top_rule_variant: Type of HR to render at the top of the pattern. "default" | "muted" (default is "default").
303+
# attrs: A dictionary of attributes to apply to the section element.
303304
{% macro vf_basic_section(
304305
title={},
305306
label_text="",
306307
subtitle={},
307308
items=[],
308309
padding="default",
309310
is_split_on_medium=false,
310-
top_rule_variant="default"
311+
top_rule_variant="default",
312+
attrs={}
311313
) -%}
312314

313315
{%- set padding = padding | trim -%}
@@ -330,7 +332,13 @@
330332
{%- set has_label = label_text|length > 0 -%}
331333
{%- set has_subtitle = subtitle_text|length > 0 -%}
332334

333-
<section class="{{ padding_classes }}">
335+
<section class="{{ padding_classes }} {{ attrs.get("class", "") -}}"
336+
{%- for attr, value in attrs.items() -%}
337+
{% if attr != "class" %}
338+
{{ attr }}="{{ value }}"
339+
{%- endif -%}
340+
{%- endfor -%}
341+
>
334342
<div class="grid-row--50-50{%- if not is_split_on_medium -%}-on-large{%- endif -%}">
335343
{{ vf_section_top_rule(top_rule_variant) }}
336344
<div class="grid-col">

templates/_macros/vf_equal-heights.jinja

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{#-
22
Params
33
- title_text (string) (required): The text to be displayed as the heading
4+
- attrs (dictionary) (optional): A dictionary of attributes to apply to the equal heights pattern.
45
- subtitle_text (string) (optional): The text to be displayed as the subtitle
56
- subtitle_heading_level (int) (optional): The heading level for the subtitle. Can be 4 or 5. Defaults to 5.
67
- highlight_images (boolean) (optional): If the images need to be highlighted, which means adding a subtle grey background. Not added by default.
@@ -11,6 +12,7 @@
1112
-#}
1213
{%- macro vf_equal_heights(
1314
title_text,
15+
attrs={},
1416
subtitle_text="",
1517
subtitle_heading_level=5,
1618
highlight_images=false,
@@ -31,7 +33,13 @@
3133
{% set subtitle_heading_level=5 %}
3234
{%- endif -%}
3335

34-
<div class="p-section">
36+
<div class="p-section {{ attrs.get("class", "") -}}"
37+
{%- for attr, value in attrs.items() -%}
38+
{% if attr != "class" %}
39+
{{ attr }}="{{ value }}"
40+
{%- endif -%}
41+
{%- endfor -%}
42+
>
3543
<hr class="p-rule is-fixed-width"/>
3644
<div class="p-section--shallow">
3745
{%- if has_two_top_cols -%}

templates/_macros/vf_pricing-block.jinja

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Params
33
- title_text (string) (required): The text to be displayed as the heading
44
- top_rule_variant (string) (optional): Variant of the top rule, default is "default". Options are "muted", "highlighted", "default", "none".
5+
- attrs (dictionary) (optional): A dictionary of attributes to apply to the Pricing block section.
56
- tiers (Array<{
67
tier_name_text: String (optional),
78
tier_price_text: String,
@@ -20,6 +21,7 @@
2021
{%- macro vf_pricing_block(
2122
top_rule_variant="default",
2223
title_text="",
24+
attrs={},
2325
tiers=[]
2426
) -%}
2527
{% set top_rule_variant = top_rule_variant | trim %}
@@ -86,7 +88,13 @@
8688
<hr class="p-rule{% if top_rule_variant != 'default' %}--{{ rule_class }}{% endif %} is-fixed-width" />
8789
{% endif %}
8890
{%- endmacro -%}
89-
<div class="p-section">
91+
<div class="p-section {{ attrs.get("class", "") -}}"
92+
{%- for attr, value in attrs.items() -%}
93+
{% if attr != "class" %}
94+
{{ attr }}="{{ value }}"
95+
{%- endif -%}
96+
{%- endfor -%}
97+
>
9098
{{ _top_rule() }}
9199
<div class="grid-row">
92100
<div class="grid-col-4 grid-col-medium-4 grid-col-small-4">

templates/docs/examples/patterns/basic-section/mixed-content.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@
124124
}
125125
}
126126
}
127-
]
127+
],
128+
attrs= {"id": "mixed-content-section"}
128129
) }}
129130

130131
{% endblock %}

templates/docs/examples/patterns/equal-heights/2-columns-responsive.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
{% call(slot) vf_equal_heights(
1010
title_text="Keep this heading to 2 lines on large screens.",
11+
attrs={ "id": "2-columns-responsive" },
1112
subtitle_text="Ensure the right hand side of this 50/50 split is taller than the left hand side (heading) on its left. This includes the subtitle and description.",
1213
items=[
1314
{

templates/docs/examples/patterns/equal-heights/3-columns-responsive.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
{% call(slot) vf_equal_heights(
1010
title_text="Keep this heading to 2 lines on large screens.",
11+
attrs={ "id": "3-columns-responsive" },
1112
subtitle_text="Ensure the right hand side of this 50/50 split is taller than the left hand side (heading) on its left. This includes the subtitle and description.",
1213
items=[
1314
{

templates/docs/examples/patterns/equal-heights/4-columns-responsive.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
{% call(slot) vf_equal_heights(
1010
title_text="Keep this heading to 2 lines on large screens.",
11+
attrs={ "id": "4-columns-responsive" },
1112
subtitle_text="Ensure the right hand side of this 50/50 split is taller than the left hand side (heading) on its left. This includes the subtitle and description.",
1213
items=[
1314
{

templates/docs/examples/patterns/pricing-block/1-block.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{% block content %}
66
{% call(slot) vf_pricing_block(
77
title_text='Kubernetes pricing',
8+
attrs={"id": "1-block"},
89
tiers=[
910
{
1011
'tier_name_text': 'Kubernetes Explorer',

0 commit comments

Comments
 (0)