Skip to content

Commit

Permalink
Move card actions into card body (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood authored Aug 30, 2024
1 parent 1f31d74 commit 930f2bb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
28 changes: 10 additions & 18 deletions src/nationalarchives/components/card/card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,19 @@
&__body {
order: 3;

p {
margin-top: spacing.space(1);
display: flex;
flex-direction: column;

&:first-child {
margin-top: 0;
}
gap: spacing.space(1);

> * {
margin-top: 0;
}
}

&__actions {
display: flex;
gap: spacing.space(1) spacing.space(2);

order: 4;
}

&__action {
Expand All @@ -91,8 +90,7 @@
}

&--padded &__heading,
&--padded &__body,
&--padded &__actions {
&--padded &__body {
padding-right: spacing.space(1);
padding-left: spacing.space(1);
}
Expand All @@ -102,11 +100,10 @@
padding-bottom: 0;

display: grid;
grid-template: min-content min-content 1fr / 50% 50%;
grid-template: min-content 1fr / 50% 50%;
grid-template-areas:
"image header"
"image body"
"image footer";
"image body";
gap: 0;

> * + * {
Expand All @@ -130,8 +127,7 @@
}

&--horizontal &__heading,
&--horizontal &__body,
&--horizontal &__actions {
&--horizontal &__body {
padding-right: spacing.space(2);
padding-left: spacing.space(2);
}
Expand All @@ -152,10 +148,6 @@
&--horizontal &__body {
grid-area: body;
}

&--horizontal &__actions {
grid-area: footer;
}
}

@include colour.on-high-contrast {
Expand Down
10 changes: 5 additions & 5 deletions src/nationalarchives/components/card/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
}
]
},
"html": "<article class=\"tna-card\"><h3 class=\"tna-heading-m tna-card__heading\">Card title</h3><div class=\"tna-card__body\"><p>Card body</p></div><div class=\"tna-card__actions\"><a href=\"#\" class=\"tna-card__action\">Card action</a></div></article>"
"html": "<article class=\"tna-card\"><h3 class=\"tna-heading-m tna-card__heading\">Card title</h3><div class=\"tna-card__body\"><p>Card body</p><div class=\"tna-card__actions\"><a href=\"#\" class=\"tna-card__action\">Card action</a></div></div></article>"
},
{
"name": "with actions with titles",
Expand All @@ -194,7 +194,7 @@
}
]
},
"html": "<article class=\"tna-card\"><h3 class=\"tna-heading-m tna-card__heading\">Card title</h3><div class=\"tna-card__body\"><p>Card body</p></div><div class=\"tna-card__actions\"><a href=\"#\" class=\"tna-card__action\" title=\"Go and do the action\">Card action</a></div></article>"
"html": "<article class=\"tna-card\"><h3 class=\"tna-heading-m tna-card__heading\">Card title</h3><div class=\"tna-card__body\"><p>Card body</p><div class=\"tna-card__actions\"><a href=\"#\" class=\"tna-card__action\" title=\"Go and do the action\">Card action</a></div></div></article>"
},
{
"name": "with actions with classes",
Expand All @@ -210,7 +210,7 @@
}
]
},
"html": "<article class=\"tna-card\"><h3 class=\"tna-heading-m tna-card__heading\">Card title</h3><div class=\"tna-card__body\"><p>Card body</p></div><div class=\"tna-card__actions\"><a href=\"#\" class=\"tna-card__action card__test-class\">Card action</a></div></article>"
"html": "<article class=\"tna-card\"><h3 class=\"tna-heading-m tna-card__heading\">Card title</h3><div class=\"tna-card__body\"><p>Card body</p><div class=\"tna-card__actions\"><a href=\"#\" class=\"tna-card__action card__test-class\">Card action</a></div></div></article>"
},
{
"name": "with actions with attributes",
Expand All @@ -228,7 +228,7 @@
}
]
},
"html": "<article class=\"tna-card\"><h3 class=\"tna-heading-m tna-card__heading\">Card title</h3><div class=\"tna-card__body\"><p>Card body</p></div><div class=\"tna-card__actions\"><a href=\"#\" class=\"tna-card__action\" data-testattribute=\"foobar\">Card action</a></div></article>"
"html": "<article class=\"tna-card\"><h3 class=\"tna-heading-m tna-card__heading\">Card title</h3><div class=\"tna-card__body\"><p>Card body</p><div class=\"tna-card__actions\"><a href=\"#\" class=\"tna-card__action\" data-testattribute=\"foobar\">Card action</a></div></div></article>"
},
{
"name": "with a label",
Expand Down Expand Up @@ -345,7 +345,7 @@
}
]
},
"html": "<article class=\"tna-card\"><h3 class=\"tna-heading-m tna-card__heading\"><a href=\"#\" class=\"tna-card__heading-link\">Card title</a></h3><div class=\"tna-card__body\"><p>Card body</p></div><div class=\"tna-card__actions\"><a href=\"#\" class=\"tna-card__action\">Card action</a></div></article>"
"html": "<article class=\"tna-card\"><h3 class=\"tna-heading-m tna-card__heading\"><a href=\"#\" class=\"tna-card__heading-link\">Card title</a></h3><div class=\"tna-card__body\"><p>Card body</p><div class=\"tna-card__actions\"><a href=\"#\" class=\"tna-card__action\">Card action</a></div></div></article>"
},
{
"name": "with a different element",
Expand Down
20 changes: 10 additions & 10 deletions src/nationalarchives/components/card/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</div>
{%- endif %}
{%- endif %}
{%- if params.meta or params.text or params.body %}
{%- if params.meta or params.text or params.body or params.actions %}
<div class="tna-card__body">
{%- if params.meta %}
<dl class="tna-card__meta tna-dl-chips{{ '' if params.accentMeta else ' tna-dl-chips--plain' }}">
Expand All @@ -86,15 +86,15 @@
{%- else %}
{{ params.body | safe }}
{%- endif %}
</div>
{%- endif %}
{%- if params.actions %}
<div class="tna-card__actions">
{%- for item in params.actions %}
<a href="{{ item.href }}" class="tna-card__action{% if item.classes %} {{ item.classes }}{% endif %}" {%- if item.title %} title="{{ item.title }}"{% endif %} {%- for attribute, value in item.attributes %} {{ attribute }}{% if value !== '' %}="{{ value }}"{% endif %}{% endfor %}>
{{ item.text }}
</a>
{%- endfor %}
{%- if params.actions %}
<div class="tna-card__actions">
{%- for item in params.actions %}
<a href="{{ item.href }}" class="tna-card__action{% if item.classes %} {{ item.classes }}{% endif %}" {%- if item.title %} title="{{ item.title }}"{% endif %} {%- for attribute, value in item.attributes %} {{ attribute }}{% if value !== '' %}="{{ value }}"{% endif %}{% endfor %}>
{{ item.text }}
</a>
{%- endfor %}
</div>
{%- endif %}
</div>
{%- endif %}
</{{ htmlElement }}>

0 comments on commit 930f2bb

Please sign in to comment.