Sha256: 4d8b74fa211263985cae5ce0980023f673a14ee819159348e333fb0d286a2a41

Contents?: true

Size: 1.14 KB

Versions: 130

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module NfgUi
  module Bootstrap
    module Utilities
      # Allows component to swap out the main component wrapping element (ex. :div vs. :span)
      # Pass in :as -- only unique logic at the moment
      # is converting :link to :a for tag generation
      module Wrappable
        attr_accessor :as

        def utility_initialize
          self.as = options.fetch(:as, automatic_as)
          super
        end

        private

        def assistive_html_attributes
          if as == :button
            super.merge(type: options.fetch(:type, 'button')) # prefer type submit
          else
            super
          end
        end

        def automatic_as
          if href
            :a
          elsif options[:type] == 'submit'
            :button
          else
            default_html_wrapper_element
          end
        end

        # Set default_html_wrapper_element on individual components as needed
        def default_html_wrapper_element
          @default_html_wrapper_element ||= :span
        end

        def non_html_attribute_options
          super.push(:as)
        end
      end
    end
  end
end

Version data entries

130 entries across 130 versions & 1 rubygems

Version Path
nfg_ui-0.12.12 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.11 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.10 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.9 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.8 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.7 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.6 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.5 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.4 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.3 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.2 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.1 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.0.5 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.0.4 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.0.3 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.0.2 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.0.1 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.0 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.11.18 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.11.17 lib/nfg_ui/bootstrap/utilities/wrappable.rb