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-6.17.2 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-6.17.1 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-6.17.0 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-6.16.3 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-6.16.2 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-6.16.1 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-6.16.0 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-5.15.7 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-5.15.6 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-5.15.5 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-5.15.4 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-5.15.3 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.15.2 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.15.1 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.15.0 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.7 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.6.3 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.6.2 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.6.1 lib/nfg_ui/bootstrap/utilities/wrappable.rb
nfg_ui-0.14.6 lib/nfg_ui/bootstrap/utilities/wrappable.rb