Skip to content

Commit

Permalink
Add secondary card option
Browse files Browse the repository at this point in the history
This adds the ability to render a card component using the secondary
styles.
  • Loading branch information
thomasleese committed Oct 17, 2024
1 parent eb3203e commit 5acdab3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/components/app_card_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ class AppCardComponent < ViewComponent::Base
renders_one :heading
renders_one :description

def initialize(colour: nil, link_to: nil)
def initialize(colour: nil, link_to: nil, secondary: false)
super

@link_to = link_to
@colour = colour
@secondary = secondary
end

private
Expand All @@ -43,7 +44,8 @@ def card_classes
"app-card",
("nhsuk-card--feature" if @colour.present?),
("app-card--#{@colour}" if @colour.present?),
("nhsuk-card--clickable" if @link_to.present?)
("nhsuk-card--clickable" if @link_to.present?),
("nhsuk-card--secondary" if @secondary)
].compact.join(" ")
end

Expand Down
6 changes: 6 additions & 0 deletions spec/components/app_card_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@
it { should have_css(".nhsuk-card--feature") }
it { should have_css(".app-card--red") }
end

context "when secondary" do
before { render_inline(described_class.new(secondary: true)) }

it { should have_css(".nhsuk-card--secondary") }
end
end

0 comments on commit 5acdab3

Please sign in to comment.