From ce78ddc75707d532ca8efbc40431b6b699ab1013 Mon Sep 17 00:00:00 2001 From: Don Barlow Date: Thu, 11 Nov 2021 14:48:13 -0700 Subject: [PATCH] add more overridable styles for the pagination component; visual bug fix --- lib/components/live_helpers.ex | 9 +++++- lib/components/pagination.ex | 53 +++++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/lib/components/live_helpers.ex b/lib/components/live_helpers.ex index 5b4a185..7a15352 100644 --- a/lib/components/live_helpers.ex +++ b/lib/components/live_helpers.ex @@ -48,7 +48,14 @@ defmodule CrunchBerry.Components.LiveHelpers do In order to customize the look and feel, you may pass in a map. The following keys are supported: - active - Classes applied to the currently active page. - - text - Classes applied to all children, except the currently active page. + - ellipsis - Classes applied to the "..." ellipsis page gap. + - first - Classes applied to the first pagination button ("<<" (previous) or page number 1). + - last - Classes applied to the last pagination button (">>" (next) or last page number). + - list - Classes applied to the containing list. + - next - Classes applied to the ">>" next button. + - page - Classes applied to page buttons other than the "<<" previous and ">>" next buttons. + - previous - Classes applied to the "<<" previous button. + - text - Classes applied to all children, except the currently active page and the ellipsis page gap. ## Pagination diff --git a/lib/components/pagination.ex b/lib/components/pagination.ex index 8304fd6..1985565 100644 --- a/lib/components/pagination.ex +++ b/lib/components/pagination.ex @@ -8,13 +8,46 @@ defmodule CrunchBerry.Components.Pagination do use Phoenix.HTML use Phoenix.LiveComponent + @type classes :: %{ + active: String.t(), + ellipsis: String.t(), + first: String.t(), + last: String.t(), + list: String.t(), + next: String.t(), + page: String.t(), + previous: String.t(), + text: String.t() + } + + @first "rounded-l" + @last "rounded-r" + @button "block border-1 -ml-px px-3 py-2" + + @classes_defaults %{ + active: "", + ellipsis: "block -ml-px px-3 pt-4", + first: @first, + last: @last, + list: "flex rounded", + next: "#{@last} #{@button}", + page: @button, + previous: "#{@first} #{@button}", + text: "" + } + @impl Phoenix.LiveComponent def update(assigns, socket) do + classes = + assigns + |> Map.get(:classes, %{}) + |> then(fn classes -> Map.merge(@classes_defaults, classes) end) + socket = assign(socket, name: assigns.name, page: assigns.page, - classes: assigns[:classes] || %{}, + classes: classes, page_event_name: Map.get(assigns, :page_event_name, "page") ) @@ -26,11 +59,11 @@ defmodule CrunchBerry.Components.Pagination do ~H""" <%= unless @page.total_pages == 1 do %>