Skip to content

Commit 1f985c0

Browse files
committed
feat: update api
feat: rename package and prepare release
1 parent 596daab commit 1f985c0

File tree

12 files changed

+65
-62
lines changed

12 files changed

+65
-62
lines changed

.idea/discord.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# KeyShort
1+
# react-keybinds
22

33
Simple package to manage keyboard shortcuts
44

@@ -7,35 +7,35 @@ Simple package to manage keyboard shortcuts
77
#### Using npm
88

99
```bash
10-
npm i keyshort
10+
npm i react-keybinds
1111
```
1212

1313
#### Using Yarn
1414

1515
```bash
16-
yarn add keyshort
16+
yarn add react-keybinds
1717
```
1818

1919
#### Using pnpm
2020

2121
```bash
22-
pnpm add keyshort
22+
pnpm add react-keybinds
2323
```
2424

2525
# Usage
2626

2727
<sub>You can take a look at the [example](./example) </sub>
2828

29-
### 1. Configuring the KeyShort provider
29+
### 1. Configuring the KeyBind provider
3030

3131
```tsx
32-
import {KeyShortProvider} from 'keyshort';
32+
import {KeyBindProvider} from 'react-keybinds';
3333

3434
const App = () => {
3535
return (
36-
<KeyShortProvider>
36+
<KeyBindProvider>
3737
hello world
38-
</KeyShortProvider>
38+
</KeyBindProvider>
3939
);
4040
};
4141
```
@@ -48,12 +48,12 @@ const App = () => {
4848
You can register commands globally
4949

5050
```tsx
51-
import {KeyShortProvider, ShortcutType} from 'keyshort';
51+
import {KeyBindProvider, ShortcutType} from 'react-keybinds';
5252

5353
const GLOBAL_COMMANDS: ShortcutType[] = [
5454
{
5555
keys: {
56-
Mac: ['Meta', 'Shift', 'P'],
56+
Mac: ['Control', 'Shift', 'P'],
5757
Windows: ['Control', 'Shift', 'P'],
5858
},
5959
label: 'Test command',
@@ -65,9 +65,9 @@ const GLOBAL_COMMANDS: ShortcutType[] = [
6565

6666
const App = () => {
6767
return (
68-
<KeyShortProvider shortcuts={GLOBAL_COMMANDS}>
68+
<KeyBindProvider shortcuts={GLOBAL_COMMANDS}>
6969
hello world
70-
</KeyShortProvider>
70+
</KeyBindProvider>
7171
);
7272
};
7373
```
@@ -78,10 +78,10 @@ You can register a command in a specific part of your application. This is usefu
7878
handler that exists in a specific component.
7979

8080
```tsx
81-
import {KeyShortProvider, useKeyShort} from 'keyshort';
81+
import {KeyBindProvider, useKeyBind} from 'react-keybinds';
8282

8383
const RegisterShortcutButton = () => {
84-
const {registerShortcut} = useKeyShort();
84+
const {registerShortcut} = useKeyBind();
8585

8686
const handleClickRegister = () => {
8787
registerShortcut({
@@ -104,22 +104,22 @@ const RegisterShortcutButton = () => {
104104

105105
const App = () => {
106106
return (
107-
<KeyShortProvider>
107+
<KeyBindProvider>
108108
<RegisterShortcutButton/>
109-
</KeyShortProvider>
109+
</KeyBindProvider>
110110
);
111111
};
112112
```
113113

114114
### 4. List registered shortcuts
115115

116-
You can list the registered shortcuts using the useKeyShort hook
116+
You can list the registered shortcuts using the useKeyBind hook
117117

118118
```tsx
119-
import {KeyShortProvider, useKeyShort} from 'keyshort';
119+
import {KeyBindProvider, useKeyBind} from 'react-keybinds';
120120

121121
const ShowShortcuts = () => {
122-
const {shortcuts} = useKeyShort();
122+
const {shortcuts} = useKeyBind();
123123
const shortcutsList = shortcuts?.map((shortcut, index) => {
124124
return (
125125
<div key={index}>
@@ -143,9 +143,9 @@ const ShowShortcuts = () => {
143143
};
144144
const App = () => {
145145
return (
146-
<KeyShortProvider>
146+
<KeyBindProvider>
147147
<ShowShortcuts/>
148-
</KeyShortProvider>
148+
</KeyBindProvider>
149149
);
150150
};
151151
```

example/components/RegisterShortcut.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from 'react';
2-
import { useKeyShort } from '../../.';
2+
import { useKeyBind } from '../../.';
33

44
const RegisterShortcut = () => {
5-
const { registerShortcut } = useKeyShort();
5+
const { registerShortcut } = useKeyBind();
66

77
const handleClickRegister = () => {
88
registerShortcut({

example/components/ShowShortcuts.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from 'react';
2-
import { useKeyShort } from '../../.';
2+
import { useKeyBind } from '../../.';
33

44
const ShowShortcuts = () => {
5-
const { shortcuts } = useKeyShort();
5+
const { shortcuts } = useKeyBind();
66
const shortcutsList = shortcuts?.map((shortcut, index) => {
77
return (
88
<div key={index}>

example/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import 'react-app-polyfill/ie11';
22
import * as React from 'react';
33
import * as ReactDOM from 'react-dom';
4-
import { KeyShortProvider, ShortcutType } from '../.';
4+
import { KeyBindProvider, ShortcutType } from '../.';
55
import ShowShortcuts from './components/ShowShortcuts';
66
import RegisterShortcut from './components/RegisterShortcut';
77

88
const GLOBAL_COMMANDS: ShortcutType[] = [
99
{
1010
keys: {
11-
Mac: ['Meta', 'Shift', 'P'],
11+
Mac: ['Control', 'Shift', 'P'],
1212
Windows: ['Control', 'Shift', 'P'],
1313
},
1414
label: 'Test command',
1515
callback: () => {
16+
// eslint-disable-next-line no-alert
1617
alert('Hello world');
1718
},
1819
},
@@ -21,10 +22,10 @@ const GLOBAL_COMMANDS: ShortcutType[] = [
2122
const App = () => {
2223
return (
2324
<div>
24-
<KeyShortProvider shortcuts={GLOBAL_COMMANDS}>
25+
<KeyBindProvider shortcuts={GLOBAL_COMMANDS}>
2526
<ShowShortcuts />
2627
<RegisterShortcut />
27-
</KeyShortProvider>
28+
</KeyBindProvider>
2829
</div>
2930
);
3031
};

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.1.0",
2+
"version": "1.0.0",
33
"license": "MIT",
44
"main": "dist/index.js",
55
"typings": "dist/index.d.ts",
@@ -22,17 +22,19 @@
2222
"build-storybook": "build-storybook"
2323
},
2424
"keywords": [
25-
"keyshort",
25+
"react-keybinds",
2626
"nextjs",
2727
"javascript",
2828
"typescript",
2929
"react",
3030
"keyboard",
31-
"shortcuts"
31+
"shortcuts",
32+
"hotkeys",
33+
"keybinds"
3234
],
3335
"repository": {
3436
"type": "git",
35-
"url": "https://github.com/lifespikes/keyshort.git"
37+
"url": "https://github.com/lifespikes/react-keybinds.git"
3638
},
3739
"peerDependencies": {
3840
"react": ">=16"
@@ -48,7 +50,7 @@
4850
"singleQuote": true,
4951
"trailingComma": "es5"
5052
},
51-
"name": "keyshort",
53+
"name": "react-keybinds",
5254
"author": "santigp258",
5355
"description": "Simple package to manage keyboard shortcuts",
5456
"module": "dist/keyshort.esm.js",

src/context/KeyShortContext.tsx renamed to src/context/KeyBindContext.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import React, {
77
} from 'react';
88

99
import {
10-
KeyShortContextState,
11-
KeyShortProviderPropsI,
10+
KeyBindContextState,
11+
KeyBindProviderPropsI,
1212
ShortcutType,
1313
} from '../types';
1414
import { isDuplicate } from '../utils';
1515
import { useShortcuts } from '../hooks';
1616

17-
export const KeyShortContext = createContext({
17+
export const KeyBindContext = createContext({
1818
shortcuts: [] as ShortcutType[],
1919
registerShortcut: (shortcut: ShortcutType) => {
2020
console.log('Not implemented', { shortcut });
2121
},
22-
} as KeyShortContextState);
22+
} as KeyBindContextState);
2323

24-
const KeyShortProvider: FC<KeyShortProviderPropsI> = ({
24+
const KeyBindProvider: FC<KeyBindProviderPropsI> = ({
2525
children,
2626
shortcuts = [],
2727
}) => {
@@ -40,18 +40,18 @@ const KeyShortProvider: FC<KeyShortProviderPropsI> = ({
4040

4141
useShortcuts(storeShortcuts);
4242

43-
const commandsContext = useMemo<KeyShortContextState>(
43+
const commandsContext = useMemo<KeyBindContextState>(
4444
() => ({
4545
shortcuts: storeShortcuts,
4646
registerShortcut,
4747
}),
4848
[storeShortcuts]
4949
);
5050
return (
51-
<KeyShortContext.Provider value={commandsContext}>
51+
<KeyBindContext.Provider value={commandsContext}>
5252
{children}
53-
</KeyShortContext.Provider>
53+
</KeyBindContext.Provider>
5454
);
5555
};
5656

57-
export default KeyShortProvider;
57+
export default KeyBindProvider;

src/context/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default as KeyShortProvider } from './KeyShortContext';
1+
export { default as KeyBindProvider } from './KeyBindContext';

src/hooks/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { useKeyShort } from './useKeyShort';
1+
export { useKeyBind } from './useKeyBind';
22
export { useShortcuts } from './useShortcuts';

src/hooks/useKeyBind.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useContext } from 'react';
2+
import { KeyBindContext } from '../context/KeyBindContext';
3+
import { KeyBindContextState } from '../types';
4+
5+
export const useKeyBind = (): KeyBindContextState => {
6+
const keyBindContext = useContext(KeyBindContext);
7+
8+
if (!keyBindContext) {
9+
throw new Error('useKeyBind hook must be used with KeyBindProvider');
10+
}
11+
12+
return keyBindContext;
13+
};

0 commit comments

Comments
 (0)