index.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { RiArrowDownSLine } from '@remixicon/react'
  5. import cn from '@/utils/classnames'
  6. import Popover from '@/app/components/base/popover'
  7. import { languages } from '@/i18n/language'
  8. export type ILanguageSelectProps = {
  9. currentLanguage: string
  10. onSelect: (language: string) => void
  11. disabled?: boolean
  12. }
  13. const LanguageSelect: FC<ILanguageSelectProps> = ({
  14. currentLanguage,
  15. onSelect,
  16. disabled,
  17. }) => {
  18. return (
  19. <Popover
  20. manualClose
  21. trigger='click'
  22. disabled={disabled}
  23. htmlContent={
  24. <div className='w-full py-1'>
  25. {languages.filter(language => language.supported).map(({ prompt_name }) => (
  26. <div
  27. key={prompt_name}
  28. className='py-2 px-3 mx-1 flex items-center gap-2 hover:bg-gray-100 rounded-lg cursor-pointer text-gray-700 text-sm'
  29. onClick={() => onSelect(prompt_name)}>{prompt_name}
  30. </div>
  31. ))}
  32. </div>
  33. }
  34. btnElement={
  35. <div className='inline-flex items-center'>
  36. <span className='pr-[2px] text-xs leading-[18px] font-medium'>{currentLanguage}</span>
  37. <RiArrowDownSLine className='w-3 h-3 opacity-60' />
  38. </div>
  39. }
  40. btnClassName={open => cn('!border-0 !px-0 !py-0 !bg-inherit !hover:bg-inherit', open ? 'text-blue-600' : 'text-gray-500')}
  41. className='!w-[120px] h-fit !z-20 !translate-x-0 !left-[-16px]'
  42. />
  43. )
  44. }
  45. export default React.memo(LanguageSelect)