Class: Flowbite::Link

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/flowbite/link.rb

Overview

The link component can be used to set hyperlinks from one page to another or to an external website when clicking on an inline text item, button, or card

Use this component to add default styles to an inline link element.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(href:, class: nil, **options) ⇒ Link

Initialize the Link component.

‘link_to` supports. See `ActionView::Helpers::UrlHelper#link_to` for more details.

Parameters:

  • href

    What to link to. This can be a String or anything else that

  • options (Hash)

    Additional HTML options for the link element



24
25
26
27
28
29
# File 'app/components/flowbite/link.rb', line 24

def initialize(href:, class: nil, **options)
  super()
  @class = Array.wrap(binding.local_variable_get(:class))
  @href = href
  @options = options
end

Instance Attribute Details

#hrefObject (readonly)

Returns the value of attribute href.



9
10
11
# File 'app/components/flowbite/link.rb', line 9

def href
  @href
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'app/components/flowbite/link.rb', line 9

def options
  @options
end

Class Method Details

.classesObject



12
13
14
# File 'app/components/flowbite/link.rb', line 12

def classes
  ["font-medium", "text-fg-brand", "hover:underline"]
end

Instance Method Details

#callObject



31
32
33
# File 'app/components/flowbite/link.rb', line 31

def call
  link_to(content, href, {class: classes}.merge(options))
end