Class: Primer::BaseComponent

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

Overview

Base component used by other Primer components.

Constant Summary collapse

TEST_SELECTOR_TAG =
:test_selector

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from FetchOrFallbackHelper

#fetch_or_fallback

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(tag:, classes: nil, **args) ⇒ BaseComponent

Returns a new instance of BaseComponent.

Examples:

34|Default

<%= render(Primer::BaseComponent.new(tag: :a, href: "http://www.google.com", mt: 4)) { "Link" } %>

Parameters:

  • tag (Symbol)

    HTML tag name to be passed to tag.send(tag)

  • classes (String) (defaults to: nil)

    CSS class name value to be concatenated with generated Primer CSS classes



14
15
16
17
18
19
20
# File 'app/components/primer/base_component.rb', line 14

def initialize(tag:, classes: nil, **args)
  @tag = tag
  @result = Primer::Classify.call(**args.merge(classes: classes))

  # Filter out Primer keys so they don't get assigned as HTML attributes
  @content_tag_args = add_test_selector(args).except(*Primer::Classify::VALID_KEYS)
end

Instance Method Details

#callObject



22
23
24
# File 'app/components/primer/base_component.rb', line 22

def call
  (@tag, content, **@content_tag_args.merge(@result))
end