Class: Maglev::Uikit::AppLayout::Sidebar::LinkComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Maglev::Uikit::AppLayout::Sidebar::LinkComponent
- Defined in:
- app/components/maglev/uikit/app_layout/sidebar/link_component.rb
Constant Summary collapse
- LINK_BASE_CLASSES =
[ 'relative flex w-full min-h-11 items-center justify-center rounded py-3', 'outline-none transition-colors duration-200', 'focus-visible:ring-2 focus-visible:ring-editor-primary/50', 'focus-visible:ring-offset-2 focus-visible:ring-offset-white' ].join(' ')
- LINK_ACTIVE_CLASSES =
'bg-gray-100 text-editor-primary hover:bg-gray-100'- LINK_INACTIVE_CLASSES =
'text-black hover:bg-gray-100'
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#icon_size ⇒ Object
readonly
Returns the value of attribute icon_size.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#initialize(path:, icon:, active: false, label: nil, options: {}) ⇒ LinkComponent
constructor
A new instance of LinkComponent.
- #link_classes ⇒ Object
- #link_html_options ⇒ Object
- #top? ⇒ Boolean
Methods inherited from BaseComponent
Constructor Details
#initialize(path:, icon:, active: false, label: nil, options: {}) ⇒ LinkComponent
Returns a new instance of LinkComponent.
21 22 23 24 25 26 27 28 29 |
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 21 def initialize(path:, icon:, active: false, label: nil, options: {}) @path = path @active = active @icon = icon @label = label @icon_size = [:icon_size] || '1.5rem' @position = [:position] || :top @data = [:data] end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
19 20 21 |
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 19 def active @active end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
19 20 21 |
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 19 def data @data end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
19 20 21 |
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 19 def icon @icon end |
#icon_size ⇒ Object (readonly)
Returns the value of attribute icon_size.
19 20 21 |
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 19 def icon_size @icon_size end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
19 20 21 |
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 19 def label @label end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
19 20 21 |
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 19 def path @path end |
Instance Method Details
#active? ⇒ Boolean
31 32 33 |
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 31 def active? @active end |
#link_classes ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 48 def link_classes(...) class_variants( base: LINK_BASE_CLASSES, variants: { active: LINK_ACTIVE_CLASSES, '!active': LINK_INACTIVE_CLASSES } ).render(...) end |
#link_html_options ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 39 def { class: link_classes(active: active?), data: data, title: label.presence, aria: link_aria_attributes }.compact end |
#top? ⇒ Boolean
35 36 37 |
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 35 def top? @position == :top end |