morethanadiagnosis-hub/web/components/common/Select.tsx
Claude 9232ebe294
feat(web): complete Phase 1 - foundation components, layouts, and hooks
Implemented complete design system and foundational infrastructure:

**Design System Components:**
- Button (all variants: primary, secondary, ghost, danger)
- Input & Textarea (with validation and error states)
- Card (elevated, outlined, flat variants)
- Modal/Dialog (with focus trap and accessibility)
- Avatar (with fallback initials)
- Badge (all color variants)
- Form helpers (FormField, Checkbox, Select)
- Link component with Next.js integration
- Navigation (Header, Footer with responsive design)

**Layouts:**
- MainLayout (with Header/Footer for public pages)
- AuthLayout (minimal layout for auth flows)
- DashboardLayout (with sidebar navigation)

**Hooks & Utilities:**
- useAuth() - authentication state management
- useApi() - API calls with loading/error states
- useLocalStorage() - persistent state management
- apiClient - Axios instance with token refresh
- authStore - Zustand store for auth state

**Configuration:**
- Tailwind config with design tokens
- Dark mode support via CSS variables
- Global styles with accessibility focus
- WCAG 2.2 AA+ compliant focus indicators

All components follow accessibility best practices with proper ARIA labels,
keyboard navigation, and screen reader support.

Job ID: MTAD-IMPL-2025-11-18-CL
2025-11-18 01:02:05 +00:00

107 lines
2.9 KiB
TypeScript

'use client'
import React from 'react'
export interface SelectOption {
value: string
label: string
disabled?: boolean
}
export interface SelectProps extends Omit<React.SelectHTMLAttributes<HTMLSelectElement>, 'size'> {
label?: string
error?: string
helperText?: string
options: SelectOption[]
placeholder?: string
fullWidth?: boolean
}
export const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
(
{
label,
error,
helperText,
options,
placeholder,
fullWidth = false,
className = '',
id,
required,
disabled,
...props
},
ref
) => {
const selectId = id || `select-${Math.random().toString(36).substr(2, 9)}`
const errorId = `${selectId}-error`
const helperId = `${selectId}-helper`
const hasError = Boolean(error)
const baseStyles = 'block w-full rounded-md border transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-offset-0 px-4 py-2'
const normalStyles = 'border-gray-300 focus:border-primary-500 focus:ring-primary-500 dark:border-gray-600 dark:bg-gray-800 dark:text-white'
const errorStyles = 'border-error-500 focus:border-error-500 focus:ring-error-500'
const disabledStyles = 'disabled:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-60 dark:disabled:bg-gray-900'
const selectClassName = `${baseStyles} ${hasError ? errorStyles : normalStyles} ${disabledStyles} ${className}`.trim()
const containerWidth = fullWidth ? 'w-full' : ''
return (
<div className={containerWidth}>
{label && (
<label
htmlFor={selectId}
className="block text-sm font-medium text-gray-700 dark:text-gray-200 mb-1"
>
{label}
{required && <span className="text-error-500 ml-1" aria-label="required">*</span>}
</label>
)}
<select
ref={ref}
id={selectId}
className={selectClassName}
aria-invalid={hasError}
aria-describedby={
hasError ? errorId : helperText ? helperId : undefined
}
required={required}
disabled={disabled}
{...props}
>
{placeholder && (
<option value="" disabled>
{placeholder}
</option>
)}
{options.map((option) => (
<option
key={option.value}
value={option.value}
disabled={option.disabled}
>
{option.label}
</option>
))}
</select>
{error && (
<p className="mt-1 text-sm text-error-500" id={errorId} role="alert">
{error}
</p>
)}
{helperText && !error && (
<p className="mt-1 text-sm text-gray-500 dark:text-gray-400" id={helperId}>
{helperText}
</p>
)}
</div>
)
}
)
Select.displayName = 'Select'