Module: Barnardos::RubyDesignSystem::ComponentHelper
- Included in:
- BarnardosDesignSystemHelper
- Defined in:
- lib/barnardos/ruby_design_system/component_helper.rb
Overview
Provides helper methods available in the host app’s server.
Usage: Add the following to /app/helpers/application_helper.rb within the module ApplicationHelper:
include Barnardos::RubyDesignSystem::ComponentHelper
Instance Method Summary collapse
-
#fieldset(legend: nil, hint: nil) ⇒ String
Creates a FieldSet Component around passed in block.
-
#link(name = nil, options = nil, html_options = {}, &block) ⇒ String
Creates a Link Component.
-
#link_to(name = nil, options = nil, html_options = {}, &block) ⇒ String
Overrides the Rails helper method
link_toAdds thehtml_optionsoptionnew_windowwhich changes the link so that it will link to a new window. -
#prominent_link(name = nil, options = nil, html_options = {}, &block) ⇒ String
Creates a ProminentLink Component.
-
#skip_link(text, anchor: '#main-anchor') ⇒ String
Creates a SkipLink Component.
Instance Method Details
#fieldset(legend: nil, hint: nil) ⇒ String
Creates a FieldSet Component around passed in block. Also adds Fieldset-children inner wrapper around block
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/barnardos/ruby_design_system/component_helper.rb', line 55 def fieldset(legend: nil, hint: nil) content_tag :fieldset, class: 'Fieldset' do concat(content_tag(:legend, legend, class: 'Fieldset-legend')) if legend concat( content_tag(:div, class: 'Fieldset-children') do concat(content_tag(:p, hint, class: 'Hint')) if hint concat(yield) end ) end end |
#link(name = nil, options = nil, html_options = {}, &block) ⇒ String
Creates a Link Component
All parameters are as link_to see Rails API
37 38 39 40 |
# File 'lib/barnardos/ruby_design_system/component_helper.rb', line 37 def link(name = nil, = nil, = {}, &block) [:class] = [[:class], 'Link'].flatten.compact link_to(name, , , &block) end |
#link_to(name = nil, options = nil, html_options = {}, &block) ⇒ String
Overrides the Rails helper method link_to Adds the html_options option new_window which changes the link so that it will link to a new window
45 46 47 48 |
# File 'lib/barnardos/ruby_design_system/component_helper.rb', line 45 def link_to(name = nil, = nil, = {}, &block) [:target] = '_blank' if .delete(:new_window) super end |
#prominent_link(name = nil, options = nil, html_options = {}, &block) ⇒ String
Creates a ProminentLink Component.
17 18 19 20 21 22 |
# File 'lib/barnardos/ruby_design_system/component_helper.rb', line 17 def prominent_link(name = nil, = nil, = {}, &block) colour = .delete(:colour) colour_class = colour && "ProminentLink--#{colour}" [:class] = [[:class], 'ProminentLink', colour_class].flatten.compact link_to(name, , , &block) end |
#skip_link(text, anchor: '#main-anchor') ⇒ String
Creates a SkipLink Component
29 30 31 |
# File 'lib/barnardos/ruby_design_system/component_helper.rb', line 29 def skip_link(text, anchor: '#main-anchor') link_to text, anchor, class: 'SkipLink' end |