aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/frontend/src/main/components/search/dokkaSearchAnchor.tsx
blob: a22dc77dbe1af7a3ec27cbf225a7216b7985f906 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import React from "react";
import Tooltip from '@jetbrains/ring-ui/components/tooltip/tooltip';
import SearchIcon from 'react-svg-loader!../assets/searchIcon.svg';
import {CustomAnchorProps} from "./types";
import {Hotkey} from "../utils/hotkey";

const HOTKEY_LETTER = 'k'
const HOTKEY_TOOLTIP_DISPLAY_DELAY = 0.5 * 1000 // seconds

export const DokkaSearchAnchor = ({wrapperProps, buttonProps, popup}: CustomAnchorProps) => {
    const hotkeys = new Hotkey()
    hotkeys.registerHotkeyWithAccel(buttonProps.onClick, HOTKEY_LETTER)

    return (
        <span {...wrapperProps}>
            <Tooltip
                title={`${hotkeys.getOsAccelKeyName()} + ${HOTKEY_LETTER.toUpperCase()}`}
                delay={HOTKEY_TOOLTIP_DISPLAY_DELAY}
                popupProps={{className: "search-hotkey-popup"}}
            >
                <button type="button" {...buttonProps}>
                    <SearchIcon/>
                </button>
            </Tooltip>
            {popup}
        </span>
    )
}