Class: Lookbook::BaseComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Lookbook::BaseComponent
- Includes:
- ClassNamesHelper, UiElementsHelper
- Defined in:
- app/components/lookbook/base_component.rb
Direct Known Subclasses
Button::Component, ButtonGroup::Component, Code::Component, CopyButton::Component, DebugMenu::Component, DimensionsDisplay::Component, Editor::Component, Embed::Component, Embed::Inspector::Component, EmbedCodeDropdown::Component, Field::Component, FileSource::Component, Filter::Component, Header::Component, Icon::Component, IconButton::Component, InspectorPanel::Component, Logo::Component, Message::Component, Nav::Component, Nav::Item::Component, PageTabs::Component, Prose::Component, SplitLayout::Component, TabPanels::Component, TabPanels::Panel::Component, Tabs::Component, Tabs::DropdownTab::Component, Tabs::Tab::Component, TextButton::Component, Toolbar::Component, Viewport::Component
Instance Method Summary collapse
- #component_name ⇒ Object
-
#initialize(alpine_data: [], **html_attrs) ⇒ BaseComponent
constructor
A new instance of BaseComponent.
- #render_component_tag(tag = :div, **attrs, &block) ⇒ Object
Methods included from ClassNamesHelper
#build_tag_values, #class_names
Methods included from UiElementsHelper
#code, #icon, #lookbook_render, #lookbook_tag, #prose
Constructor Details
#initialize(alpine_data: [], **html_attrs) ⇒ BaseComponent
Returns a new instance of BaseComponent.
7 8 9 10 11 |
# File 'app/components/lookbook/base_component.rb', line 7 def initialize(alpine_data: [], **html_attrs) @alpine_data ||= alpine_data @html_attrs = html_attrs @html_attrs[:class] = {"#{@html_attrs[:class]}": true} if @html_attrs[:class].is_a? String end |
Instance Method Details
#component_name ⇒ Object
23 24 25 |
# File 'app/components/lookbook/base_component.rb', line 23 def component_name self.class.name.chomp("::Component").delete_prefix("Lookbook::").underscore.tr("/", "_").tr("_", "-") end |
#render_component_tag(tag = :div, **attrs, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'app/components/lookbook/base_component.rb', line 13 def render_component_tag(tag = :div, **attrs, &block) merged_classes = class_names(attrs[:class], @html_attrs[:class]) merged_attrs = @html_attrs.except(:class).deep_merge(attrs.except(:class)) lookbook_tag tag, name: component_name, **merged_attrs, "x-data": prepare_alpine_data(merged_attrs[:"x-data"]), class: merged_classes, &block end |