From cdec3510352cc7281e75ef1957e32bc6e712cf04 Mon Sep 17 00:00:00 2001 From: Innei Date: Sat, 21 Sep 2024 20:44:42 +0800 Subject: [PATCH] fix: add tooltip for resize panel Signed-off-by: Innei --- .../components/ui/divider/PanelSpliter.tsx | 37 ++++++++++++++----- apps/renderer/src/constants/shortcuts.ts | 2 +- .../src/modules/feed-column/header.tsx | 10 ++++- apps/renderer/src/pages/(main)/layout.tsx | 37 ++++++++++++++++--- locales/app/en.json | 2 + 5 files changed, 71 insertions(+), 17 deletions(-) diff --git a/apps/renderer/src/components/ui/divider/PanelSpliter.tsx b/apps/renderer/src/components/ui/divider/PanelSpliter.tsx index adeb23c1c..84325904a 100644 --- a/apps/renderer/src/components/ui/divider/PanelSpliter.tsx +++ b/apps/renderer/src/components/ui/divider/PanelSpliter.tsx @@ -1,14 +1,19 @@ import * as React from "react" +import { useMeasure } from "~/hooks/common" import { cn } from "~/lib/utils" +import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip" + export const PanelSplitter = ( props: React.DetailedHTMLProps, HTMLDivElement> & { isDragging?: boolean cursor?: string + + tooltip?: React.ReactNode }, ) => { - const { isDragging, cursor, ...rest } = props + const { isDragging, cursor, tooltip, ...rest } = props React.useEffect(() => { if (!isDragging) return @@ -26,16 +31,30 @@ export const PanelSplitter = ( } }, [cursor, isDragging]) + const [ref, { height }] = useMeasure() + + const El = ( +
+ ) + return (
-
+ {tooltip ? ( + + {El} + {tooltip} + + ) : ( + El + )}
) } diff --git a/apps/renderer/src/constants/shortcuts.ts b/apps/renderer/src/constants/shortcuts.ts index 80d0ed4aa..38efb5e1b 100644 --- a/apps/renderer/src/constants/shortcuts.ts +++ b/apps/renderer/src/constants/shortcuts.ts @@ -18,7 +18,7 @@ export const shortcuts = { layout: { toggleSidebar: { name: "keys.layout.toggleSidebar", - key: "Meta+B", + key: "Meta+B, [", }, showShortcuts: { name: "keys.layout.showShortcuts", diff --git a/apps/renderer/src/modules/feed-column/header.tsx b/apps/renderer/src/modules/feed-column/header.tsx index e2a87dddf..f91331c1d 100644 --- a/apps/renderer/src/modules/feed-column/header.tsx +++ b/apps/renderer/src/modules/feed-column/header.tsx @@ -1,6 +1,6 @@ import { m } from "framer-motion" import type { FC, PropsWithChildren } from "react" -import { memo, useCallback, useRef, useState } from "react" +import { memo, useCallback, useEffect, useRef, useState } from "react" import { useTranslation } from "react-i18next" import { Link } from "react-router-dom" import { toast } from "sonner" @@ -77,10 +77,16 @@ export const FeedColumnHeader = memo(() => { const LayoutActionButton = () => { const feedColumnShow = useFeedColumnShow() - const [animation] = useState({ + const [animation, setAnimation] = useState({ width: !feedColumnShow ? "auto" : 0, }) + useEffect(() => { + setAnimation({ + width: !feedColumnShow ? "auto" : 0, + }) + }, [feedColumnShow]) + const t = useI18n() return ( diff --git a/apps/renderer/src/pages/(main)/layout.tsx b/apps/renderer/src/pages/(main)/layout.tsx index 7a264e37f..a34dea0f5 100644 --- a/apps/renderer/src/pages/(main)/layout.tsx +++ b/apps/renderer/src/pages/(main)/layout.tsx @@ -4,7 +4,7 @@ import { throttle } from "lodash-es" import type { PropsWithChildren } from "react" import React, { useEffect, useRef, useState } from "react" import { useHotkeys } from "react-hotkeys-hook" -import { useTranslation } from "react-i18next" +import { Trans, useTranslation } from "react-i18next" import { useResizable } from "react-resizable-layout" import { Outlet } from "react-router-dom" @@ -15,12 +15,14 @@ import { useLoginModalShow, useWhoami } from "~/atoms/user" import { AppErrorBoundary } from "~/components/common/AppErrorBoundary" import { ErrorComponentType } from "~/components/errors/enum" import { PanelSplitter } from "~/components/ui/divider" +import { Kbd } from "~/components/ui/kbd/Kbd" import { DeclarativeModal } from "~/components/ui/modal/stacked/declarative-modal" import { NoopChildren } from "~/components/ui/modal/stacked/utils" import { RootPortal } from "~/components/ui/portal" import { HotKeyScopeMap } from "~/constants" import { shortcuts } from "~/constants/shortcuts" import { useDailyTask } from "~/hooks/biz/useDailyTask" +import { useI18n } from "~/hooks/common" import { preventDefault } from "~/lib/dom" import { cn } from "~/lib/utils" import { EnvironmentIndicator } from "~/modules/app/EnvironmentIndicator" @@ -200,6 +202,7 @@ const FeedResponsiveResizerContainer = ({ timer = clearTimeout(timer) } }, [feedColumnShow]) + const t = useI18n() return ( <> @@ -217,9 +220,6 @@ const FeedResponsiveResizerContainer = ({ "--fo-feed-col-w": `${position}px`, }} > - {/* {React.cloneElement(children, { - className: "!bg-native", - })} */} {children}
@@ -231,7 +231,34 @@ const FeedResponsiveResizerContainer = ({ /> {delayShowSplitter && ( - + { + setFeedColumnShow(false) + }} + tooltip={ + !isDragging && ( + <> +
+ {/* Drag to resize */} + }} /> +
+
+ + }} + /> + {" "} + {"["} +
+ + ) + } + /> )} ) diff --git a/locales/app/en.json b/locales/app/en.json index eade1ec5c..7a428a993 100644 --- a/locales/app/en.json +++ b/locales/app/en.json @@ -127,6 +127,8 @@ "player.playback_rate": "Playback Rate", "player.unmute": "Unmute", "player.volume": "Volume", + "resize.tooltip.double_click_to_collapse": "Double click to collapse", + "resize.tooltip.drag_to_resize": "Drag to resize", "search.empty.no_results": "No results found.", "search.group.entries": "Entries", "search.group.feeds": "Feeds",