Module: UI::FieldLabelBehavior
- Included in:
- FieldLabel, FieldLabelComponent
- Defined in:
- app/behaviors/ui/field_label_behavior.rb
Overview
FieldLabelBehavior
Shared behavior for FieldLabel component across ERB, ViewComponent, and Phlex implementations. FieldLabel provides styled labels for form fields with disability states.
Instance Method Summary collapse
-
#field_label_classes ⇒ Object
Returns combined CSS classes for the field label.
-
#field_label_html_attributes ⇒ Object
Returns HTML attributes for the field label element.
Instance Method Details
#field_label_classes ⇒ Object
Returns combined CSS classes for the field label
19 20 21 22 23 24 |
# File 'app/behaviors/ui/field_label_behavior.rb', line 19 def field_label_classes classes_value = respond_to?(:classes, true) ? classes : @classes base = "group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4 has-data-[state=checked]:bg-primary/5 has-data-[state=checked]:border-primary dark:has-data-[state=checked]:bg-primary/10" TailwindMerge::Merger.new.merge([base, classes_value].compact.join(" ")) end |
#field_label_html_attributes ⇒ Object
Returns HTML attributes for the field label element
9 10 11 12 13 14 15 16 |
# File 'app/behaviors/ui/field_label_behavior.rb', line 9 def field_label_html_attributes attributes_value = respond_to?(:attributes, true) ? attributes : @attributes { for: @for_id, "data-slot": "field-label", class: field_label_classes }.merge(attributes_value).compact end |