Class: ShadcnPhlexcomponents::PaginationLink

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/pagination.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) ⇒ PaginationLink

Returns a new instance of PaginationLink.



129
130
131
132
133
# File 'lib/shadcn_phlexcomponents/components/pagination.rb', line 129

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

Instance Method Details

#view_templateObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/shadcn_phlexcomponents/components/pagination.rb', line 135

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

  @html_options ||= {}
  @html_options = mix(default_attributes, @html_options)

  active = @html_options.delete(:active)
  size = @html_options.delete(:size)

  if active
    @html_options = mix({ aria: { current: "page" } }, @html_options)
  end

  @html_options[:class] = Button.new.class_variants(
    variant: active ? :outline : :ghost,
    size: size || :icon,
    class: @html_options[:class],
  )

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