Class: Fluxbit::Form::LabelComponent
- Inherits:
-
Component
- Object
- Component
- Fluxbit::Form::LabelComponent
- Defined in:
- app/components/fluxbit/form/label_component.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(color: :default, form: nil, with_content: nil, helper_text: nil, sizing: :sm, helper_popover: nil, helper_popover_placement: "right", **props) ⇒ LabelComponent
constructor
A new instance of LabelComponent.
- #render_popover ⇒ Object
- #span_helper_popover ⇒ Object
Constructor Details
#initialize(color: :default, form: nil, with_content: nil, helper_text: nil, sizing: :sm, helper_popover: nil, helper_popover_placement: "right", **props) ⇒ LabelComponent
Returns a new instance of LabelComponent.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/components/fluxbit/form/label_component.rb', line 23 def initialize(color: :default, form: nil, with_content: nil, helper_text: nil, sizing: :sm, helper_popover: nil, helper_popover_placement: "right", **props) super @props = props @sizing = sizing.in?(styles[:sizes].keys) ? sizing : :sm @with_content = with_content @helper_text = helper_text.is_a?(Array) ? helper_text : [ helper_text ] @helper_popover = helper_popover @helper_popover_placement = helper_popover_placement color = :default unless color.in? %i[info default success failure warning] add class: styles[:colors][color], to: @props, first_element: true add class: styles[:base], to: @props, first_element: true add class: styles[:sizes][@sizing], to: @props, first_element: true end |
Instance Method Details
#call ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'app/components/fluxbit/form/label_component.rb', line 56 def call safe_join( [ content_tag(:label, safe_join([ content || @with_content, span_helper_popover ]), @props), helper_text, render_popover ] ) end |
#render_popover ⇒ Object
50 51 52 53 54 |
# File 'app/components/fluxbit/form/label_component.rb', line 50 def render_popover return "" if @helper_popover.nil? Fluxbit::PopoverComponent.new(id: target).with_content(@helper_popover).render_in(view_context) end |
#span_helper_popover ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/components/fluxbit/form/label_component.rb', line 38 def span_helper_popover return "" if @helper_popover.nil? content_tag :span, anyicon(icon: "heroicons_solid:question-mark-circle", class: "w-4 h-4"), { "data-popover-placement": @helper_popover_placement, "data-popover-target": target, class: styles[:helper_popover] } end |