Files
gridpilot.gg/apps/website/ui/Select.tsx
2026-01-15 17:12:24 +01:00

71 lines
1.6 KiB
TypeScript

import React, { ChangeEvent, SelectHTMLAttributes } from 'react';
import { Stack } from './Stack';
import { Text } from './Text';
interface SelectOption {
value: string;
label: string;
}
interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
id?: string;
'aria-label'?: string;
value?: string;
onChange?: (e: ChangeEvent<HTMLSelectElement>) => void;
options: SelectOption[];
className?: string;
style?: React.CSSProperties;
label?: string;
fullWidth?: boolean;
pl?: number;
}
export function Select({
id,
'aria-label': ariaLabel,
value,
onChange,
options,
className = '',
style,
label,
fullWidth = true,
pl,
...props
}: SelectProps) {
const spacingMap: Record<number, string> = {
10: 'pl-10'
};
const defaultClasses = `${fullWidth ? 'w-full' : 'w-auto'} px-3 py-2 bg-deep-graphite border border-charcoal-outline rounded-lg text-white focus:outline-none focus:border-primary-blue transition-colors`;
const classes = [
defaultClasses,
pl !== undefined ? spacingMap[pl] : '',
className
].filter(Boolean).join(' ');
return (
<Stack gap={1.5} fullWidth={fullWidth}>
{label && (
<Text as="label" size="sm" weight="medium" color="text-gray-400">
{label}
</Text>
)}
<select
id={id}
aria-label={ariaLabel}
value={value}
onChange={onChange}
className={classes}
style={style}
{...props}
>
{options.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
</Stack>
);
}