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



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

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.



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

def href
  @href
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

.classesObject



14
15
16
# File 'app/components/flowbite/link.rb', line 14

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

Instance Method Details

#callObject



33
34
35
# File 'app/components/flowbite/link.rb', line 33

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