-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4257 from alphagov/create-priority-block
Add the Card block
- Loading branch information
Showing
14 changed files
with
280 additions
and
8 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@import "govuk_publishing_components/individual_component_support"; | ||
|
||
.app-b-card { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
margin-bottom: govuk-spacing(6); | ||
background-color: govuk-colour("dark-blue"); | ||
color: govuk-colour("white"); | ||
} | ||
|
||
.app-b-card__textbox { | ||
padding: govuk-spacing(6) govuk-spacing(7); | ||
background-color: govuk-colour("dark-blue"); | ||
color: govuk-colour("white"); | ||
} | ||
|
||
.app-b-card__figure { | ||
border-style: solid; | ||
border-width: 0 1px 1px; | ||
border-color: govuk-colour("mid-grey"); | ||
margin: auto 0 0; | ||
background-color: govuk-colour("white"); | ||
} | ||
|
||
.app-b-card__image { | ||
display: block; | ||
width: 100%; | ||
margin: 0; | ||
} | ||
|
||
@include govuk-media-query($media-type: print) { | ||
.app-b-card { | ||
background: none; | ||
padding: 0; | ||
|
||
* { | ||
color: $govuk-print-text-colour !important; // stylelint-disable-line declaration-no-important | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@import "govuk_publishing_components/individual_component_support"; | ||
|
||
@include govuk-media-query($from: desktop) { | ||
.grid-container { | ||
display: grid; | ||
grid-template-columns: repeat(3, 1fr); | ||
gap: govuk-spacing(6); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Block | ||
class BlocksContainer < Block::LayoutBase | ||
alias_method :children, :blocks | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Block | ||
CardImage = Data.define(:alt, :source) | ||
|
||
class Card < Block::Base | ||
attr_reader :image, :card_content | ||
|
||
def initialize(block_hash) | ||
super(block_hash) | ||
|
||
alt, source = data.fetch("image").values_at("alt", "source") | ||
@image = CardImage.new(alt:, source:) | ||
@card_content = BlockFactory.build_all(data.dig("card_content", "blocks")) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Block | ||
class GridContainer < Block::LayoutBase | ||
alias_method :children, :blocks | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="blocks-container"> | ||
<% block.children.each do |child| %> | ||
<%= render "landing_page/blocks/#{child.type}", block: child %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<% | ||
add_view_stylesheet("landing_page/card") | ||
|
||
link_classes = %w(app-b-card__link govuk-link gem-print-link) | ||
%> | ||
|
||
<div class="app-b-card"> | ||
<div class="app-b-card__textbox"> | ||
<% block.card_content.each do |subblock| %> | ||
<%= render "landing_page/blocks/#{subblock.type}", block: subblock, inverse: true %> | ||
<% end %> | ||
</div> | ||
<figure class="app-b-card__figure"> | ||
<%= image_tag(block.image.source, alt: block.image.alt, class: "app-b-card__image") %> | ||
</figure> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<% | ||
add_view_stylesheet("landing_page/grid") | ||
%> | ||
|
||
<div class="grid-container"> | ||
<% block.children.each do |child| %> | ||
<%= render "landing_page/blocks/#{child.type}", block: child %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
RSpec.describe Block::Card do | ||
let(:blocks_hash) do | ||
{ "type" => "card", | ||
"image" => { | ||
"alt" => "some alt text", | ||
"source" => "landing_page/placeholder/chart.png", | ||
}, | ||
"card_content" => { | ||
"blocks" => [ | ||
{ "type" => "govspeak", "content" => "<h2>Title</h2>" }, | ||
{ "type" => "govspeak", "content" => "<p>Some content!</p>" }, | ||
], | ||
} } | ||
end | ||
|
||
describe "#image" do | ||
it "returns the properties of the image" do | ||
result = described_class.new(blocks_hash).image | ||
expect(result.alt).to eq "some alt text" | ||
expect(result.source).to eq "landing_page/placeholder/chart.png" | ||
end | ||
end | ||
|
||
describe "#card_content" do | ||
it "returns an array of instantiated blocks" do | ||
result = described_class.new(blocks_hash).card_content | ||
expect(result.size).to eq 2 | ||
expect(result.first.data).to eq("type" => "govspeak", "content" => "<h2>Title</h2>") | ||
expect(result.second.data).to eq("type" => "govspeak", "content" => "<p>Some content!</p>") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters