Class: SourceMonitor::IconComponent

Inherits:
ApplicationComponent show all
Defined in:
app/components/source_monitor/icon_component.rb

Constant Summary collapse

ICONS =

SVG path data for each registered icon. Each entry is an array of hashes with :d (path data) and optional per-path attributes like :fill, :stroke, etc.

{
  menu_dots: {
    view_box: "0 0 20 20",
    fill: "currentColor",
    paths: [
      { d: "M10 3a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM10 8.5a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM11.5 15.5a1.5 1.5 0 1 0-3 0 1.5 1.5 0 0 0 3 0Z" }
    ]
  },
  refresh: {
    view_box: "0 0 24 24",
    fill: "none",
    stroke: "currentColor",
    stroke_width: "1.5",
    paths: [
      { d: "M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99",
        stroke_linecap: "round", stroke_linejoin: "round" }
    ]
  },
  chevron_down: {
    view_box: "0 0 20 20",
    fill: "currentColor",
    paths: [
      { d: "M5.23 7.21a.75.75 0 0 1 1.06.02L10 11.168l3.71-3.938a.75.75 0 1 1 1.08 1.04l-4.25 4.5a.75.75 0 0 1-1.08 0l-4.25-4.5a.75.75 0 0 1 .02-1.06z",
        fill_rule: "evenodd", clip_rule: "evenodd" }
    ]
  },
  external_link: {
    view_box: "0 0 24 24",
    fill: "none",
    stroke: "currentColor",
    stroke_width: "2",
    paths: [
      { d: "M13.5 6H5.25A2.25 2.25 0 003 8.25v10.5A2.25 2.25 0 005.25 21h10.5A2.25 2.25 0 0018 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25",
        stroke_linecap: "round", stroke_linejoin: "round" }
    ]
  },
  spinner: {
    view_box: "0 0 24 24",
    fill: "none",
    spinner: true,
    elements: [
      { type: :circle, class: "opacity-25", cx: "12", cy: "12", r: "10",
        stroke: "currentColor", stroke_width: "4" },
      { type: :path, class: "opacity-75", fill: "currentColor",
        d: "M4 12a8 8 0 0 1 8-8v4a4 4 0 0 0-4 4H4z" }
    ]
  }
}.freeze
SIZE_CLASSES =
{
  sm: "h-4 w-4",
  md: "h-5 w-5",
  lg: "h-6 w-6"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(name, size: :md, css_class: nil) ⇒ IconComponent

Returns a new instance of IconComponent.



62
63
64
65
66
# File 'app/components/source_monitor/icon_component.rb', line 62

def initialize(name, size: :md, css_class: nil)
  @name = name.to_sym
  @size = size&.to_sym
  @css_class = css_class
end

Instance Method Details

#callObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/components/source_monitor/icon_component.rb', line 68

def call
  icon = ICONS[@name]
  return "".html_safe unless icon

  size_cls = @size ? SIZE_CLASSES.fetch(@size, SIZE_CLASSES[:md]) : nil
  classes = [ size_cls, @css_class ].compact.join(" ")

  if icon[:spinner]
    render_spinner(icon, classes)
  else
    render_standard(icon, classes)
  end
end