Class: Primer::OpenProject::SubHeader

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/open_project/sub_header.rb

Overview

The SubHeader contains specific actions to modify the page content below, e.g a filter button or a create button It should not be used stand alone, but in combination with a PageHeader, either as a direct sibling or as part of a tab content

Defined Under Namespace

Classes: Button, ButtonGroup, Menu, SegmentedControl

Constant Summary collapse

SHOWN_FILTER_TARGET_SELECTOR =
"sub-header.shownItemsOnExpandedFilter"
FILTER_EXPAND_BUTTON_TARGET_SELECTOR =
"sub-header.filterExpandButton"
MOBILE_ACTIONS_DISPLAY =
[:flex, :none].freeze
DESKTOP_ACTIONS_DISPLAY =
[:none, :flex].freeze

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Constants included from AttributesHelper

AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Methods included from AttributesHelper

#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Methods included from ExperimentalSlotHelpers

included

Methods included from ExperimentalRenderHelpers

included

Constructor Details

#initialize(collapsed_search: false, **system_arguments) ⇒ SubHeader

Returns a new instance of SubHeader.

Parameters:

  • collapsed_search (Boolean) (defaults to: false)

    When true, the search bar starts collapsed as an icon button on all screen sizes. Clicking expands it.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'app/components/primer/open_project/sub_header.rb', line 218

def initialize(collapsed_search: false, **system_arguments)
  @collapsed_search = collapsed_search
  @system_arguments = system_arguments
  @system_arguments[:tag] = :"sub-header"

  filter_container_display = collapsed_search ? :none : DESKTOP_ACTIONS_DISPLAY

  @filter_container = Primer::BaseComponent.new(tag: :div,
                                                classes: "SubHeader-filterContainer",
                                                display: filter_container_display,
                                                mr: 2,
                                                data: { targets: SHOWN_FILTER_TARGET_SELECTOR })

  @system_arguments[:classes] = class_names(
    "SubHeader",
    system_arguments[:classes]
  )
end

Instance Method Details

#before_renderObject



237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'app/components/primer/open_project/sub_header.rb', line 237

def before_render
  if quick_filters.any? && filter_button.nil?
    raise ArgumentError, "You must provide a filter_button when using quick_filters."
  end

  if quick_filters.size > 5
    raise ArgumentError, "SubHeader supports a maximum of 5 quick_filters, got #{quick_filters.size}."
  end

  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "SubHeader--emptyLeftPane" => !segmented_control? && !filter_button && !filter_input && quick_filters.empty?
  )
end

#set_as_hidden_filter_target(system_arguments) ⇒ Object



252
253
254
255
# File 'app/components/primer/open_project/sub_header.rb', line 252

def set_as_hidden_filter_target(system_arguments)
  system_arguments[:classes] = class_names(system_arguments[:classes], "SubHeader-hiddenOnExpand")
  system_arguments
end