Download src/components/ui/Select.tsx from TechAvenger/kernel-convolution-visualizer: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/TechAvenger/kernel-convolution-visualizer/resolve/main/src/components/ui/Select.tsx
- Command line
-
hf download hf://spaces/TechAvenger/kernel-convolution-visualizer/src/components/ui/Select.tsx
-
curl -L -o Select.tsx https://huggingface.co/spaces/TechAvenger/kernel-convolution-visualizer/resolve/main/src/components/ui/Select.tsx
1.6 kB
| 'use client' | |
| import React, { forwardRef, SelectHTMLAttributes, OptionHTMLAttributes } from 'react' | |
| import { cn } from '@/utils/helpers' | |
| export interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> { | |
| label?: string | |
| error?: string | |
| options: { value: string; label: string }[] | |
| placeholder?: string | |
| } | |
| export const Select = forwardRef<HTMLSelectElement, SelectProps>( | |
| ({ className, label, error, options, placeholder, id, ...props }, ref) => { | |
| const selectId = id || label?.toLowerCase().replace(/\s+/g, '-') | |
| return ( | |
| <div className="w-full"> | |
| {label && ( | |
| <label | |
| htmlFor={selectId} | |
| className="block text-sm font-medium text-current mb-1" | |
| > | |
| {label} | |
| </label> | |
| )} | |
| <select | |
| ref={ref} | |
| id={selectId} | |
| className={cn( | |
| 'clay-input', | |
| error && 'border-red-500 focus:ring-red-500', | |
| className | |
| )} | |
| aria-invalid={error ? 'true' : 'false'} | |
| {...props} | |
| > | |
| {placeholder && ( | |
| <option value="" disabled> | |
| {placeholder} | |
| </option> | |
| )} | |
| {options.map((option) => ( | |
| <option key={option.value} value={option.value}> | |
| {option.label} | |
| </option> | |
| ))} | |
| </select> | |
| {error && ( | |
| <p id={`${selectId}-error`} className="mt-1 text-sm text-red-600 dark:text-red-400" role="alert"> | |
| {error} | |
| </p> | |
| )} | |
| </div> | |
| ) | |
| } | |
| ) | |
| Select.displayName = 'Select' |