All files / src/components/pages/create-group/fields/cap-field index.tsx

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

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

import { AnyFieldApi } from '@tanstack/react-form';

import { Icon } from '@/components/icon';
import { Input, Label } from '@/components/ui';

interface Props {
  field: AnyFieldApi;
}

export const GroupCapField = ({ field }: Props) => {
  return (
    <div className='mt-3 flex w-full flex-col gap-1'>
      <Label htmlFor='create-group-cap' required>
        최대 인원
      </Label>
      <Input
        id='create-group-cap'
        className='bg-mono-white focus:border-mint-500 rounded-2xl border border-gray-300'
        frontIcon={
          <Icon
            id='users-1'
            width={20}
            className='pointer-events-none absolute top-0 left-4 flex h-full items-center text-gray-500'
            height={20}
          />
        }
        max={12}
        min={2}
        placeholder='최대 인원을 선택해주세요'
        required
        type='number'
        value={!!field.state.value && field.state.value}
        onBlur={(e) => {
          const value = Number(e.target.value);
          if (value < 2) field.handleChange(2);
          else if (value > 12) field.handleChange(12);
        }}
        onChange={(e) => {
          field.handleChange(Number(e.target.value));
        }}
      />
    </div>
  );
};