Skip to content
Open
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
74 changes: 74 additions & 0 deletions examples/official-site/content/components/facet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
icon: filter
since: 0.46.0
category: navigation
summary: Let readers choose filters for a dataset.
top:
- name: all_active
type: BOOLEAN
description: Whether the link that clears the filter is active. Defaults to false.
- name: all_link
type: URL
description: URL that clears the filter. If omitted, no All link is displayed.
- name: all_title
type: TEXT
description: Text for the link that clears the filter. Defaults to "ALL".
- name: center
type: BOOLEAN
description: Whether to center the facet selector
- class
- name: compact
type: BOOLEAN
description: Displays the facets in a dropdown instead of links.
- name: description
type: TEXT
description: The facet category label.
- name: dropdown_title
type: TEXT
description: Text shown on the compact-mode dropdown button when no facet is selected. Defaults to `Choose
facet`.
- id
- name: selected_facet
type: TEXT
description: An alias for `dropdown_title`.
row:
- name: active
type: BOOLEAN
description: Whether the link is active or not. Defaults to false.
- name: link
type: URL
required: true
description: URL for the facet.
- name: title
type: TEXT
required: true
description: Facet title.
---

Navigation links for filtering a dataset by a category, status, owner, or other attribute.

This component only renders the filter navigation. **Your SQL query is responsible for filtering the data** based on the URL parameter selected by the user.

Use it alongside a [table](?component=table), [list](?component=list), or [card](?component=card). The links use GET parameters, so the selected filter can be bookmarked and shared.

Set `compact` to display the facets in a dropdown, which is useful for a moderate number of choices or on narrow screens. Use `selected_facet` to show the active facet in the closed dropdown. `all_link` and `all_title` add a link that clears the filter.

The following portable pattern filters a table by category. `sqlpage.link` preserves the current page path while safely generating the URL.

```sql
select 'table' as component;
select title, category
from my_table
where $category is null or category = $category;

select 'facet' as component,
'Category' as description,
sqlpage.link(sqlpage.path(), json_object('category', null)) as all_link,
$category is null as all_active;
select category as title,
sqlpage.link(sqlpage.path(), json_object('category', category)) as link,
category = $category as active
from my_table
group by category
order by category;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
rows:
- component: table
- name: USS Enterprise (NCC-1701)
class: Constitution
- name: USS Exeter (NCC-1672)
class: Galaxy
- name: USS Exeter (NCC-1672)
class: Constitution
- component: facet
description: Classes
all_link: ?component=facet
all_title: All
all_active: false
- title: Constitution
link: ?component=facet&class=Constitution
active: true
- title: Galaxy
link: ?component=facet&class=Galaxy
---

A category selector with an All link. In an application, the SQL pattern above uses the chosen URL parameter to filter the displayed data.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
rows:
- component: table
- name: USS Enterprise (NCC-1701)
class: Constitution
- name: USS Defiant (NCC-1764)
class: Constitution
- name: USS Exeter (NCC-1672)
class: Constitution
- component: facet
description: Classes
all_link: ?component=facet
all_title: All
all_active: false
compact: true
dropdown_title: Select a spaceship class
selected_facet: Constitution
- title: Constitution
link: ?component=facet&class=Constitution
active: true
- title: Galaxy
link: ?component=facet&class=Galaxy
---

Compact mode displays the facet choices in a dropdown.
105 changes: 105 additions & 0 deletions examples/official-site/content/components/pagination.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
icon: sailboat-2
since: 0.40.0
category: navigation
summary: Link to other pages of a query result.
top:
- name: circle
type: BOOLEAN
description: Whether to use circle version of the pagination.
- class
- name: first_disabled
type: BOOLEAN
description: disables the button to go to the first page.
- name: first_link
type: URL
description: A target URL to which the user should be directed to get to the first page. If none, the link
is not displayed.
- name: first_title
type: TEXT
description: The text displayed on the button to go to the first page.
- id
- name: last_disabled
type: BOOLEAN
description: disables the button to go to the last page.
- name: last_link
type: URL
description: A target URL to which the user should be directed to get to the last page. If none, the link
is not displayed.
- name: last_title
type: TEXT
description: The text displayed on the button to go to the last page.
- name: next_disabled
type: BOOLEAN
description: Disables the button to go to the next page.
- name: next_link
type: URL
description: A target URL to which the user should be directed to get to the next page. If none, the link
is not displayed.
- name: next_title
type: TEXT
description: The text displayed on the button to go to the next page.
- name: outline
type: BOOLEAN
description: Whether to use outline version of the pagination.
- name: previous_disabled
type: BOOLEAN
description: disables the button to go to the previous page.
- name: previous_link
type: URL
description: A target URL to which the user should be directed to get to the previous page. If none, the
link is not displayed.
- name: previous_title
type: TEXT
description: The text displayed on the button to go to the previous page.
row:
- name: active
type: BOOLEAN
description: Whether the link is active or not. Defaults to false.
- name: contents
type: INTEGER
required: true
description: Page number.
- name: link
type: URL
description: A target URL to which the user should be redirected to view the requested page of data.
- name: offset
type: BOOLEAN
description: Whether to use offset to show only a few pages at a time. Usefull if the count of pages is
too large. Defaults to false
---

Navigation links to go to the first, previous, next, or last page of a dataset.
Useful when data is divided into pages, each containing a fixed number of rows.

This component only handles the display of pagination.
**Your sql queries are responsible for filtering data** based on the page number passed as a URL parameter.

This component is typically used in conjunction with a [table](?component=table),
[list](?component=list), or [card](?component=card) component.

The pagination component displays navigation buttons (first, previous, next, last) customizable with text or icons.

For large numbers of pages, an offset can limit the visible page links.

This SQLite example uses the first page when no offset is supplied. Order by a unique key so successive pages have a stable order.
```sql
set offset = max(0, coalesce(cast($offset as integer), 0));
select 'table' as component;
select * from my_table order by id limit 100 offset cast($offset as integer);

