import classNames from 'classnames'; import type { CSSProperties, ReactNode } from 'react'; import { useState } from 'react'; import { useOsInfo } from '../../hooks/useOsInfo'; import type { ButtonProps } from './Button'; import { Button } from './Button'; import type { RadioDropdownItem } from './RadioDropdown'; import { RadioDropdown } from './RadioDropdown'; import { HStack } from './Stacks'; export interface SelectProps { name: string; label: string; labelPosition?: 'top' | 'left'; labelClassName?: string; hideLabel?: boolean; value: T; leftSlot?: ReactNode; options: RadioDropdownItem[]; onChange: (value: T) => void; size?: ButtonProps['size']; className?: string; } export function Select({ labelPosition = 'top', name, labelClassName, hideLabel, label, value, options, leftSlot, onChange, className, size = 'md', }: SelectProps) { const osInfo = useOsInfo(); const [focused, setFocused] = useState(false); const id = `input-${name}`; const isInvalidSelection = options.find((o) => 'value' in o && o.value === value) == null; return (
{osInfo?.osType === 'macos' ? ( {leftSlot &&
{leftSlot}
}
) : ( // Use custom "select" component until Tauri can be configured to have select menus not always appear in // light mode )}
); } const selectBackgroundStyles: CSSProperties = { backgroundImage: `url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e")`, backgroundPosition: 'right 0.3rem center', backgroundRepeat: 'no-repeat', backgroundSize: '1.5em 1.5em', appearance: 'none', printColorAdjust: 'exact', };