Module: NfgUi::Components::Traits::Button
- Included in:
- Elements::Button
- Defined in:
- lib/nfg_ui/components/traits/button.rb
Overview
Access to pre-designed Button traits
Constant Summary collapse
- TRAITS =
%i[block close link outlined remote submit].freeze
Instance Method Summary collapse
- #block_trait ⇒ Object
- #close_trait ⇒ Object
-
#link_trait ⇒ Object
Link trait has some customizations because it outputs a button without button styles (useful for spacing) which makes it feel like the following SHOULD work: = ui.nfg :button, :link, :danger, icon: ‘trash-o’ Where it generates a link themed button that also has a color style.
- #outlined_trait ⇒ Object
- #remote_trait ⇒ Object
- #submit_trait ⇒ Object
Instance Method Details
#block_trait ⇒ Object
39 40 41 |
# File 'lib/nfg_ui/components/traits/button.rb', line 39 def block_trait [:block] = true end |
#close_trait ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/nfg_ui/components/traits/button.rb', line 43 def close_trait self.as = :button data[:dismiss] = .delete(:dismiss) [:theme] = nil @css_classes = 'close' @body = '×'.html_safe assistive_html_attributes.merge!(aria: { label: 'close' }) end |
#link_trait ⇒ Object
Link trait has some customizations because it outputs a button without button styles (useful for spacing) which makes it feel like the following SHOULD work:
ui.nfg :button, :link, :danger, icon: ‘trash-o’
Where it generates a link themed button that also has a color style.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nfg_ui/components/traits/button.rb', line 21 def link_trait colors = NfgUi::Components::Traits::Theme::COLOR_TRAITS # Check if we've got any color themes passed through in addition to :link if traits.collect { |t| t.in?(colors) }.any? && traits.include?(:link) # Grab and remove the theme color from traits so it # doesn't override the :link theme # and so that we can apply it to the css. theme_color = traits.delete((traits & colors).first) # Add the text styling to the button's CSS [:class] += " text-#{theme_color}" end # And finally, set the official theme as a link [:theme] = :link end |
#outlined_trait ⇒ Object
61 62 63 |
# File 'lib/nfg_ui/components/traits/button.rb', line 61 def outlined_trait [:outlined] = true end |
#remote_trait ⇒ Object
52 53 54 |
# File 'lib/nfg_ui/components/traits/button.rb', line 52 def remote_trait [:remote] = true end |
#submit_trait ⇒ Object
56 57 58 59 |
# File 'lib/nfg_ui/components/traits/button.rb', line 56 def submit_trait self.as = :button [:type] = 'submit' end |