Class: Primer::OpenProject::InlineMessage

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

Overview

A simple component to render warning text.

The warning text is rendered in the “attention” Primer color and uses a leading alert Octicon for additional emphasis. This component is designed to be used “inline”, e.g. table cells, and in places where a Banner component might be overkill.

Constant Summary collapse

SCHEME_OPTIONS =
SCHEME_ICON_MAPPINGS.keys.freeze
DEFAULT_SIZE =
:medium
SIZE_OPTIONS =
[:small, DEFAULT_SIZE].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(scheme:, size: DEFAULT_SIZE, **system_arguments) ⇒ InlineMessage

Returns a new instance of InlineMessage.

Parameters:

  • scheme (Symbol)

    <%= one_of(Primer::OpenProject::InlineMessage::SCHEME_OPTIONS) %>

  • size (Symbol) (defaults to: DEFAULT_SIZE)

    <%= one_of(Primer::OpenProject::InlineMessage::SIZE_OPTIONS) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/components/primer/open_project/inline_message.rb', line 36

def initialize(scheme:, size: DEFAULT_SIZE, **system_arguments) # rubocop:disable Lint/MissingSuper
  resolved_scheme = fetch_or_fallback(SCHEME_OPTIONS, scheme)
  resolved_size   = fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)

  @system_arguments = system_arguments
  @system_arguments[:tag] ||= :div
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "InlineMessage"
  )
  @system_arguments[:data] = merge_data(
    @system_arguments,
    { data: { size: resolved_size, variant: resolved_scheme } }
  )

  @icon_arguments = { classes: "InlineMessageIcon" }
  if resolved_size == :small
    @icon_arguments[:icon] = SCHEME_SMALL_ICON_MAPPINGS[resolved_scheme]
    @icon_arguments[:size] = :xsmall
  else
    @icon_arguments[:icon] = SCHEME_ICON_MAPPINGS[resolved_scheme]
  end
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/components/primer/open_project/inline_message.rb', line 60

def render?
  content.present?
end