import { type } from "@tauri-apps/plugin-os"; import classNames from "classnames"; import type { CSSProperties, ReactNode } from "react"; import { useState } from "react"; import type { ButtonProps } from "./Button"; import { Button } from "./Button"; import { Label } from "./Label"; 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; help?: ReactNode; leftSlot?: ReactNode; options: RadioDropdownItem[]; onChange: (value: T) => void; defaultValue?: T; size?: ButtonProps["size"]; className?: string; disabled?: boolean; filterable?: boolean; } export function Select({ labelPosition = "top", name, help, labelClassName, disabled, hideLabel, label, value, options, leftSlot, onChange, className, defaultValue, filterable, size = "md", }: SelectProps) { const [focused, setFocused] = useState(false); const id = `input-${name}`; const isInvalidSelection = options.find((o) => "value" in o && o.value === value) == null; const handleChange = (value: T) => { onChange?.(value); }; return (
{type() === "macos" && !filterable ? ( {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", };