Record faceted — Search block

Pro

search-record-faceted · for app, search pages

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.

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-record-faceted

Usage

Its demo data, shortened (Using blocks).

<script setup lang="ts">
import SearchRecordFaceted from '@/components/trame/blocks/search/search-record-faceted.vue'

const props = {
title: "Search",
query: "launch",
types: [
{
key: "project",
label: "Projects",
count: 3,
icon: "project"
},
{
key: "task",
label: "Tasks",
count: 24,
icon: "task"
}
],
rows: [
{
id: "p-14",
type: "project",
title: "Spring launch",
code: "SPR",
snippet: "Everything for the spring launch: the new pricing page, the onboarding emails and the press kit.",
place: [
"Marketing"
],
meta: "18 open tasks",
marks: {
title: [
[
7,
13
]
],
snippet: [
[
26,
32
]
]
}
},
{
id: "p-9",
type: "project",
title: "Mobile app launch",
code: "MOB",
snippet: "Store listings, the beta group and the launch week plan for iOS and Android.",
place: [
"Product"
],
meta: "7 open tasks",
marks: {
title: [
[
11,
17
]
],
snippet: [
[
39,
45
]
]
}
}
],
total: 38,
search: "search",
more: "search.more",
typeLink: "search.type",
open: "record.open"
}
</script>

<template>
<SearchRecordFaceted v-bind="props" />
</template>

Props

Each prop says who changes it: Words, Picture, Action, Design, Data.* required.

PropTypeDescription
titlestringWordsthe page’s heading ("Search")
query*stringWordsthe words searched, as the person typed them; shown in the field and the summary, empty before any search
types*Type[]the kinds of record the search covers, in the order shown, each with its count for this query
typestringDatathe key of the kind the results are narrowed to (the address’s `type`); all kinds when absent
rows*Row[]Datathe hits, best match first; with `type`, only that kind’s; may be empty when nothing matches
totalnumberDatahow many hits there are in all for this query (or this kind); the sum of the kinds’ counts when absent
afterstring | numberDatathe cursor of the next page of hits, when there is one
searchstringActionthe search page: the field is a GET form to href(search) sending `q` (and `type` once narrowed), so it works without script; with a host that answers queries, the hits update as the person types, through query(search, { q }), whose `items` are hits
morestringActionthe next page of hits: query(more, { after }) appends its `items`; without a host that answers queries, a link to href(more, { after, q, type })
typeLinkstringActionthe results narrowed to one kind: href(typeLink, { type, q }) is a kind’s address, and href(typeLink, { q }) every kind’s; without it the kinds are shown as words
open*stringActionthe page of one hit: href(open, hit) receives the whole hit, its `type` and `id` included
optionsOptionsthe block’s settings: layout choices and secondary words, read by every variant
Type types[] · 4 props
PropTypeDescription
key*stringDesignthe kind’s key, as hits name it in `type` ("task")
label*stringWordsthe kind in words, plural ("Tasks")
count*numberDatahow many records of this kind match, as the host counted them
icon'project' | 'task' | 'document' | 'person' | 'company' | 'deal' | 'contact' | 'message' | 'file' | 'event' | 'ticket' | 'invoice' | 'folder' | 'page'Designthe sign drawn beside the kind and its hits, from the block’s set; a neutral sign when absent
Row rows[] · 8 props
PropTypeDescription
id*string | numberDatathe record’s id in the app
type*stringDesignthe key of the record’s kind, one of `types[].key` ("task")
title*stringWordsthe record’s name as the app shows it ("Launch checklist")
codestringWordsthe record’s short reference, if the app has one ("WEB-142")
snippetstringWordsa passage of the record around the matched words, plain text ("…the launch checklist is shared with…")
placestring[]Wordswhere the record lives, outermost first: a breadcrumb in words
metastringWordsone short fact about it ("Updated 2 days ago", "Due Nov 12")
marksMarkswhere the searched words were found, as offsets the search engine answered; never HTML
Marks rows[].marks · 2 props
PropTypeDescription
titleunknown[]the matched stretches of the title
snippetunknown[]the matched stretches of the snippet
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 }
querya live read: a quick search, « see more »
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
  • No motion; still under reduced motion
  • Real buttons and links, a visible focus
  • Asks your app through actions: search, more, link, link
  • Reads rows from your app

A search section, for app, search 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.
  • Filter builder rows: Above a data table or in a filter panel: a stack of condition rows (field, operator, value) under "Match all / any", with "Add condition", "Apply" and "Save view" at the foot.
  • 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.
  • Inline commands open panel: the panel open in the page, for a search page or the app’s empty search state.

All 7 search blocks