Class: HakumiComponents::Tabs::Item::Component
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- HakumiComponents::Tabs::Item::Component
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/tabs/item/component.rb
Constant Summary collapse
- IconValue =
T.type_alias { T.nilable(T.any(Symbol, ViewComponent::Base)) }
Constants inherited from BaseComponent
BaseComponent::ControllerOptions, BaseComponent::DateInput, BaseComponent::DateLikeValue, BaseComponent::DimensionInput, BaseComponent::HtmlPayloadInput, BaseComponent::I18nOptionValue, BaseComponent::PresenceArray, BaseComponent::PresenceScalar, BaseComponent::PresenceValue, BaseComponent::RawHtmlInput, BaseComponent::SIZES, BaseComponent::SizeValue, BaseComponent::SymbolInput
Instance Attribute Summary collapse
-
#closable ⇒ Object
readonly
Returns the value of attribute closable.
-
#close_icon ⇒ Object
readonly
Returns the value of attribute close_icon.
-
#content ⇒ Object
Returns the value of attribute content.
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#force_render ⇒ Object
readonly
Returns the value of attribute force_render.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
- #display_label ⇒ Object
- #icon_component ⇒ Object
-
#initialize(key:, label: nil, icon: nil, disabled: false, closable: false, close_icon: nil, force_render: false, parent: nil, **html_options) ⇒ Component
constructor
A new instance of Component.
- #pane_attributes(active) ⇒ Object
- #pane_classes(active) ⇒ Object
- #render_close_icon ⇒ Object
- #tab_attributes(active) ⇒ Object
- #tab_classes(active) ⇒ Object
Methods inherited from BaseComponent
#append_data_token, boolean_html_param, #build_inline_style, cast_boolean, #cast_boolean, #class_names, #component_classes, #data_attributes_from, #dimension_to_css, #ensure_dom_id!, float_html_param, #generate_id, #html_classes, html_param, html_primitive_param, #html_style, #i18n_scope, integer_html_param, #merge_attributes, #render_value, #size_to_pixels, #stimulus_attrs, string_html_param, string_or_symbol_array_html_param, symbol_html_param, #t_default, #translate_with_default, #validate_inclusion!, #validate_required!, #value_present?
Constructor Details
#initialize(key:, label: nil, icon: nil, disabled: false, closable: false, close_icon: nil, force_render: false, parent: nil, **html_options) ⇒ Component
Returns a new instance of Component.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 25 def initialize( key:, label: nil, icon: nil, disabled: false, closable: false, close_icon: nil, force_render: false, parent: nil, ** ) @key = T.let(key, Types::StringOrSymbol) @label = T.let(label, T.nilable(Types::Renderable)) @icon = T.let(icon, IconValue) @disabled = T.let(disabled, T::Boolean) @closable = T.let(closable, T::Boolean) @close_icon = T.let(close_icon, IconValue) @force_render = T.let(force_render, T::Boolean) @parent = T.let(parent, T.nilable(HakumiComponents::Tabs::Component)) @html_options = T.let(, Types::HtmlAttributes) @content = T.let(nil, Types::RenderedContent) end |
Instance Attribute Details
#closable ⇒ Object (readonly)
Returns the value of attribute closable.
58 59 60 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 58 def closable @closable end |
#close_icon ⇒ Object (readonly)
Returns the value of attribute close_icon.
55 56 57 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 55 def close_icon @close_icon end |
#content ⇒ Object
Returns the value of attribute content.
61 62 63 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 61 def content @content end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
58 59 60 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 58 def disabled @disabled end |
#force_render ⇒ Object (readonly)
Returns the value of attribute force_render.
58 59 60 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 58 def force_render @force_render end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
55 56 57 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 55 def icon @icon end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
49 50 51 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 49 def key @key end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
52 53 54 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 52 def label @label end |
Instance Method Details
#display_label ⇒ Object
129 130 131 132 133 134 135 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 129 def display_label label_value = @label return @key.to_s if label_value.nil? return label_value if label_value.is_a?(String) || label_value.is_a?(ActiveSupport::SafeBuffer) render(label_value) end |
#icon_component ⇒ Object
138 139 140 141 142 143 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 138 def icon_component raw_icon = @icon return nil if raw_icon.nil? raw_icon.is_a?(Symbol) ? HakumiComponents::Icon::Component.new(name: raw_icon) : raw_icon end |
#pane_attributes(active) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 107 def pane_attributes(active) { class: pane_classes(active), role: "tabpanel", "aria-hidden": (!active).to_s, tabindex: active ? "0" : "-1", data: { "hakumi--tabs-target": "pane", key: @key } } end |
#pane_classes(active) ⇒ Object
99 100 101 102 103 104 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 99 def pane_classes(active) classes = [ "hakumi-tabs-tabpane" ] classes << "hakumi-tabs-tabpane-active" if active classes << "hakumi-tabs-tabpane-hidden" unless active classes.join(" ") end |
#render_close_icon ⇒ Object
121 122 123 124 125 126 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 121 def render_close_icon icon = @close_icon return icon if icon.is_a?(Symbol) :close end |
#tab_attributes(active) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 78 def tab_attributes(active) base_attrs = { class: tab_classes(active), role: "tab", "aria-selected": active.to_s, "aria-disabled": @disabled.to_s, tabindex: active ? "0" : "-1", data: { "hakumi--tabs-target": "tab", key: @key } } unless @disabled base_attrs[:data][:action] = "click->hakumi--tabs#selectTab" end merge_attributes(base_attrs, @html_options.except(:class)) end |
#tab_classes(active) ⇒ Object
69 70 71 72 73 74 75 |
# File 'app/components/hakumi_components/tabs/item/component.rb', line 69 def tab_classes(active) classes = [ "hakumi-tabs-tab" ] classes << "hakumi-tabs-tab-active" if active classes << "hakumi-tabs-tab-disabled" if @disabled classes << "hakumi-tabs-tab-with-remove" if @closable classes.join(" ") end |