Class: Fluxbit::ModalComponent
- Includes:
- Config::ModalComponent
- Defined in:
- app/components/fluxbit/modal_component.rb
Overview
The ‘Fluxbit::ModalComponent` is a component for rendering customizable modals. It extends `Fluxbit::Component` and provides options for configuring the modal’s appearance, behavior, and content areas. You can control the modal’s title, size, placement, backdrop behavior, and other interactive elements. The modal is divided into different sections (header, content, and footer), each of which can be styled or customized through various properties.
Constant Summary
Constants inherited from Component
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(**props) ⇒ ModalComponent
constructor
Initializes the modal component with the given properties.
Methods inherited from Component
#add, #add_popover_or_tooltip, #anyicon, #element_name, #fx_id, #options, #random_id, #remove_class, #render_popover_or_tooltip, #target
Constructor Details
#initialize(**props) ⇒ ModalComponent
Initializes the modal component with the given properties.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 |
# File 'app/components/fluxbit/modal_component.rb', line 31 def initialize(**props) super # Main properties @props = props @title = @props.delete(:title) @opened = (@props.delete(:opened), default: @@opened) @close_button = (@props.delete(:close_button), default: @@close_button) @flat = (@props.delete(:flat), default: @@flat) @size = (@props.delete(:size), default: @@size) @placement = (@props.delete(:placement), default: @@placement) @only_css = (@props.delete(:only_css), default: @@only_css) @static = (@props.delete(:static), default: @@static) add(class: modal_classes, to: @props, first_element: true) @props["data-modal-placement"] = @placement.to_s if @placement @props["aria-hidden"] = !@opened @props["data-modal-backdrop"] = "static" if @static @props["onclick"] = "if(event.target === this) this.classList.add('hidden')" if @only_css && !@static @props[:class] = remove_class(@props.delete(:remove_class) || "", @props[:class]) # Content properties @content_props = @props.delete(:content_props) || {} add(class: content_classes, to: @content_props, first_element: true) @content_props[:class] = remove_class(@content_props.delete(:remove_class) || "", @content_props[:class]) # Header properties @header_props = @props.delete(:header_props) || {} add(class: header_classes, to: @header_props, first_element: true) @header_props[:class] = remove_class(@header_props.delete(:remove_class) || "", @header_props[:class]) # Footer properties @footer_props = @props.delete(:footer_props) || {} add(class: , to: @footer_props, first_element: true) @footer_props[:class] = remove_class(@footer_props.delete(:remove_class) || "", @footer_props[:class]) # Close button properties @close_button_props = @props.delete(:close_button_props) || {} add(class: styles[:header][:close][:base], to: @close_button_props, first_element: true) @close_button_props[:class] = remove_class(@close_button_props.delete(:remove_class) || "", @close_button_props[:class]) @close_button_props[:type] = "button" @close_button_props["data-modal-hide"] = @props[:id] @close_button_props["aria-label"] = "Close" end |
Instance Method Details
#call ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/components/fluxbit/modal_component.rb', line 76 def call content_tag( :div, **@props ) do content_tag(:div, **@content_props) do content_tag(:div, class: styles[:content][:inner]) do concat(header) if title? || @title.present? || @close_button concat(content_tag(:div, content, class: body_classes)) concat(content_tag(:div, , **@footer_props)) if end end end end |