All files / web/src/components FormatSelectField.tsx

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

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                                                                                                                                                                                                                                                                                                                                                                   
'use client'

import * as Select from '@radix-ui/react-select'
import { ChevronDown } from 'lucide-react'
import { css } from '../../styled-system/css'
import { hstack, stack } from '../../styled-system/patterns'

interface FormatOption {
  value: string
  label: string
  icon: string
  description: string
}

interface FormatSelectFieldProps {
  value: string
  onValueChange: (value: string) => void
}

const formatOptions: FormatOption[] = [
  {
    value: 'pdf',
    label: 'PDF',
    icon: '📄',
    description: 'Print-ready vector document with layout options',
  },
  {
    value: 'html',
    label: 'HTML',
    icon: '🌐',
    description: 'Interactive web flashcards',
  },
  {
    value: 'svg',
    label: 'SVG',
    icon: '🖼️',
    description: 'Scalable vector images',
  },
  {
    value: 'png',
    label: 'PNG',
    icon: '📷',
    description: 'High-resolution images',
  },
]

export function FormatSelectField({ value, onValueChange }: FormatSelectFieldProps) {
  const selectedOption = formatOptions.find((option) => option.value === value) || formatOptions[0]

  return (
    <Select.Root value={value} onValueChange={onValueChange}>
      <Select.Trigger
        asChild={false}
        className={css({
          w: 'full',
          px: '4',
          py: '3',
          bg: 'white',
          border: '1px solid',
          borderColor: 'gray.300',
          rounded: 'lg',
          fontSize: 'sm',
          transition: 'all',
          cursor: 'pointer',
          userSelect: 'none',
          _hover: { borderColor: 'gray.400' },
          _focus: {
            outline: 'none',
            borderColor: 'brand.500',
            boxShadow: '0 0 0 3px rgba(59, 130, 246, 0.1)',
          },
          '&[data-state=open]': {
            borderColor: 'brand.500',
            boxShadow: '0 0 0 3px rgba(59, 130, 246, 0.1)',
          },
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'space-between',
          minH: '12',
        })}
      >
        <Select.Value asChild>
          <div className={hstack({ gap: '3', alignItems: 'center' })}>
            <span className={css({ fontSize: 'lg' })}>{selectedOption.icon}</span>
            <div className={stack({ gap: '0', alignItems: 'start' })}>
              <span className={css({ fontWeight: 'medium', color: 'gray.900' })}>
                {selectedOption.label}
              </span>
              <span
                className={css({
                  fontSize: 'xs',
                  color: 'gray.500',
                  lineHeight: 'tight',
                })}
              >
                {selectedOption.description}
              </span>
            </div>
          </div>
        </Select.Value>
        <Select.Icon>
          <ChevronDown size={16} className={css({ color: 'gray.400' })} />
        </Select.Icon>
      </Select.Trigger>

      <Select.Portal>
        <Select.Content
          className={css({
            bg: 'white',
            rounded: 'xl',
            shadow: 'modal',
            border: '1px solid',
            borderColor: 'gray.200',
            p: '2',
            zIndex: 999,
            minW: '320px',
            maxH: '300px',
            overflow: 'hidden',
          })}
          position="popper"
          sideOffset={4}
        >
          <Select.Viewport>
            {formatOptions.map((option) => (
              <Select.Item
                key={option.value}
                value={option.value}
                className={css({
                  px: '3',
                  py: '3',
                  rounded: 'lg',
                  cursor: 'pointer',
                  transition: 'all',
                  outline: 'none',
                  _hover: { bg: 'brand.50' },
                  '&[data-state=checked]': {
                    bg: 'brand.100',
                    color: 'brand.800',
                  },
                })}
              >
                <div className={hstack({ gap: '3', alignItems: 'center' })}>
                  <span className={css({ fontSize: 'xl' })}>{option.icon}</span>
                  <div
                    className={stack({
                      gap: '1',
                      alignItems: 'start',
                      flex: 1,
                    })}
                  >
                    <Select.ItemText
                      className={css({
                        fontWeight: 'medium',
                        fontSize: 'sm',
                      })}
                    >
                      {option.label}
                    </Select.ItemText>
                    <div
                      className={css({
                        fontSize: 'xs',
                        color: 'gray.600',
                        lineHeight: 'relaxed',
                      })}
                    >
                      {option.description}
                    </div>
                  </div>
                </div>
              </Select.Item>
            ))}
          </Select.Viewport>
        </Select.Content>
      </Select.Portal>
    </Select.Root>
  )
}