Class: ShadcnPhlexcomponents::Link

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/link.rb

Constant Summary

Constants inherited from Base

Base::SANITIZER_ALLOWED_ATTRIBUTES, Base::SANITIZER_ALLOWED_TAGS, Base::TAILWIND_MERGER

Instance Method Summary collapse

Methods inherited from Base

#before_template, #convert_collection_hash_to_struct, #default_attributes, #find_as_child, #icon, #item_disabled?, #merge_default_attributes, #merged_as_child_attributes, #nokogiri_attributes_to_hash, #overlay, #sanitize_as_child

Constructor Details

#initialize(name = nil, options = nil, html_options = nil) ⇒ Link

Returns a new instance of Link.



14
15
16
17
18
# File 'lib/shadcn_phlexcomponents/components/link.rb', line 14

def initialize(name = nil, options = nil, html_options = nil)
  @name = name
  @options = options
  @html_options = html_options
end

Instance Method Details

#view_templateObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/shadcn_phlexcomponents/components/link.rb', line 20

def view_template(&)
  if block_given?
    @html_options = @options
    @options = @name
  end

  @html_options ||= {}
  variant = @html_options.delete(:variant)
  size = @html_options.delete(:size) || :default

  @html_options[:class] = if variant
    Button.new.class_variants(variant: variant, size: size, class: @html_options[:class])
  else
    class_variants(class: @html_options[:class])
  end

  if block_given?
    link_to(@options, @html_options, &)
  else
    link_to(@name, @options, @html_options)
  end
end