Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable page size to the Default UI #497

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/content/docs/ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ new PagefindUI({ element: "#search" });

A selector for the HTML element to attach Pagefind UI to. This is the only required argument.

### Page size

{{< diffcode >}}
```javascript
new PagefindUI({
element: "#search",
+ pageSize: 5
});
```
{{< /diffcode >}}

The number of search results to load at once, before a "Load more" button is shown. Defaults to `5`.

### Show sub results

{{< diffcode >}}
Expand Down
7 changes: 4 additions & 3 deletions pagefind_ui/default/svelte/ui.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}

export let base_path = "/pagefind/";
export let page_size = 5;
export let reset_styles = true;
export let show_images = true;
export let show_sub_results = false;
Expand Down Expand Up @@ -64,7 +65,7 @@
let searched = false;
let search_id = 0;
let search_term = "";
let show = 5;
let show = page_size;
let initial_filters = null;
let available_filters = null;
let selected_filters = {};
Expand Down Expand Up @@ -199,7 +200,7 @@
}
searchResult = results;
loading = false;
show = 5;
show = page_size;
}
};

Expand All @@ -212,7 +213,7 @@

const showMore = (e) => {
e?.preventDefault();
show += 5;
show += page_size;
};
</script>

Expand Down
3 changes: 3 additions & 0 deletions pagefind_ui/default/ui-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class PagefindUI {

let selector = opts.element ?? "[data-pagefind-ui]";
let bundlePath = opts.bundlePath ?? scriptBundlePath;
let pageSize = opts.pageSize ?? 5;
let resetStyles = opts.resetStyles ?? true;
let showImages = opts.showImages ?? true;
let showSubResults = opts.showSubResults ?? false;
Expand All @@ -34,6 +35,7 @@ export class PagefindUI {
// Remove the UI-specific config before passing it along to the Pagefind backend
delete opts["element"];
delete opts["bundlePath"];
delete opts["pageSize"];
delete opts["resetStyles"];
delete opts["showImages"];
delete opts["showSubResults"];
Expand All @@ -54,6 +56,7 @@ export class PagefindUI {
target: dom,
props: {
base_path: bundlePath,
page_size: pageSize,
reset_styles: resetStyles,
show_images: showImages,
show_sub_results: showSubResults,
Expand Down