analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
92 lines • 4.3 kB
TypeScript
import React, { HTMLAttributes, ThHTMLAttributes } from 'react';
import type { EmptyStateConfig, LoadingStateConfig, NoSearchResultConfig } from '../TableProvider/TableProvider';
type TableVariant = 'default' | 'borderless';
type TableRowState = 'default' | 'selected' | 'invalid' | 'disabled';
export type SortDirection = 'asc' | 'desc' | null;
export interface UseTableSortOptions {
/** Se true, sincroniza o estado de ordenação com os parâmetros da URL */
syncWithUrl?: boolean;
}
/**
* Hook para gerenciar ordenação de dados da tabela
*
* @param data - Array de dados a serem ordenados
* @param options - Opções de configuração do hook
* @returns Objeto com dados ordenados, coluna/direção atual e função de sort
*
* @example
* ```tsx
* const activities = [
* { id: 1, name: 'Task A', date: '2024-01-01' },
* { id: 2, name: 'Task B', date: '2024-01-02' },
* ];
*
* // Sem sincronização com URL
* const { sortedData, sortColumn, sortDirection, handleSort } = useTableSort(activities);
*
* // Com sincronização com URL
* const { sortedData, sortColumn, sortDirection, handleSort } = useTableSort(activities, { syncWithUrl: true });
*
* <TableHead
* sortDirection={sortColumn === 'name' ? sortDirection : null}
* onSort={() => handleSort('name')}
* >
* Name
* </TableHead>
* ```
*/
export declare function useTableSort<T extends Record<string, unknown>>(data: T[], options?: UseTableSortOptions): {
sortedData: T[];
sortColumn: string | null;
sortDirection: SortDirection;
handleSort: (column: string) => void;
};
interface TableProps extends HTMLAttributes<HTMLTableElement> {
variant?: TableVariant;
/** Show loading state (controlled by TableProvider) */
showLoading?: boolean;
/** Loading state configuration */
loadingState?: LoadingStateConfig;
/** Show no search result state (controlled by TableProvider) */
showNoSearchResult?: boolean;
/** No search result state configuration */
noSearchResultState?: NoSearchResultConfig;
/** Show empty state (controlled by TableProvider) */
showEmpty?: boolean;
/** Empty state configuration */
emptyState?: EmptyStateConfig;
}
interface TableRowProps extends HTMLAttributes<HTMLTableRowElement> {
state?: TableRowState;
}
declare const Table: React.ForwardRefExoticComponent<TableProps & React.RefAttributes<HTMLTableElement>>;
declare const TableHeader: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLTableSectionElement> & React.RefAttributes<HTMLTableSectionElement>>;
interface TableBodyProps extends HTMLAttributes<HTMLTableSectionElement> {
variant?: TableVariant;
}
declare const TableBody: React.ForwardRefExoticComponent<TableBodyProps & React.RefAttributes<HTMLTableSectionElement>>;
interface TableFooterProps extends HTMLAttributes<HTMLTableSectionElement> {
variant?: TableVariant;
}
declare const TableFooter: React.ForwardRefExoticComponent<TableFooterProps & React.RefAttributes<HTMLTableSectionElement>>;
interface TableRowPropsExtended extends TableRowProps {
variant?: TableVariant | 'defaultBorderless';
clickable?: boolean;
}
declare const TableRow: React.ForwardRefExoticComponent<TableRowPropsExtended & React.RefAttributes<HTMLTableRowElement>>;
interface TableHeadProps extends ThHTMLAttributes<HTMLTableCellElement> {
/** Enable sorting on this column (default: true) */
sortable?: boolean;
/** Current sort direction for this column */
sortDirection?: SortDirection;
/** Callback when column header is clicked */
onSort?: () => void;
}
declare const TableHead: React.ForwardRefExoticComponent<TableHeadProps & React.RefAttributes<HTMLTableCellElement>>;
declare const TableCell: React.ForwardRefExoticComponent<React.TdHTMLAttributes<HTMLTableCellElement> & React.RefAttributes<HTMLTableCellElement>>;
declare const TableCaption: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLTableCaptionElement> & React.RefAttributes<HTMLTableCaptionElement>>;
export { default as TablePagination } from './TablePagination';
export type { TablePaginationProps } from './TablePagination';
export default Table;
export { TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption, };
//# sourceMappingURL=Table.d.ts.map