Class: OkonomiUiKit::Components::ButtonBase
- Inherits:
-
OkonomiUiKit::Component
- Object
- OkonomiUiKit::Component
- OkonomiUiKit::Components::ButtonBase
- Defined in:
- app/helpers/okonomi_ui_kit/components/button_base.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from OkonomiUiKit::Component
Instance Method Summary collapse
- #build_button_class(variant:, color:, classes: "") ⇒ Object
-
#extract_icon_config(options) ⇒ Object
Extracts and normalizes icon configuration from options Returns [icon_config, updated_options] icon_config will be nil or { path: "icon/path", position: :start/:end }.
-
#render_button_content(icon_config, content = nil, &block) ⇒ Object
Renders button content with optional icon icon_config: { path: "icon/path", position: :start/:end } content: String or block content block: Optional block for content.
Methods inherited from OkonomiUiKit::Component
#combined_styles, config_class?, config_class_name, config_classes, config_namespace, #config_styles_registry, config_styles_registry, deep_merge, #initialize, #internal_styles_registry, internal_styles_registry, #name, parent_styles_registry, register_styles, resolve_config_classes, #style, #styles, #template_path, #theme_name, #tw_merge, #variant_style
Constructor Details
This class inherits a constructor from OkonomiUiKit::Component
Instance Method Details
#build_button_class(variant:, color:, classes: "") ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'app/helpers/okonomi_ui_kit/components/button_base.rb', line 4 def (variant:, color:, classes: "") [ style(:root) || "", style(variant.to_sym, :root) || "", style(variant.to_sym, :colors, color.to_sym) || "", classes ].reject(&:blank?).join(" ") end |
#extract_icon_config(options) ⇒ Object
Extracts and normalizes icon configuration from options Returns [icon_config, updated_options] icon_config will be nil or { path: "icon/path", position: :start/:end }
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/okonomi_ui_kit/components/button_base.rb', line 16 def extract_icon_config() return [nil, ] unless .is_a?(Hash) icon_option = .delete(:icon) return [nil, ] unless icon_option icon_config = case icon_option when String { path: icon_option, position: :start } when Hash if icon_option[:start] { path: icon_option[:start], position: :start } elsif icon_option[:end] { path: icon_option[:end], position: :end } else # Invalid hash format, ignore nil end else nil end [icon_config, ] end |
#render_button_content(icon_config, content = nil, &block) ⇒ Object
Renders button content with optional icon icon_config: { path: "icon/path", position: :start/:end } content: String or block content block: Optional block for content
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/okonomi_ui_kit/components/button_base.rb', line 45 def (icon_config, content = nil, &block) icon_html = if icon_config view.ui.icon(icon_config[:path], class: style(:icon, icon_config[:position])) end content_html = if block_given? view.capture(&block) else content end # Check if we have actual content (not empty/nil) has_content = content_html.present? if icon_config && has_content # Both icon and content - wrap in flex container with gap wrapper_class = "inline-flex items-center gap-1.5" if icon_config[:position] == :end view.content_tag(:span, class: wrapper_class) do view.safe_join([content_html, icon_html].compact) end else view.content_tag(:span, class: wrapper_class) do view.safe_join([icon_html, content_html].compact) end end elsif icon_config # Icon only - no wrapper needed icon_html else # Content only content_html end end |