Module: Protege::Components::BadgesHelper
- Included in:
- ComponentsHelper
- Defined in:
- app/helpers/protege/components/badges_helper.rb
Overview
Compact status indicators: the pill badge and the labelled status_dot. Both take a semantic
color and resolve it through the badge_colors / dot_colors maps defined alongside them, so the
palette lives with the components that use it.
Instance Method Summary collapse
-
#badge(text, color = :gray) ⇒ ActiveSupport::SafeBuffer
Render a small pill badge tinted by semantic color.
-
#badge_colors(color) ⇒ Array(nil, String)
Map a semantic badge color to its
[background, foreground]classes. -
#dot_colors(color) ⇒ String
Map a semantic status color to its dot background class.
-
#status_dot(text, color = :gray) ⇒ ActiveSupport::SafeBuffer
Render a colored status dot followed by its label.
Instance Method Details
#badge(text, color = :gray) ⇒ ActiveSupport::SafeBuffer
Render a small pill badge tinted by semantic color.
14 15 16 17 18 |
# File 'app/helpers/protege/components/badges_helper.rb', line 14 def badge(text, color = :gray) _, fg = badge_colors(color) tag.span(text, class: "inline-flex items-center rounded px-1.5 py-0.5 text-xs font-medium #{fg}", style: 'background: var(--surface-subtle); border: 1px solid var(--border)') end |
#badge_colors(color) ⇒ Array(nil, String)
Map a semantic badge color to its [background, foreground] classes.
24 25 26 27 28 29 30 31 |
# File 'app/helpers/protege/components/badges_helper.rb', line 24 def badge_colors(color) case color when :green then [nil, 'text-green-600'] when :red then [nil, 'text-red-600'] when :yellow then [nil, 'text-yellow-600'] else [nil, ''] end end |
#dot_colors(color) ⇒ String
Map a semantic status color to its dot background class.
49 50 51 52 53 54 55 56 |
# File 'app/helpers/protege/components/badges_helper.rb', line 49 def dot_colors(color) case color when :green then 'bg-green-600' when :red then 'bg-red-600' when :yellow then 'bg-yellow-600' else 'bg-gray-500' end end |
#status_dot(text, color = :gray) ⇒ ActiveSupport::SafeBuffer
Render a colored status dot followed by its label.
38 39 40 41 42 43 |
# File 'app/helpers/protege/components/badges_helper.rb', line 38 def status_dot(text, color = :gray) dot_color = dot_colors(color) tag.span(class: 'inline-flex items-center gap-1.5 text-xs', style: 'color: var(--text-muted)') do tag.span('', class: "h-1.5 w-1.5 rounded-full #{dot_color}") + text end end |