Class: BetterUi::Drawer::NavItemComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- BetterUi::Drawer::NavItemComponent
- Defined in:
- app/components/better_ui/drawer/nav_item_component.rb
Overview
A navigation item component for sidebar menus with icon, label, and badge support.
Constant Summary collapse
- VARIANTS =
Visual variant configurations
{ light: { base: "text-grayscale-700", active: "bg-primary-50 text-primary-700", inactive: "hover:bg-grayscale-100", badge_bg: "bg-primary-100", badge_text: "text-primary-700" }, dark: { base: "text-grayscale-300", active: "bg-white/10 text-white", inactive: "hover:bg-white/5", badge_bg: "bg-white/20", badge_text: "text-white" }, primary: { base: "text-primary-100", active: "bg-white/20 text-white", inactive: "hover:bg-white/10", badge_bg: "bg-white/20", badge_text: "text-white" } }.freeze
- METHODS =
Allowed HTTP methods
%i[get post put patch delete].freeze
Constants inherited from ApplicationComponent
ApplicationComponent::SHADOWS, ApplicationComponent::VARIANT_BODY_DIVIDE, ApplicationComponent::VARIANT_DIVIDE, ApplicationComponent::VARIANT_HEADER_BG, ApplicationComponent::VARIANT_HEADER_TEXT, ApplicationComponent::VARIANT_HIGHLIGHTED, ApplicationComponent::VARIANT_HOVERABLE, ApplicationComponent::VARIANT_RING, ApplicationComponent::VARIANT_SORT_ICON, ApplicationComponent::VARIANT_STRIPED
Instance Attribute Summary collapse
-
#href ⇒ String
readonly
Returns the href URL.
-
#label ⇒ String
readonly
Returns the label text.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Returns whether the item is active.
-
#initialize(label:, href:, active: false, method: nil, variant: :light, container_classes: nil, **options) ⇒ NavItemComponent
constructor
Initializes a new nav item component.
-
#with_badge ⇒ Object
Slot for rendering a badge/counter (displayed after label).
-
#with_icon ⇒ Object
Slot for rendering the icon (displayed before label).
Constructor Details
#initialize(label:, href:, active: false, method: nil, variant: :light, container_classes: nil, **options) ⇒ NavItemComponent
Initializes a new nav item component.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/components/better_ui/drawer/nav_item_component.rb', line 84 def initialize( label:, href:, active: false, method: nil, variant: :light, container_classes: nil, ** ) @label = label @href = href @active = active @method = validate_method(method) @variant = validate_variant(variant) @container_classes = container_classes @options = end |
Instance Attribute Details
#href ⇒ String (readonly)
Returns the href URL.
110 111 112 |
# File 'app/components/better_ui/drawer/nav_item_component.rb', line 110 def href @href end |
#label ⇒ String (readonly)
Returns the label text.
105 106 107 |
# File 'app/components/better_ui/drawer/nav_item_component.rb', line 105 def label @label end |
Instance Method Details
#active? ⇒ Boolean
Returns whether the item is active.
115 116 117 |
# File 'app/components/better_ui/drawer/nav_item_component.rb', line 115 def active? @active end |
#with_badge ⇒ Object
Slot for rendering a badge/counter (displayed after label).
70 |
# File 'app/components/better_ui/drawer/nav_item_component.rb', line 70 renders_one :badge |
#with_icon ⇒ Object
Slot for rendering the icon (displayed before label).
65 |
# File 'app/components/better_ui/drawer/nav_item_component.rb', line 65 renders_one :icon |