Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up card styling #8

Merged
merged 4 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion kmicms/core/blocks/elements.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Any

from django.core.exceptions import ValidationError
from wagtail import blocks
from wagtail.images.blocks import ImageChooserBlock

Expand Down Expand Up @@ -33,7 +36,6 @@ class Meta:

class CallToActionBlock(blocks.StructBlock):
label = blocks.CharBlock()
link = blocks.PageChooserBlock()
style = blocks.ChoiceBlock(
choices=[
("primary", "Primary"),
Expand All @@ -46,15 +48,25 @@ class CallToActionBlock(blocks.StructBlock):
("dark", "Dark"),
]
)
link = blocks.PageChooserBlock(required=False, label="Internal Link")
external_link = blocks.URLBlock(required=False, label="External Link")

class Meta:
template = "core/blocks/elements/call-to-action.html"
help_text = "bees"

def clean(self, value: Any) -> Any:
result = super().clean(value)
if not (bool(result["link"]) ^ bool(result["external_link"])):
raise ValidationError("Please add either an internal or external link.")
return result


class CardBlock(blocks.StructBlock):
image = ImageChooserBlock()
title = blocks.TextBlock()
text = blocks.RichTextBlock()
cta_list = blocks.ListBlock(CallToActionBlock(), label="Calls to Action")

class Meta:
label = "Card"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load wagtailcore_tags %}
<a class="btn btn-{{ value.style }} ms-2 me-2" href="{% pageurl value.link %}">
<a class="btn btn-{{ value.style }} me-2" href="{% if value.link %}{% pageurl value.link %}{% else %}{{ value.external_link }}{% endif %}">
{{ value.label }}
</a>
4 changes: 2 additions & 2 deletions kmicms/core/templates/core/blocks/elements/card-grid.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% load wagtailcore_tags %}
<div class="row row-cols-1 {{ value.grid_class }} g-4">
<div class="row row-cols-1 card-grid {{ value.grid_class }} g-4">
{% for card in value.card_list %}
<div class="col">
<div class="col d-flex align-items-stretch">
{% include_block card %}
</div>
{% endfor %}
Expand Down
3 changes: 3 additions & 0 deletions kmicms/core/templates/core/blocks/elements/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<div class="card-body">
<h5 class="card-title">{{ value.title }}</h5>
<p class="card-text">{{ value.text|richtext}}</p>
{% for cta in value.cta_list %}
{% include_block cta %}
{% endfor %}
</div>
</div>
1 change: 1 addition & 0 deletions kmicms/static/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

// Sections
@import "./sections/auth-panel";
@import "./sections/card-grid";
@import "./sections/masthead";
@import "./sections/showcase";
@import "./sections/testimonials";
Expand Down
13 changes: 13 additions & 0 deletions kmicms/static/css/sections/_card-grid.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Card Grid
//

.card-grid {
.card-img, .card-img-top, .card-img-bottom {
margin-left: auto;
margin-right: auto;
max-height: 6rem;
max-width: 100%;
padding: 1rem;
}
}
Loading