keyborg/README.md

67 строки
2.5 KiB
Markdown
Исходник Постоянная ссылка Обычный вид История

# Keyborg ⌨️🤖
2021-11-18 11:41:20 +03:00
Keyborg is a library that tracks the state of current keyboard input on a web page through focus events.
**It does not do anything invasive to the DOM** but provides an event subscription system that allows users to choose how they want to react to changes in focus.
2021-11-18 11:41:20 +03:00
2021-11-18 13:42:11 +03:00
## Getting started
2021-11-18 11:41:20 +03:00
2021-11-18 13:42:11 +03:00
### Installation
```bash
# NPM
npm install --save keyborg
# Yarn
yarn add keyborg
```
2021-11-18 13:42:11 +03:00
### Usage
```js
2021-11-18 17:13:00 +03:00
import { createKeyborg } from "keyborg";
2021-11-18 13:42:11 +03:00
// initializes keyborg on the current window
const keyborg = createKeyborg(window);
// This is called every time the keyboard input state changes
const handler = (isUsingKeyboard) => {
if (isUsingKeyboard) {
document.body.setAttribute("data-is-keyboard", "true");
2021-11-18 13:42:11 +03:00
} else {
document.body.removeAttribute("data-is-keyboard");
2021-11-18 13:42:11 +03:00
}
2021-11-18 17:13:00 +03:00
};
2021-11-18 13:42:11 +03:00
keyborg.subscribe(handler);
keyborg.unsubscribe(handler);
```
2021-11-18 11:41:20 +03:00
## Contributing
2021-11-18 13:42:11 +03:00
Pretty simple currently, you only need to know about theese commands
2021-11-18 17:13:00 +03:00
- `npm install` - install dependencies
- `npm run build` - builds the library
2021-11-18 20:58:46 +03:00
- `npm run format:fix` - runs prettier to format code
- `npm run lint:fix` - runs eslint and fixes issues
2021-11-18 13:42:11 +03:00
This project welcomes contributions and suggestions. Most contributions require you to agree to a
2021-11-18 11:41:20 +03:00
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
## Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow
2021-11-18 11:41:20 +03:00
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.