Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

toggle-button.tsx 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import React from 'react'
  2. import Button from '../base/button'
  3. import { RiArrowLeftSLine, RiArrowRightSLine } from '@remixicon/react'
  4. import cn from '@/utils/classnames'
  5. import Tooltip from '../base/tooltip'
  6. import { useTranslation } from 'react-i18next'
  7. import { getKeyboardKeyNameBySystem } from '../workflow/utils'
  8. type TooltipContentProps = {
  9. expand: boolean
  10. }
  11. const TOGGLE_SHORTCUT = ['ctrl', 'B']
  12. const TooltipContent = ({
  13. expand,
  14. }: TooltipContentProps) => {
  15. const { t } = useTranslation()
  16. return (
  17. <div className='flex items-center gap-x-1'>
  18. <span className='system-xs-medium px-0.5 text-text-secondary'>{expand ? t('layout.sidebar.collapseSidebar') : t('layout.sidebar.expandSidebar')}</span>
  19. <div className='flex items-center gap-x-0.5'>
  20. {
  21. TOGGLE_SHORTCUT.map(key => (
  22. <span
  23. key={key}
  24. className='system-kbd inline-flex items-center justify-center rounded-[4px] bg-components-kbd-bg-gray px-1 text-text-tertiary'
  25. >
  26. {getKeyboardKeyNameBySystem(key)}
  27. </span>
  28. ))
  29. }
  30. </div>
  31. </div>
  32. )
  33. }
  34. type ToggleButtonProps = {
  35. expand: boolean
  36. handleToggle: () => void
  37. className?: string
  38. }
  39. const ToggleButton = ({
  40. expand,
  41. handleToggle,
  42. className,
  43. }: ToggleButtonProps) => {
  44. return (
  45. <Tooltip
  46. popupContent={<TooltipContent expand={expand} />}
  47. popupClassName='p-1.5 rounded-lg'
  48. position='right'
  49. >
  50. <Button
  51. size='small'
  52. onClick={handleToggle}
  53. className={cn('rounded-full px-1', className)}
  54. >
  55. {
  56. expand
  57. ? <RiArrowLeftSLine className='size-4' />
  58. : <RiArrowRightSLine className='size-4' />
  59. }
  60. </Button>
  61. </Tooltip>
  62. )
  63. }
  64. export default React.memo(ToggleButton)