Class: HakumiComponents::Select::Component

Inherits:
BaseComponent
  • Object
show all
Extended by:
T::Sig
Includes:
Concerns::SelectionControl
Defined in:
app/components/hakumi_components/select/component.rb

Constant Summary collapse

VARIANTS =
T.let([ :default, :borderless ].freeze, T::Array[Symbol])
TRIGGERS =
T.let([ :click, :hover ].freeze, T::Array[Symbol])

Constants inherited from BaseComponent

BaseComponent::ControllerOptions, BaseComponent::DateInput, BaseComponent::DateLikeValue, BaseComponent::DimensionInput, BaseComponent::HtmlPayloadInput, BaseComponent::I18nOptionValue, BaseComponent::PresenceArray, BaseComponent::PresenceScalar, BaseComponent::PresenceValue, BaseComponent::RawHtmlInput, BaseComponent::SIZES, BaseComponent::SizeValue, BaseComponent::SymbolInput

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::SelectionControl

#selection_control_allow_clear, #selection_control_contract, #selection_control_disabled, #selection_control_has_value?, #selection_control_placeholder, #selection_control_size, #selection_control_value

Methods included from Concerns::SelectionControlInterface

#selection_control_allow_clear, #selection_control_contract, #selection_control_disabled, #selection_control_has_value?, #selection_control_placeholder, #selection_control_size, #selection_control_value

Methods included from Concerns::FormField

#describedby_ids, #error?, #error_message, #form_field_caption, #form_field_contract, #form_field_errors, #form_field_html_options, #form_field_label, #form_field_name, #form_field_required, #form_field_rules, #form_field_standalone, #form_item_attributes, #form_item_classes, #input_id, #render_caption, #render_error, #render_explain, #render_label, #standalone?

Methods included from Concerns::FormFieldInterface

#form_field_contract

Methods inherited from BaseComponent

#append_data_token, boolean_html_param, #build_inline_style, cast_boolean, #cast_boolean, #class_names, #component_classes, #data_attributes_from, #dimension_to_css, #ensure_dom_id!, float_html_param, #generate_id, #html_classes, html_param, html_primitive_param, #html_style, #i18n_scope, integer_html_param, #merge_attributes, #render_value, #size_to_pixels, #stimulus_attrs, string_html_param, string_or_symbol_array_html_param, symbol_html_param, #t_default, #translate_with_default, #validate_inclusion!, #validate_required!, #value_present?

Constructor Details

#initialize(name: nil, options: [], label: nil, caption: nil, value: nil, placeholder: nil, size: :default, variant: :default, trigger: :click, icon: nil, disabled: false, required: false, allow_clear: false, show_search: false, standalone: true, rules: nil, errors: [], **html_options) ⇒ Component

Returns a new instance of Component.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/components/hakumi_components/select/component.rb', line 36

def initialize(
  name: nil,
  options: [],
  label: nil,
  caption: nil,
  value: nil,
  placeholder: nil,
  size: :default,
  variant: :default,
  trigger: :click,
  icon: nil,
  disabled: false,
  required: false,
  allow_clear: false,
  show_search: false,
  standalone: true,
  rules: nil,
  errors: [],
  **html_options
)
  @name = T.let(name || generate_id("select"), Types::FormFieldName)
  @options = T.let(HakumiComponents::SelectionControl::Coercion.options(Array(options)), T::Array[HakumiComponents::SelectionControl::Option])
  @label = label
  @caption = caption
  @value = T.let(value, Types::FormFieldValue)
  @placeholder = placeholder
  @size = size
  @variant = variant
  @trigger = trigger
  @icon = icon
  @disabled = disabled
  @required = required
  @allow_clear = allow_clear
  @show_search = show_search
  @standalone = standalone
  @rules = T.let(rules, T.nilable(T::Array[Types::ValidationRule]))
  @errors = T.let(errors, Types::FormFieldErrors)
  @html_options = T.let(html_options, Types::HtmlAttributes)
  initialize_selection_control_contract!(
    name: @name,
    label: @label,
    caption: @caption,
    value: @value,
    placeholder: @placeholder,
    size: @size,
    disabled: @disabled,
    allow_clear: @allow_clear,
    errors: @errors,
    standalone: @standalone,
    required: @required,
    html_options: @html_options,
    rules: @rules
  )

  validate_props!
end

Instance Attribute Details

#iconObject (readonly)

Returns the value of attribute icon.



100
101
102
# File 'app/components/hakumi_components/select/component.rb', line 100

def icon
  @icon
end

#triggerObject (readonly)

Returns the value of attribute trigger.



97
98
99
# File 'app/components/hakumi_components/select/component.rb', line 97

def trigger
  @trigger
end

#variantObject (readonly)

Returns the value of attribute variant.



94
95
96
# File 'app/components/hakumi_components/select/component.rb', line 94

def variant
  @variant
end