Class: Primer::OpenProject::Pagination

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/open_project/pagination.rb

Defined Under Namespace

Classes: PageData

Constant Summary collapse

DEFAULT_MARGIN_PAGE_COUNT =
1
DEFAULT_SURROUNDING_PAGE_COUNT =
2
PAGE_TYPE__BREAK =
:break
PAGE_TYPE__PREV =
:prev
PAGE_TYPE__NEXT =
:next
PAGE_TYPE__NUM =
:num

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Constants included from AttributesHelper

AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Methods included from AttributesHelper

#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Methods included from ExperimentalSlotHelpers

included

Methods included from ExperimentalRenderHelpers

included

Constructor Details

#initialize(page_count:, current_page:, href_builder: nil, margin_page_count: DEFAULT_MARGIN_PAGE_COUNT, show_pages: true, surrounding_page_count: DEFAULT_SURROUNDING_PAGE_COUNT, link_arguments: {}, **system_arguments) ⇒ Pagination

Returns a new instance of Pagination.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/components/primer/open_project/pagination.rb', line 25

def initialize(
  page_count:,
  current_page:,
  href_builder: nil,
  margin_page_count: DEFAULT_MARGIN_PAGE_COUNT,
  show_pages: true,
  surrounding_page_count: DEFAULT_SURROUNDING_PAGE_COUNT,
  link_arguments: {},
  **system_arguments
)
  @page_count = cast_integer!(page_count, "page_count")
  @current_page = cast_integer!(current_page, "current_page")
  @href_builder = href_builder || method(:default_href_builder)
  @margin_page_count = cast_integer!(margin_page_count, "margin_page_count")
  @show_pages = show_pages
  @surrounding_page_count = cast_integer!(surrounding_page_count, "surrounding_page_count")
  @link_arguments = link_arguments
  @system_arguments = system_arguments

  @system_arguments[:tag] = :nav
  @system_arguments[:classes] = class_names(
    "PaginationContainer",
    @system_arguments[:classes]
  )
  @system_arguments["aria-label"] = I18n.t("pagination.label")

  validate_arguments!
end

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



18
19
20
# File 'app/components/primer/open_project/pagination.rb', line 18

def current_page
  @current_page
end

#href_builderObject (readonly)

Returns the value of attribute href_builder.



18
19
20
# File 'app/components/primer/open_project/pagination.rb', line 18

def href_builder
  @href_builder
end

#margin_page_countObject (readonly)

Returns the value of attribute margin_page_count.



18
19
20
# File 'app/components/primer/open_project/pagination.rb', line 18

def margin_page_count
  @margin_page_count
end

#page_countObject (readonly)

Returns the value of attribute page_count.



18
19
20
# File 'app/components/primer/open_project/pagination.rb', line 18

def page_count
  @page_count
end

#show_pagesObject (readonly)

Returns the value of attribute show_pages.



18
19
20
# File 'app/components/primer/open_project/pagination.rb', line 18

def show_pages
  @show_pages
end

#surrounding_page_countObject (readonly)

Returns the value of attribute surrounding_page_count.



18
19
20
# File 'app/components/primer/open_project/pagination.rb', line 18

def surrounding_page_count
  @surrounding_page_count
end

Instance Method Details

#pagesObject



54
55
56
57
58
# File 'app/components/primer/open_project/pagination.rb', line 54

def pages
  build_pagination_model.map do |page|
    build_component_data(page)
  end
end