Class: IronAdmin::Form::CheckboxComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
Concerns::FormInputBehavior
Defined in:
app/components/iron_admin/form/checkbox_component.rb

Overview

Renders a checkbox input.

Examples:

Basic checkbox

render IronAdmin::Form::CheckboxComponent.new(
  name: "record[active]",
  checked: @record.active,
  label: "Active"
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, checked: false, label: nil, disabled: false, field: nil, current_user: nil) ⇒ CheckboxComponent

Returns a new instance of CheckboxComponent.

Parameters:

  • name (String)

    Checkbox name

  • checked (Boolean) (defaults to: false)

    Checked state

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

    Label text

  • disabled (Boolean) (defaults to: false)

    Disabled state

  • field (IronAdmin::Field, nil) (defaults to: nil)

    Field config

  • current_user (Object, nil) (defaults to: nil)

    Current user



31
32
33
34
35
36
37
38
# File 'app/components/iron_admin/form/checkbox_component.rb', line 31

def initialize(name:, checked: false, label: nil, disabled: false, field: nil, current_user: nil)
  @name = name
  @checked = checked
  @label = label
  @disabled = disabled
  @field = field
  @current_user = current_user
end

Instance Attribute Details

#checkedBoolean (readonly)

Returns Whether checkbox is checked.

Returns:

  • (Boolean)

    Whether checkbox is checked



20
21
22
# File 'app/components/iron_admin/form/checkbox_component.rb', line 20

def checked
  @checked
end

#labelString? (readonly)

Returns Label text.

Returns:

  • (String, nil)

    Label text



23
24
25
# File 'app/components/iron_admin/form/checkbox_component.rb', line 23

def label
  @label
end

#nameString (readonly)

Returns Checkbox name attribute.

Returns:

  • (String)

    Checkbox name attribute



17
18
19
# File 'app/components/iron_admin/form/checkbox_component.rb', line 17

def name
  @name
end

Instance Method Details

#checkbox_classesString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns CSS classes for checkbox input.

Returns:

  • (String)

    CSS classes for checkbox input



42
43
44
45
# File 'app/components/iron_admin/form/checkbox_component.rb', line 42

def checkbox_classes
  "h-4 w-4 rounded border-gray-300 text-indigo-600 #{theme.checkbox_checked} " \
    "transition duration-150 ease-in-out"
end

#label_classesString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns CSS classes for label text.

Returns:

  • (String)

    CSS classes for label text



49
50
51
# File 'app/components/iron_admin/form/checkbox_component.rb', line 49

def label_classes
  "text-sm #{theme.body_text}"
end