|
1 | 1 | import React from 'react'; |
2 | 2 | import isFunction from 'lodash/isFunction'; |
3 | | -import {Button, Hotkey, Icon, Menu, Popup, Tooltip} from '@gravity-ui/uikit'; |
| 3 | +import {Button, Hotkey, Icon, Menu, Popover, Popup, Tooltip} from '@gravity-ui/uikit'; |
4 | 4 | import {HelpPopover} from '@gravity-ui/components'; |
5 | 5 | import {ChevronDown} from '@gravity-ui/icons'; |
6 | 6 |
|
7 | 7 | import {cn} from '../classname'; |
| 8 | +import {i18n} from '../i18n/common'; |
8 | 9 | import {useBooleanState} from '../react-utils/hooks'; |
9 | 10 | import {ToolbarTooltipDelay} from './const'; |
10 | 11 | import {ToolbarBaseProps, ToolbarIconData, ToolbarItemData} from './types'; |
@@ -34,7 +35,6 @@ export function ToolbarListButton<E>({ |
34 | 35 | withArrow, |
35 | 36 | data, |
36 | 37 | alwaysActive, |
37 | | - hideDisabled, |
38 | 38 | }: ToolbarListButtonProps<E>) { |
39 | 39 | const buttonRef = React.useRef<HTMLButtonElement>(null); |
40 | 40 | const [open, , hide, toggleOpen] = useBooleanState(false); |
@@ -62,58 +62,75 @@ export function ToolbarListButton<E>({ |
62 | 62 |
|
63 | 63 | return ( |
64 | 64 | <> |
65 | | - <Tooltip |
66 | | - content={titleText} |
67 | | - disabled={popupOpen} |
68 | | - openDelay={ToolbarTooltipDelay.Open} |
69 | | - closeDelay={ToolbarTooltipDelay.Close} |
| 65 | + <Popover |
| 66 | + className={b('action-disabled-popover')} |
| 67 | + tooltipContentClassName={b('action-disabled-tooltip')} |
| 68 | + content={i18n('toolbar_action_disabled')} |
| 69 | + placement={'bottom'} |
| 70 | + disabled={!everyDisabled} |
70 | 71 | > |
71 | | - <Button |
72 | | - size="m" |
73 | | - ref={buttonRef} |
74 | | - view={someActive || popupOpen ? 'normal' : 'flat'} |
75 | | - selected={someActive} |
76 | | - disabled={everyDisabled} |
77 | | - className={b({arrow: withArrow}, [className])} |
78 | | - onClick={toggleOpen} |
| 72 | + <Tooltip |
| 73 | + content={titleText} |
| 74 | + disabled={popupOpen} |
| 75 | + openDelay={ToolbarTooltipDelay.Open} |
| 76 | + closeDelay={ToolbarTooltipDelay.Close} |
79 | 77 | > |
80 | | - {buttonContent} |
81 | | - </Button> |
82 | | - </Tooltip> |
| 78 | + <Button |
| 79 | + size="m" |
| 80 | + ref={buttonRef} |
| 81 | + view={someActive || popupOpen ? 'normal' : 'flat'} |
| 82 | + selected={someActive} |
| 83 | + disabled={everyDisabled} |
| 84 | + className={b({arrow: withArrow}, [className])} |
| 85 | + onClick={toggleOpen} |
| 86 | + > |
| 87 | + {buttonContent} |
| 88 | + </Button> |
| 89 | + </Tooltip> |
| 90 | + </Popover> |
83 | 91 | <Popup anchorRef={buttonRef} open={popupOpen} onClose={hide}> |
84 | 92 | <Menu size="l" className={b('menu')}> |
85 | 93 | {data |
86 | 94 | .map(({id, title, icon, hotkey, isActive, isEnable, exec, hint}) => { |
87 | 95 | const titleText = isFunction(title) ? title() : title; |
88 | 96 | const hintText = isFunction(hint) ? hint() : hint; |
89 | 97 | const disabled = !isEnable(editor); |
90 | | - return hideDisabled && disabled ? null : ( |
91 | | - <Menu.Item |
| 98 | + return ( |
| 99 | + <Popover |
| 100 | + className={b('action-disabled-popover')} |
| 101 | + tooltipContentClassName={b('action-disabled-tooltip')} |
| 102 | + content={i18n('toolbar_action_disabled')} |
| 103 | + placement={'left'} |
| 104 | + disabled={!disabled} |
92 | 105 | key={id} |
93 | | - active={isActive(editor)} |
94 | | - disabled={!isEnable(editor)} |
95 | | - onClick={() => { |
96 | | - hide(); |
97 | | - focus(); |
98 | | - exec(editor); |
99 | | - onClick?.(id); |
100 | | - }} |
101 | | - icon={<Icon data={icon.data} size={icon.size ?? 16} />} |
102 | | - extraProps={{'aria-label': titleText}} |
103 | 106 | > |
104 | | - <div className={b('item')}> |
105 | | - {titleText} |
106 | | - <div className={b('extra')}> |
107 | | - {hotkey && <Hotkey value={hotkey} />} |
108 | | - {hintText && ( |
109 | | - <HelpPopover |
110 | | - className={b('hint')} |
111 | | - content={hintText} |
112 | | - /> |
113 | | - )} |
| 107 | + <Menu.Item |
| 108 | + key={id} |
| 109 | + active={isActive(editor)} |
| 110 | + disabled={!isEnable(editor)} |
| 111 | + onClick={() => { |
| 112 | + hide(); |
| 113 | + focus(); |
| 114 | + exec(editor); |
| 115 | + onClick?.(id); |
| 116 | + }} |
| 117 | + icon={<Icon data={icon.data} size={icon.size ?? 16} />} |
| 118 | + extraProps={{'aria-label': titleText}} |
| 119 | + > |
| 120 | + <div className={b('item')}> |
| 121 | + {titleText} |
| 122 | + <div className={b('extra')}> |
| 123 | + {hotkey && <Hotkey value={hotkey} />} |
| 124 | + {hintText && ( |
| 125 | + <HelpPopover |
| 126 | + className={b('hint')} |
| 127 | + content={hintText} |
| 128 | + /> |
| 129 | + )} |
| 130 | + </div> |
114 | 131 | </div> |
115 | | - </div> |
116 | | - </Menu.Item> |
| 132 | + </Menu.Item> |
| 133 | + </Popover> |
117 | 134 | ); |
118 | 135 | }) |
119 | 136 | .filter(Boolean)} |
|
0 commit comments