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.14.5 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.4.1 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.4 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.3.2 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.3.1 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.3 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.2.2 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.2.1 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.2 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.1 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.0.1 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.0 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.13.2 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.13.1 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.13.0 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.16.1 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.16 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.15 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.14 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.12.13 lib/nfg_ui/bootstrap/utilities/wrappable.rb