select 'pagination' as component;
with recursive pages as (
select 0 as offset
union all
select offset + 100 from pages
where offset + 100 < (select count(*) from my_table)
)
select
(offset/100+1) as contents,
sqlpage.link(sqlpage.path(), json_object('offset', offset)) as link,
offset = cast($offset as integer) as active
from pages;
```

For more advanced usage, the [pagination guide](blog.sql?post=How+to+use+the+pagination+component) provides a complete tutorial.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
rows:
- component: pagination
- contents: 1
link: ?component=pagination&page=1
active: true
- contents: 2
link: ?component=pagination&page=2
- contents: 3
link: ?component=pagination&page=3
---

This is an extremely simple example of a pagination component that displays only the page numbers, with the first page being the current page.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
rows:
- component: pagination
outline: true
- contents: 1
link: ?component=pagination&page=1
active: true
- contents: 2
link: ?component=pagination&page=2
- contents: 3
link: ?component=pagination&page=3
---

The ouline style adds a rectangular border to each navigation link.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
rows:
- component: pagination
circle: true
- contents: 1
link: ?component=pagination&page=1
active: true
- contents: 2
link: ?component=pagination&page=2
- contents: 3
link: ?component=pagination&page=3
---

The circle style adds a circular border to each navigation link.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
rows:
- component: pagination
first_link: ?component=pagination
first_disabled: true
previous_link: ?component=pagination
previous_disabled: true
next_link: '#?page=2'
last_link: '#?page=3'
- contents: 1
link: ?component=pagination&page=1
active: true
- contents: 2
link: ?component=pagination&page=2
- contents: 3
link: ?component=pagination&page=3
---

The following example implements navigation links that can be enabled or disabled as needed. Since a navigation link does not appear if no link is assigned to it, you must always assign a link to display it as disabled.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
rows:
- component: pagination
first_title: First
last_title: Last
previous_title: Previous
next_title: Next
first_link: ?component=pagination
first_disabled: true
previous_link: ?component=pagination
previous_disabled: true
next_link: '#?page=2'
last_link: '#?page=3'
- contents: 1
link: ?component=pagination&page=1
active: true
- contents: 2
link: ?component=pagination&page=2
- contents: 3
link: ?component=pagination&page=3
---

Instead of using icons, you can apply text to the navigation links.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
rows:
- component: pagination
first_link: '#?page=1'
previous_link: '#?page=3'
next_link: '#?page=4'
last_link: '#?page=99'
- contents: 1
link: ?component=pagination&page=1
- contents: 2
link: ?component=pagination&page=2
- contents: 3
link: ?component=pagination&page=3
- contents: 4
link: ?component=pagination&page=4
active: true
- contents: 5
link: ?component=pagination&page=5
- contents: 6
link: ?component=pagination&page=6
- offset: true
- contents: 99
link: ?component=pagination&page=99
---

If you have a large number of pages to display, you can use an offset to represent a group of pages.
Loading
Loading