RocketChat/Rocket.Chat

View on GitHub
apps/meteor/client/components/GenericTable/hooks/useShowingResultsLabel.ts

Summary

Maintainability
A
0 mins
Test Coverage
import type { Pagination } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentProps } from 'react';
import { useCallback } from 'react';

type Props<T extends ComponentProps<typeof Pagination>['showingResultsLabel'] = ComponentProps<typeof Pagination>['showingResultsLabel']> =
    T extends (...args: any[]) => any ? Parameters<T> : never;

export const useShowingResultsLabel = (): ((...params: Props) => string) => {
    const t = useTranslation();
    return useCallback(
        ({ count, current, itemsPerPage }) => t('Showing_results_of', current + 1, Math.min(current + itemsPerPage, count), count),
        [t],
    );
};