Skip to content

Commit 4756666

Browse files
committed
Add new styled page links blocks for blog index
1 parent 363a425 commit 4756666

File tree

11 files changed

+139
-8
lines changed

11 files changed

+139
-8
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 5.2.5 on 2025-10-22 09:34
2+
3+
from django.db import migrations
4+
5+
import tbx.core.utils.fields
6+
7+
8+
class Migration(migrations.Migration):
9+
dependencies = [
10+
("blog", "0030_adds_introduction_field"),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name="blogindexpage",
16+
name="page_links",
17+
field=tbx.core.utils.fields.StreamField(
18+
blank=True, block_lookup={}, help_text="Add up to 3 styled page links."
19+
),
20+
),
21+
]

tbx/blog/models.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from bs4 import BeautifulSoup
2525

26-
from tbx.core.blocks import StoryBlock
26+
from tbx.core.blocks import StoryBlock, StyledPageLinkBlock
2727
from tbx.core.models import BasePage
2828
from tbx.core.utils.fields import StreamField
2929
from tbx.core.utils.models import (
@@ -43,8 +43,18 @@ class BlogIndexPage(BasePage):
4343
blank=True,
4444
)
4545

46+
page_links = StreamField(
47+
[
48+
("styled_page_link", StyledPageLinkBlock()),
49+
],
50+
blank=True,
51+
max_num=3,
52+
help_text="Add up to 3 styled page links.",
53+
)
54+
4655
content_panels = BasePage.content_panels + [
4756
FieldPanel("introduction"),
57+
FieldPanel("page_links"),
4858
]
4959

5060
@cached_property

tbx/core/blocks.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,33 @@ def text(self):
4848
return page.title
4949

5050

51+
class StyledPageLinkBlock(blocks.StructBlock):
52+
"""
53+
A styled page link block with optional title and style choices.
54+
"""
55+
56+
class StyleChoice(models.TextChoices):
57+
CHARITY = "charity", "Charity"
58+
PUBLIC = "public", "Public"
59+
WAGTAIL = "wagtail", "Wagtail"
60+
61+
page = blocks.PageChooserBlock()
62+
title = blocks.CharBlock(
63+
required=False,
64+
help_text="Optional custom title. If not provided, the page title will be used.",
65+
)
66+
style = blocks.ChoiceBlock(
67+
choices=StyleChoice.choices,
68+
default=StyleChoice.CHARITY,
69+
help_text="Choose the visual style for this link.",
70+
)
71+
72+
class Meta:
73+
icon = "link"
74+
label = "Styled Page Link"
75+
template = "patterns/molecules/streamfield/blocks/styled_page_link_block.html"
76+
77+
5178
class InternalLinkBlock(blocks.StructBlock):
5279
page = blocks.PageChooserBlock()
5380
link_text = blocks.CharBlock(required=False)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% load wagtailcore_tags %}
2+
3+
<a href="{% pageurl value.page %}" class="contact-cta__button button styled-page-link--{{ value.style }}">
4+
{% if value.title %}
5+
{{ value.title }}
6+
{% else %}
7+
{{ value.page.title }}
8+
{% endif %}
9+
</a>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
context:
2+
value:
3+
page:
4+
title: Charity
5+
url: '#'
6+
title: Charity
7+
style: charity
8+
9+
tags:
10+
pageurl:
11+
value.page:
12+
raw: '#'

tbx/project_styleguide/templates/patterns/molecules/title-filters/title-filters.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ <h1 class="heading heading--mega">{{ item.title }}</h1>
1111
</div>
1212
{% endif %}
1313

14+
{% if page_links %}
15+
<div class="styled-page-links">
16+
{% for block in page_links %}
17+
{% include_block block %}
18+
{% endfor %}
19+
</div>
20+
{% endif %}
21+
1422
{% if tags and not hide_tags %}
1523
<div class="title-filters__tags">
1624
<div class="tags">

tbx/project_styleguide/templates/patterns/pages/blog/blog_listing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{% block content %}
1212
<div class="grid grid--spacer-large">
1313

14-
{% include "patterns/molecules/title-filters/title-filters.html" with item=page tags=tags introduction=page.introduction %}
14+
{% include "patterns/molecules/title-filters/title-filters.html" with item=page tags=tags introduction=page.introduction page_links=page.page_links %}
1515

1616
<ul class="page-listing page-listing--blog">
1717
{% for post in blog_posts %}

tbx/static_src/sass/components/_four-photo-collage.scss

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@
4444
grid-template-columns:
4545
minmax(100px, 200px) minmax(60px, 120px) minmax(210px, 420px)
4646
minmax(320px, 640px);
47-
grid-template-rows: minmax(180px, 360px) minmax(230px, 460px) minmax(
48-
40px,
49-
80px
50-
);
47+
grid-template-rows:
48+
minmax(180px, 360px) minmax(230px, 460px)
49+
minmax(40px, 80px);
5150
gap: $spacer-mini-plus;
5251
// ensures the individual images remain at the correct aspect ratio
5352
aspect-ratio: 7 / 4;

tbx/static_src/sass/components/_grid.scss

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
margin: 0 auto;
99

1010
@include media-query(large) {
11-
grid-template-columns: $grid-gutters-large repeat(12, 1fr) $grid-gutters-large;
11+
grid-template-columns:
12+
$grid-gutters-large repeat(12, 1fr)
13+
$grid-gutters-large;
1214
}
1315

1416
@include media-query(x-large) {
15-
grid-template-columns: $grid-gutters-x-large repeat(12, 1fr) $grid-gutters-x-large;
17+
grid-template-columns:
18+
$grid-gutters-x-large repeat(12, 1fr)
19+
$grid-gutters-x-large;
1620
}
1721

1822
&--spacer-large {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@use 'config' as *;
2+
3+
.styled-page-links {
4+
display: flex;
5+
flex-wrap: wrap;
6+
gap: $spacer-mini;
7+
margin-bottom: $spacer-small;
8+
9+
@include media-query(large) {
10+
margin-bottom: $spacer-medium;
11+
}
12+
}
13+
14+
// Style variations for the contact-cta__button button
15+
.styled-page-link--charity {
16+
&:hover,
17+
&:focus {
18+
background-color: $color--coral;
19+
color: var(--color--background);
20+
border-color: $color--coral;
21+
}
22+
}
23+
24+
.styled-page-link--public {
25+
&:hover,
26+
&:focus {
27+
background-color: $color--nebuline;
28+
color: var(--color--background);
29+
border-color: $color--nebuline;
30+
}
31+
}
32+
33+
.styled-page-link--wagtail {
34+
&:hover,
35+
&:focus {
36+
background-color: $color--lagoon;
37+
color: var(--color--background);
38+
border-color: $color--lagoon;
39+
}
40+
}

0 commit comments

Comments
 (0)