diff --git a/src/toolbar/ActionButton.tsx b/src/toolbar/ActionButton.tsx index f84eb5d2..269fcda4 100644 --- a/src/toolbar/ActionButton.tsx +++ b/src/toolbar/ActionButton.tsx @@ -3,16 +3,14 @@ import { Button, - Hotkey, - Hotkeys, - HotkeysTarget, Intent, Position, Spinner, Tooltip, + useHotkeys, } from '@blueprintjs/core'; -import { WithI18nProps, withI18n } from '@shopify/react-i18n'; -import React from 'react'; +import { useI18n } from '@shopify/react-i18n'; +import React, { useMemo, useRef } from 'react'; import { tooltipDelay } from '../app/constants'; import { TooltipId } from './i18n'; import en from './i18n.en.json'; @@ -38,84 +36,68 @@ export interface ActionButtonProps { readonly onAction: () => void; } -type Props = ActionButtonProps & WithI18nProps; +const ActionButton: React.FC = (props) => { + const buttonRef = useRef - - ); - } - - renderHotkeys(): React.ReactElement { - if (!this.props.keyboardShortcut) { - return ; + const hotkeys = useMemo(() => { + if (!props.keyboardShortcut) { + return []; } - return ( - - { - if (this.props.enabled) { - this.props.onAction(); - } - }} - /> - - ); - } -} + return [ + { + global: true, + allowInInput: true, + preventDefault: true, + combo: props.keyboardShortcut.replaceAll('-', '+'), + label: i18n.translate(props.tooltip), + onKeyDown: () => { + if (props.enabled) { + props.onAction(); + } + }, + }, + ]; + }, [props, i18n]); -export default withI18n({ id: 'actionButton', fallback: en, translations: { en } })( - ActionButton, -); + useHotkeys(hotkeys); + + return ( + + + + ); +}; + +export default ActionButton;