-
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.
Use component wrapper in hint component
This adds the component wrapper to the hint component in order to provide additional options to a hint. The primary motivation of this was that we want to dynamically change the value of a hint in GOV.UK Chat and thus want to set a .js-class to act as a selector [1] (private repo) and instead are using a custom id to work around it. Looking at other components it seemed that using the component wrapper was a more conventional approach than just utilising the shared helper to add only classes. [1]: alphagov/govuk-chat#660 (comment)
- Loading branch information
Showing
4 changed files
with
26 additions
and
7 deletions.
There are no files selected for viewing
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
13 changes: 6 additions & 7 deletions
13
app/views/govuk_publishing_components/components/_hint.html.erb
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 |
---|---|---|
@@ -1,18 +1,17 @@ | ||
<% | ||
add_gem_component_stylesheet("hint") | ||
|
||
id ||= "hint-#{SecureRandom.hex(4)}" | ||
local_assigns[:id] ||= "hint-#{SecureRandom.hex(4)}" | ||
is_radio_label_hint ||= false | ||
right_to_left ||= false | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns) | ||
|
||
css_classes = %w( gem-c-hint govuk-hint ) | ||
css_classes << "govuk-radios__hint" if is_radio_label_hint | ||
|
||
custom_margin_bottom_class = shared_helper.get_margin_bottom if [*0..9].include?(local_assigns[:margin_bottom]) | ||
css_classes << custom_margin_bottom_class if local_assigns[:margin_bottom] | ||
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns) | ||
component_helper.add_class("gem-c-hint govuk-hint") | ||
component_helper.add_class("govuk-radios__hint") if is_radio_label_hint | ||
component_helper.add_class(shared_helper.get_margin_bottom) if [*0..9].include?(local_assigns[:margin_bottom]) | ||
%> | ||
<%= tag.div id: id, class: css_classes, dir: right_to_left ? "rtl" : nil do %> | ||
<%= tag.div(**component_helper.all_attributes, dir: right_to_left ? "rtl" : nil) do %> | ||
<%= text %> | ||
<% 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
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