Class: Panda::Core::Admin::CalloutComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/panda/core/admin/callout_component.rb

Overview

Lightweight callout for inline notices (info, warning, success, error). Intended for static, in-form guidance (not toast/flash).

Constant Summary

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text: nil, title: nil, kind: :info, icon: nil, **attrs) ⇒ CalloutComponent

Returns a new instance of CalloutComponent.



9
10
11
12
13
14
15
# File 'app/components/panda/core/admin/callout_component.rb', line 9

def initialize(text: nil, title: nil, kind: :info, icon: nil, **attrs)
  @text = text
  @title = title
  @kind = kind
  @icon = icon
  super(**attrs)
end

Instance Attribute Details

#iconObject (readonly)

Returns the value of attribute icon.



17
18
19
# File 'app/components/panda/core/admin/callout_component.rb', line 17

def icon
  @icon
end

#kindObject (readonly)

Returns the value of attribute kind.



17
18
19
# File 'app/components/panda/core/admin/callout_component.rb', line 17

def kind
  @kind
end

#textObject (readonly)

Returns the value of attribute text.



17
18
19
# File 'app/components/panda/core/admin/callout_component.rb', line 17

def text
  @text
end

#titleObject (readonly)

Returns the value of attribute title.



17
18
19
# File 'app/components/panda/core/admin/callout_component.rb', line 17

def title
  @title
end

Instance Method Details

#default_attrsObject



19
20
21
22
23
# File 'app/components/panda/core/admin/callout_component.rb', line 19

def default_attrs
  {
    class: "rounded-2xl border px-4 py-3 text-sm #{tone_classes}"
  }
end

#default_iconObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/components/panda/core/admin/callout_component.rb', line 29

def default_icon
  case kind
  when :success
    "fa-circle-check"
  when :warning
    "fa-triangle-exclamation"
  when :error, :alert
    "fa-circle-xmark"
  else
    "fa-circle-info"
  end
end

#icon_classObject



25
26
27
# File 'app/components/panda/core/admin/callout_component.rb', line 25

def icon_class
  icon || default_icon
end

#tone_classesObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/components/panda/core/admin/callout_component.rb', line 42

def tone_classes
  case kind
  when :success
    "bg-emerald-50 text-emerald-700 border-emerald-200"
  when :warning
    "bg-amber-50 text-amber-700 border-amber-200"
  when :error, :alert
    "bg-rose-50 text-rose-700 border-rose-200"
  else
    "bg-gray-50 text-gray-700 border-gray-200"
  end
end