Class: Shadcn::Pagination::Link::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/pagination/link/component.rb

Overview

PaginationLink — styled with the button's own variants, like the TSX does via buttonVariants({ variant: isActive ? "outline" : "ghost", size }).

Direct Known Subclasses

Next::Component, Previous::Component

Constant Summary

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#call, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(active: false, size: :icon, **attributes) ⇒ Component

Returns a new instance of Component.



14
15
16
17
18
# File 'app/components/shadcn/pagination/link/component.rb', line 14

def initialize(active: false, size: :icon, **attributes)
  @active = active
  @size = size&.to_sym || :icon
  super(**attributes)
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



12
13
14
# File 'app/components/shadcn/pagination/link/component.rb', line 12

def active
  @active
end

#sizeObject (readonly)

Returns the value of attribute size.



12
13
14
# File 'app/components/shadcn/pagination/link/component.rb', line 12

def size
  @size
end

Instance Method Details

#css_classes(extra = nil) ⇒ Object



27
28
29
30
31
32
33
# File 'app/components/shadcn/pagination/link/component.rb', line 27

def css_classes(extra = nil)
  Button::Component.variant_classes(
    variant: active ? :outline : :ghost,
    size:,
    class: extra
  )
end

#element_attributes(**defaults) ⇒ Object



20
21
22
23
24
25
# File 'app/components/shadcn/pagination/link/component.rb', line 20

def element_attributes(**defaults)
  super(**{
    "aria-current" => ("page" if active),
    "data-active" => active
  }.merge(defaults))
end