resolution-picker.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useCallback } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import cn from 'classnames'
  6. import { Resolution } from '@/types/app'
  7. const i18nPrefix = 'workflow.nodes.llm'
  8. type ItemProps = {
  9. title: string
  10. value: Resolution
  11. onSelect: (value: Resolution) => void
  12. isSelected: boolean
  13. }
  14. const Item: FC<ItemProps> = ({ title, value, onSelect, isSelected }) => {
  15. const handleSelect = useCallback(() => {
  16. if (isSelected)
  17. return
  18. onSelect(value)
  19. }, [value, onSelect, isSelected])
  20. return (
  21. <div
  22. className={cn(isSelected ? 'bg-white border-[2px] border-primary-400 shadow-xs' : 'bg-gray-25 border border-gray-100', 'flex items-center h-8 px-3 rounded-lg text-[13px] font-normal text-gray-900 cursor-pointer')}
  23. onClick={handleSelect}
  24. >
  25. {title}
  26. </div>
  27. )
  28. }
  29. type Props = {
  30. value: Resolution
  31. onChange: (value: Resolution) => void
  32. }
  33. const ResolutionPicker: FC<Props> = ({
  34. value,
  35. onChange,
  36. }) => {
  37. const { t } = useTranslation()
  38. return (
  39. <div className='flex items-center justify-between'>
  40. <div className='mr-2 text-xs font-medium text-gray-500 uppercase'>{t(`${i18nPrefix}.resolution.name`)}</div>
  41. <div className='flex items-center space-x-1'>
  42. <Item
  43. title={t(`${i18nPrefix}.resolution.high`)}
  44. value={Resolution.high}
  45. onSelect={onChange}
  46. isSelected={value === Resolution.high}
  47. />
  48. <Item
  49. title={t(`${i18nPrefix}.resolution.low`)}
  50. value={Resolution.low}
  51. onSelect={onChange}
  52. isSelected={value === Resolution.low}
  53. />
  54. </div>
  55. </div>
  56. )
  57. }
  58. export default React.memo(ResolutionPicker)