bazza/ui
repository·main·Indexed 21 days ago
https://github.com/bazzalabs/uiAn open-source library of modern React components. It features specialized tools for data tables, including the useDataTableFilters hook for managing client-side and server-side filtering, a type-safe column configuration builder (createColumnConfigHelper), and the DataTableFilter UI component. The library also provides utility components like TypeTable for displaying technical property information and Info for popover descriptions, with built-in integration support for TanStack Table.
What's inside bazza/ui
- bazza/ui is a collection of React components and hooks designed to help you build your own custom component library. It is built on top of shadcn/ui, utilizing shadcn/ui's primitive components as building blocks for more complex, high-level components.
Available components in bazza/ui
mainCurrently, bazza/ui offers a single high-level component: a data table filter component. This component is inspired by the design and functionality of Linear.How to handle option and multi-option columns
mainFor columns with discrete choices (
optionormultiOption), you can provide options in two ways:1. Declared Options
Use this for fixed sets of options (static) or options fetched from an API (remote). Use the
.options()method on the builder.2. Inferred Options
Only available for client-side filtering. This is useful when options aren't known at build time and you don't have a dedicated endpoint. The component loops through the available data to extract unique values. If the values aren't already in the
ColumnOptionshape, use.transformOptionFn()to map them.Note: For server-side filtering, you must use the declared options approach because the client data is not representative of the full dataset.
dtf .option() .accessor((row) => row.assignee) .id('assignee') .displayName('Assignee') .icon(UserCheckIcon) .transformOptionFn((u) => ({ value: u.id, label: u.name, icon: <UserAvatar user={u} /> }))How filtering strategies work (Client vs Server)
mainThe
FilterStrategydetermines where the data filtering logic is executed:clientstrategy: The client receives the entire dataset and performs filtering locally in the browser. This is ideal for smaller datasets.serverstrategy: The client sends filter requests to the server. The server applies the filters and returns only the matching subset of data. This is required for large datasets to avoid loading everything into memory.
How useDataTableFilters works
mainThe
useDataTableFiltershook is the primary entrypoint for managing filter state and logic. It decouples the filtering logic from the UI, allowing you to use the same state with any table library (TanStack Table, AG Grid, etc.) or even no library at all.Each table should have its own instance. The hook returns:
columns: The processed column configurations.filters: The current state of all active filters.actions: Methods to mutate the filter state.strategy: The filtering strategy being used ('client'or'server').
To render the UI, pass these returned values into the
<DataTableFilters />component.const { columns, filters, actions, strategy } = useDataTableFilters({ strategy: 'client', data: issues.data ?? [], columnsConfig, }) return ( <div> <DataTableFilters columns={columns} filters={filters} actions={actions} strategy={strategy} /> <DataTable /> <DataTablePagination /> </div> )Integrate data table filters with TanStack Table
mainIf you are using TanStack Table (TST) with client-side filtering, you can use the provided integration to automatically map the data table's filter state and logic to TST.
Note: If you are using server-side filtering, this integration is not required; simply feed your data into your TST instance.
Key Functions
createTSTColumns: Overrides thefilterFnproperty for each filterable TST column with the appropriate internal filter function based on your column configurations.createTSTFilters: Converts the filter state fromuseDataTableFilters()into a TST-compatibleColumnFiltersState.
Requirements
Important: You must specify an
idfor each TST column definition that matches theidof the corresponding column filter configuration.const { columns, filters, actions, strategy } = useDataTableFilters({ /* ... */ }) const tstColumns = useMemo( () => createTSTColumns({ columns: tstColumnDefs, // your TanStack Table column definitions configs: columns, // Your column configurations }), [columns], ) const tstFilters = useMemo(() => createTSTFilters(filters), [filters]) const table = useReactTable({ data: issues.data ?? [], columns: tstColumns, getRowId: (row) => row.id, getCoreRowModel: getCoreRowModel(), getFilteredRowModel: getFilteredRowModel(), state: { columnFilters: tstFilters } })Get started with bazza/ui
mainTo begin usingbazza/uiin your projects, refer to the official documentation at https://ui.bazza.dev/docs. The library provides hand-crafted, modern React components that are open source and free to use.Install the data table filters component
mainYou can add the data table filters component to your project using the shadcn CLI:
npx shadcn@latest add https://ui.bazza.dev/r/filtersMigrate TanStack Table to the new filtering system
mainIf you are using TanStack Table, you must migrate from using the
metaproperty in column definitions to the new column configuration builder and filter instance model.Follow these steps to migrate:
- Remove
metaproperty: Delete themetaproperty from your existing TanStack Table column definitions. - Use Column Configuration Builder: Implement the new column configuration using the column configuration builder.
- Create a Filters Instance: Initialize a new filters instance to manage filtering logic.
- Setup TST Integration: Configure the TanStack Table (TST) integration to connect the new filtering logic with your table instance.
- Remove
Setup your project with shadcn/ui
mainBefore installing anybazza/uicomponents, you must first initialize and set up your project usingshadcn/ui. This is a prerequisite for using the component library. Follow the official installation guide for your specific framework (e.g., Next.js, Vite, Remix) at ui.shadcn.com/docs/installation.Contribute to bazza/ui
mainThe
bazza/uiproject is open source. If you want to contribute code, components, or improvements directly, you can do so via the GitHub repository.https://github.com/kianbazza/uiImplement server-side filtering
mainTo perform filtering on the server rather than the client, set the
strategyto'server'in theuseDataTableFiltersconfiguration.When using server-side filtering, you typically:
- Manage filter state in the URL (e.g., using
nuqs). - Pass the
filtersstate to your data fetching query. - Provide
options(for option-based columns) andfaceteddata (for unique/min/max values) to the hook so it can render the UI correctly.
Example configuration:
const { columns, filters, actions, strategy } = useDataTableFilters({ strategy: 'server', data: issues.data ?? [], columnsConfig, options: { status: statusOptions, assignee: userOptions, labels: labelOptions, }, faceted: { status: facetedStatuses.data, assignee: facetedUsers.data, labels: facetedLabels.data, estimatedHours: facetedEstimatedHours.data, }, })- Manage filter state in the URL (e.g., using