Class: BetterUi::General::Dropdown::ItemComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- BetterUi::General::Dropdown::ItemComponent
- Includes:
- Components::Icon::IconHelper
- Defined in:
- app/components/better_ui/general/dropdown/item_component.rb
Constant Summary collapse
- DROPDOWN_ITEM_BASE_CLASSES =
Classi base per l’elemento del dropdown
"flex items-center w-full px-4 py-2 text-sm transition-colors"
- DROPDOWN_ITEM_THEME =
Temi per gli elementi del dropdown con classi Tailwind dirette
{ default: "text-gray-700 hover:bg-gray-100 hover:text-gray-900", white: "text-gray-900 hover:bg-gray-50", red: "text-red-700 hover:bg-red-50 hover:text-red-900", rose: "text-rose-700 hover:bg-rose-50 hover:text-rose-900", orange: "text-orange-700 hover:bg-orange-50 hover:text-orange-900", green: "text-green-700 hover:bg-green-50 hover:text-green-900", blue: "text-blue-700 hover:bg-blue-50 hover:text-blue-900", yellow: "text-yellow-700 hover:bg-yellow-50 hover:text-yellow-900", violet: "text-violet-700 hover:bg-violet-50 hover:text-violet-900" }.freeze
- DROPDOWN_ITEM_STATE_DISABLED =
Stati per gli elementi del dropdown
"opacity-50 cursor-not-allowed pointer-events-none"
- DROPDOWN_ITEM_STATE_ACTIVE =
"bg-gray-100 text-gray-900"
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#html_options ⇒ Object
readonly
Returns the value of attribute html_options.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
Instance Method Summary collapse
-
#initialize(text:, icon: nil, href: nil, theme: :default, disabled: false, active: false, classes: nil, **html_options) ⇒ ItemComponent
constructor
A new instance of ItemComponent.
-
#item_attributes ⇒ Object
Restituisce gli attributi per l’elemento.
-
#item_classes ⇒ Object
Combina tutte le classi per l’elemento.
-
#render? ⇒ Boolean
Verifica se rendere il componente.
-
#tag_name ⇒ Object
Determina se usare un link o un button.
Methods included from Components::Icon::IconHelper
Constructor Details
#initialize(text:, icon: nil, href: nil, theme: :default, disabled: false, active: false, classes: nil, **html_options) ⇒ ItemComponent
Returns a new instance of ItemComponent.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/components/better_ui/general/dropdown/item_component.rb', line 31 def initialize( text:, icon: nil, href: nil, theme: :default, disabled: false, active: false, classes: nil, ** ) @text = text @icon = icon @href = href @theme = theme.to_sym @disabled = disabled @active = active @classes = classes = validate_params end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
9 10 11 |
# File 'app/components/better_ui/general/dropdown/item_component.rb', line 9 def active @active end |
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
9 10 11 |
# File 'app/components/better_ui/general/dropdown/item_component.rb', line 9 def classes @classes end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
9 10 11 |
# File 'app/components/better_ui/general/dropdown/item_component.rb', line 9 def disabled @disabled end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
9 10 11 |
# File 'app/components/better_ui/general/dropdown/item_component.rb', line 9 def href @href end |
#html_options ⇒ Object (readonly)
Returns the value of attribute html_options.
9 10 11 |
# File 'app/components/better_ui/general/dropdown/item_component.rb', line 9 def end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
9 10 11 |
# File 'app/components/better_ui/general/dropdown/item_component.rb', line 9 def icon @icon end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
9 10 11 |
# File 'app/components/better_ui/general/dropdown/item_component.rb', line 9 def text @text end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
9 10 11 |
# File 'app/components/better_ui/general/dropdown/item_component.rb', line 9 def theme @theme end |
Instance Method Details
#item_attributes ⇒ Object
Restituisce gli attributi per l’elemento
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/components/better_ui/general/dropdown/item_component.rb', line 68 def item_attributes attrs = { class: item_classes, role: "menuitem", "data-bui-dropdown-target": "item" } if @href.present? && !@disabled attrs[:href] = @href end if @disabled attrs["aria-disabled"] = "true" attrs[:tabindex] = "-1" end .except(:class).each do |key, value| attrs[key] = value end attrs end |
#item_classes ⇒ Object
Combina tutte le classi per l’elemento
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/components/better_ui/general/dropdown/item_component.rb', line 54 def item_classes classes = [ DROPDOWN_ITEM_BASE_CLASSES, get_theme_classes, @classes ] classes << DROPDOWN_ITEM_STATE_DISABLED if @disabled classes << DROPDOWN_ITEM_STATE_ACTIVE if @active classes.compact.join(" ") end |
#render? ⇒ Boolean
Verifica se rendere il componente
97 98 99 |
# File 'app/components/better_ui/general/dropdown/item_component.rb', line 97 def render? @text.present? end |
#tag_name ⇒ Object
Determina se usare un link o un button
92 93 94 |
# File 'app/components/better_ui/general/dropdown/item_component.rb', line 92 def tag_name @href.present? && !@disabled ? :a : :button end |