Class: HakumiComponents::Menu::Component

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

Constant Summary collapse

MODES =
T.let(%i[horizontal vertical inline].freeze, T::Array[Symbol])
TRIGGER_SUBMENU_ACTIONS =
T.let(%i[hover click].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 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(mode: :vertical, selectable: true, multiple: false, inline_collapsed: false, inline_indent: 24, default_selected_keys: [], default_open_keys: [], trigger_submenu_action: :hover, **html_options) ⇒ Component

Returns a new instance of Component.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/components/hakumi_components/menu/component.rb', line 53

def initialize(
  mode: :vertical,
  selectable: true,
  multiple: false,
  inline_collapsed: false,
  inline_indent: 24,
  default_selected_keys: [],
  default_open_keys: [],
  trigger_submenu_action: :hover,
  **html_options
)
  @mode = T.let(mode, Symbol)
  @selectable = T.let(selectable, T::Boolean)
  @multiple = T.let(multiple, T::Boolean)
  @inline_collapsed = T.let(inline_collapsed, T::Boolean)
  @inline_indent = T.let(inline_indent, Integer)
  @default_selected_keys = T.let(Array(default_selected_keys), Types::StringOrSymbolArray)
  @default_open_keys = T.let(Array(default_open_keys), Types::StringOrSymbolArray)
  @trigger_submenu_action = T.let(trigger_submenu_action, Symbol)
  @html_options = T.let(html_options, Types::HtmlAttributes)

  validate_props!
end

Instance Attribute Details

#inline_indentObject (readonly)

Returns the value of attribute inline_indent.



81
82
83
# File 'app/components/hakumi_components/menu/component.rb', line 81

def inline_indent
  @inline_indent
end

#modeObject (readonly)

Returns the value of attribute mode.



78
79
80
# File 'app/components/hakumi_components/menu/component.rb', line 78

def mode
  @mode
end

Instance Method Details



84
85
86
87
88
89
90
91
# File 'app/components/hakumi_components/menu/component.rb', line 84

def menu_classes
  modifiers = T.let({
    root: true,
    @mode => true,
    "inline-collapsed": @inline_collapsed && @mode == :inline
  }, Types::ClassModifiers)
  class_names("menu", modifiers)
end

#wrapper_attributesObject



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/components/hakumi_components/menu/component.rb', line 94

def wrapper_attributes
  data = stimulus_attrs("hakumi--menu", T.let({
    mode: @mode.to_s,
    selectable: @selectable,
    multiple: @multiple,
    inline_collapsed: @inline_collapsed,
    inline_indent: @inline_indent,
    default_selected_keys: @default_selected_keys.to_json,
    default_open_keys: @default_open_keys.to_json,
    trigger_submenu_action: @trigger_submenu_action.to_s
  }, Types::StimulusValues))
  merge_attributes({ class: menu_classes, role: "menu", data: data }, @html_options)
end