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
Taxonomy List Component #476
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.gem-c-taxonomy-list { | ||
display: flex; | ||
flex-wrap: wrap; | ||
margin-top: $gutter-half; | ||
|
||
@include media(tablet) { | ||
margin-right: -25px; | ||
} | ||
} | ||
|
||
.gem-c-taxonomy-list__item { | ||
list-style: none; | ||
|
||
@include media(tablet) { | ||
@include box-sizing(border-box); | ||
width: 33%; | ||
padding-right: $gutter-one-third; | ||
vertical-align: top; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<% | ||
items ||= [] | ||
within_multitype_list ||= false | ||
within_multitype_list_class = " gem-c-document-list__multi-list" if within_multitype_list | ||
margin_top_class = " gem-c-document-list--top-margin" if local_assigns[:margin_top] | ||
margin_bottom_class = " gem-c-document-list--bottom-margin" if local_assigns[:margin_bottom] | ||
title_with_context_class = " gem-c-document-list__item-title--context" | ||
|
@@ -8,9 +10,11 @@ | |
brand_helper = GovukPublishingComponents::AppHelpers::BrandHelper.new(brand) | ||
%> | ||
<% if items.any? %> | ||
<ol class="gem-c-document-list<%= margin_bottom_class %><%= margin_top_class %> <%= brand_helper.brand_class %>"> | ||
<% unless within_multitype_list %> | ||
<ol class="gem-c-document-list<%= margin_bottom_class %><%= margin_top_class %>"> | ||
<% end %> | ||
<% items.each do |item| %> | ||
<li class="gem-c-document-list__item"> | ||
<li class="gem-c-document-list__item<%= within_multitype_list_class %> <%= brand_helper.brand_class %>"> | ||
<%= | ||
link_to( | ||
item[:link][:text], | ||
|
@@ -45,5 +49,7 @@ | |
<% end %> | ||
</li> | ||
<% end %> | ||
</ol> | ||
<% unless within_multitype_list %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't hugely untidy, so this suggestion may be overkill, but have you considered passing this chunk into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how this would work, can you please give an example? 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking you'd wrap up the code in a block somehow and then do an if statement of some kind of either just output the block or do |
||
</ol> | ||
<% end %> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
<% | ||
items ||= [] | ||
inverse ||= false | ||
within_multitype_list ||= false | ||
inverse_class = "gem-c-highlight-boxes--inverse" if inverse | ||
highlight_boxes_helper = GovukPublishingComponents::Presenters::HighlightBoxesHelper.new(local_assigns) | ||
%> | ||
<% if items.any? %> | ||
<ol class="gem-c-highlight-boxes" <%= "data-module=track-click" if highlight_boxes_helper.data_tracking? %>> | ||
<% unless within_multitype_list %> | ||
<ol class="gem-c-highlight-boxes" <%= "data-module=track-click" if highlight_boxes_helper.data_tracking? %>> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't really part of this PR, but is there a way of writing this line that github will like? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't been able to find much info on this - I tried a few things but nothing seemed to fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. I'll take a look at the rest shortly. |
||
<% end %> | ||
<% items.each do |content_item| %> | ||
<li class="gem-c-highlight-boxes__item-wrapper"> | ||
<div class="gem-c-highlight-boxes__item <%= inverse_class %>"> | ||
|
@@ -35,5 +38,7 @@ | |
</div> | ||
</li> | ||
<% end %> | ||
</ol> | ||
<% unless within_multitype_list %> | ||
</ol> | ||
<% end %> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<% | ||
highlight_box ||= false | ||
document_list ||= false | ||
image_cards ||= false | ||
|
||
highlight_box.merge!({within_multitype_list: true}) if highlight_box | ||
document_list.merge!({within_multitype_list: true}) if document_list | ||
|
||
taxonomy_list_helper = GovukPublishingComponents::Presenters::TaxonomyListHelper.new(image_cards) | ||
%> | ||
<% if highlight_box || document_list || image_cards %> | ||
<ul class="gem-c-taxonomy-list" data-module="track-click"> | ||
<% if image_cards %> | ||
<% taxonomy_list_helper.image_card_data.each do |image_card| %> | ||
<li class="gem-c-taxonomy-list__item"> | ||
<%= render "govuk_publishing_components/components/image_card", image_card %> | ||
</li> | ||
<% end %> | ||
<% end %> | ||
|
||
<% if highlight_box %> | ||
<%= render "govuk_publishing_components/components/highlight_boxes", highlight_box %> | ||
<% end %> | ||
|
||
<% if document_list %> | ||
<%= render "govuk_publishing_components/components/document_list", document_list %> | ||
<% end %> | ||
</ul> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
name: Taxonomy list | ||
description: Wraps the highlight box, document list and image card components in one list. This is commonly used on topic pages for links to tagged content. | ||
body: | | ||
The [highlight box](/component-guide/highlight_boxes), [document list](/component-guide/document_list) and [image card](/component-guide/image_card) components are standalone components. | ||
|
||
However, there are some use cases where we want to use these components together to render one list of links. This is not possible when using the components separately. | ||
This component wraps these components in one list, and applies relevant styling to get them to display appropriately together. | ||
|
||
**Note:** At the moment, this component only works when displaying either highlight box + document list **or** image cards + document list. The layout for combining all three together hasn't been fixed. | ||
accessibility_criteria: | | ||
The taxonomy list should: | ||
|
||
- Wrap all links in one list | ||
- Should not be used to display links that don't belong together in one list | ||
shared_accessibility_criteria: | ||
- link | ||
examples: | ||
default: | ||
data: | ||
highlight_box: | ||
inverse: true | ||
items: | ||
- link: | ||
text: If your child is taken into care | ||
path: /child-into-care | ||
description: Information on what to do if your child is taken into care | ||
metadata: | ||
document_type: Detailed guide | ||
- link: | ||
text: High needs funding | ||
path: /high-needs-funding | ||
metadata: | ||
document_type: Guide | ||
public_updated_at: 2016-06-27 10:29:44 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for testing the layout I'd suggest adding another two |
||
- link: | ||
text: Student Finance | ||
path: /student-finance | ||
description: Student loan information | ||
metadata: | ||
document_type: Detailed guide | ||
- link: | ||
text: If your child is taken into care | ||
path: /child-into-care | ||
description: Information on what to do if your child is taken into care | ||
metadata: | ||
document_type: Detailed guide | ||
document_list: | ||
items: | ||
- link: | ||
text: If your child is taken into care | ||
path: /child-into-care | ||
metadata: | ||
document_type: Detailed guide | ||
- link: | ||
text: High needs funding | ||
path: /high-needs-funding | ||
metadata: | ||
document_type: Guide | ||
with_image_cards: | ||
data: | ||
image_cards: | ||
items: | ||
- link: | ||
path: /not-a-page | ||
text: News headline | ||
heading_level: 0 | ||
image: | ||
url: https://assets.publishing.service.gov.uk/government/uploads/system/uploads/feature/image/62756/s300_courts-of-justice.JPG | ||
alt: some meaningful alt text please | ||
context: The Rt Hon | ||
- link: | ||
path: /not-a-page | ||
text: News headline | ||
heading_level: 0 | ||
image: | ||
url: https://assets.publishing.service.gov.uk/government/uploads/system/uploads/feature/image/62756/s300_courts-of-justice.JPG | ||
alt: some meaningful alt text please | ||
context: The Rt Hon | ||
- link: | ||
path: /not-a-page | ||
text: News headline | ||
heading_level: 0 | ||
image: | ||
url: https://assets.publishing.service.gov.uk/government/uploads/system/uploads/feature/image/62756/s300_courts-of-justice.JPG | ||
alt: some meaningful alt text please | ||
context: The Rt Hon | ||
- link: | ||
path: /not-a-page | ||
text: News headline | ||
heading_level: 0 | ||
image: | ||
url: https://assets.publishing.service.gov.uk/government/uploads/system/uploads/feature/image/62756/s300_courts-of-justice.JPG | ||
alt: some meaningful alt text please | ||
context: The Rt Hon | ||
document_list: | ||
items: | ||
- link: | ||
text: If your child is taken into care | ||
path: /child-into-care | ||
description: What happens if your child is taken into care | ||
metadata: | ||
document_type: Detailed guide | ||
- link: | ||
text: High needs funding | ||
path: /high-needs-funding | ||
metadata: | ||
document_type: Guide | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could there be an example of all three together? Also if we wanted to combine one image card, one highlight box, and a document list, what would it look like - would they all stack? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this doesn't render perfectly at the moment (the highlight boxes end up on the same line as the image cards). I've had a look into this today but it's proving tricky to fix. As we don't need this yet, I'm going to create a separate card so it doesn't block this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you tried applying a class to the last element of each component type to provide (whatever is the flex equivalent of) clearing? Although I've had a quick look and can't see what that might be... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andysellick Yeah, there doesn't seem to be an easy flex equivalent, annoyingly. I got a partial solution, but it then got confusing with different numbers of image cards and on mobile There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. Maybe add a note to the documentation body to point this out until we can get a fix. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module GovukPublishingComponents | ||
module Presenters | ||
class TaxonomyListHelper | ||
def initialize(image_cards) | ||
@image_cards = image_cards | ||
end | ||
|
||
def image_card_data | ||
@image_cards[:items].map do |image_card| | ||
{ | ||
context: image_card[:image][:context], | ||
href: image_card[:link][:path], | ||
heading_text: image_card[:link][:text], | ||
image_src: image_card[:image][:url], | ||
image_alt: image_card[:image][:alt], | ||
heading_level: image_card[:link][:heading_level], | ||
href_data_attributes: (image_card[:link][:data_attributes] if image_card[:link][:data_attributes]) | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just noticed that the right edge of this (the grey dividing border) seems to overlap the page width (although I'm not sure how this will look in production). See below.
Might need to put a margin-right on it of 25px to counter the negative margin on the parent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot, I thought it didn't look quite right! 👍