Skip to content

Commit cdec351

Browse files
committed
fix: add tooltip for resize panel
Signed-off-by: Innei <i@innei.in>
1 parent cd4473b commit cdec351

File tree

5 files changed

+71
-17
lines changed

5 files changed

+71
-17
lines changed

apps/renderer/src/components/ui/divider/PanelSpliter.tsx

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import * as React from "react"
22

3+
import { useMeasure } from "~/hooks/common"
34
import { cn } from "~/lib/utils"
45

6+
import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip"
7+
58
export const PanelSplitter = (
69
props: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
710
isDragging?: boolean
811
cursor?: string
12+
13+
tooltip?: React.ReactNode
914
},
1015
) => {
11-
const { isDragging, cursor, ...rest } = props
16+
const { isDragging, cursor, tooltip, ...rest } = props
1217

1318
React.useEffect(() => {
1419
if (!isDragging) return
@@ -26,16 +31,30 @@ export const PanelSplitter = (
2631
}
2732
}, [cursor, isDragging])
2833

34+
const [ref, { height }] = useMeasure()
35+
36+
const El = (
37+
<div
38+
tabIndex={-1}
39+
ref={ref}
40+
{...rest}
41+
className={cn(
42+
"absolute inset-0 z-[11] w-[2px] -translate-x-1/2 cursor-ew-resize bg-transparent hover:bg-gray-400 active:!bg-accent hover:dark:bg-neutral-500",
43+
isDragging ? "bg-accent" : "",
44+
)}
45+
/>
46+
)
47+
2948
return (
3049
<div className="relative h-full w-0 shrink-0">
31-
<div
32-
tabIndex={-1}
33-
{...rest}
34-
className={cn(
35-
"absolute inset-0 z-[11] w-[2px] -translate-x-1/2 cursor-ew-resize bg-transparent hover:bg-gray-400 active:!bg-accent hover:dark:bg-neutral-500",
36-
isDragging ? "bg-accent" : "",
37-
)}
38-
/>
50+
{tooltip ? (
51+
<Tooltip>
52+
<TooltipTrigger>{El}</TooltipTrigger>
53+
<TooltipContent sideOffset={height / 2}>{tooltip}</TooltipContent>
54+
</Tooltip>
55+
) : (
56+
El
57+
)}
3958
</div>
4059
)
4160
}

apps/renderer/src/constants/shortcuts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const shortcuts = {
1818
layout: {
1919
toggleSidebar: {
2020
name: "keys.layout.toggleSidebar",
21-
key: "Meta+B",
21+
key: "Meta+B, [",
2222
},
2323
showShortcuts: {
2424
name: "keys.layout.showShortcuts",

apps/renderer/src/modules/feed-column/header.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { m } from "framer-motion"
22
import type { FC, PropsWithChildren } from "react"
3-
import { memo, useCallback, useRef, useState } from "react"
3+
import { memo, useCallback, useEffect, useRef, useState } from "react"
44
import { useTranslation } from "react-i18next"
55
import { Link } from "react-router-dom"
66
import { toast } from "sonner"
@@ -77,10 +77,16 @@ export const FeedColumnHeader = memo(() => {
7777
const LayoutActionButton = () => {
7878
const feedColumnShow = useFeedColumnShow()
7979

80-
const [animation] = useState({
80+
const [animation, setAnimation] = useState({
8181
width: !feedColumnShow ? "auto" : 0,
8282
})
8383

84+
useEffect(() => {
85+
setAnimation({
86+
width: !feedColumnShow ? "auto" : 0,
87+
})
88+
}, [feedColumnShow])
89+
8490
const t = useI18n()
8591
return (
8692
<m.div initial={animation} animate={animation} className="overflow-hidden">

apps/renderer/src/pages/(main)/layout.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { throttle } from "lodash-es"
44
import type { PropsWithChildren } from "react"
55
import React, { useEffect, useRef, useState } from "react"
66
import { useHotkeys } from "react-hotkeys-hook"
7-
import { useTranslation } from "react-i18next"
7+
import { Trans, useTranslation } from "react-i18next"
88
import { useResizable } from "react-resizable-layout"
99
import { Outlet } from "react-router-dom"
1010

@@ -15,12 +15,14 @@ import { useLoginModalShow, useWhoami } from "~/atoms/user"
1515
import { AppErrorBoundary } from "~/components/common/AppErrorBoundary"
1616
import { ErrorComponentType } from "~/components/errors/enum"
1717
import { PanelSplitter } from "~/components/ui/divider"
18+
import { Kbd } from "~/components/ui/kbd/Kbd"
1819
import { DeclarativeModal } from "~/components/ui/modal/stacked/declarative-modal"
1920
import { NoopChildren } from "~/components/ui/modal/stacked/utils"
2021
import { RootPortal } from "~/components/ui/portal"
2122
import { HotKeyScopeMap } from "~/constants"
2223
import { shortcuts } from "~/constants/shortcuts"
2324
import { useDailyTask } from "~/hooks/biz/useDailyTask"
25+
import { useI18n } from "~/hooks/common"
2426
import { preventDefault } from "~/lib/dom"
2527
import { cn } from "~/lib/utils"
2628
import { EnvironmentIndicator } from "~/modules/app/EnvironmentIndicator"
@@ -200,6 +202,7 @@ const FeedResponsiveResizerContainer = ({
200202
timer = clearTimeout(timer)
201203
}
202204
}, [feedColumnShow])
205+
const t = useI18n()
203206

204207
return (
205208
<>
@@ -217,9 +220,6 @@ const FeedResponsiveResizerContainer = ({
217220
"--fo-feed-col-w": `${position}px`,
218221
}}
219222
>
220-
{/* {React.cloneElement(children, {
221-
className: "!bg-native",
222-
})} */}
223223
<Slot className={!feedColumnShow ? "!bg-native" : ""}>{children}</Slot>
224224
</div>
225225

@@ -231,7 +231,34 @@ const FeedResponsiveResizerContainer = ({
231231
/>
232232

233233
{delayShowSplitter && (
234-
<PanelSplitter isDragging={isDragging} cursor={separatorCursor} {...separatorProps} />
234+
<PanelSplitter
235+
isDragging={isDragging}
236+
cursor={separatorCursor}
237+
{...separatorProps}
238+
onDoubleClick={() => {
239+
setFeedColumnShow(false)
240+
}}
241+
tooltip={
242+
!isDragging && (
243+
<>
244+
<div>
245+
{/* <b>Drag</b> to resize */}
246+
<Trans t={t} i18nKey="resize.tooltip.drag_to_resize" components={{ b: <b /> }} />
247+
</div>
248+
<div className="center">
249+
<span>
250+
<Trans
251+
t={t}
252+
i18nKey="resize.tooltip.double_click_to_collapse"
253+
components={{ b: <b /> }}
254+
/>
255+
</span>{" "}
256+
<Kbd className="ml-1">{"["}</Kbd>
257+
</div>
258+
</>
259+
)
260+
}
261+
/>
235262
)}
236263
</>
237264
)

locales/app/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@
127127
"player.playback_rate": "Playback Rate",
128128
"player.unmute": "Unmute",
129129
"player.volume": "Volume",
130+
"resize.tooltip.double_click_to_collapse": "<b>Double click</b> to collapse",
131+
"resize.tooltip.drag_to_resize": "<b>Drag</b> to resize",
130132
"search.empty.no_results": "No results found.",
131133
"search.group.entries": "Entries",
132134
"search.group.feeds": "Feeds",

0 commit comments

Comments
 (0)