Module: Iron::UiHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/iron/ui_helper.rb

Constant Summary collapse

FIELD_TYPE_BADGE_CLASSES =
{
  "stone" => "badge-stone",
  "indigo" => "badge-indigo",
  "amber" => "badge-amber",
  "sky" => "badge-sky",
  "green" => "badge-green",
  "orange" => "badge-orange",
  "violet" => "badge-violet",
  "cyan" => "badge-cyan"
}.freeze

Instance Method Summary collapse

Instance Method Details

#back_button_to(title, url, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/iron/ui_helper.rb', line 3

def back_button_to(title, url, options = {}, &)
  link_to url,
    class: tw(
      "inline-flex items-center gap-2 text-sm/6 text-stone-500 dark:text-stone-400",
      options.delete(:class)
    ) do
    safe_join([
      icon("chevron-left", class: "size-4"),
      tag.span(title)
    ])
  end
end

#badge(content = nil, **options, &block) ⇒ Object



16
17
18
19
20
# File 'app/helpers/iron/ui_helper.rb', line 16

def badge(content = nil, **options, &block)
  tag.span class: tw("badge", options.delete(:class)), **options do
    block_given? ? capture(&block) : content
  end
end

#field_type_badge(field_definition) ⇒ Object



50
51
52
53
# File 'app/helpers/iron/ui_helper.rb', line 50

def field_type_badge(field_definition)
  meta = field_type_meta(field_definition)
  badge field_definition.humanized_type, class: FIELD_TYPE_BADGE_CLASSES[meta[:color]]
end

#field_type_meta(field_definition) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/iron/ui_helper.rb', line 22

def field_type_meta(field_definition)
  case field_definition.type_handle
  when "text_field"     then { icon: "type",         color: "stone" }
  when "text_area"      then { icon: "text",         color: "stone" }
  when "rich_text_area" then { icon: "text-quote",   color: "indigo" }
  when "number"         then { icon: "hash",         color: "amber" }
  when "file"           then { icon: "file",         color: "sky" }
  when "boolean"        then { icon: "toggle-right", color: "green" }
  when "date"           then { icon: "calendar",     color: "orange" }
  when "block"          then { icon: "blocks",       color: "violet" }
  when "block_list"     then { icon: "list",         color: "violet" }
  when "reference"      then { icon: "link",         color: "cyan" }
  when "reference_list" then { icon: "link",         color: "cyan" }
  else                       { icon: "circle-help",  color: "stone" }
  end
end