add keyboard listener

main
Mike Fix 3 years ago
parent 27108aa76c
commit 7557b5563e

@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import { useAsyncCallback, useOnline } from 'actionsack' import { useAsyncCallback, useOnline, useKeyboardListener } from 'actionsack'
import Button from './Button' import Button from './Button'
import Toolbar from './Toolbar' import Toolbar from './Toolbar'
@ -51,6 +51,29 @@ function DuplicateButton(props) {
) )
} }
function SaveButton({ loading, onClick }) {
useKeyboardListener('⌥-s', e => {
e.preventDefault()
onClick()
})
return (
<Button
border
large
center
color={COLORS.GREEN}
onClick={onClick}
data-cy="save-button"
style={{ minWidth: 84, borderBottomRightRadius: 0, borderTopRightRadius: 0 }}
title="Save"
disabled={loading}
>
{loading ? 'Saving…' : 'Save'}
</Button>
)
}
function SnippetToolbar({ function SnippetToolbar({
toggleVisibility, toggleVisibility,
isVisible, isVisible,
@ -108,21 +131,8 @@ function SnippetToolbar({
}} }}
> >
<div className="flex"> <div className="flex">
<SaveButton loading={loading} onClick={saveSnippet} />
<Button <Button
border
large
center
color={COLORS.GREEN}
onClick={saveSnippet}
data-cy="save-button"
style={{ minWidth: 84, borderBottomRightRadius: 0, borderTopRightRadius: 0 }}
title="Save"
disabled={loading}
>
{loading ? 'Saving…' : 'Save'}
</Button>
<Button
id="save-menu"
title="Save menu dropdown" title="Save menu dropdown"
border border
large large

@ -144,6 +144,12 @@ export default function About() {
<kbd> S</kbd> <kbd> S</kbd>
</td> </td>
</tr> </tr>
<tr>
<td>Save snippet</td>
<td>
<kbd> S</kbd>
</td>
</tr>
<tr> <tr>
<td>Copy image to clipboard</td> <td>Copy image to clipboard</td>
<td> <td>

Loading…
Cancel
Save