Skip to content

Commit 2946581

Browse files
Merge pull request #5744 from canonical/WD-33048
feat(Logo section): Support block level usage
2 parents ad94436 + fa18247 commit 2946581

File tree

7 files changed

+199
-21
lines changed

7 files changed

+199
-21
lines changed

releases.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
- version: 4.40.0
2+
features:
3+
- component: Logo section
4+
url: /docs/patterns/logo-section
5+
status: Updated
6+
notes: Added a new <code>mode</code> parameter. Updated <code>padding</code> and <code>top_rule_variant</code> parameters.
7+
- component: Logo block
8+
url: /docs/patterns/logo-block
9+
status: Deprecated
10+
notes: Logo block is now deprecated in favor of the <a href="/docs/patterns/logo-section#full-vs-minimal-mode">Logo section</a> pattern.
111
- version: 4.39.0
212
features:
313
- component: CTA section

templates/_macros/vf_logo-section.jinja

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,24 @@
2929
- title (object) (required): A dictionary with the title configuration.
3030
- text (string) (required): The text to be displayed as the title.
3131
- link_attrs (object) (optional): A dictionary of link attributes for the title.
32-
- padding (string) (optional): Type of padding to apply. Options are "deep", "default". Default is "default".
32+
- padding (string) (optional): Type of padding to apply. Options are "deep", "default", "none". Default is "default".
3333
- blocks (array<object>) (required): List of blocks to be displayed in the section. Supported block types include:
3434
- cta-block: Configuration for a call-to-action block.
3535
- logo-block: Configuration for a logo block. Must include:
3636
- item.logos (array): A list of logos to display.
37-
37+
- top_rule_variant (string) (optional): The variant of the top rule to apply. Options are "default", "none". Default is "default".
38+
- mode (string) (optional): The layout mode. Allowed values: "default" or "minimal".
39+
"default": renders a <section> as the root element, and includes title, description and cta (suitable when used standalone).
40+
"minimal": renders a <div> as the root element, and does not render title, description and cta (suitable when used inside another section).
41+
3842
Slots
3943
- description (optional): Paragraph-style content displayed below the title. Can include one or more paragraphs.
4044
#}
41-
{%- macro vf_logo_section(title, padding="regular", blocks=[], caller=None) -%}
45+
{%- macro vf_logo_section(title, padding="default", blocks=[], top_rule_variant="default", mode="default", caller=None) -%}
4246
{% set description_content = caller('description') %}
4347
{% set has_description = description_content|trim|length > 0 %}
4448
{%- set padding = padding | trim -%}
45-
{%- if padding not in ["deep", "default"] -%}
49+
{%- if padding not in ["deep", "default", "none"] -%}
4650
{%- set padding = "default" -%}
4751
{%- endif -%}
4852
{%- if padding == "default" -%}
@@ -52,6 +56,14 @@
5256
{%- endif -%}
5357
{%- set cta_block = blocks | selectattr("type", "equalto", "cta-block") | first -%}
5458
{%- set logo_block = blocks | selectattr("type", "equalto", "logo-block") | first -%}
59+
{%- set top_rule_variant = top_rule_variant | trim -%}
60+
{%- if top_rule_variant not in ["default", "none"] -%}
61+
{%- set top_rule_variant = "default" -%}
62+
{%- endif -%}
63+
{%- set mode = mode | trim -%}
64+
{%- if mode not in ["default", "minimal"] -%}
65+
{%- set mode = "default" -%}
66+
{%- endif -%}
5567
{%- macro _title_block(title={}) -%}
5668
<h2 class="p-text--small-caps">
5769
{%- if "link_attrs" in title and "href" in title.get("link_attrs", {}) -%}
@@ -68,15 +80,27 @@
6880
{%- macro _description_block() -%}
6981
{% if has_description %}{{ description_content | safe }}{% endif %}
7082
{%- endmacro -%}
71-
<section class="{{ padding_classes }}">
72-
<hr class="p-rule is-fixed-width" />
73-
<div class="grid-row--50-50">
74-
<div class="grid-col">{{- _title_block(title) -}}</div>
75-
<div class="grid-col">
76-
{{- _description_block() -}}
77-
{% if cta_block %}{{- basic_section_item(cta_block) -}}{% endif %}
83+
84+
{%- set rootElement = "div" if mode == "minimal" else "section" -%}
85+
86+
<{{ rootElement }}{%- if padding != 'none' %} class="{{ padding_classes }}"{% endif %}>
87+
{%- if mode == "default" -%}
88+
{%- if top_rule_variant == "default" -%}
89+
<hr class="p-rule is-fixed-width" />
90+
{%- endif -%}
91+
<div class="grid-row--50-50">
92+
{%- if title and title.get('text') -%}
93+
<div class="grid-col">{{- _title_block(title) -}}</div>
94+
{%- endif -%}
95+
{%- if has_description or cta_block -%}
96+
<div class="grid-col">
97+
{{- _description_block() -}}
98+
{% if cta_block %}{{- basic_section_item(cta_block) -}}{% endif %}
99+
</div>
100+
{%- endif -%}
78101
</div>
79-
</div>
102+
{%- endif -%}
103+
80104
{{- _logo_block(logo_block) -}}
81-
</section>
105+
</{{ rootElement }}>
82106
{%- endmacro -%}

