feat(core): add tooltips to sidebar resize handle (#8717)

close PD-1865
![CleanShot 2024-11-06 at 12 52 35@2x](https://github.com/user-attachments/assets/b7353448-f8c5-4cfb-bfed-d1acff2923c4)
This commit is contained in:
JimmFly
2024-11-06 06:19:38 +00:00
parent 584d095895
commit 59264b9996
7 changed files with 89 additions and 32 deletions

View File

@@ -3,6 +3,7 @@ import clsx from 'clsx';
import { forwardRef, useCallback, useLayoutEffect, useRef } from 'react';
import { useTransition } from 'react-transition-state';
import { Tooltip, type TooltipProps } from '../../ui/tooltip';
import * as styles from './resize-panel.css';
export interface ResizeHandleProps
@@ -17,6 +18,10 @@ export interface ResizeHandleProps
onOpen: (open: boolean) => void;
onResizing: (resizing: boolean) => void;
onWidthChange: (width: number) => void;
tooltip?: TooltipProps['content'];
tooltipShortcut?: TooltipProps['shortcut'];
tooltipOptions?: Partial<Omit<TooltipProps, 'content' | 'shortcut'>>;
tooltipShortcutClassName?: string;
}
export interface ResizePanelProps
@@ -29,6 +34,12 @@ export interface ResizePanelProps
resizeHandlePos: 'left' | 'right';
resizeHandleOffset?: number;
resizeHandleVerticalPadding?: number;
resizeHandleTooltip?: TooltipProps['content'];
resizeHandleTooltipShortcut?: TooltipProps['shortcut'];
resizeHandleTooltipShortcutClassName?: string;
resizeHandleTooltipOptions?: Partial<
Omit<TooltipProps, 'content' | 'shortcut'>
>;
enableAnimation?: boolean;
width: number;
unmountOnExit?: boolean;
@@ -49,6 +60,10 @@ const ResizeHandle = ({
onOpen,
onResizing,
onWidthChange,
tooltip,
tooltipShortcut,
tooltipOptions,
tooltipShortcutClassName,
...rest
}: ResizeHandleProps) => {
const ref = useRef<HTMLDivElement>(null);
@@ -101,24 +116,31 @@ const ResizeHandle = ({
);
return (
<div
{...rest}
data-testid="resize-handle"
ref={ref}
style={assignInlineVars({
[styles.resizeHandleOffsetVar]: `${resizeHandleOffset ?? 0}px`,
[styles.resizeHandleVerticalPadding]: `${
resizeHandleVerticalPadding ?? 0
}px`,
})}
className={clsx(styles.resizeHandleContainer, className)}
data-handle-position={resizeHandlePos}
data-resizing={resizing}
data-open={open}
onMouseDown={onResizeStart}
<Tooltip
content={tooltip}
shortcut={tooltipShortcut}
shortcutClassName={tooltipShortcutClassName}
{...tooltipOptions}
>
<div className={styles.resizerInner} />
</div>
<div
{...rest}
data-testid="resize-handle"
ref={ref}
style={assignInlineVars({
[styles.resizeHandleOffsetVar]: `${resizeHandleOffset ?? 0}px`,
[styles.resizeHandleVerticalPadding]: `${
resizeHandleVerticalPadding ?? 0
}px`,
})}
className={clsx(styles.resizeHandleContainer, className)}
data-handle-position={resizeHandlePos}
data-resizing={resizing}
data-open={open}
onMouseDown={onResizeStart}
>
<div className={styles.resizerInner} />
</div>
</Tooltip>
);
};
@@ -143,6 +165,10 @@ export const ResizePanel = forwardRef<HTMLDivElement, ResizePanelProps>(
resizeHandlePos,
resizeHandleOffset,
resizeHandleVerticalPadding,
resizeHandleTooltip,
resizeHandleTooltipShortcut,
resizeHandleTooltipShortcutClassName,
resizeHandleTooltipOptions,
...rest
},
ref
@@ -176,6 +202,10 @@ export const ResizePanel = forwardRef<HTMLDivElement, ResizePanelProps>(
resizeHandlePos={resizeHandlePos}
resizeHandleOffset={resizeHandleOffset}
resizeHandleVerticalPadding={resizeHandleVerticalPadding}
tooltip={resizeHandleTooltip}
tooltipOptions={resizeHandleTooltipOptions}
tooltipShortcut={resizeHandleTooltipShortcut}
tooltipShortcutClassName={resizeHandleTooltipShortcutClassName}
maxWidth={maxWidth}
minWidth={minWidth}
onOpen={onOpen}

View File

@@ -40,15 +40,22 @@ export interface TooltipProps {
rootOptions?: Omit<RootProps, 'children'>;
portalOptions?: TooltipPortalProps;
options?: Omit<TooltipContentProps, 'side' | 'align'>;
shortcutClassName?: string;
}
const TooltipShortcut = ({ shortcut }: { shortcut: string | string[] }) => {
const TooltipShortcut = ({
shortcut,
className,
}: {
shortcut: string | string[];
className?: string;
}) => {
const commands = (Array.isArray(shortcut) ? shortcut : [shortcut])
.map(cmd => cmd.trim())
.map(cmd => getCommand(cmd));
return (
<div className={styles.shortcut}>
<div className={clsx(styles.shortcut, className)}>
{commands.map((cmd, index) => (
<div
key={`${index}-${cmd}`}
@@ -71,6 +78,7 @@ export const Tooltip = ({
options,
rootOptions,
portalOptions,
shortcutClassName,
}: TooltipProps) => {
if (!content) {
return children;
@@ -94,7 +102,10 @@ export const Tooltip = ({
{shortcut ? (
<div className={styles.withShortcut}>
<div className={styles.withShortcutContent}>{content}</div>
<TooltipShortcut shortcut={shortcut} />
<TooltipShortcut
shortcut={shortcut}
className={shortcutClassName}
/>
</div>
) : (
content