Class: Polaris::LabelledComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/labelled_component.rb

Constant Summary

Constants included from ViewHelper

ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from ViewHelper

#polaris_body_styles, #polaris_html_classes, #polaris_html_styles, #polaris_icon_source

Methods included from StylesListHelper

#styles_list

Methods included from OptionHelper

#append_option, #prepend_option

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #fetch_or_fallback_nested

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(form: nil, attribute: nil, name: nil, label: nil, label_hidden: false, label_action: nil, required: false, help_text: nil, error: nil, **system_arguments) ⇒ LabelledComponent

Returns a new instance of LabelledComponent.



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
38
39
40
41
42
43
# File 'app/components/polaris/labelled_component.rb', line 9

def initialize(
  form: nil,
  attribute: nil,
  name: nil,
  label: nil,
  label_hidden: false,
  label_action: nil,
  required: false,
  help_text: nil,
  error: nil,
  **system_arguments
)
  @help_text = help_text
  @error = error

  if label_action && label_action[:content].present?
    label_content = label_action.delete(:content)
    with_label_action(**label_action) { label_content }
  end

  @system_arguments = system_arguments
  @system_arguments[:tag] = "div"
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "Polaris-Labelled--hidden": label_hidden
  )

  @label_arguments = {
    form: form,
    attribute: attribute,
    name: name,
    label: label,
    required: required
  }
end

Instance Method Details

#renders_error?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/components/polaris/labelled_component.rb', line 45

def renders_error?
  @error.present? && @error.is_a?(String)
end