mirror of
https://github.com/langgenius/dify.git
synced 2026-06-17 14:51:10 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: fatelei <fatelei@gmail.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com> Co-authored-by: gigglewang <gigglewang@dify.ai> Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai> Co-authored-by: chariri <w@chariri.moe> Co-authored-by: Evan <2869018789@qq.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
73 lines
2.0 KiB
TypeScript
73 lines
2.0 KiB
TypeScript
import { Button } from '@langgenius/dify-ui/button'
|
|
import { cn } from '@langgenius/dify-ui/cn'
|
|
import { Kbd, KbdGroup } from '@langgenius/dify-ui/kbd'
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@langgenius/dify-ui/tooltip'
|
|
import { formatForDisplay } from '@tanstack/react-hotkeys'
|
|
import * as React from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
type ToggleTooltipContentProps = {
|
|
expand: boolean
|
|
}
|
|
|
|
const TOGGLE_SHORTCUT = ['Mod', 'B']
|
|
|
|
const ToggleTooltipContent = ({
|
|
expand,
|
|
}: ToggleTooltipContentProps) => {
|
|
const { t } = useTranslation()
|
|
|
|
return (
|
|
<div className="flex items-center gap-x-1">
|
|
<span className="px-0.5 system-xs-medium text-text-secondary">{expand ? t('sidebar.collapseSidebar', { ns: 'layout' }) : t('sidebar.expandSidebar', { ns: 'layout' })}</span>
|
|
<KbdGroup>
|
|
{TOGGLE_SHORTCUT.map(key => (
|
|
<Kbd key={key}>{formatForDisplay(key)}</Kbd>
|
|
))}
|
|
</KbdGroup>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
type ToggleButtonProps = {
|
|
expand: boolean
|
|
handleToggle: () => void
|
|
className?: string
|
|
icon?: React.ReactNode
|
|
iconClassName?: string
|
|
}
|
|
|
|
const ToggleButton = ({
|
|
expand,
|
|
handleToggle,
|
|
className,
|
|
icon,
|
|
iconClassName,
|
|
}: ToggleButtonProps) => {
|
|
return (
|
|
<Tooltip>
|
|
<TooltipTrigger
|
|
render={(
|
|
<Button
|
|
size="small"
|
|
onClick={handleToggle}
|
|
className={cn('rounded-full px-1', className)}
|
|
/>
|
|
)}
|
|
>
|
|
{icon
|
|
|| (iconClassName
|
|
? <span aria-hidden className={cn('size-4', iconClassName)} />
|
|
: expand
|
|
? <span aria-hidden className="i-ri-arrow-left-s-line size-4" />
|
|
: <span aria-hidden className="i-ri-arrow-right-s-line size-4" />)}
|
|
</TooltipTrigger>
|
|
<TooltipContent placement="right" className="rounded-lg p-1.5">
|
|
<ToggleTooltipContent expand={expand} />
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
)
|
|
}
|
|
|
|
export default React.memo(ToggleButton)
|