UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

76 lines 3.19 kB
import { ReactNode } from 'react'; export interface ColumnFilterOption { value: string; label: ReactNode; /** * Text a local search matches against. Needed because `label` is a ReactNode * (a badge, an icon + text) and `value` is often an opaque id — neither is * searchable. Ignored when the config supplies `onSearch`, since the server * does the matching then. */ searchText?: string; } export interface ColumnFilterConfig { /** Choices shown in the header menu. */ options: ColumnFilterOption[]; /** Allow more than one value at a time (default: false). */ multiple?: boolean; /** Label of the "clear filter" entry at the top of the menu (default: "Todos"). */ allLabel?: string; /** * Key this filter is emitted under in the table params — i.e. the field name * the API expects. Defaults to the column's `key`. */ paramKey?: string; /** * Show a search box at the top of the menu. * * Needed whenever the option list is too long to scan — a school manager sees * over a thousand schools, and a plain list of those is unusable. */ searchable?: boolean; /** Placeholder of the search box (default: "Buscar..."). */ searchPlaceholder?: string; /** * Called (debounced) as the user types, for options fetched from a server. * * The consumer keeps owning `options`: it refreshes them as results arrive. * When omitted, a `searchable` menu filters the given `options` in place. */ onSearch?: (query: string) => void; /** Show a loading state in the menu while the search is in flight. */ loading?: boolean; } /** Minimum shape `useColumnFilters` needs out of a column definition. */ export interface FilterableColumn { key: string; filter?: ColumnFilterConfig; } export interface UseColumnFiltersOptions { /** Persist the active filters in the query string. */ syncWithUrl?: boolean; /** Prefix for the URL keys, so two tables on one page don't collide. */ urlKeyPrefix?: string; /** Called on every change (the TableProvider uses it to go back to page 1). */ onFiltersChange?: () => void; } export interface UseColumnFiltersReturn { /** Active values per paramKey. Columns with no selection are absent. */ columnFilters: Record<string, string[]>; /** * The same thing, shaped for the request: single-value filters unwrapped, * multi-value ones left as arrays. Stable identity — safe to spread into a * memo that feeds `onParamsChange`. */ columnFilterParams: Record<string, string | string[]>; setColumnFilter: (paramKey: string, values: string[]) => void; } /** * State for the per-column filter menus rendered in the table header. * * Single-phase on purpose: picking a value applies it immediately. (The modal * filters in `useTableFilter` are two-phase — draft, then "Apply" — which is * the wrong shape for a dropdown that closes on selection.) */ export declare function useColumnFilters(columns: FilterableColumn[], options?: UseColumnFiltersOptions): UseColumnFiltersReturn; //# sourceMappingURL=useColumnFilters.d.ts.map