Class: HakumiComponents::TreeSelect::Component
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- HakumiComponents::TreeSelect::Component
- Extended by:
- T::Sig
- Includes:
- Concerns::SelectionControl
- Defined in:
- app/components/hakumi_components/tree_select/component.rb
Constant Summary collapse
- VARIANTS =
T.let([ :default, :borderless ].freeze, T::Array[Symbol])
- STATUSES =
T.let([ nil, :error, :warning ].freeze, T::Array[T.nilable(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
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#prefix_icon ⇒ Object
readonly
Returns the value of attribute prefix_icon.
Instance Method Summary collapse
- #borderless? ⇒ Boolean
- #display_label ⇒ Object
- #effective_status ⇒ Object
- #empty_options? ⇒ Boolean
-
#initialize(name: nil, options: [], value: nil, placeholder: nil, multiple: false, tree_checkable: false, show_search: false, tree_default_expand_all: false, tree_selectable_leaf_only: false, disabled: false, allow_clear: false, size: :default, variant: :default, status: nil, max_count: nil, prefix: nil, prefix_icon: nil, label: nil, caption: nil, rules: nil, errors: [], standalone: true, required: false, **html_options) ⇒ Component
constructor
A new instance of Component.
- #input_value ⇒ Object
- #prefix? ⇒ Boolean
- #value? ⇒ Boolean
- #wrapper_attributes ⇒ Object
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
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: [], value: nil, placeholder: nil, multiple: false, tree_checkable: false, show_search: false, tree_default_expand_all: false, tree_selectable_leaf_only: false, disabled: false, allow_clear: false, size: :default, variant: :default, status: nil, max_count: nil, prefix: nil, prefix_icon: nil, label: nil, caption: nil, rules: nil, errors: [], standalone: true, required: false, **html_options) ⇒ Component
Returns a new instance of Component.
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/components/hakumi_components/tree_select/component.rb', line 42 def initialize( name: nil, options: [], value: nil, placeholder: nil, multiple: false, tree_checkable: false, show_search: false, tree_default_expand_all: false, tree_selectable_leaf_only: false, disabled: false, allow_clear: false, size: :default, variant: :default, status: nil, max_count: nil, prefix: nil, prefix_icon: nil, label: nil, caption: nil, rules: nil, errors: [], standalone: true, required: false, ** ) @name = T.let(name || generate_id("tree_select"), Types::FormFieldName) @options = T.let( || [], T::Array[HakumiComponents::SelectionControl::TreeNode]) @value = T.let(value, Types::FormFieldValue) @placeholder = T.let(placeholder || t_default(:placeholder, default: "Select"), T.nilable(String)) @multiple = multiple @tree_checkable = tree_checkable @show_search = show_search @tree_default_expand_all = @tree_selectable_leaf_only = tree_selectable_leaf_only @disabled = disabled @allow_clear = allow_clear @size = size @variant = variant @status = status @max_count = max_count @prefix = prefix @prefix_icon = prefix_icon @label = label @caption = caption @rules = T.let(rules, T.nilable(T::Array[Types::ValidationRule])) @errors = T.let(errors, Types::FormFieldErrors) @standalone = standalone @required = required @html_options = T.let(, 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
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
112 113 114 |
# File 'app/components/hakumi_components/tree_select/component.rb', line 112 def prefix @prefix end |
#prefix_icon ⇒ Object (readonly)
Returns the value of attribute prefix_icon.
115 116 117 |
# File 'app/components/hakumi_components/tree_select/component.rb', line 115 def prefix_icon @prefix_icon end |
Instance Method Details
#borderless? ⇒ Boolean
148 149 150 |
# File 'app/components/hakumi_components/tree_select/component.rb', line 148 def borderless? @variant == :borderless end |
#display_label ⇒ Object
169 170 171 172 173 174 |
# File 'app/components/hakumi_components/tree_select/component.rb', line 169 def display_label labels = selected_labels return nil if labels.empty? labels.join(", ") end |
#effective_status ⇒ Object
153 154 155 156 157 |
# File 'app/components/hakumi_components/tree_select/component.rb', line 153 def effective_status return :error if error? @status end |
#empty_options? ⇒ Boolean
143 144 145 |
# File 'app/components/hakumi_components/tree_select/component.rb', line 143 def .empty? end |
#input_value ⇒ Object
160 161 162 163 164 165 166 |
# File 'app/components/hakumi_components/tree_select/component.rb', line 160 def input_value if multi_value? selected_keys.to_json else selected_keys.first end end |
#prefix? ⇒ Boolean
138 139 140 |
# File 'app/components/hakumi_components/tree_select/component.rb', line 138 def prefix? value_present?(@prefix) || !@prefix_icon.nil? end |
#value? ⇒ Boolean
177 178 179 |
# File 'app/components/hakumi_components/tree_select/component.rb', line 177 def value? selected_keys.any? end |
#wrapper_attributes ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'app/components/hakumi_components/tree_select/component.rb', line 118 def wrapper_attributes data_attrs = T.let({ controller: "hakumi--tree-select", hakumi__tree_select_allow_clear_value: selection_control_allow_clear, hakumi__tree_select_disabled_value: selection_control_disabled, hakumi__tree_select_multiple_value: @multiple, hakumi__tree_select_tree_checkable_value: @tree_checkable }.compact, Types::DataAttributes) data_attrs[:hakumi__tree_select_max_count_value] = @max_count if @max_count base_attrs = { class: wrapper_classes, data: data_attrs } merge_attributes(base_attrs, ) end |