Sha256: 51a3ccb687c37645074e70eff3cd9f5a53cb561cab58f384238d5f6240891b41

Contents?: true

Size: 1.39 KB

Versions: 40

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module NfgUi
  module Bootstrap
    module Components
      # Bootstrap Nav Component
      # https://getbootstrap.com/docs/4.1/components/navs/
      class NavLink < NfgUi::Bootstrap::Components::Base
        include Bootstrap::Utilities::Activatable
        include Bootstrap::Utilities::Disableable
        include Bootstrap::Utilities::Remotable

        def component_family
          :nav
        end

        def dropdown
          options.fetch(:dropdown, false)
        end

        def href
          options.fetch(:href, nil)
        end

        def tab
          options.fetch(:tab, nil)
        end

        def data
          tab ? super.merge!(toggle: 'tab') : super
        end

        def render
          if dropdown
            NfgUi::Bootstrap::Components::DropdownToggle.new({ body: (block_given? ? yield : body), as: :a, **html_options, theme: nil, nav_link: true }, view_context).render
          else
            super
          end
        end

        private

        def base_element
          :a
        end

        def component_css_class
          'nav-link'
        end

        def non_html_attribute_options
          super.push(:tab, :dropdown)
        end

        def assistive_html_attributes
          return super unless tab
          { role: 'tab', aria: { controls: tab.tr('#', ''), selected: active } }
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
nfg_ui-0.10.6 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.10.5 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.10.4.1 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.10.4 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.10.3 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.10.2 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.10.1 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.10 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.28 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.27 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.26 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.25.1 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.25 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.24.3 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.24.2 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.24.1 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.24 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.23 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.22 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.21 lib/nfg_ui/bootstrap/components/nav_link.rb