Sha256: 64ed31e7838744a9d5a4f74a61a817c8311e5376d900d2861ee92dd22ce35eb3
Contents?: true
Size: 1.31 KB
Versions: 10
Compression:
Stored size: 1.31 KB
Contents
# frozen_string_literal: true module ActiveAdmin module Views class Tabs < ActiveAdmin::Component builder_method :tabs def tab(title, options = {}, &block) title = title.to_s.titleize if title.is_a? Symbol @menu << build_menu_item(title, options, &block) @tabs_content << build_content_item(title, options, &block) end def build(attributes = {}, &block) super(attributes) add_class "tabs" @menu = nav(class: "tabs-nav", role: "tablist", "data-tabs-toggle": "#tabs-container-#{object_id}") @tabs_content = div(class: "tabs-content", id: "tabs-container-#{object_id}") end def build_menu_item(title, options, &block) fragment = options.fetch(:id, fragmentize(title)) html_options = options.fetch(:html_options, {}).merge("data-tabs-target": "##{fragment}", role: "tab", "aria-controls": fragment, href: "#") a html_options do title end end def build_content_item(title, options, &block) options = options.reverse_merge(id: fragmentize(title), class: "hidden", role: "tabpanel", "aria-labelledby": "#{title}-tab") div(options, &block) end private def fragmentize(string) "tabs-#{string.parameterize}-#{object_id}" end end end end
Version data entries
10 entries across 10 versions & 1 rubygems