Class: Shadcn::LabelComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/shadcn/label_component.rb

Overview

Label component for form fields Matches shadcn/ui Label component

Examples:

Basic label

<%= render Shadcn::LabelComponent.new(for: "email") { "Email Address" } %>

Required field label

<%= render Shadcn::LabelComponent.new(for: "name", required: true) { "Name" } %>

With custom styling

<%= render Shadcn::LabelComponent.new(for: "bio", class_name: "text-lg") { "Biography" } %>

Constant Summary collapse

BASE_CLASSES =
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"

Instance Attribute Summary

Attributes inherited from BaseComponent

#class_name, #data, #html_options

Instance Method Summary collapse

Methods inherited from BaseComponent

#content

Methods included from Rails::Helpers::ClassNameHelper

#cn

Constructor Details

#initialize(for: nil, required: false, **options) ⇒ LabelComponent

Returns a new instance of LabelComponent.

Parameters:

  • for (String, nil) (defaults to: nil)

    The ID of the input this label is for

  • required (Boolean) (defaults to: false)

    Whether to show a required indicator



21
22
23
24
25
# File 'app/components/shadcn/label_component.rb', line 21

def initialize(for: nil, required: false, **options)
  super(**options)
  @for = binding.local_variable_get(:for)
  @required = required
end