Resource filters that combine dimensions
Types are alternatives; an owner filter narrows the same resource list.
Keyboard
- Tab moves between facets and removable summary buttons.
- Space toggles choices without closing the picker.
States covered
- OR within a facet
- AND across facets
- Removable summaries
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-facets-resources.jsonComplete source
/*!
MIT License
Copyright (c) 2026 Jaison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useState} from 'react';
import {Avatar,Button,DataTable,FacetedFilter,type Column,type FacetOption} from '@bld8/ui';
const resources=[{id:'brief',title:'Interface brief',type:'doc',owner:'design'},{id:'tokens',title:'Token reference',type:'code',owner:'engineering'},{id:'review',title:'Review notes',type:'doc',owner:'engineering'}];
export function ResourceFacets(){const [types,setTypes]=useState<string[]>([]),[owners,setOwners]=useState<string[]>([]);const visible=resources.filter(row=>(!types.length||types.includes(row.type))&&(!owners.length||owners.includes(row.owner)));return <section className="bui-stack"><div className="bui-form-grid"><FacetedFilter label="Resource type" options={[{value:'doc',label:'Documents',group:'Content'},{value:'code',label:'Code',group:'Content'}]} value={types} onValueChange={setTypes} showChips/><FacetedFilter label="Resource owner" options={[{value:'design',label:'Design'},{value:'engineering',label:'Engineering'}]} value={owners} onValueChange={setOwners} showChips/></div><ul aria-label="Filtered resources">{visible.map(row=><li key={row.id}>{row.title}</li>)}</ul>{!visible.length&&<p>No resources match both filters.</p>}<p role="status">{visible.length} resources</p><Button variant="ghost" onClick={()=>{setTypes([]);setOwners([]);}}>Clear resource filters</Button></section>;}