SecondLevelNav.ResourcePicker.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { cn, Command, CommandGroup, CommandItem, CommandList } from 'ui'
  2. import type { ResourcePickerRenderProps } from './SecondLevelNav.Layout'
  3. type NamedResource = { name: string }
  4. type ResourcePickerListProps = ResourcePickerRenderProps & {
  5. items: NamedResource[]
  6. emptyMessage: string
  7. }
  8. export const ResourcePickerList = ({
  9. items,
  10. emptyMessage,
  11. selectedResource,
  12. onSelect,
  13. closePopover,
  14. }: ResourcePickerListProps) => {
  15. const handleSelect = (value: string) => {
  16. onSelect(value)
  17. closePopover()
  18. }
  19. return (
  20. <Command>
  21. <CommandList>
  22. <CommandGroup>
  23. {items.length === 0 && (
  24. <CommandItem disabled className="cursor-default px-4">
  25. <p className="text-foreground-light">{emptyMessage}</p>
  26. </CommandItem>
  27. )}
  28. {items.map((item) => {
  29. const isActive = item.name === selectedResource
  30. return (
  31. <CommandItem
  32. key={item.name}
  33. className={cn(
  34. 'cursor-pointer px-4',
  35. isActive ? 'text-foreground bg-selection' : 'text-foreground-light'
  36. )}
  37. onSelect={() => handleSelect(item.name)}
  38. >
  39. <p className="truncate">{item.name}</p>
  40. </CommandItem>
  41. )
  42. })}
  43. </CommandGroup>
  44. </CommandList>
  45. </Command>
  46. )
  47. }