presets-parameter.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import type { FC } from 'react'
  2. import { useCallback } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import { RiArrowDownSLine } from '@remixicon/react'
  5. import Dropdown from '@/app/components/base/dropdown'
  6. import { SlidersH } from '@/app/components/base/icons/src/vender/line/mediaAndDevices'
  7. import { Brush01 } from '@/app/components/base/icons/src/vender/solid/editor'
  8. import { Scales02 } from '@/app/components/base/icons/src/vender/solid/FinanceAndECommerce'
  9. import { Target04 } from '@/app/components/base/icons/src/vender/solid/general'
  10. import { TONE_LIST } from '@/config'
  11. type PresetsParameterProps = {
  12. onSelect: (toneId: number) => void
  13. }
  14. const PresetsParameter: FC<PresetsParameterProps> = ({
  15. onSelect,
  16. }) => {
  17. const { t } = useTranslation()
  18. const renderTrigger = useCallback((open: boolean) => {
  19. return (
  20. <div
  21. className={`
  22. flex items-center px-[7px] h-7 rounded-md border-[0.5px] border-gray-200 shadow-xs
  23. text-xs font-medium text-gray-700 cursor-pointer
  24. ${open && 'bg-gray-100'}
  25. `}
  26. >
  27. <SlidersH className='mr-[5px] w-3.5 h-3.5 text-gray-500' />
  28. {t('common.modelProvider.loadPresets')}
  29. <RiArrowDownSLine className='ml-0.5 w-3.5 h-3.5 text-gray-500' />
  30. </div>
  31. )
  32. }, [])
  33. const getToneIcon = (toneId: number) => {
  34. const className = 'mr-2 w-[14px] h-[14px]'
  35. const res = ({
  36. 1: <Brush01 className={`${className} text-[#6938EF]`} />,
  37. 2: <Scales02 className={`${className} text-indigo-600`} />,
  38. 3: <Target04 className={`${className} text-[#107569]`} />,
  39. })[toneId]
  40. return res
  41. }
  42. const options = TONE_LIST.slice(0, 3).map((tone) => {
  43. return {
  44. value: tone.id,
  45. text: (
  46. <div className='flex items-center h-full'>
  47. {getToneIcon(tone.id)}
  48. {t(`common.model.tone.${tone.name}`) as string}
  49. </div>
  50. ),
  51. }
  52. })
  53. return (
  54. <Dropdown
  55. renderTrigger={renderTrigger}
  56. items={options}
  57. onSelect={item => onSelect(item.value as number)}
  58. popupClassName='z-[1003]'
  59. />
  60. )
  61. }
  62. export default PresetsParameter