class UiBibz::Ui::Core::Navigations::Nav

Create a nav

This element is an extend of UiBibz::Ui::Core::Component.

Attributes

Options

You can add HTML attributes using the html_options. You can pass arguments in options attribute:

Signatures

UiBibz::Ui::Core::Navigations::Nav.new(content, options = nil, html_options = nil)

UiBibz::Ui::Core::Navigations::Nav.new(options = nil, html_options = nil).tap do |n|
  ...
  n.link content = nil, options = nil, html_options = nil, block
  n.link content = nil, options = nil, html_options = nil, block
  n.dropdown content = nil, options = nil, html_options = nil, block
  ...
end

Examples

UiBibz::Ui::Core::Navigations::Nav.new(type: :pills).tap do |n|
  n.link 'Test', url: '#test'
  n.link 'Test2', url: '#test2', state: :active
  n.dropdown('Action') do |d|
    d.list content = nil, options = nil, html_options = nil, &block
  end
end.render

Helper

nav(options = {}, html_options = {}) do |n|
  n.link(content, options = {}, html_options = {})
  n.link(options = {}, html_options = {}) do
    content
  end
  n.dropdown(name, options = {}, html_options = {}) do |d|
    d.list(content, options = {}, html_options = {})
    d.list(options = {}, html_options = {}) do
      content
    end
  end
end

Public Class Methods

new(content = nil, options = nil, html_options = nil, &block) click to toggle source

See UiBibz::Ui::Core::Component.initialize

Calls superclass method UiBibz::Ui::Core::Component::new
# File lib/ui_bibz/ui/core/navigations/nav.rb, line 73
def initialize(content = nil, options = nil, html_options = nil, &block)
  super
  @items = []
end

Public Instance Methods

dropdown(content = nil, options = {}, html_options = nil, &block) click to toggle source

Add nav dropdown items See UiBibz::Ui::Core::Navigations::NavDropdown

nav(content = nil, options = {}, html_options = nil, &block) click to toggle source

Add nav in nav

pre_render() click to toggle source

Render html tag

# File lib/ui_bibz/ui/core/navigations/nav.rb, line 79
def pre_render
  content_tag htlm_tag, @items.map(&:render).join.html_safe, html_options
end
text(content = nil, options = {}, html_options = nil, &block) click to toggle source
# File lib/ui_bibz/ui/core/navigations/nav.rb, line 96
def text(content = nil, options = {}, html_options = nil, &block)
  block ? content[:nav_type] = type : options[:nav_type] = type
  @items << NavText.new(content, options, html_options, &block)
end

Protected Instance Methods

component_html_classes() click to toggle source
# File lib/ui_bibz/ui/core/navigations/nav.rb, line 114
def component_html_classes
  [nav_class, type, position, stacked, justify, fill]
end
component_html_options() click to toggle source
# File lib/ui_bibz/ui/core/navigations/nav.rb, line 118
def component_html_options
  %i[tabs list].include?(@options[:type]) ? { role: 'tablist' } : super
end
fill() click to toggle source
# File lib/ui_bibz/ui/core/navigations/nav.rb, line 146
def fill
  'nav-fill' if @options[:fill]
end
htlm_tag() click to toggle source
# File lib/ui_bibz/ui/core/navigations/nav.rb, line 154
def htlm_tag
  options[:tag] || tag_type
end
justify() click to toggle source
# File lib/ui_bibz/ui/core/navigations/nav.rb, line 140
def justify
  return unless @options[:justify]

  type == 'nav-links' ? 'nav-justified' : 'nav-fill'
end
nav_class() click to toggle source
nav_tags() click to toggle source
position() click to toggle source
# File lib/ui_bibz/ui/core/navigations/nav.rb, line 131
def position
  case @options[:position]
  when :center
    'justify-content-center'
  when :right
    'justify-content-end'
  end
end
stacked() click to toggle source
# File lib/ui_bibz/ui/core/navigations/nav.rb, line 150
def stacked
  'flex-column' if @options[:stacked]
end
tag_type() click to toggle source
# File lib/ui_bibz/ui/core/navigations/nav.rb, line 162
def tag_type
  case type
  when 'nav-links'
    :nav
  when 'list-group'
    :div
  else
    :ul
  end
end
type() click to toggle source

tabs or pills

# File lib/ui_bibz/ui/core/navigations/nav.rb, line 123
def type
  if @options[:type] == :list
    'list-group'
  else
    "nav-#{@options[:type]}" unless @options[:type].nil?
  end
end