Class: LcpRuby::Display::Renderers::BooleanIcon
- Inherits:
-
BaseRenderer
- Object
- BaseRenderer
- LcpRuby::Display::Renderers::BooleanIcon
- Defined in:
- lib/lcp_ruby/display/renderers/boolean_icon.rb
Overview
Renders a boolean as a glyph (✓ / ✗) wrapped in a Lucide icon placeholder. When the host page loads the Lucide icon library, the ‘<i data-lucide=“check”>` element is replaced with an inline SVG; without Lucide the unicode glyph stays visible — graceful fallback. The visible text label is provided as an `.sr-only` span for screen readers and disabled-image users.
Constant Summary collapse
- DEFAULT_TRUE_GLYPH =
"✓".freeze
- DEFAULT_FALSE_GLYPH =
"✗".freeze
- DEFAULT_TRUE_LUCIDE =
"check".freeze
- DEFAULT_FALSE_LUCIDE =
"x".freeze
Instance Method Summary collapse
Methods inherited from BaseRenderer
Instance Method Details
#render(value, options = {}, record: nil, view_context: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lcp_ruby/display/renderers/boolean_icon.rb', line 16 def render(value, = {}, record: nil, view_context: nil) if ["true_icon"] || ["false_icon"] return render_legacy(value, , view_context) end glyph = value ? DEFAULT_TRUE_GLYPH : DEFAULT_FALSE_GLYPH lucide_name = value ? DEFAULT_TRUE_LUCIDE : DEFAULT_FALSE_LUCIDE css_class = value ? "lcp-bool-true" : "lcp-bool-false" icon_html = view_context.content_tag(:i, glyph, "data-lucide" => lucide_name, "aria-hidden" => "true", class: "lcp-bool-glyph") label_html = view_context.content_tag(:span, bool_label(value), class: "sr-only") view_context.content_tag(:span, icon_html + label_html, class: css_class) end |