All files / web/src/app/create/worksheets/components FloatingPageIndicator.tsx

0% Statements 0/181
0% Branches 0/1
0% Functions 0/1
0% Lines 0/181

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182                                                                                                                                                                                                                                                                                                                                                                           
'use client'

import { useState } from 'react'
import { css } from '@styled/css'
import { useTheme } from '@/contexts/ThemeContext'
import { useIsMobile } from '@/hooks/useMediaQuery'
import NumberFlow from '@number-flow/react'

interface FloatingPageIndicatorProps {
  currentPage: number
  totalPages: number
  onJumpToPage: (pageIndex: number) => void
  isScrolling?: boolean
}

export function FloatingPageIndicator({
  currentPage,
  totalPages,
  onJumpToPage,
  isScrolling = false,
}: FloatingPageIndicatorProps) {
  const { resolvedTheme } = useTheme()
  const isDark = resolvedTheme === 'dark'
  const isMobile = useIsMobile()
  const [isHovered, setIsHovered] = useState(false)

  if (totalPages <= 1) return null

  const isActive = isHovered || isScrolling

  return (
    <div
      data-component="floating-page-indicator"
      onMouseEnter={() => setIsHovered(true)}
      onMouseLeave={() => setIsHovered(false)}
      className={css({
        position: 'absolute',
        // Mobile: top-left with margin, Desktop: centered at top
        top: '4',
        left: isMobile ? '3' : '50%',
        transform: isMobile ? 'none' : 'translateX(-50%)',
        zIndex: 10,
        bg: isDark ? 'rgba(31, 41, 55, 0.95)' : 'rgba(255, 255, 255, 0.95)',
        backdropFilter: 'blur(8px)',
        border: '1px solid',
        borderColor: isDark ? 'gray.600' : 'gray.200',
        rounded: 'full',
        // Mobile: smaller padding
        px: isMobile ? '2' : '4',
        py: isMobile ? '1' : '2',
        shadow: 'lg',
        display: 'inline-flex',
        alignItems: 'center',
        gap: isMobile ? '2' : '3',
        opacity: isActive ? 1 : 0.7,
        transition: 'opacity 0.3s ease-in-out',
        // Mobile: slightly smaller scale
        fontSize: isMobile ? 'xs' : 'sm',
      })}
    >
      <button
        onClick={() => onJumpToPage(Math.max(0, currentPage - 1))}
        disabled={currentPage === 0}
        className={css({
          px: isMobile ? '1' : '2',
          py: '1',
          rounded: 'md',
          fontSize: isMobile ? 'xs' : 'sm',
          fontWeight: 'medium',
          color: isDark ? 'gray.300' : 'gray.700',
          cursor: 'pointer',
          transition: 'all 0.2s',
          _disabled: {
            opacity: 0.3,
            cursor: 'not-allowed',
          },
          _hover: {
            bg: isDark ? 'gray.700' : 'gray.100',
          },
        })}
      >

      </button>

      <span
        className={css({
          fontSize: isMobile ? 'xs' : 'sm',
          fontWeight: 'semibold',
          color: isDark ? 'gray.100' : 'gray.900',
          minW: isMobile ? '16' : '20',
          textAlign: 'center',
          display: 'flex',
          alignItems: 'center',
          gap: '1',
          whiteSpace: 'nowrap',
        })}
      >
        {isMobile ? (
          // Mobile: compact format "1/5"
          <>
            <NumberFlow
              value={currentPage + 1}
              format={{ notation: 'standard' }}
              trend={0}
              animated
              style={{
                fontWeight: 'inherit',
                fontSize: 'inherit',
                color: 'inherit',
              }}
            />
            /
            <NumberFlow
              value={totalPages}
              format={{ notation: 'standard' }}
              trend={0}
              animated
              style={{
                fontWeight: 'inherit',
                fontSize: 'inherit',
                color: 'inherit',
              }}
            />
          </>
        ) : (
          // Desktop: full format "Page 1 of 5"
          <>
            Page{' '}
            <NumberFlow
              value={currentPage + 1}
              format={{ notation: 'standard' }}
              trend={0}
              animated
              style={{
                fontWeight: 'inherit',
                fontSize: 'inherit',
                color: 'inherit',
              }}
            />{' '}
            of{' '}
            <NumberFlow
              value={totalPages}
              format={{ notation: 'standard' }}
              trend={0}
              animated
              style={{
                fontWeight: 'inherit',
                fontSize: 'inherit',
                color: 'inherit',
              }}
            />
          </>
        )}
      </span>

      <button
        onClick={() => onJumpToPage(Math.min(totalPages - 1, currentPage + 1))}
        disabled={currentPage === totalPages - 1}
        className={css({
          px: isMobile ? '1' : '2',
          py: '1',
          rounded: 'md',
          fontSize: isMobile ? 'xs' : 'sm',
          fontWeight: 'medium',
          color: isDark ? 'gray.300' : 'gray.700',
          cursor: 'pointer',
          transition: 'all 0.2s',
          _disabled: {
            opacity: 0.3,
            cursor: 'not-allowed',
          },
          _hover: {
            bg: isDark ? 'gray.700' : 'gray.100',
          },
        })}
      >

      </button>
    </div>
  )
}