Class: Primer::OcticonComponent

Inherits:
Component
  • Object
show all
Includes:
OcticonsHelper, ClassNameHelper
Defined in:
app/components/primer/octicon_component.rb

Constant Summary collapse

SIZE_DEFAULT =
:small
SIZE_MAPPINGS =
{
  SIZE_DEFAULT => 16,
  :medium => 32,
  :large => 64,
}.freeze
SIZE_OPTIONS =
SIZE_MAPPINGS.keys

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from ClassNameHelper

#class_names

Methods included from FetchOrFallbackHelper

#fetch_or_fallback

Constructor Details

#initialize(icon:, size: SIZE_DEFAULT, **kwargs) ⇒ OcticonComponent

Returns a new instance of OcticonComponent.



16
17
18
19
20
21
# File 'app/components/primer/octicon_component.rb', line 16

def initialize(icon:, size: SIZE_DEFAULT, **kwargs)
  @icon, @kwargs = icon, kwargs

  @kwargs[:height] = SIZE_MAPPINGS[size.to_sym]
  @kwargs[:class] = class_names(@kwargs[:class], Primer::Classify.call(**@kwargs)[:class])
end

Instance Method Details

#callObject



23
24
25
# File 'app/components/primer/octicon_component.rb', line 23

def call
  octicon(@icon, **@kwargs)
end