Skip to content

Commit

Permalink
Add option to warning text component for no icon
Browse files Browse the repository at this point in the history
  • Loading branch information
andysellick committed Nov 22, 2018
1 parent 4d06a76 commit 2fd3cc4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
@import "helpers/govuk-frontend-settings";
@import "govuk-frontend/components/warning-text/warning-text";

.gem-c-warning-text__text--no-indent {
padding-left: 0;
margin-left: 0;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<%
id ||= "warning-text-#{SecureRandom.hex(4)}"
classes ||= ''
css_classes = %w(gem-c-warning-text govuk-warning-text)
css_classes << classes if classes
text_assistive ||= 'Warning'
text_icon ||= '!'

css_classes = %w(gem-c-warning-text govuk-warning-text)
css_classes << classes if classes
%>

<%= tag.div id: id, class: css_classes do %>
<%= tag.span text_icon, class: "govuk-warning-text__icon", "aria-hidden": "true" %>
<%= tag.strong class: "govuk-warning-text__text" do %>
<% unless text_icon.empty? %>
<%= tag.span text_icon, class: "govuk-warning-text__icon", "aria-hidden": "true" %>
<% end %>
<%= tag.strong class: "govuk-warning-text__text #{'gem-c-warning-text__text--no-indent' if text_icon.empty?}" do %>
<%= tag.span text_assistive, class: "govuk-warning-text__assistive" %>
<%= text %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ examples:
data:
text_icon: "£"
text: "You can be fined up to £5,000 if you don’t register."
without_icon:
data:
text_icon: ""
text: "You can be fined up to £320 if you don't register."
6 changes: 6 additions & 0 deletions spec/components/warning_text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ def component_name
render_component(text_icon: ":(", text: "You can be fined up to £5,000 if you don’t register.")
assert_select(".govuk-warning-text__icon", text: ":(")
end

it "renders no icon" do
render_component(text_icon: "", text: "You can be fined up to £5,000 if you don’t register.")
assert_select(".govuk-warning-text__icon", false)
assert_select(".gem-c-warning-text__text--no-indent", text: /You can be fined up to £5,000 if you don’t register/i)
end
end

0 comments on commit 2fd3cc4

Please sign in to comment.