2023-01-11 17:57:42 +00:00
|
|
|
import {makeT} from 'app/client/lib/localization';
|
2021-03-08 21:08:13 +00:00
|
|
|
import {ITooltipControl, showTooltip, tooltipCloseButton} from 'app/client/ui/tooltips';
|
2023-09-21 16:57:58 +00:00
|
|
|
import {testId, theme} from 'app/client/ui2018/cssVars';
|
2021-03-05 15:17:07 +00:00
|
|
|
import {icon} from 'app/client/ui2018/icons';
|
|
|
|
import {cssLink} from 'app/client/ui2018/links';
|
|
|
|
import {dom, styled} from 'grainjs';
|
|
|
|
|
2023-01-24 12:51:53 +00:00
|
|
|
const t = makeT('EditorTooltip');
|
2023-01-11 17:57:42 +00:00
|
|
|
|
2021-03-05 15:17:07 +00:00
|
|
|
export function showTooltipToCreateFormula(editorDom: HTMLElement, convert: () => void) {
|
|
|
|
function buildTooltip(ctl: ITooltipControl) {
|
|
|
|
return cssConvertTooltip(icon('Convert'),
|
2023-01-11 17:57:42 +00:00
|
|
|
cssLink(t('Convert column to formula'),
|
2021-03-05 15:17:07 +00:00
|
|
|
dom.on('mousedown', (ev) => { ev.preventDefault(); convert(); }),
|
|
|
|
testId('editor-tooltip-convert'),
|
|
|
|
),
|
2021-03-08 21:08:13 +00:00
|
|
|
tooltipCloseButton(ctl),
|
2021-03-05 15:17:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
const offerCtl = showTooltip(editorDom, buildTooltip, {key: 'col-to-formula'});
|
|
|
|
|
|
|
|
dom.onDisposeElem(editorDom, offerCtl.close);
|
|
|
|
const lis = dom.onElem(editorDom, 'keydown', () => {
|
|
|
|
lis.dispose();
|
|
|
|
offerCtl.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const cssConvertTooltip = styled('div', `
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2023-09-21 16:57:58 +00:00
|
|
|
--icon-color: ${theme.controlFg};
|
2021-03-05 15:17:07 +00:00
|
|
|
|
|
|
|
& > .${cssLink.className} {
|
|
|
|
margin-left: 8px;
|
|
|
|
}
|
|
|
|
`);
|