Filter builder sentence — Search block

Pro

search-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-sentence

Usage

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.

PropTypeDescription
titlestringWordsthe builder’s heading ("Filter deals")
nounstringWordswhat 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
conditionsCondition[]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*stringActionthe 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
saveSavesaving the conditions as a named view; without it, the builder only applies
viewsView[]the views already saved (the host’s or the person’s own), as links; the one shown now is marked active
optionsOptionsthe block’s settings: layout choices and secondary words, read by every variant
Field fields[] · 4 props
PropTypeDescription
key*stringDesignthe field’s key, sent as a condition’s `field` ("stage")
label*stringWordsthe 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)
optionsOption[]for a select field: the values to choose from
Option fields[].options[] · 2 props
PropTypeDescription
value*stringDesignthe option’s value, sent as the condition’s value ("won")
label*stringWordsthe option’s words ("Won")
Condition conditions[] · 3 props
PropTypeDescription
field*stringDesignthe 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
valuestringDatathe 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
PropTypeDescription
label*stringWordsthe words on the save button ("Save view")
action*stringActionsaves 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
PropTypeDescription
label*stringWordsthe link’s words, e.g. "Unpaid"
activebooleantrue: this is the one shown now
action*stringActionthe page action that shows it
recordRecord<string, unknown>Datawhat the action needs (the filter’s value)
Options options · 1 props
PropTypeDescription
mood'inverse' | 'brand' | 'warm' | 'tint' | stringa 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).

MemberWhat it is for
hrefthe address an action leads to, or null to hide what leads there
actruns a change (subscribe, add to cart, save) and answers { ok } or { ok: false, error }
canwhether the page has this action
Linkyour router’s link component
cartCountthe cart badge’s number
cartDrawerwhether your app has a cart drawer
cartOpenwhether the cart drawer is open
labelyour 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:

KeyEnglishFrench
newsletter.alreadyYou are already subscribed.Vous êtes déjà inscrit.
newsletter.doneDone: you are subscribed.C’est noté : vous êtes inscrit.
newsletter.invalidCheck the email address.Vérifiez l’adresse e-mail.
newsletter.tooManyToo 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 fields from 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.

All 7 search blocks