react18-tools/esbuild-plugin-react18-css

View on GitHub
packages/shared-ui/src/common/select.tsx

Summary

Maintainability
A
0 mins
Test Coverage
import type { HTMLProps, ReactNode } from "react";

export interface SelectOptionsProps {
  value: string;
  children: ReactNode;
}

interface SelectProps extends HTMLProps<HTMLSelectElement> {
  options: string[] | SelectOptionsProps[];
}

export function Select({ options, ...props }: SelectProps) {
  const renderOptions = options.map(option =>
    typeof option === "string" ? { value: option, children: option } : option,
  );
  return (
    <select {...props}>
      {renderOptions.map(option => (
        <option key={option.value} value={option.value}>
          {option.children}
        </option>
      ))}
    </select>
  );
}