import type { MouseEvent, PropsWithChildren } from 'react' import React, { useMemo } from 'react' import Button from '../../atoms/Button' export interface BulletsProps { /** * Number of bullets that should be rendered. */ totalQuantity: number /** * The currently active bullet (zero-indexed). */ activeBullet: number /** * Event handler for clicks on each bullet. The handler will be called with * the index of the bullet that received the click. */ onClick: (e: MouseEvent, bulletIdx: number) => void /** * ID to find this component in testing tools (e.g.: cypress, * testing-library, and jest). */ testId?: string /** * Function that should be used to generate the aria-label attribute added * to each bullet that is inactive. It receives the bullet index as an * argument so that it can be interpolated in the generated string. */ ariaLabelGenerator?: (index: number, isActive: boolean) => string } interface BulletProps { isActive: boolean testId: string } function Bullet({ isActive, testId, children, }: PropsWithChildren) { return (
  • {children}
  • ) } const defaultAriaLabel = (idx: number, isActive: boolean) => isActive ? 'Current page' : `Go to page ${idx + 1}` function Bullets({ totalQuantity, activeBullet, onClick, testId = 'store-bullets', ariaLabelGenerator = defaultAriaLabel, }: BulletsProps) { const bulletIndexes = useMemo(() => Array(totalQuantity).fill(0), [ totalQuantity, ]) return (
      {bulletIndexes.map((_, idx) => { const isActive = activeBullet === idx return (
    ) } export default Bullets