Class: Jav::FieldWrapperComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Jav::FieldWrapperComponent
- Defined in:
- app/components/jav/field_wrapper_component.rb
Instance Attribute Summary collapse
-
#compact ⇒ Object
readonly
Returns the value of attribute compact.
-
#dash_if_blank ⇒ Object
readonly
Returns the value of attribute dash_if_blank.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#full_width ⇒ Object
readonly
Returns the value of attribute full_width.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #classes(extra_classes = "") ⇒ Object
- #compact? ⇒ Boolean
- #data ⇒ Object
- #full_width? ⇒ Boolean
- #help ⇒ Object
-
#initialize(dash_if_blank: true, data: {}, compact: false, help: nil, field: nil, form: nil, full_width: false, label: nil, resource: nil, stacked: nil, style: "", view: :show, **args) ⇒ FieldWrapperComponent
constructor
A new instance of FieldWrapperComponent.
- #label ⇒ Object
- #on_edit? ⇒ Boolean
- #on_show? ⇒ Boolean
- #record ⇒ Object
- #stacked? ⇒ Boolean
- #style ⇒ Object
Constructor Details
#initialize(dash_if_blank: true, data: {}, compact: false, help: nil, field: nil, form: nil, full_width: false, label: nil, resource: nil, stacked: nil, style: "", view: :show, **args) ⇒ FieldWrapperComponent
Returns a new instance of FieldWrapperComponent.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/components/jav/field_wrapper_component.rb', line 6 def initialize( dash_if_blank: true, data: {}, compact: false, help: nil, # do we really need it? field: nil, form: nil, full_width: false, label: nil, # do we really need it? resource: nil, stacked: nil, style: "", view: :show, **args ) super @args = args @classes = args[:class].presence || "" @dash_if_blank = dash_if_blank @data = data @compact = compact @help = help @field = field @form = form @full_width = full_width @label = label @resource = resource @action = field.action @stacked = stacked @style = style @view = view end |
Instance Attribute Details
#compact ⇒ Object (readonly)
Returns the value of attribute compact.
4 5 6 |
# File 'app/components/jav/field_wrapper_component.rb', line 4 def compact @compact end |
#dash_if_blank ⇒ Object (readonly)
Returns the value of attribute dash_if_blank.
4 5 6 |
# File 'app/components/jav/field_wrapper_component.rb', line 4 def dash_if_blank @dash_if_blank end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
4 5 6 |
# File 'app/components/jav/field_wrapper_component.rb', line 4 def field @field end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
4 5 6 |
# File 'app/components/jav/field_wrapper_component.rb', line 4 def form @form end |
#full_width ⇒ Object (readonly)
Returns the value of attribute full_width.
4 5 6 |
# File 'app/components/jav/field_wrapper_component.rb', line 4 def full_width @full_width end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
4 5 6 |
# File 'app/components/jav/field_wrapper_component.rb', line 4 def resource @resource end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
4 5 6 |
# File 'app/components/jav/field_wrapper_component.rb', line 4 def view @view end |
Instance Method Details
#classes(extra_classes = "") ⇒ Object
39 40 41 |
# File 'app/components/jav/field_wrapper_component.rb', line 39 def classes(extra_classes = "") "field-wrapper relative flex flex-col grow pb-2 md:pb-0 leading-tight min-h-14 h-full #{stacked? ? 'field-wrapper-layout-stacked' : 'field-wrapper-layout-inline md:flex-row md:items-center'} #{compact? ? 'field-wrapper-size-compact' : 'field-wrapper-size-regular'} #{full_width? ? 'field-width-full' : 'field-width-regular'} #{@classes || ''} #{extra_classes || ''} #{@field.get_html(:classes, view: view, element: :wrapper)}" end |
#compact? ⇒ Boolean
101 102 103 |
# File 'app/components/jav/field_wrapper_component.rb', line 101 def compact? @compact end |
#data ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/components/jav/field_wrapper_component.rb', line 71 def data attributes = { field_id: @field.id, field_type: @field.type, **@data } # Fetch the data attributes off the html option wrapper_data_attributes = @field.get_html :data, view: view, element: :wrapper attributes.merge! wrapper_data_attributes if wrapper_data_attributes.present? # Add the built-in stimulus integration data tags. add_stimulus_attributes_for(@resource, attributes) if @resource.present? add_stimulus_attributes_for(@action, attributes) if @action.present? attributes end |
#full_width? ⇒ Boolean
105 106 107 |
# File 'app/components/jav/field_wrapper_component.rb', line 105 def full_width? @full_width end |
#help ⇒ Object
59 60 61 62 63 64 65 |
# File 'app/components/jav/field_wrapper_component.rb', line 59 def help help_value = @help || @field.help return Jav::Hosts::ResourceViewRecordHost.new(block: help_value, record: record, resource: resource, view: view).handle if help_value.respond_to?(:call) help_value end |
#label ⇒ Object
47 48 49 |
# File 'app/components/jav/field_wrapper_component.rb', line 47 def label @label || @field.name end |
#on_edit? ⇒ Boolean
55 56 57 |
# File 'app/components/jav/field_wrapper_component.rb', line 55 def on_edit? view == :edit end |
#on_show? ⇒ Boolean
51 52 53 |
# File 'app/components/jav/field_wrapper_component.rb', line 51 def on_show? view == :show end |
#record ⇒ Object
67 68 69 |
# File 'app/components/jav/field_wrapper_component.rb', line 67 def record resource.present? ? resource.model : nil end |
#stacked? ⇒ Boolean
90 91 92 93 94 95 96 97 98 99 |
# File 'app/components/jav/field_wrapper_component.rb', line 90 def stacked? # Override on the declaration level return @stacked unless @stacked.nil? # Fetch it from the field return field.stacked unless field.stacked.nil? # Fallback to defaults Jav.configuration.field_wrapper_layout == :stacked end |
#style ⇒ Object
43 44 45 |
# File 'app/components/jav/field_wrapper_component.rb', line 43 def style "#{@style} #{@field.get_html(:style, view: view, element: :wrapper)}" end |