Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.7 KB
Raw Blame
import type { ReactNode } from 'react'
import { IconButton } from '@langgenius/dify-ui/icon-button'
import { Kbd, KbdGroup } from '@langgenius/dify-ui/kbd'
import { Tooltip, TooltipContent, TooltipTrigger } from '@langgenius/dify-ui/tooltip'
import { formatForDisplay } from '@tanstack/react-hotkeys'
import { useTranslation } from 'react-i18next'
import { DETAIL_SIDEBAR_TOGGLE_HOTKEY } from './hotkeys'

type DetailSidebarToggleButtonProps = {
  expand: boolean
  onToggle: () => void
  className?: string
  icon?: ReactNode
}

export function DetailSidebarToggleButton({
  expand,
  onToggle,
  className,
  icon,
}: DetailSidebarToggleButtonProps) {
  const { t } = useTranslation(['layout'])
  const label = expand
    ? t(($) => $['sidebar.collapseSidebar'], { ns: 'layout' })
    : t(($) => $['sidebar.expandSidebar'], { ns: 'layout' })

  return (
    <Tooltip>
      <TooltipTrigger
        render={
          <IconButton size="lg" aria-label={label} onClick={onToggle} className={className}>
            <span aria-hidden className="inline-flex">
              {icon ??
                (expand ? (
                  <span className="i-ri-arrow-left-s-line size-4" />
                ) : (
                  <span className="i-ri-arrow-right-s-line size-4" />
                ))}
            </span>
          </IconButton>
        }
      />
      <TooltipContent side="right" className="flex items-center gap-1">
        <span className="px-0.5">{label}</span>
        <KbdGroup>
          {formatForDisplay(DETAIL_SIDEBAR_TOGGLE_HOTKEY, { parts: true }).map((key) => (
            <Kbd key={key}>{key}</Kbd>
          ))}
        </KbdGroup>
      </TooltipContent>
    </Tooltip>
  )
}