Class: Practical::Views::IconSet

Inherits:
Object
  • Object
show all
Defined in:
app/lib/practical/views/icon_set.rb

Defined Under Namespace

Classes: IconDefinition, Preset, SpritesheetIconDefinition

Constant Summary collapse

PRESETS =
{
  brand: Preset.new(family: :brands, variant: nil),
  duotone: Preset.new(family: :duotone, variant: :solid),
  regular: Preset.new(family: :classic, variant: :regular),
  solid: Preset.new(family: :solid, variant: nil)
}.freeze

Class Method Summary collapse

Class Method Details

.checkbox_indeterminate_iconObject



154
155
156
# File 'app/lib/practical/views/icon_set.rb', line 154

def self.checkbox_indeterminate_icon
  solid_icon(name: :minus, options: {class: "indeterminate-icon"})
end

.define_icons(icon_definitions:) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/lib/practical/views/icon_set.rb', line 38

def self.define_icons(icon_definitions:)
  icon_definitions.each do |icon_definition|
    define_singleton_method(icon_definition.method_name) do |options = {}|
      preset = presets.fetch(icon_definition.preset.to_sym)
      return icon(**options.merge(
        family: preset.family,
        variant: preset.variant,
        name: icon_definition.icon_name
      ))
    end
  end
end

.define_spritesheet_icons(spritesheet_icon_definitions:) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'app/lib/practical/views/icon_set.rb', line 51

def self.define_spritesheet_icons(spritesheet_icon_definitions:)
  spritesheet_icon_definitions.each do |icon_definition|
    define_singleton_method(icon_definition.method_name) do |options = {}|
      return spritesheet_icon(**options.merge(
        library: icon_definition.library,
        name: icon_definition.icon_name
      ))
    end
  end
end

.emergency_passkey_registration_iconObject



158
159
160
161
# File 'app/lib/practical/views/icon_set.rb', line 158

def self.emergency_passkey_registration_icon
  duotone_icon(name: :"light-emergency-on",
               options: {style: "--secondary-color: var(--wa-color-danger-fill-loud); --secondary-opacity: 0.7;"})
end

.error_callout_iconObject



141
142
143
144
145
146
147
148
149
150
# File 'app/lib/practical/views/icon_set.rb', line 141

def self.error_callout_icon
  preset = presets[:solid]

  return icon(
    name: :"circle-exclamation",
    family: preset.family,
    variant: preset.variant,
    options: {slot: :icon}
  )
end

.icon(**options) ⇒ Object



20
21
22
# File 'app/lib/practical/views/icon_set.rb', line 20

def self.icon(**options)
  Practical::Views::IconComponent.new(**options)
end

.presetsObject



16
17
18
# File 'app/lib/practical/views/icon_set.rb', line 16

def self.presets
  PRESETS
end

.profile_iconObject



152
# File 'app/lib/practical/views/icon_set.rb', line 152

def self.profile_icon = badge_icon

.signin_iconObject



163
164
165
166
# File 'app/lib/practical/views/icon_set.rb', line 163

def self.
  duotone_icon(name: :"person-to-portal",
               options: {style: "--secondary-color: var(--wa-color-brand-fill-normal); --secondary-opacity: 0.9;"})
end

.signout_iconObject



168
169
170
171
# File 'app/lib/practical/views/icon_set.rb', line 168

def self.signout_icon
  duotone_icon(name: :"person-from-portal",
               options: {style: "--secondary-color: var(--wa-color-brand-fill-normal); --secondary-opacity: 0.9;"})
end

.spritesheet_icon(library:, **options) ⇒ Object



24
25
26
27
28
29
# File 'app/lib/practical/views/icon_set.rb', line 24

def self.spritesheet_icon(library:, **options)
  Practical::Views::IconComponent.new(**options.with_defaults(
    family: :default,
    options: {library: library}
  ))
end