Class: Primer::OpenProject::PageHeader

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/open_project/page_header.rb,
app/components/primer/open_project/page_header/menu.rb,
app/components/primer/open_project/page_header/title.rb,
app/components/primer/open_project/page_header/dialog.rb

Overview

A ViewComponent PageHeader inspired by the primer react variant

Defined Under Namespace

Classes: Dialog, Menu, Title

Constant Summary collapse

DEFAULT_HEADER_VARIANT =
:medium
HEADER_VARIANT_OPTIONS =
[
  DEFAULT_HEADER_VARIANT,
  :large
].freeze
DEFAULT_BACK_BUTTON_ICON =
"arrow-left"
BACK_BUTTON_ICON_OPTIONS =
[
  DEFAULT_BACK_BUTTON_ICON,
  "chevron-left",
  "triangle-left"
].freeze
DEFAULT_ACTION_SCHEME =
:default
MOBILE_ACTIONS_DISPLAY =
[:flex, :none].freeze
DEFAULT_LEADING_ACTION_DISPLAY =
[:none, :flex].freeze
DEFAULT_BREADCRUMBS_DISPLAY =
[:none, :flex].freeze
[:block, :none].freeze
STATE_DEFAULT =
:show
STATE_EDIT =
:edit
STATE_OPTIONS =
[STATE_DEFAULT, STATE_EDIT].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(mobile_menu_label: I18n.t("label_more"), state: STATE_DEFAULT, **system_arguments) ⇒ PageHeader

Returns a new instance of PageHeader.

Parameters:

  • mobile_menu_label (String) (defaults to: I18n.t("label_more"))

    The tooltip label of the mobile menu

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



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

def initialize(mobile_menu_label: I18n.t("label_more"), state: STATE_DEFAULT, **system_arguments)
  @system_arguments = deny_tag_argument(**system_arguments)
  @mobile_menu_label = mobile_menu_label

  @system_arguments[:tag] = :"page-header"
  @system_arguments[:classes] =
    class_names(
      @system_arguments[:classes],
      "PageHeader"
    )

  @state = fetch_or_fallback(STATE_OPTIONS, state, STATE_DEFAULT)

  @mobile_action_menu = Primer::Alpha::ActionMenu.new(
    display: MOBILE_ACTIONS_DISPLAY,
    anchor_align: :end
  )
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


254
255
256
257
258
259
# File 'app/components/primer/open_project/page_header.rb', line 254

def render?
  raise ArgumentError, "PageHeader needs a title and a breadcrumb. Please use the `with_title` and `with_breadcrumbs` slot" unless breadcrumbs? || Rails.env.production?
  raise ArgumentError, "PageHeader allows only a maximum of 5 actions" if actions.count > 5

  title? && breadcrumbs?
end

#render_mobile_menu?Boolean

Returns:

  • (Boolean)


261
262
263
# File 'app/components/primer/open_project/page_header.rb', line 261

def render_mobile_menu?
  actions.count > 1
end

#show_state?Boolean

Returns:

  • (Boolean)


265
266
267
# File 'app/components/primer/open_project/page_header.rb', line 265

def show_state?
  @state == STATE_DEFAULT
end