Skip to content

0.10.0

Compare
Choose a tag to compare
@woylie woylie released this 24 Oct 08:05
· 642 commits to main since this release
499b1bc

Added

  • It is now possible to set global options for the components in your config.
config :flop_phoenix,
  pagination: [opts: {MyApp.ViewHelpers, :pagination_opts}],
  table: [opts: {MyApp.ViewHelpers, :table_opts}]

Changed

  • The for, event and target options moved from the opts assign to the
    root. The opts assign is now exclusively used for customization options
    that modify the appearance, which are usually set globally for a
    project and are not related to the specific data or view.
  • The row_func/2 function passed to the table component receives the new
    row_opts assign now instead of the opts assign.
  • The pagination and table components only pass the for option to the query
    builder, instead of all opts.
  • The path_helper and path_helper_args assigns are now optional if an
    event is passed. A descriptive error is raised if neither of them are
    passed.
  • The opts assign for the pagination and table components is now optional.
  • Aria labels were added to the links to the first and last page.
  • The aria-sort attribute was added to the table headers.

How to upgrade

  1. Remove the for, event and target from the opts assign and add them
    as regular assigns at the root level.
  2. Move any key/value pairs that are needed by your row_func from opts to
    row_opts.

For example, if your row_func looks like this:

def table_row(%Pet{id: id, name: name}, opts) do
  socket = Keyword.fetch!(opts, :socket)
  [name, link("show", to: Routes.pet_path(socket, :show, id))]
end

Update your template like this:

<Flop.Phoenix.sortable_table
  row_func={&table_row/2}
-   opts={[
-     container: true,
-     for: Pet,
-     event: "sort-table",
-     target: @myself,
-     socket: @socket
-   ]}
+   row_opts={[socket: @socket]}
+   for={Pet}
+   event="sort-table"
+   target={@myself}
+   opts={[container: true]}
/>

<Flop.Phoenix.pagination
-   opts={[
-     for: Pet,
-     event: "paginate",
-     target: @myself,
-     page_links: {:ellipsis, 7}
-   ]}
+   for={Pet}
+   event="paginate"
+   target={@myself}
+   opts={[page_links: {:ellipsis, 7}]}
/>