Module: Lookbook::UiElementsHelper
- Included in:
- BaseComponent, TagComponent
- Defined in:
- lib/lookbook/helpers/ui_elements_helper.rb
Overview
Helpers for rendering UI elements.
These are available for use in documentation page templates and custom preview inspector panel templates.
Instance Method Summary collapse
-
#code(language = :html, **opts, &block) ⇒ Object
Display a syntax-highlighted block of code.
-
#icon(name, **opts) ⇒ Object
Render an icon.
- #lookbook_render(ref, **attrs, &block) ⇒ Object private
- #lookbook_tag(tag = :div, **attrs, &block) ⇒ Object private
- #prose(**opts, &block) ⇒ Object private
Instance Method Details
#code(language = :html, **opts, &block) ⇒ Object
Display a syntax-highlighted block of code.
An alternative to using markdown code blocks for templates that have markdown parsing disabled, or for when more control is required.
32 33 34 35 |
# File 'lib/lookbook/helpers/ui_elements_helper.rb', line 32 def code(language = :html, **opts, &block) opts[:language] ||= language lookbook_render :code, **opts, &block end |
#icon(name, **opts) ⇒ Object
Render an icon.
Lookbook uses icons from the [Lucide Icons](lucide.dev/) set and a full list of available icon names can be found on that site.
20 21 22 |
# File 'lib/lookbook/helpers/ui_elements_helper.rb', line 20 def icon(name, **opts) lookbook_render(:icon, name: name, **opts) end |
#lookbook_render(ref, **attrs, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lookbook/helpers/ui_elements_helper.rb', line 48 def lookbook_render(ref, **attrs, &block) comp = if ref.is_a? ViewComponent::Base ref else klass = component_class(ref) attrs.key?(:content) ? klass.new(**attrs.except(:content)).with_content(attrs[:content]) : klass.new(**attrs) end if block && !attrs.key?(:content) public_send render_method_name, comp, &block else public_send render_method_name, comp end end |
#lookbook_tag(tag = :div, **attrs, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 |
# File 'lib/lookbook/helpers/ui_elements_helper.rb', line 43 def lookbook_tag(tag = :div, **attrs, &block) lookbook_render(:tag, tag: tag, **attrs, &block) end |
#prose(**opts, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 |
# File 'lib/lookbook/helpers/ui_elements_helper.rb', line 38 def prose(**opts, &block) lookbook_render(:prose, **opts, &block) end |