svelte-use-mousetrap
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

svelte-use-mousetrap

Use mousetrap in svelte. Everything is reactive. The 'destroy' works.

Installation

npm i svelte-use-mousetrap ## yarn add svelte-use-mousetrap

Usage

<script>
/* App.svelte */
import mousetrap from 'svelte-use-mousetrap';

// run on 'command+q', 'ctrl+q'
const fn1 = (e) => console.log('fn1', e);

// run on 'shift+q'
const fn2 = (e) => console.log('fn2', e);
// run on 'shift+q'
const fn3 = (e) => console.log('fn3', e);
</script>

<!-- simplest way -->
<div use:mousetrap={['command+q', 'ctrl+q', fn1, 'shift+q' fn2, fn3]}>...</div>

<!-- or exactly the same -->
<div use:mousetrap={[
  ['command+q', 'ctrl+q', fn1],
  ['shift+q', fn2, fn3]
]}>...</div>

<!-- or exactly the same -->
<div use:mousetrap={[
  [['command+q', 'ctrl+q'], fn1],
  ['shift+q', [fn2, fn3]]
]}>...</div>

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i svelte-use-mousetrap

Weekly Downloads

89

Version

1.0.1

License

MIT

Unpacked Size

5.29 kB

Total Files

7

Last publish

Collaborators

  • nk12