-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5286 from solidusio/elia/admin/pagination-buttons
[Admin] Use `ui/button` for the pagination component
- Loading branch information
Showing
14 changed files
with
109 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 24 additions & 29 deletions
53
admin/app/components/solidus_admin/ui/table/pagination/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,24 @@ | ||
<div> | ||
<nav aria-label="pagination"> | ||
<ul class="flex items-center"> | ||
<li> | ||
<% if @page.first? %> | ||
<span class="<%= link_classes(rounded: :left) %>", "aria-label"=<%= t(".prev") %>, "aria-disabled"=true> | ||
<%= icon_tag("arrow-left-s-line", class: "fill-current text-grey-400 w-5 h-5") %> | ||
</span> | ||
<% else %> | ||
<%= link_to @path.call(@page.number - 1), class: link_classes(rounded: :left), "aria-label" => t(".prev") do %> | ||
<%= icon_tag("arrow-left-s-line", class: "w-5 h-5") %> | ||
<% end %> | ||
<% end %> | ||
</li> | ||
|
||
<li> | ||
<% if @page.last? %> | ||
<span class="<%= link_classes(rounded: :right) %>", "aria-label"=<%= t(".next") %>, "aria-disabled"=true> | ||
<%= icon_tag("arrow-right-s-line", class: "fill-current text-grey-400 w-5 h-5") %> | ||
</span> | ||
<% else %> | ||
<%= link_to @path.call(@page.next_param), class: link_classes(rounded: :right), "aria-label" => t(".next") do %> | ||
<%= icon_tag("arrow-right-s-line", class: "w-5 h-5") %> | ||
<% end %> | ||
<% end %> | ||
</li> | ||
</ul> | ||
</nav> | ||
</div> | ||
<nav aria-label="pagination" class="flex items-center"> | ||
<%= render component('ui/button').new( | ||
icon: 'arrow-left-s-line', | ||
class: 'rounded-tr-none rounded-br-none border-r-0', | ||
scheme: :secondary, | ||
size: :s, | ||
tag: :a, | ||
href: @prev_link, | ||
'aria-disabled': @prev_link.blank?, | ||
rel: 'prev', | ||
text: content_tag(:span, t('.previous'), class: 'sr-only'), | ||
) -%> | ||
<%= render component('ui/button').new( | ||
icon: 'arrow-right-s-line', | ||
class: 'rounded-tl-none rounded-bl-none', | ||
scheme: :secondary, | ||
size: :s, | ||
tag: :a, | ||
href: @next_link, | ||
'aria-disabled': @next_link.blank?, | ||
rel: 'next', | ||
text: content_tag(:span, t('.next'), class: 'sr-only'), | ||
) %> | ||
</nav> |
42 changes: 7 additions & 35 deletions
42
admin/app/components/solidus_admin/ui/table/pagination/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::UI::Table::Pagination::Component < SolidusAdmin::BaseComponent | ||
# @param page [GearedPagination::Page] The Geared Pagination page object | ||
# @param path [Proc] (optional) A callable object that generates the path, | ||
# e.g. ->(page_number){ products_path(page: page_number) } | ||
def initialize(page:, path: nil) | ||
@page = page | ||
@path = path || default_path | ||
# @param prev_link [String] The link to the previous page. | ||
# @param next_link [String] The link to the next page. | ||
def initialize(prev_link: nil, next_link: nil) | ||
@prev_link = prev_link | ||
@next_link = next_link | ||
end | ||
|
||
def default_path | ||
model_name = @page.records.model.model_name.param_key | ||
lambda { |page_number| send("#{model_name.pluralize}_path", page: page_number) } | ||
end | ||
|
||
def link_classes(rounded: nil) | ||
classes = %w[ | ||
flex | ||
items-center | ||
justify-center | ||
px-2 | ||
h-10 | ||
ml-0 | ||
leading-tight | ||
text-gray-500 | ||
bg-white | ||
border | ||
border-gray-300 | ||
hover:bg-gray-100 | ||
hover:text-gray-700 | ||
dark:bg-gray-800 | ||
dark:border-gray-700 | ||
dark:text-gray-400 | ||
dark:hover:bg-gray-700 | ||
dark:hover:text-white | ||
] | ||
classes << 'rounded-l-lg' if rounded == :left | ||
classes << 'rounded-r-lg' if rounded == :right | ||
classes.join(' ') | ||
def render? | ||
@prev_link.present? || @next_link.present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
admin/spec/components/previews/solidus_admin/ui/button/component_preview/group.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<%= render current_component.new( | ||
tag: :a, | ||
rel: 'prev', | ||
href: '#', | ||
icon: 'arrow-left-s-line', | ||
class: 'rounded-tr-none rounded-br-none border-r-0', | ||
scheme: :secondary, | ||
size: :s | ||
) -%> | ||
<%= render current_component.new( | ||
tag: :a, | ||
rel: 'next', | ||
icon: 'arrow-right-s-line', | ||
class: 'rounded-tl-none rounded-bl-none', | ||
scheme: :secondary, | ||
size: :s, | ||
'aria-disabled': true | ||
) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
admin/spec/components/previews/solidus_admin/ui/table/component_preview/simple.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<%= render current_component.new( | ||
page: page, | ||
footer: render(component("ui/table/pagination").new( | ||
prev_link: nil, | ||
next_link: '#2', | ||
)), | ||
columns: [ | ||
{ header: :id, data: -> { _1.id.to_s } }, | ||
{ header: :name, data: :name }, | ||
{ header: -> { "Availability at #{Time.current}" }, data: -> { "#{time_ago_in_words _1.available_on} ago" } }, | ||
{ header: -> { component("ui/badge").new(name: "$$$") }, data: -> { component("ui/badge").new(name: _1.display_price, color: :green) } }, | ||
{ header: "Generated at", data: Time.current.to_s }, | ||
] | ||
) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
...components/previews/solidus_admin/ui/table/pagination/component_preview/overview.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters