-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathdata_table_pagination.rb
More file actions
60 lines (55 loc) · 1.86 KB
/
data_table_pagination.rb
File metadata and controls
60 lines (55 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
53
54
55
56
57
58
59
60
# frozen_string_literal: true
module RubyUI
class DataTablePagination < Base
def initialize(current_page:, total_pages:, **attrs)
@current_page = current_page
@total_pages = total_pages
super(**attrs)
end
def view_template
div(**attrs) do
div(class: "flex items-center justify-between px-2") do
div(class: "flex-1 text-sm text-muted-foreground") do
plain "Page #{@current_page} of #{@total_pages}"
end
div(class: "flex items-center space-x-2") do
nav_button(
direction: "previous",
disabled: @current_page <= 1,
action: "click->ruby-ui--data-table#previousPage",
icon_path: "m15 18-6-6 6-6"
)
nav_button(
direction: "next",
disabled: @current_page >= @total_pages,
action: "click->ruby-ui--data-table#nextPage",
icon_path: "m9 18 6-6-6-6"
)
end
end
end
end
private
def nav_button(direction:, disabled:, action:, icon_path:)
button(
type: "button",
class: "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-accent hover:text-accent-foreground h-8 w-8 p-0 #{disabled ? "opacity-50 pointer-events-none" : ""}",
disabled: disabled,
aria_label: direction,
data: {action: action}
) do
svg(
xmlns: "http://www.w3.org/2000/svg",
width: "16", height: "16", viewBox: "0 0 24 24",
fill: "none", stroke: "currentColor",
stroke_width: "2", stroke_linecap: "round", stroke_linejoin: "round"
) { |s| s.path(d: icon_path) }
end
end
def default_attrs
{
class: "flex items-center justify-end py-4"
}
end
end
end