Class: Ariadne::BaseComponent
Overview
Direct Known Subclasses
Ariadne::Behaviors::Caption, Ariadne::Behaviors::Tooltip, ConditionalWrapper, Form::BaseComponent, Form::BaseInputComponent, Form::ToggleGroup::Component, Form::ToggleGroup::Option::Component, Layout::Grid::Component, Layout::Grid::Item::Component, Layout::LabelBlock::Component, Layout::Narrow::Component, Layout::NavBar::Component, Layout::SectionBlock::Component, Layout::SectionBlock::Header::Component, Layout::TwoPanel::Component, Layout::Wide::Component, Turbo::Frame::Component, Turbo::StreamAction::Component, UI::Accordion::Component, UI::Accordion::Item::Component, UI::Avatar::Component, UI::Badge::Component, UI::Blankslate::Component, UI::Button::Component, UI::Card::Body::Component, UI::Card::Component, UI::Card::Footer::Component, UI::Card::Header::Component, UI::ColorDot::Component, UI::Combobox::Component, UI::DataTable::Component, UI::Dialog::Component, UI::Flash::Component, UI::Heroicon::Component, UI::Image::Component, UI::Link::Component, UI::List::Component, UI::List::Item::Component, UI::Overlay::Component, UI::Pagination::Component, UI::Popover::Component, UI::Shortcut::Component, UI::Skeleton::Component, UI::StatsPanel::Component, UI::StatsPanel::Item::Component, UI::Table::Cell::Component, UI::Table::Component, UI::Table::Footer::Component, UI::Table::Header::Component, UI::Table::Row::Component, UI::TimeAgo::Component, UI::Typography::Component
Constant Summary
collapse
- ACCEPT_ANYTHING =
lambda { |static_content = nil, &block|
next static_content if static_content.present?
view_context.capture { block&.call }
}
Constants included
from ViewHelper
ViewHelper::HELPERS
AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from ViewHelper
generate_id
#aria, #data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes, #prepend_action, #prepend_controller, #prepend_data_attribute
#merged_styles
Class Method Details
.component_id(&block) ⇒ Object
44
45
46
|
# File 'app/components/ariadne/base_component.rb', line 44
def component_id(&block)
@component_id ||= block || proc { self.class.component_name.delete_prefix("ui/").gsub(/[^a-z0-9]+/, "-") }
end
|
.component_name ⇒ Object
40
41
42
|
# File 'app/components/ariadne/base_component.rb', line 40
def component_name
@component_name ||= name.sub(/::Component$/, "").underscore
end
|
.i18n_scope ⇒ Object
53
54
55
|
# File 'app/components/ariadne/base_component.rb', line 53
def i18n_scope
@i18n_scope ||= component_name.split("/")
end
|
.stimulus_name ⇒ Object
48
49
50
51
|
# File 'app/components/ariadne/base_component.rb', line 48
def stimulus_name
@stimulus_name ||= component_name.gsub(/[^a-z0-9]+/, "-")
end
|
.translate(key, scope: nil, **options) ⇒ Object
57
58
59
|
# File 'app/components/ariadne/base_component.rb', line 57
def translate(key, scope: nil, **options)
I18n.t(key, **options, scope: [*i18n_scope, *Array.wrap(scope)])
end
|
Instance Method Details
#class_for(name) ⇒ Object
77
78
79
80
81
82
83
|
# File 'app/components/ariadne/base_component.rb', line 77
def class_for(name)
modulename = self.class.name.split("::")[1...-1].join("--").downcase
"ariadne-#{modulename}-#{name}"
end
|
#component(name) ⇒ Object
Support relative component names within components
65
66
67
68
69
70
71
|
# File 'app/components/ariadne/base_component.rb', line 65
def component(name, ...)
return super unless name.starts_with?(".")
full_name = Pathname.new(File.join(self.class.component_name, name)).cleanpath.to_s
super(full_name, ...)
end
|
#component_id ⇒ Object
73
74
75
|
# File 'app/components/ariadne/base_component.rb', line 73
def component_id
@component_id ||= instance_eval(&self.class.component_id)
end
|
#html_attributes ⇒ Object
97
98
99
|
# File 'app/components/ariadne/base_component.rb', line 97
def html_attributes
tag.attributes(html_attrs.except(:class))
end
|
#in_turbo_frame(**options) ⇒ Object
85
86
87
|
# File 'app/components/ariadne/base_component.rb', line 85
def in_turbo_frame(**options)
Ariadne::Turbo::Frame::Component.new(component: self, **options)
end
|
#in_turbo_stream(action: "update", **options) ⇒ Object
89
90
91
|
# File 'app/components/ariadne/base_component.rb', line 89
def in_turbo_stream(action: "update", **options)
Ariadne::Turbo::StreamAction::Component.new(component: self, action: action, **options)
end
|
#options ⇒ Object
93
94
95
|
# File 'app/components/ariadne/base_component.rb', line 93
def options
@options ||= self.class.dry_initializer.attributes(self)
end
|
#styles ⇒ Object
101
102
|
# File 'app/components/ariadne/base_component.rb', line 101
def styles
end
|
#validate_aria_label!(html_attrs) ⇒ Object
104
105
106
107
108
|
# File 'app/components/ariadne/base_component.rb', line 104
def validate_aria_label!(html_attrs)
aria_label = aria(html_attrs, "label")
aria_labelledby = aria(html_attrs, "labelledby")
raise ArgumentError, "`aria-label` or `aria-labelledby` is required." if aria_label.blank? && aria_labelledby.blank?
end
|