Skip to content

Commit

Permalink
Routes wizard results box (#4472)
Browse files Browse the repository at this point in the history
* recreated results box component and associated styling

* added spec test for results box component

* added results box to completed page of routes wizard

* adjusted media query to improve responsiveness on mobile/tablet

* Fixed spacing

* removed results box from completed page of routes wizard

* fixed indenting on results box css file

---------

Co-authored-by: Spencer Dixon <spencerlloyddixon@gmail.com>
  • Loading branch information
sarahcrack and spencerldixon authored Jan 9, 2025
1 parent 32a854c commit 2bf0f62
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/components/content/results_box_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="results-box-component">
<% if title %>
<div class="results-box__title">
<%= title %>
</div>
<% end %>
<section class="results-box results-box--<%= border_color %>">
<h2 class="results-box__heading">
<%= heading %>
</h2>
<div class="results-box__course-info-container results-box__text">
<div class="results-box__info-row">
<div class="results-box__label">Course fee</div>
<div class="results-box__value"><%= fee %></div>
</div>
<hr>
<div class="results-box__info-row">
<div class="results-box__label">Course length </div>
<div class="results-box__value"><%= course_length %></div>
</div>
<hr>
<div class="results-box__info-row">
<div class="results-box__label">Funding </div>
<div class="results-box__value"><%= funding %></div>
</div>
<hr>
</div>
<div class="results-box__text results-box__full-width-text"><%= text %></div>
<div class="results-box__cta">
<%= render Content::LinkAsButtonComponent.new(link_text: @link_text, href: @link_target) %>
</div>
</section>
</div>
21 changes: 21 additions & 0 deletions app/components/content/results_box_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Content
class ResultsBoxComponent < ViewComponent::Base
attr_reader :title, :heading, :fee, :course_length, :funding, :text, :link_text, :link_target, :border_color

include ContentHelper

def initialize(heading:, fee:, course_length:, funding:, text:, link_text:, link_target:, title: nil, border_color: :grey)
super

@title = substitute_values(title)
@heading = substitute_values(heading)
@fee = substitute_values(fee)
@course_length = substitute_values(course_length)
@funding = substitute_values(funding)
@text = substitute_values(text)
@link_text = link_text
@link_target = link_target
@border_color = border_color
end
end
end
100 changes: 100 additions & 0 deletions app/webpacker/styles/components/results-box.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
.results-box {
background: $white;
color: $white;

&--yellow {
border: 2px solid $yellow;
}

&--grey {
border: 2px solid $grey
}

&__background {
display: none;
padding: 1em;
}

&__title {
background: $yellow;
color: $black;
font-weight: bolder;
display: inline-block;
padding: 0.25em 0.5em;
}

&__heading {
@include font-size("small");
color: $black;
background-color: $white;
line-height: 1.25em;
max-width: 80%;
}

&__text {
@include font-size("small");
color: $black;
background-color: $white;
}

&__course-info-container {
margin-top: 2.5rem;
}

&__info-row {
display: flex;
justify-content: flex-start;
align-items: flex-start;
}

&__label {
flex: 1;
text-align: left;
font-weight: bold;
}

&__value {
flex: 2;
text-align: left;
}

hr {
margin-top: 0.7em;
margin-bottom: 0.5em;
}

&__full-width-text {
padding: 1rem 0;
text-align: left;
margin-top: 1em;
margin-bottom: 1em;
}

&__cta {
margin-top: 1rem;
margin-bottom: 1rem;
}

&__heading,
&__text,
&__cta {
margin-inline: 2rem;
}

@include mq($until: tablet) {
.results-box__info-row {
flex-direction: column;
align-items: flex-start;
}

.results-box__label,
.results-box__value {
flex: none;
width: 100%;
}

.results-box__label {
margin-bottom: 0.25rem;
}
}
}
1 change: 1 addition & 0 deletions app/webpacker/styles/git.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
@import "./components/mailing-list";
@import "./components/purple-box";
@import "./components/feedback";
@import "./components/results-box";

@import "./campaigns/numbered-headings";

Expand Down
52 changes: 52 additions & 0 deletions spec/components/content/results_box_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require "rails_helper"

describe Content::ResultsBoxComponent, type: :component do
subject(:render) do
render_inline(component)
page
end

let(:heading) { "Postgraduate Initial Teacher Training with fees" }
let(:fee) { "Yes" }
let(:course_length) { "9 months (full-time) or up to 2 years (part-time)" }
let(:funding) { "Scholarships or bursaries, as well as student loans, are available if you're eligible" }
let(:text) { "Find out which qualifications you need, what funding you can get and how to train to teach." }
let(:title) { nil }
let(:border_color) { :grey }
let(:link_text) { "Find out more about postgraduate initial teacher training" }
let(:link_target) { "/train-to-be-a-teacher" }

let(:component) do
described_class.new(
heading: heading,
fee: fee,
course_length: course_length,
funding: funding,
text: text,
title: title,
border_color: border_color,
link_text: link_text,
link_target: link_target,
)
end

it { is_expected.to have_css(".results-box .results-box__heading") }
it { is_expected.to have_css(".results-box__full-width-text", text: text) }
it { is_expected.to have_css(".results-box__value", text: fee) }
it { is_expected.to have_css(".results-box__value", text: course_length) }
it { is_expected.to have_css(".results-box__value", text: funding) }
it { is_expected.to have_css(".results-box--grey") }
it { is_expected.to have_no_css(".results-box__title", text: title) }

context "when a title is provided" do
let(:title) { "Most popular route" }

it { is_expected.to have_css(".results-box__title", text: title) }
end

context "when the border color is yellow" do
let(:border_color) { :yellow }

it { is_expected.to have_css(".results-box--yellow") }
end
end

0 comments on commit 2bf0f62

Please sign in to comment.