Socket
Socket
Sign inDemoInstall

react-tangent

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-tangent

Create a simple virtual keyboard in SVG


Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

react-tangent

Create a simple, virtual SVG keyboard.

Install

npm i -S react-tangent

Example

import Tangent from 'react-tangent';

<Tangent keys={ ['A', 'B', 'C' ] } />

More examples here

Properties

propdefaultdescription
cellWidth20Width in pixels of grid cells that make up the keyboard layout.
cellHeight20Height in pixels of grid cells that make up the keyboard layout.
innerPadding1Padding in pixels. Space between adjacent keys is twice this value.
borderRadius10Radius in pixels of rounded corners of keys.
defaultKeyWidth4Number of grid cells a key occupies, if not set.
defaultKeyHeight4Number of grid cells a key occupies, if not set.
maxCols-1The maximum number of grid cells per row, if the keys' positions are not set manually
keyColor'#333'Color of the keys. Can be overridden with css.
textColor'#eee'Color of the text in keys. Can be overridden with css.
fontName'Open Sans'Font name of text in keys.
fontSize'30'Font size of text in keys
fontEmbednullA base64 encoded woff font to be embedded inside the svg. Might be useful to avoid cross-domain issues in some browsers.
keys[]An array of keys that make up the keyboard. See more info below.
onKeyClicknullCallback for key click. See more below.
onKeyPressnullCallback for key pressed. See more below.
onKeyReleasenullCallback for key released. See more below.
onDimensionsChangenullCallback when the svg size changes. An object is passed to the callback containing the width and height.

keys

The keys array can either consist of strings or objects. Use the maxCols prop to control number of keys per row when using strings.

Key strings
// A key is 4 cells be default, 
// this will result in 2 keys per row:

<Tangent maxCols={ 8 } keys={ 'qwerty'.split('') } />
Key objects

Key object has the following fields

fielddefaultdescription
label''The text displayed in the key.
id''An identifier for the key. Is returned with onKeyPress callback. Can also be used to match key in css with .tangent-key--[id].
x0The keys' leftmost grid cell.
y0The keys top grid cell.
width4The number of grid cells a key occupies horizontally.
height4The number of grid cells a key occupies vertically.
// The beginning of a keyboard...

<Tangent keys={[
  {
    label: '§',
    id: 'paragraph'
  }, {
    label: '1',
    id: '1',
    x: 4
  }, {
    label: '2',
    id: '2',
    x: 8
  }, {
    label: 'Tab',
    id: 'tab',
    y: 4,
    width: 6
  }, {
    label: 'Q',
    id: 'q',
    x: 6,
    y: 4
  }
]} />

Key listeners

<Tangent 
  onKeyClick={ keyListener }
  onKeyPress={ keyListener }
  onKeyRelease={ keyListener }
  keys={ '12345'.split('') } />
keyListener(data) {
  // Will return id and label
  
  const { id, label } = data;
}

React alternatives

react-tangent works well with Preact.

License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Last updated on 06 May 2018

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