Socket
Socket
Sign inDemoInstall

@autosys/react-mui-keyboard

Package Overview
Dependencies
89
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @autosys/react-mui-keyboard

This is an example application featuring a virtual on-screen keyboard, developed using React and Material-UI (MUI).


Version published
Weekly downloads
93
increased by89.8%
Maintainers
2
Install size
47.3 MB
Created
Weekly downloads
 

Readme

Source

On-Screen Keyboard App

This is an example application featuring a virtual on-screen keyboard, developed using React and Material-UI (MUI).

TypeScript React MUI

Yarn Licence

Read this in other languages: Русский

Screenshot

With this application, users can input text using the virtual keyboard, select the keyboard layout language (Russian or English), use Caps Lock, Backspace, Space, and Enter keys.

Installation:

NPM

Install with npm:

npm install @autosys/react-mui-keyboard

Install with yarn:

yarn add @autosys/react-mui-keyboard

Usage

  1. To input text, click on the virtual keyboard buttons or use the Caps Lock, Backspace, Space, and Enter keys.

  2. To change the keyboard layout language, click on the "RU" button (Russian layout) or "EN" button (English layout).

Technologies

  • React: JavaScript library for building user interfaces.
  • Material-UI (MUI): Component library for creating stylish user interfaces.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Example Usage:

import React, { useState } from 'react';
import { TextField } from '@mui/material';
import { MuiKeyboard } from '@autosys/react-mui-keyboard';
import { russianButtons, englishButtons, numbers } from 'path_to_your_button_data';

const App = () => {
  const [checked, setChecked] = useState(false);
  const [inputValue, setInputValue] = useState<string>('');

  const handleUrlChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    setInputValue(event.target.value);
  };

  const handleChange = () => {
    setChecked((prev) => !prev);
  };

  return (
    <MuiKeyboard
      textField={
        <TextField
          onChange={handleUrlChange}
          onClick={handleChange}
          value={inputValue}
          fullWidth
          multiline
        />
      }
      slide
      direction="up"
      checked={checked}
      setInputValue={setInputValue}
      numbers={numbers}
      firstLanguage={russianButtons}
      secondLanguage={englishButtons}
      secondLangLabel="EN"
      firstLangLabel="RU"
      keyboardWidth={'900px'}
      buttonSize="medium"
      labelLangButton
      reverseButton
      sx={{ display: 'flex' }}
    />
  );
};

export default App;

Properties

NameTypeDescription
textFieldJSX.ElementText input field component.
slidebooleanA flag indicating whether the keyboard should appear with a Slide animation. By default, true.
directionSlideProps <"left" | "right" | "up" | "down">Slide animation direction (used if slide is set to true). By default, up.
checkedbooleanKeyboard visibility state flag.
setInputValueReact.Dispatch<React.SetStateAction<string>>Callback to set the input field's value.
numbersstring[]Array of characters for keyboard number buttons.
firstLanguage*string[]Array of characters for keyboard buttons in the first language.
secondLanguagestring[]Array of characters for keyboard buttons in the second language.
secondLangLabelstringLabel for the second language.
firstLangLabelstringLabel for the first language.
keyboardWidthstring | numberKeyboard width.
buttonSizeButtonProps <"small" | "medium" | "large">Button size.
labelLangButtonbooleanLanguage switch button.
reverseButtonbooleanText reset button.
singlyBackbooleanIf true, the backspace button is separate from the block with numbers.
labelLetterButtonbooleanIf true, a button is added to switch between the layout with letters and numbers.
betweenButtonsstring | numberDistance between buttons.
numbersColumnsstringThe number of columns for numeric keypad when it is separate from letters. By default, 5.
numbersRowsstringThe number of rows for numeric keypad when it is separate from letters. By default, 3.
allKeyboardStyleSxPropsThe sx prop is a shortcut for defining custom styles that has access to the theme.
timeoutSlideProps <number | { appear?: number, enter?: number, exit?: number }>The duration for the transition, in milliseconds. You may specify a single timeout for all transitions, or individually with an object.

Props marked with * are required.

Usage without TextField and with Context

If you want to use the MuiKeyboard component without a built-in TextField and manage the input value using context, follow these steps:

  1. Wrap your application with the MuiKeyboardProvider:
// index.tsx
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { MuiKeyboardProvider } from '@autosys/react-mui-keyboard';
import { russianButtons } from '@autosys/react-mui-keyboard';

ReactDOM.render(
  <MuiKeyboardProvider
    firstLanguage={russianButtons}
    sx={{ display: 'flex', justifyContent: 'center', mt: 50 }}
    keyboardWidth={'900px'}
  >
    <App />
  </MuiKeyboardProvider>,
  document.getElementById('root'),
);
  1. Then yo may use the useMuiKeyboard hook in any another component to access the input value and setter from the context.
// App.tsx
import React from 'react';
import { TextField } from '@mui/material';
import { useMuiKeyboard } from '@autosys/react-mui-keyboard';

const App = () => {
  const { inputValue, keyboardFeature } = useMuiKeyboard();
  return (
    <TextField
      value={inputValue}
      onClick={() => keyboardFeature({ slideEffect: true })}
      label="Click!"
    >
      Hello
    </TextField>
  );
};

export default App;

If you want your component (for example, a button) to only be able to close the keyboard, use onClick={() => keyboardFeature({ slideEffect: false })}

Example_context

If you want to reset the inputValue, but don't want to do it with a button on the keyboard, you can use any other button with onClick={() => keyboardFeature({ resetText: true })}

Keywords

FAQs

Last updated on 10 Oct 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc