Packages
flop_phoenix
0.22.6
0.26.1
0.26.0
0.25.3
0.25.2
0.25.1
0.25.0
0.24.1
0.24.0
0.23.1
0.23.0
0.22.10
0.22.9
0.22.8
0.22.7
0.22.6
0.22.5
0.22.4
0.22.3
0.22.2
0.22.1
0.22.0
0.21.2
0.21.1
0.21.0
0.20.0
0.19.1
0.19.0
0.18.2
0.18.1
0.18.0
0.17.2
0.17.1
0.17.0
0.16.0
0.15.2
0.15.1
0.15.0
0.14.2
0.14.1
0.14.0
0.13.0
0.12.0
0.11.1
0.11.0
0.10.0
0.9.1
0.9.0
0.8.1
0.8.0
0.7.0
0.6.1
0.6.0
0.5.1
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0
Phoenix components for pagination, sortable tables and filter forms using Flop.
Current section
Files
Jump to
Current section
Files
lib/flop_phoenix/cursor_pagination.ex
defmodule Flop.Phoenix.CursorPagination do
@moduledoc false
use Phoenix.Component
alias Flop.Meta
alias Flop.Phoenix.Misc
require Logger
@spec default_opts() :: [Flop.Phoenix.cursor_pagination_option()]
def default_opts do
[
disabled_class: "disabled",
next_link_attrs: [
aria: [label: "Go to next page"],
class: "pagination-next"
],
next_link_content: "Next",
previous_link_attrs: [
aria: [label: "Go to previous page"],
class: "pagination-previous"
],
previous_link_content: "Previous",
wrapper_attrs: [
class: "pagination",
role: "navigation",
aria: [label: "pagination"]
]
]
end
def merge_opts(opts) do
default_opts()
|> Misc.deep_merge(Misc.get_global_opts(:cursor_pagination))
|> Misc.deep_merge(opts)
end
# meta, direction, reverse
def disable?(%Meta{has_previous_page?: true}, :previous, false), do: false
def disable?(%Meta{has_next_page?: true}, :next, false), do: false
def disable?(%Meta{has_previous_page?: true}, :next, true), do: false
def disable?(%Meta{has_next_page?: true}, :previous, true), do: false
def disable?(%Meta{}, _, _), do: true
def pagination_path(_, nil, _), do: nil
def pagination_path(direction, path, %Flop.Meta{} = meta) do
params =
meta
|> Flop.set_cursor(direction)
|> Flop.Phoenix.to_query(backend: meta.backend, for: meta.schema)
Flop.Phoenix.build_path(path, params)
end
end