Class: Maglev::Uikit::AppLayout::Sidebar::LinkComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/maglev/uikit/app_layout/sidebar/link_component.rb

Constant Summary collapse

[
  '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(' ')
'bg-gray-100 text-editor-primary hover:bg-gray-100'
'text-black hover:bg-gray-100'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

#button_class_names

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 = options[:icon_size] || '1.5rem'
  @position = options[:position] || :top
  @data = options[:data]
end

Instance Attribute Details

#activeObject (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

#dataObject (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

#iconObject (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_sizeObject (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

#labelObject (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

#pathObject (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

Returns:

  • (Boolean)


31
32
33
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 31

def active?
  @active
end


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


39
40
41
42
43
44
45
46
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 39

def link_html_options
  {
    class: link_classes(active: active?),
    data: data,
    title: label.presence,
    aria: link_aria_attributes
  }.compact
end

#top?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/components/maglev/uikit/app_layout/sidebar/link_component.rb', line 35

def top?
  @position == :top
end