ConceptPortal-public/rsconcept/frontend/src/components/data-table/select-pagination.tsx
Ivan d90cf08b6c
Some checks are pending
Frontend CI / build (22.x) (push) Waiting to run
Frontend CI / notify-failure (push) Blocked by required conditions
R: Refactor const global objects
2025-04-30 01:10:45 +03:00

47 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use no memo';
'use client';
import { useCallback } from 'react';
import { type Table } from '@tanstack/react-table';
import { prefixes } from '@/utils/constants';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../input/select';
interface SelectPaginationProps<TData> {
id?: string;
table: Table<TData>;
paginationOptions: readonly number[];
onChange?: (newValue: number) => void;
}
export function SelectPagination<TData>({ id, table, paginationOptions, onChange }: SelectPaginationProps<TData>) {
const handlePaginationOptionsChange = useCallback(
(newValue: string) => {
const perPage = Number(newValue);
table.setPageSize(perPage);
onChange?.(perPage);
},
[table, onChange]
);
return (
<Select onValueChange={handlePaginationOptionsChange} defaultValue={String(table.getState().pagination.pageSize)}>
<SelectTrigger
id={id}
aria-label='Выбор количества строчек на странице'
className='mx-2 cursor-pointer bg-transparent focus-outline border-0 w-28 max-h-6 px-2 justify-end'
>
<SelectValue />
</SelectTrigger>
<SelectContent>
{paginationOptions?.map(option => (
<SelectItem key={`${prefixes.page_size}${option}`} value={String(option)}>
{option} на стр
</SelectItem>
))}
</SelectContent>
</Select>
);
}