import React, { useCallback, useEffect, useState } from 'react'; import { ComponentMeta, ComponentStory } from '@storybook/react'; import { ChevronLeftIcon, ChevronRightIcon } from '@100mslive/react-icons'; import { StyledPagination } from '.'; type PaginationProps = { page: number; setPage: (page: number) => void; numPages: number; }; const PaginationComponent = ({ page: propsPage, setPage: propsSetPage, numPages }: PaginationProps) => { const [page, setPage] = useState(propsPage); const disableLeft = page === 0; const disableRight = page === numPages - 1; const handlePageChange = useCallback( (page: number) => { setPage(page); propsSetPage(page); }, [propsSetPage], ); const nextPage = () => { handlePageChange(Math.min(page + 1, numPages - 1)); }; const prevPage = () => { handlePageChange(Math.max(page - 1, 0)); }; useEffect(() => { handlePageChange(propsPage); }, [propsPage, handlePageChange]); return ( {[...Array(numPages)].map((_, i) => ( handlePageChange(i)} type="button" /> ))} ); }; export default { title: 'UI Components/Pagination', component: PaginationComponent, argTypes: { setPage: { action: { type: 'click' } }, page: { control: { type: 'number' }, defaultValue: 0 }, numPages: { control: { type: 'number' }, defaultValue: 5 }, }, } as ComponentMeta; const Template: ComponentStory = args => { return ; }; export const Example = Template.bind({}); Example.storyName = 'Pagination';