Class: Shadcn::Field::Component

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

Overview

Port of registry/new-york-v4/ui/field.tsx

Constant Summary

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, #tag_name

Constructor Details

#initialize(orientation: :vertical, **attributes) ⇒ Component

Returns a new instance of Component.



43
44
45
46
# File 'app/components/shadcn/field/component.rb', line 43

def initialize(orientation: :vertical, **attributes)
  @orientation = orientation&.to_sym || :vertical
  super(**attributes)
end

Instance Attribute Details

#orientationObject (readonly)

Returns the value of attribute orientation.



41
42
43
# File 'app/components/shadcn/field/component.rb', line 41

def orientation
  @orientation
end

Instance Method Details

#callObject



56
57
58
# File 'app/components/shadcn/field/component.rb', line 56

def call
  render_element(body: safe_join([ label, field_content, content, description, error ].compact))
end

#element_attributes(**defaults) ⇒ Object



52
53
54
# File 'app/components/shadcn/field/component.rb', line 52

def element_attributes(**defaults)
  super(**{ role: "group", "data-orientation" => orientation }.merge(defaults))
end

#style_variantsObject



48
49
50
# File 'app/components/shadcn/field/component.rb', line 48

def style_variants
  { orientation: }
end