templates/docs/examples/patterns/logo-section/combined.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
<section>
2222
{% include 'docs/examples/patterns/logo-section/padding-variants.html' %}
2323
</section>
24+
<section>
25+
{% include 'docs/examples/patterns/logo-section/minimal.html' %}
26+
</section>
2427
{% endwith %}
2528
{% endblock %}

templates/docs/examples/patterns/logo-section/default.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{% set is_paper = true %}
66
{% block content %}
77
{% call(slot) vf_logo_section(
8+
mode="default",
89
title={
910
"text": "The quick brown fox jumps over the lazy dog"
1011
},
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{% extends "_layouts/examples.html" %}
2+
{% from "_macros/vf_logo-section.jinja" import vf_logo_section %}
3+
{% block title %}Logo section / Minimal mode{% endblock %}
4+
{% block standalone_css %}patterns_all{% endblock %}
5+
{% set is_paper = true %}
6+
{% block content %}
7+
{% call(slot) vf_logo_section(
8+
mode="minimal",
9+
blocks=[
10+
{
11+
"type": "logo-block",
12+
"item": {
13+
"logos": [
14+
{
15+
"src": "https://assets.ubuntu.com/v1/38fdfd23-Dell-logo.png",
16+
"alt": "Dell Technologies"
17+
},
18+
{
19+
"src": "https://assets.ubuntu.com/v1/cd5f636a-hp-logo.png",
20+
"alt": "Hewlett Packard"
21+
},
22+
{
23+
"src": "https://assets.ubuntu.com/v1/f90702cd-lenovo-logo.png",
24+
"alt": "Lenovo"
25+
},
26+
{
27+
"src": "https://assets.ubuntu.com/v1/2ef3c028-amazon-web-services-logo.png",
28+
"alt": "Amazon Web Services"
29+
},
30+
{
31+
"src": "https://assets.ubuntu.com/v1/cb7ef8ac-ibm-cloud-logo.png",
32+
"alt": "IBM Cloud"
33+
},
34+
{
35+
"src": "https://assets.ubuntu.com/v1/210f44e4-microsoft-azure-new-logo.png",
36+
"alt": "Microsoft Azure"
37+
},
38+
{
39+
"src": "https://assets.ubuntu.com/v1/a554a818-google-cloud-logo.png",
40+
"alt": "Google Cloud Platform"
41+
},
42+
{
43+
"src": "https://assets.ubuntu.com/v1/b3e692f4-oracle-new-logo.png",
44+
"alt": "Oracle"
45+
}
46+
]
47+
}
48+
}
49+
]
50+
) -%}
51+
{% endcall -%}
52+
{% endblock %}

templates/docs/patterns/logo-block/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ context:
77
{% from "docs/macros/notice.jinja" import documentation_notice %}
88

99
{{- documentation_notice(
10-
icon_class="p-notification--information",
11-
message_text="Please use this component if you would like to simply display logos within another section, as it should be treated as a building block that can be inserted into other patterns, without needing to include a title. If you would instead like to use a designated logo section with an accompanying heading and optional description, please use the <a href='/docs/patterns/logo-section'>Logo section</a> pattern."
10+
icon_class="p-notification--negative",
11+
message_text="Logo block is now deprecated in favor of the new <a href='/docs/patterns/logo-section'>Logo section</a> pattern."
1212
) }}
1313

1414
The logo block can be used to showcase a group of related images, such as a group of customer or partner logos.

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

Lines changed: 94 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ context:
99

1010
{{- pattern_wip_notice() }}
1111

12-
{{- documentation_notice(
13-
icon_class="p-notification--information",
14-
message_text="Please use this pattern if you would like to use a designated logo section with an accompanying heading and optional description. If you would instead like to simply display logos within another section, please use the <a href='/docs/patterns/logo-block'>Logo block component</a>, which should be treated as a building block that can be inserted into other patterns without needing to include a title."
15-
) }}
16-
1712
The logo section is a pattern where the logo block serves as the main content, combined with a muted heading, optional description, and a CTA block.
1813

1914
It is composed of the following elements:
@@ -151,6 +146,56 @@ View example of the logo section pattern without CTA block
151146
View example of the logo section pattern without description and CTA block
152147
</a></div>
153148

149+
#### Default vs Minimal mode
150+
151+
Use the <code>mode</code> parameter to control how much content the pattern renders. Two modes are supported: "default" and "minimal".
152+
153+
- default
154+
155+
- Renders the title with a top rule, description, CTA, and logo block.
156+
- Renders the root element as a <code>&lt;section&gt;</code>
157+
158+
- minimal
159+
- Renders a compact layout that displays only the logo block.
160+
- Title, description slot and CTA are not rendered (useful inside other patterns or tight page areas).
161+
- Renders the root element as a <code>&lt;div&gt;</code>
162+
163+
Usage
164+
165+
- Add the mode property at the pattern level when invoking the macro.
166+
167+
##### Example: default
168+
169+
```json
170+
{
171+
"title": {"text": "Trusted by organizations worldwide"},
172+
"mode": "default",
173+
"description": "<p>We power the digital services of many public sector organizations.</p>",
174+
"blocks": [
175+
{"type": "logo-block", "item": {"logos": [{"attrs": {"src": "logo.png", "alt": "Org"}}]}},
176+
{"type": "cta-block", "item": {"link": {"content_html": "Learn more", "attrs": {"href": "/about"}}}}
177+
]
178+
}
179+
```
180+
181+
<div class="embedded-example"><a href="/docs/examples/patterns/logo-section/default" class="js-example" data-lang="jinja">
182+
View example of the "default" mode Logo section
183+
</a></div>
184+
185+
##### Example: minimal
186+
187+
```json
188+
{
189+
"title": {"text": "Trusted by organizations worldwide"},
190+
"mode": "minimal",
191+
"blocks": [{"type": "logo-block", "item": {"logos": [{"attrs": {"src": "logo.png", "alt": "Org"}}]}}]
192+
}
193+
```
194+
195+
<div class="embedded-example"><a href="/docs/examples/patterns/logo-section/minimal" class="js-example" data-lang="jinja">
196+
View example of the "minimal" mode Logo section
197+
</a></div>
198+
154199
## Jinja Macro
155200

156201
The `vf_logo_section` Jinja macro can be used to generate a logo section pattern. The API for the macro is shown
@@ -247,7 +292,8 @@ below.
247292
<td>
248293
One of:<br>
249294
<code>'deep'</code>,<br>
250-
<code>'default'</code>
295+
<code>'default'</code>,<br>
296+
<code>'none'</code>
251297
</td>
252298
<td>
253299
<code>'default'</code>
@@ -256,6 +302,48 @@ below.
256302
Padding variant for the entire section
257303
</td>
258304
</tr>
305+
<tr>
306+
<td>
307+
<code>top_rule_variant</code>
308+
</td>
309+
<td>
310+
No
311+
</td>
312+
<td>
313+
One of:<br>
314+
<code>'default'</code>,<br>
315+
<code>'none'</code>
316+
</td>
317+
<td>
318+
<code>'default'</code>
319+
</td>
320+
<td>
321+
Variant of <a href="/docs/patterns/rule">horizontal rule</a> to display at the top of the section."
322+
</td>
323+
</tr>
324+
<tr>
325+
<td>
326+
<code>mode</code>
327+
</td>
328+
<td>
329+
No
330+
</td>
331+
<td>
332+
One of:<br>
333+
<code>'default'</code>,<br>
334+
<code>'minimal'</code>
335+
</td>
336+
<td>
337+
<code>'default'</code>
338+
</td>
339+
<td>
340+
Layout for the pattern.
341+
<ul>
342+
<li>"default": renders a &lt;section&gt; as the root element, and renders title, description and cta (suitable when used standalone).</li>
343+
<li>"minimal": renders a &lt;div&gt; as the root element, and does not render title, description and cta (suitable when used inside another section).</li>
344+
</ul>
345+
</td>
346+
</tr>
259347
</tbody>
260348
</table>
261349
</div>

0 commit comments

Comments
 (0)