Skip to content

Commit

Permalink
Setup (#1)
Browse files Browse the repository at this point in the history
* Initial

* Remove getting_started

* Write tests

* Tweak

* Add keywords

* Rename

* Rest of rename

* Replace use-key-event with use-key-down

* Rename 'use-key-down' to 'use-keydown'

* Tweaks

* Force rename

* Revert

* Fix

* Create tests for bug flagged

* Fix plural

* Remove empty line

* Tweak

* Add @buildinams/lint
  • Loading branch information
PauloMFJ authored Jan 19, 2023
1 parent 03c9631 commit b9fb953
Show file tree
Hide file tree
Showing 12 changed files with 1,418 additions and 429 deletions.
14 changes: 1 addition & 13 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["prettier", "unused-imports", "simple-import-sort"],
"extends": [
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"rules": {
"react/react-in-jsx-scope": "off",
"unused-imports/no-unused-imports": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error"
}
"extends": "./node_modules/@buildinams/lint/react-typescript"
}
128 changes: 0 additions & 128 deletions GETTING_STARTED.md

This file was deleted.

71 changes: 23 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,56 @@
# PACKAGE-NAME
# use-keydown

[![NPM version][npm-image]][npm-url]
[![Actions Status][ci-image]][ci-url]
[![PR Welcome][npm-downloads-image]][npm-downloads-url]

PACKAGE-DESCRIPTION
React hook for listening to custom `keydown` [events](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code).

## Introduction

Package introduction, couple of paragraphs.
This hook optimizes keyboard event handling by utilizing a single window `keydown` event listener for all instances of the hook, resulting in a more streamlined and efficient process.

```typescript
import useHook from "@buildinams/PACKAGE-NAME";

const baz = useHook({
foo: "something",
bar: "something else",
});
```
This library is also SSR safe, and only runs on the client.

## Installation

Install this package with `npm`.

```bash
npm i @buildinams/PACKAGE-NAME
npm i @buildinams/use-keydown
```

## Usage

Example 1 description.
To listen to a single key:

```tsx
import React from 'react';
import useHook from '@buildinams/PACKAGE-NAME';

const SomeExample = () = {
const baz = useHook({
foo: "something",
bar: "something else",
});

return (
<p>{baz}</p>
);
}
```

## API

### Input
import useKeydown from "@buildinams/use-keydown";

- `foo`: Required - Description of argument.
- `baz`: Optional - Description of argument.

### Input as a table
useKeydown("Escape", () => {}); // Do something on "Escape"...
```

| Property | Type | Required | Notes |
| -------- | ------ | -------- | ------------------------ |
| **foo** | string | **Yes** | Description of argument. |
| **baz** | string | No | Description of argument. |
To listen to key modifiers:

### Output
```tsx
import useKeydown from "@buildinams/use-keydown";

- `baz`: Description of output.
useKeydown("KeyG", (event: KeyboardEvent) => {
if (event.ctrlKey) // Do something on "Ctrl + G"...
});
```

## Requirements

This library requires a minimum React version of `18.0.0`.

## Requests and Contributing

Found an issue? Want a new feature? Get involved! Please contribute using our guideline [here](https://github.com/buildinamsterdam/PACKAGE-NAME/blob/main/CONTRIBUTING.md).
Found an issue? Want a new feature? Get involved! Please contribute using our guideline [here](https://github.com/buildinamsterdam/use-keydown/blob/main/CONTRIBUTING.md).

[npm-image]: https://img.shields.io/npm/v/@buildinams/PACKAGE-NAME.svg?style=flat-square&logo=react
[npm-url]: https://npmjs.org/package/@buildinams/PACKAGE-NAME
[ci-image]: https://github.com/buildinamsterdam/PACKAGE-NAME/actions/workflows/test.yml/badge.svg
[ci-url]: https://github.com/buildinamsterdam/PACKAGE-NAME/actions
[npm-downloads-image]: https://img.shields.io/npm/dm/@buildinams/PACKAGE-NAME.svg
[npm-downloads-url]: https://npmcharts.com/compare/@buildinams/PACKAGE-NAME?minimal=true
[npm-image]: https://img.shields.io/npm/v/@buildinams/use-keydown.svg?style=flat-square&logo=react
[npm-url]: https://npmjs.org/package/@buildinams/use-keydown
[ci-image]: https://github.com/buildinamsterdam/use-keydown/actions/workflows/test.yml/badge.svg
[ci-url]: https://github.com/buildinamsterdam/use-keydown/actions
[npm-downloads-image]: https://img.shields.io/npm/dm/@buildinams/use-keydown.svg
[npm-downloads-url]: https://npmcharts.com/compare/@buildinams/use-keydown?minimal=true
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Config } from "@jest/types";
const config: Config.InitialOptions = {
verbose: true,
testEnvironment: "jsdom",
transform: { "^.+\\.tsx?$": "ts-jest" },
roots: ["<rootDir>/tests"],
};

Expand Down
Loading

0 comments on commit b9fb953

Please sign in to comment.