Class: PhlexKit::Icon

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/icon/icon.rb

Overview

A glyph from the configured icon library (ui.shadcn.com/create's "Icon Library" option): :lucide (default), :tabler, :phosphor, or :remix — set kit-wide via PhlexKit.config.icon_library or per-instance with library:. Names are PhlexKit's canonical semantic set (PhlexKit::Icons.names); unknown names/libraries fail loud (KeyError).

size: emits width/height attributes (default 16, shadcn's size-4); pass size: nil to defer sizing to CSS (existing .pk-x svg { … } rules). Stroke libraries (lucide/tabler) render stroke="currentColor"; fill libraries (phosphor/remix) render fill="currentColor" — both follow text color. Attrs pass through via mix.

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(name, library: nil, size: 16, **attrs) ⇒ Icon

Returns a new instance of Icon.



14
15
16
17
18
19
# File 'app/components/phlex_kit/icon/icon.rb', line 14

def initialize(name, library: nil, size: 16, **attrs)
  @name = name
  @library = library
  @size = size
  @attrs = attrs
end

Instance Method Details

#view_templateObject



21
22
23
24
25
26
# File 'app/components/phlex_kit/icon/icon.rb', line 21

def view_template
  icon = Icons.fetch(@name, library: @library || PhlexKit.config.icon_library)
  svg(**mix(base_attrs(icon), @attrs)) do |s|
    icon[:elements].each { |tag, attrs| s.public_send(tag, **attrs) }
  end
end