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.9.20 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.19.1 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.19 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.18.3 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.18.2 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.18.1 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.18 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.17 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.16 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.15 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.14 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.13 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.12 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.11 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.10 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.9 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.8.18 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.8.17 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.8.16 lib/nfg_ui/bootstrap/components/nav_link.rb
nfg_ui-0.9.8.15 lib/nfg_ui/bootstrap/components/nav_link.rb