native-select.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import * as React from 'react';
  2. import { cn } from '@/lib/utils';
  3. import { ChevronDownIcon } from 'lucide-react';
  4. type NativeSelectProps = Omit<React.ComponentProps<'select'>, 'size'> & {
  5. size?: 'sm' | 'default';
  6. };
  7. function NativeSelect({
  8. className,
  9. size = 'default',
  10. ...props
  11. }: NativeSelectProps) {
  12. return (
  13. <div
  14. className={cn(
  15. 'group/native-select relative w-fit has-[select:disabled]:opacity-50',
  16. className,
  17. )}
  18. data-slot="native-select-wrapper"
  19. data-size={size}
  20. >
  21. <select
  22. data-slot="native-select"
  23. data-size={size}
  24. className="border-input placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 h-8 w-full min-w-0 appearance-none rounded-lg border bg-transparent py-1 pr-8 pl-2.5 text-sm transition-colors select-none focus-visible:ring-3 aria-invalid:ring-3 data-[size=sm]:h-7 data-[size=sm]:rounded-[min(var(--radius-md),10px)] data-[size=sm]:py-0.5 outline-none disabled:pointer-events-none disabled:cursor-not-allowed"
  25. {...props}
  26. />
  27. <ChevronDownIcon
  28. className="text-muted-foreground top-1/2 right-2.5 size-4 -translate-y-1/2 pointer-events-none absolute select-none"
  29. aria-hidden="true"
  30. data-slot="native-select-icon"
  31. />
  32. </div>
  33. );
  34. }
  35. function NativeSelectOption({
  36. className,
  37. ...props
  38. }: React.ComponentProps<'option'>) {
  39. return (
  40. <option
  41. data-slot="native-select-option"
  42. className={cn('bg-[Canvas] text-[CanvasText]', className)}
  43. {...props}
  44. />
  45. );
  46. }
  47. function NativeSelectOptGroup({
  48. className,
  49. ...props
  50. }: React.ComponentProps<'optgroup'>) {
  51. return (
  52. <optgroup
  53. data-slot="native-select-optgroup"
  54. className={cn('bg-[Canvas] text-[CanvasText]', className)}
  55. {...props}
  56. />
  57. );
  58. }
  59. export { NativeSelect, NativeSelectOptGroup, NativeSelectOption };