Class: Optics::Icon::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/optics/icon/component.rb

Constant Summary collapse

SIZES =
%w[normal large x-large].freeze
WEIGHTS =
%w[light normal semi-bold bold].freeze
EMPHASES =
%w[low normal high].freeze

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

accepts, #class_for, #class_names, #class_names_for, #container_class, #data_for, #data_method, #data_target, #data_values, #identifier, inherited, #initialize, requires

Constructor Details

This class inherits a constructor from Optics::ApplicationViewComponent

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/components/optics/icon/component.rb', line 18

def call
  (
    :span,
    class: classes,
    'aria-label': title,
    title:,
    data:,
    **@attributes.except(:class)
  ) do
    name
  end
end

#classesObject



31
32
33
34
35
36
37
38
39
40
# File 'app/components/optics/icon/component.rb', line 31

def classes
  class_names(
    'material-symbols-outlined',
    @attributes[:class],
    size_class,
    weight_class,
    emphasis_class,
    'icon--filled': filled
  ).join(' ')
end

#emphasis_classObject



54
55
56
57
58
# File 'app/components/optics/icon/component.rb', line 54

def emphasis_class
  return if emphasis == 'normal'

  "icon--#{emphasis}-emphasis"
end

#size_classObject



42
43
44
45
46
# File 'app/components/optics/icon/component.rb', line 42

def size_class
  return if size == 'normal'

  "icon--#{size}"
end

#weight_classObject



48
49
50
51
52
# File 'app/components/optics/icon/component.rb', line 48

def weight_class
  return if weight == 'normal'

  "icon--weight-#{weight}"
end