Class: Shadcn::Field::Error::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/field/error/component.rb

Overview

FieldError — renders nothing when there is neither content nor errors. A single error is inlined; several are listed, like the TSX does.

Constant Summary collapse

LIST_CLASSES =
"ml-4 flex list-disc flex-col gap-1"

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(errors: [], **attributes) ⇒ Component

Returns a new instance of Component.



19
20
21
22
# File 'app/components/shadcn/field/error/component.rb', line 19

def initialize(errors: [], **attributes)
  @errors = Array(errors).compact.map(&:to_s).uniq
  super(**attributes)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



17
18
19
# File 'app/components/shadcn/field/error/component.rb', line 17

def errors
  @errors
end

Instance Method Details

#callObject



32
33
34
# File 'app/components/shadcn/field/error/component.rb', line 32

def call
  render_element(body: body)
end

#element_attributes(**defaults) ⇒ Object



28
29
30
# File 'app/components/shadcn/field/error/component.rb', line 28

def element_attributes(**defaults)
  super(**{ role: "alert" }.merge(defaults))
end

#render?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/components/shadcn/field/error/component.rb', line 24

def render?
  content.present? || errors.any?
end