Skip to content

Commit

Permalink
Merge pull request #16 – feat(tooltip): add tooltip to list items
Browse files Browse the repository at this point in the history
Add tooltip for items with a drop-down list of actions. Add delay before open and close tooltip.
  • Loading branch information
d3m1d0v authored Oct 5, 2022
2 parents 52c5d3b + 2c17593 commit 4596c70
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 17 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@gravity-ui/prettier-config": "1.0.1",
"@gravity-ui/stylelint-config": "1.0.1",
"@gravity-ui/tsconfig": "1.0.0",
"@gravity-ui/uikit": "3.0.2",
"@gravity-ui/uikit": "3.1.0",
"@storybook/addon-essentials": "6.5.10",
"@storybook/preset-scss": "1.0.3",
"@storybook/react": "6.5.10",
Expand Down Expand Up @@ -105,7 +105,7 @@
},
"peerDependencies": {
"@doc-tools/transform": "^2.14.0",
"@gravity-ui/uikit": "^3.0.0",
"@gravity-ui/uikit": "^3.1.0",
"lodash": "^4.17.20",
"react": "^16.8.0 || ^17.0.0",
"react-dom": "^16.8.0 || ^17.0.0"
Expand Down
5 changes: 4 additions & 1 deletion src/toolbar/FlexToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import './FlexToolbar.scss';

const b = cn('flex-toolbar');

export type FlexToolbarProps<E> = ToolbarProps<E>;
export type FlexToolbarProps<E> = ToolbarProps<E> & {
dotsTitle: string | (() => string);
};

export function FlexToolbar<E>(props: FlexToolbarProps<E>) {
useRenderTime((time) => {
Expand All @@ -40,6 +42,7 @@ export function FlexToolbar<E>(props: FlexToolbarProps<E>) {
<ToolbarListButton
data={dots}
icon={{data: dotsIcon}}
title={props.dotsTitle}
editor={props.editor}
focus={props.focus}
onClick={props.onClick}
Expand Down
3 changes: 3 additions & 0 deletions src/toolbar/ToolbarButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {isFunction} from 'lodash';
import {Button, Icon, Tooltip} from '@gravity-ui/uikit';
import {cn} from '../classname';
import {ToolbarTooltipDelay} from './const';
import type {ToolbarBaseProps, ToolbarItemData} from './types';

import './ToolbarButton.scss';
Expand Down Expand Up @@ -31,6 +32,8 @@ export function ToolbarButton<E>({

return (
<Tooltip
openDelay={ToolbarTooltipDelay.Open}
closeDelay={ToolbarTooltipDelay.Close}
content={
<>
{titleText}
Expand Down
34 changes: 23 additions & 11 deletions src/toolbar/ToolbarListButton.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import {isFunction} from 'lodash';
import {Button, HelpPopover, Icon, Menu, Popup} from '@gravity-ui/uikit';
import {Button, HelpPopover, Icon, Menu, Popup, Tooltip} from '@gravity-ui/uikit';

import chevronIcon from '../../assets/icons/ye-chevron.svg';
import {cn} from '../classname';
import {useBooleanState} from '../react-utils/hooks';
import {ToolbarTooltipDelay} from './const';
import {ToolbarBaseProps, ToolbarIconData, ToolbarItemData} from './types';

import './ToolbarListButton.scss';
Expand All @@ -13,6 +14,7 @@ const b = cn('toolbar-list-button');

export type ToolbarListButtonData<E> = {
icon: ToolbarIconData;
title: string | (() => string);
withArrow?: boolean;
data: ToolbarItemData<E>[];
};
Expand All @@ -25,6 +27,7 @@ export function ToolbarListButton<E>({
focus,
onClick,
icon,
title,
withArrow,
data,
}: ToolbarListButtonProps<E>) {
Expand All @@ -50,19 +53,28 @@ export function ToolbarListButton<E>({
buttonContent.push(<Icon key={3} data={chevronIcon} size={16} />);
}

const titleText: string = isFunction(title) ? title() : title;

return (
<>
<Button
size="m"
ref={buttonRef}
view={someActive || popupOpen ? 'normal' : 'flat'}
selected={someActive}
disabled={everyDisabled}
className={b({arrow: withArrow}, [className])}
onClick={toggleOpen}
<Tooltip
content={titleText}
disabled={popupOpen}
openDelay={ToolbarTooltipDelay.Open}
closeDelay={ToolbarTooltipDelay.Close}
>
{buttonContent}
</Button>
<Button
size="m"
ref={buttonRef}
view={someActive || popupOpen ? 'normal' : 'flat'}
selected={someActive}
disabled={everyDisabled}
className={b({arrow: withArrow}, [className])}
onClick={toggleOpen}
>
{buttonContent}
</Button>
</Tooltip>
<Popup anchorRef={buttonRef} open={popupOpen} onClose={hide}>
<Menu size="l" className={b('menu')}>
{data.map(({id, title, icon, hotkey, isActive, isEnable, exec, hint}) => {
Expand Down
4 changes: 4 additions & 0 deletions src/toolbar/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum ToolbarTooltipDelay {
Open = 250,
Close = 150,
}
1 change: 1 addition & 0 deletions src/toolbar/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './const';
export * from './types';
export * from './Toolbar';
export * from './ToolbarButton';
Expand Down

0 comments on commit 4596c70

Please sign in to comment.