Class: Maglev::Uikit::MenuDropdownComponent

Inherits:
BaseComponent
  • Object
show all
Includes:
RenderPolymorphicItems
Defined in:
app/components/maglev/uikit/menu_dropdown_component.rb

Defined Under Namespace

Modules: RenderPolymorphicItems Classes: ButtonItemComponent, ButtonToItemComponent, DividerItemComponent, ItemComponent, LinkToItemComponent, NestedMenuComponent, TextItemComponent, WrapperItemComponent

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

#button_class_names

Constructor Details

#initialize(icon_name: nil, placement: 'bottom-start', wrapper_classes: nil, trigger_classes: nil) ⇒ MenuDropdownComponent

Returns a new instance of MenuDropdownComponent.



39
40
41
42
43
44
# File 'app/components/maglev/uikit/menu_dropdown_component.rb', line 39

def initialize(icon_name: nil, placement: 'bottom-start', wrapper_classes: nil, trigger_classes: nil)
  @icon_name = icon_name
  @placement = placement
  @wrapper_classes = wrapper_classes
  @trigger_classes = trigger_classes
end

Instance Attribute Details

#icon_nameObject (readonly)

Returns the value of attribute icon_name.



37
38
39
# File 'app/components/maglev/uikit/menu_dropdown_component.rb', line 37

def icon_name
  @icon_name
end

#placementObject (readonly)

Returns the value of attribute placement.



37
38
39
# File 'app/components/maglev/uikit/menu_dropdown_component.rb', line 37

def placement
  @placement
end

#trigger_classesObject (readonly)

Returns the value of attribute trigger_classes.



37
38
39
# File 'app/components/maglev/uikit/menu_dropdown_component.rb', line 37

def trigger_classes
  @trigger_classes
end

#wrapper_classesObject (readonly)

Returns the value of attribute wrapper_classes.



37
38
39
# File 'app/components/maglev/uikit/menu_dropdown_component.rb', line 37

def wrapper_classes
  @wrapper_classes
end

Instance Method Details

#form_item_classesObject

rubocop:enable Metrics/MethodLength



68
69
70
71
72
73
74
75
# File 'app/components/maglev/uikit/menu_dropdown_component.rb', line 68

def form_item_classes(...)
  class_variants(
    base: %w[
      col-span-3 grid grid-cols-subgrid
      flex items-center focus:outline-none cursor-pointer
    ]
  ).render(...)
end

#item_classesObject

rubocop:disable Metrics/MethodLength



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/components/maglev/uikit/menu_dropdown_component.rb', line 51

def item_classes(...)
  class_variants(
    base: %(
      col-span-3 grid grid-cols-subgrid
      flex flex-1 items-center px-2 py-3 w-full mx-1 rounded-sm text-left
      transition-colors duration-200 focus:outline-none cursor-pointer
    ),
    variants: {
      danger: 'text-red-600 hover:bg-red-100',
      '!danger': 'hover:bg-gray-100',
      subdued: 'text-gray-400'
    },
    defaults: { danger: false, subdued: false }
  ).render(...)
end

#list_item_classesObject



46
47
48
# File 'app/components/maglev/uikit/menu_dropdown_component.rb', line 46

def list_item_classes
  'text-gray-800 grid grid-cols-[auto_1fr_auto] min-w-[12rem] my-1'
end