UNPKG

@uiwwsw/virtual-keyboard

Version:

**A revolutionary virtual keyboard solution for React that solves the Korean `composition` issue.**

107 lines (72 loc) โ€ข 4.55 kB
# virtual-keyboard **A revolutionary virtual keyboard solution for React that solves the Korean `composition` issue.** [![npm version](https://img.shields.io/npm/v/@uiwwsw/virtual-keyboard.svg)](https://www.npmjs.com/package/@uiwwsw/virtual-keyboard) [![Publish](https://github.com/uiwwsw/virtual-keyboard/actions/workflows/publish.yml/badge.svg)](https://github.com/uiwwsw/virtual-keyboard/actions/workflows/publish.yml) [![License](https://img.shields.io/github/license/uiwwsw/virtual-keyboard)](https://github.com/uiwwsw/virtual-keyboard/blob/main/LICENSE) [![Stars](https://img.shields.io/github/stars/uiwwsw/virtual-keyboard?style=flat)](https://github.com/uiwwsw/virtual-keyboard/stargazers) ![Virtual Keyboard Banner](https://raw.githubusercontent.com/uiwwsw/virtual-keyboard/main/docs/banner.png) [**Visit the Demo โ†’**](https://composed-input.vercel.app/) > ๐Ÿ“ฑ ๋ฐ๋ชจ ํŽ˜์ด์ง€์—๋Š” ๋ชจ๋ฐ”์ผ ๊ณ ์ • ํ‚ค๋ณด๋“œ์™€ ์ˆซ์žยท๋‹ค์ด์–ผ๋Ÿฌ ์ „์šฉ ๋ชจ๋“œ๋ฅผ ์ง์ ‘ ์ „ํ™˜ํ•ด ๋ณผ ์ˆ˜ ์žˆ๋Š” ์„น์…˜์ด ์ค€๋น„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. > ์‹ค์ œ ๋ชจ๋ฐ”์ผ ๊ธฐ๊ธฐ ํ˜น์€ DevTools ๊ธฐ๊ธฐ ๋ชจ๋“œ(User-Agent ๋ฅผ ๋ชจ๋ฐ”์ผ๋กœ ์ „ํ™˜)์— ๋งž์ถฐ ์ ‘์†ํ•˜๋ฉด ๋„ค์ดํ‹ฐ๋ธŒ ํ‚ค๋ณด๋“œ ๋Œ€์‹  ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ๊ฐ€์ƒ ํ‚ค๋ณด๋“œ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค. --- `virtual-keyboard` is a React component library that provides a custom virtual keyboard and input field, specifically designed to solve the infamous Korean `composition` event issues in web environments. It offers a seamless and native-like typing experience, free from common bugs like character duplication, cursor jumping, and broken compositions. ## Key Features - โค๏ธ **Without <input /> **: No input, No contentEditable. Just div. - โœจ **Composition-Free Input**: Directly handles Korean character composition, bypassing native IME events to prevent common bugs. - ๐ŸŽน **Customizable Keyboard UI**: Provides a default keyboard and supports fully custom layouts for any use case (e.g., number pads, phone keypads). - ๐Ÿ“ฑ **Mobile-First**: Blocks the native mobile keyboard for a consistent and controlled user experience in web apps. - โš›๏ธ **React-Friendly API**: Simple, component-based architecture using `Provider` and `Input` for easy integration. ## Installation ```bash npm install @uiwwsw/virtual-keyboard ``` ## Usage Wrap your input fields with the `VirtualInputProvider`. This provider manages the keyboard's state and renders the UI. ### Basic Usage Use the default QWERTY keyboard for Korean and English input. ```tsx import { VirtualInput, VirtualInputProvider } from "@uiwwsw/virtual-keyboard"; function App() { return ( <VirtualInputProvider> <p>Your virtual input is here:</p> <VirtualInput placeholder="ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”..." /> </VirtualInputProvider> ); } ``` ### Custom Layout You can provide a custom layout for specialized inputs, such as a number pad for phone numbers. ```tsx import { VirtualInput, VirtualInputProvider } from "@uiwwsw/virtual-keyboard"; const numberPadLayout = [ [{ value: "1" }, { value: "2" }, { value: "3" }], [{ value: "4" }, { value: "5" }, { value: "6" }], [{ value: "7" }, { value: "8" }, { value: "9" }], // You can define special keys like 'Backspace' [{ value: "010" }, { value: "0" }, { value: "Backspace", type: "action" }], ]; function App() { return ( <VirtualInputProvider layout={numberPadLayout}> <p>Enter your phone number:</p> <VirtualInput placeholder="010-0000-0000" /> </VirtualInputProvider> ); } ``` ## Components API ### `<VirtualInputProvider />` The main provider that manages the keyboard state and UI. | Prop | Type | Description | | :--------- | :--------------------- | :-------------------------------------------------- | | `layout` | `Key[][][]` (optional) | A 2D array to define a custom keyboard layout. | | `children` | `ReactNode` | Must contain at least one `VirtualInput` component. | ### `<VirtualInput />` The replacement for the standard `<input>` element. It accepts all standard input element props like `value`, `defaultValue`, `placeholder`, `onChange`, etc. ## Star History [![Star History Chart](https://api.star-history.com/svg?repos=uiwwsw/virtual-keyboard&type=Date)](https://www.star-history.com/#uiwwsw/virtual-keyboard&Date) ## Contributors [![contributors](https://contrib.rocks/image?repo=uiwwsw/virtual-keyboard)](https://github.com/uiwwsw/virtual-keyboard/graphs/contributors) ## License [MIT](./LICENSE)