Filter builder sentence — Search block
Prosearch-filter-builder-sentence · for app pages
Filter builder sentence
When the filter should read as plain words ("Show deals where stage is Won and amount is greater than 10000"): each part is a token that opens a small popover to change it.
Documentation
Installation
One command copies the block into your project with the shadcn CLI (the registry is set once: Installation).
pnpm dlx shadcn-vue@latest add @trame/search-filter-builder-sentenceUsage
Its demo data, shortened (Using blocks).
<script setup lang="ts">
import SearchFilterBuilderSentence from '@/components/trame/blocks/search/search-filter-builder-sentence.vue'
const props = {
title: "Filter deals",
noun: "deals",
fields: [
{
key: "stage",
label: "Stage",
type: "select",
options: [
{
value: "lead",
label: "Lead"
},
{
value: "qualified",
label: "Qualified"
}
]
},
{
key: "amount",
label: "Amount (USD)",
type: "number"
}
],
conditions: [
{
field: "stage",
operator: "is",
value: "proposal"
},
{
field: "amount",
operator: "gt",
value: "10000"
}
],
match: "all",
apply: "deals.list",
save: {
label: "Save view",
action: "deals.saveView"
},
views: [
{
label: "All deals",
action: "deals.view",
record: {
id: "all"
}
},
{
label: "Big proposals",
active: true,
action: "deals.view",
record: {
id: "big-proposals"
}
}
]
}
</script>
<template>
<SearchFilterBuilderSentence v-bind="props" />
</template>Props
Each prop says who changes it: Words, Picture, Action, Design, Data.* required.
| Prop | Type | Description |
|---|---|---|
| title | string | Wordsthe builder’s heading ("Filter deals") |
| noun | string | Wordswhat the list holds, in the plural, as the sentence says it ("deals"); "records" by default |
| fields* | Field[] | the fields a condition can test, in the order the menu lists them |
| conditions | Condition[] | the conditions in effect now, as the address carries them, shown prefilled |
| match | 'all' | 'any' | how the conditions combine: all must hold (the default) or any one |
| apply* | string | Actionthe list’s address: Apply sends a GET form to it with `match` and `conditions[0][field]`, `conditions[0][operator]`, `conditions[0][value]`…; its own query parameters are kept |
| save | Save | saving the conditions as a named view; without it, the builder only applies |
| views | View[] | the views already saved (the host’s or the person’s own), as links; the one shown now is marked active |
| options | Options | the block’s settings: layout choices and secondary words, read by every variant |
Field fields[] · 4 props
| Prop | Type | Description |
|---|---|---|
| key* | string | Designthe field’s key, sent as a condition’s `field` ("stage") |
| label* | string | Wordsthe field’s name, as a person reads it ("Stage") |
| type* | 'text' | 'number' | 'date' | 'select' | 'boolean' | what the field holds: it fixes the operators offered and the value control (a text box, a number, a date, a list of options, none) |
| options | Option[] | for a select field: the values to choose from |
Option fields[].options[] · 2 props
| Prop | Type | Description |
|---|---|---|
| value* | string | Designthe option’s value, sent as the condition’s value ("won") |
| label* | string | Wordsthe option’s words ("Won") |
Condition conditions[] · 3 props
| Prop | Type | Description |
|---|---|---|
| field* | string | Designthe key of one of the fields |
| operator* | 'is' | 'is_not' | 'contains' | 'not_contains' | 'starts_with' | 'gt' | 'gte' | 'lt' | 'lte' | 'on' | 'before' | 'after' | 'is_true' | 'is_false' | 'is_empty' | 'is_not_empty' | one of the operators the field’s type offers, e.g. "contains" for text, "gt" for a number, "before" for a date |
| value | string | Datathe value as the form posts it: text, a number as written ("10000"), a date YYYY-MM-DD, an option’s value; absent when the operator takes none |
Save save · 2 props
| Prop | Type | Description |
|---|---|---|
| label* | string | Wordsthe words on the save button ("Save view") |
| action* | string | Actionsaves the conditions as a named view: through the host it receives `{ name, conditions, match }`; posted natively, the fields `name`, `match` and `conditions[i][…]`. Hidden when the page lacks it |
View views[] · 4 props
| Prop | Type | Description |
|---|---|---|
| label* | string | Wordsthe link’s words, e.g. "Unpaid" |
| active | boolean | true: this is the one shown now |
| action* | string | Actionthe page action that shows it |
| record | Record<string, unknown> | Datawhat the action needs (the filter’s value) |
Options options · 1 props
| Prop | Type | Description |
|---|---|---|
| mood | 'inverse' | 'brand' | 'warm' | 'tint' | string | a band of the page that redefines the theme surfaces inside it |
What it asks your app for
The block never knows your app: it asks it, through one context provided once, where its links lead, what its actions do, how a price reads and which words to say (The host context).
| Member | What it is for |
|---|---|
| href | the address an action leads to, or null to hide what leads there |
| act | runs a change (subscribe, add to cart, save) and answers { ok } or { ok: false, error } |
| can | whether the page has this action |
| Link | your router’s link component |
| cartCount | the cart badge’s number |
| cartDrawer | whether your app has a cart drawer |
| cartOpen | whether the cart drawer is open |
| label | your word for an interface key, or undefined to keep the block’s own |
The words it says itself, in English and French; label(key) replaces any of them:
| Key | English | French |
|---|---|---|
| newsletter.already | You are already subscribed. | Vous êtes déjà inscrit. |
| newsletter.done | Done: you are subscribed. | C’est noté : vous êtes inscrit. |
| newsletter.invalid | Check the email address. | Vérifiez l’adresse e-mail. |
| newsletter.tooMany | Too many attempts, try again in a moment. | Trop de tentatives, réessayez dans un moment. |
Features
- Every word in the server HTML
- Same markup in Vue and React
- Theme tokens only: every theme, light and dark
- Shows what you give it, invents nothing
- Subtle motion: one short reveal; still under reduced motion
- Real buttons and links, a visible focus
- Asks your app through actions:
link,view.save,views[] - Reads
fieldsfrom your app
A search section, for app pages; it uses @lucide/vue, @vueuse/core, class-variance-authority, clsx, reka-ui, tailwind-merge.
Built with
The components this block is made of; each one installs on its own too.
More search blocks
- Command menu dialog: the app’s palette: a quiet trigger showing the shortcut, the panel opens over the page.
- Inline commands open panel: the panel open in the page, for a search page or the app’s empty search state.
- Record faceted: A large index searched often: the kinds and their counts in a side column, the field and the flat list of hits beside it; on a phone the kinds fold into a row above.
- Record grouped: A first look across everything: one section per kind (projects, tasks, documents, people) with its best five hits and a "See all 24" link to that kind alone.
- Record tabbed: People who know what they want: tabs of the kinds with their counts above one flat list of mixed hits, each with its kind’s sign, its reference, the title with the matched words, a snippet and where it lives.