Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds type support for the package. #16

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const defaultConfig = require("@bigbinary/neeto-commons-frontend/configs/eslint/index.js");
const defaultConfig = require("@bigbinary/neeto-commons-frontend/configs/nanos/eslint/index.js");

const { mergeDeepLeft } = require("ramda");

module.exports = mergeDeepLeft(
{
rules: {
"@bigbinary/neeto/no-missing-localization": "off",
"@bigbinary/neeto/webpack-aliases-and-jsconfig-paths-should-be-in-sync":
"off",
},
},
defaultConfig
Expand Down
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ yalc.lock
/index.cjs.js.map
/index.mjs
/index.mjs.map
/index.d.ts
# Ignore bundler config
/.bundle

Expand Down Expand Up @@ -232,9 +231,3 @@ dump.rdb
# Ignore yalc generated files
yalc.lock
/.yalc

/index.cjs.js
/index.cjs.js.map
/index.mjs
/index.mjs.map
/index.d.ts
11 changes: 11 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type ConfigType = {
mode?: "default" | "global" | "scoped";
unbindOnUnmount?: boolean;
enabled?: boolean;
};

export default function useHotkeys(
hotkey: string | string[],
handler: (event: React.KeyboardEvent) => void,
config?: ConfigType
): React.MutableRefObject | null;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"prepare": "husky install",
"build": "NODE_ENV=production rollup -c"
},
"types": "index.d.ts",
"engines": {
"node": ">=18.12",
"npm": ">=9",
Expand Down
4 changes: 3 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const globals = Object.fromEntries(
keys(packageJSON.peerDependencies).map(lib => [lib, lib])
);

const buildFilesMatchPattern = 'index.{cjs.js,cjs.js.map,mjs,mjs.map}';

export default {
input: "./src/index.js",
output: [
Expand All @@ -39,7 +41,7 @@ export default {
],
plugins: [
// To delete previously existing bundle.
cleaner({ targets: globSync(path.resolve(__dirname, `index.*`)) }),
cleaner({ targets: globSync(path.resolve(__dirname, buildFilesMatchPattern)) }),
// To automatically externalize peerDependencies in a rollup bundle.
peerDepsExternal(),
// To use third party modules from node_modules
Expand Down
11 changes: 3 additions & 8 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ export const MAC_TO_WINDOWS_KEYS_MAP = {
delete: "backspace",
};

export const OS = {
mac: "OS X",
windows: "Windows",
};
// eslint-disable-next-line @bigbinary/neeto/hard-coded-strings-should-be-localized
export const OS = { mac: "OS X", windows: "Windows" };

export const KEY_NAMES = {
delete: "delete",
backspace: "backspace",
};
export const KEY_NAMES = { delete: "delete", backspace: "backspace" };
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useRef } from "react";

import { mergeLeft } from "ramda";

import { DEFAULT_CONFIG, MODES } from "src/constants";
import {
bindHotKey,
Expand Down
Loading