Sha256: b0d0a82d58a92c3cd14ddb3b07cd4bee01e4f954a7f1e562125617d138841b9d
Contents?: true
Size: 970 Bytes
Versions: 1
Compression:
Stored size: 970 Bytes
Contents
# frozen_string_literal: true require "active_support/concern" module Primer # Helper to share tab validation logic between components. # The component will raise an error if there are 0 or 2+ selected tabs. module TabbedComponentHelper extend ActiveSupport::Concern class MultipleSelectedTabsError < StandardError; end def before_render validate_single_selected_tab unless Rails.env.production? end private def navigation_tag(with_panel) with_panel ? :div : :nav end def wrapper(with_panel:, **system_arguments) return yield unless with_panel render Primer::TabContainerComponent.new(**system_arguments) do yield if block_given? end end def validate_single_selected_tab raise MultipleSelectedTabsError, "only one tab can be selected" if selected_tabs_count > 1 end def selected_tabs_count @selected_tabs_count ||= tabs.count(&:selected) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
primer_view_components-0.0.54 | app/lib/primer/tabbed_component_helper.rb |