12.0.12 • Published 3 years ago

react-pattern-lock v12.0.12

Weekly downloads
185
License
MIT
Repository
github
Last release
3 years ago

React-Pattern-Lock

Lint & Test

Android's pattern lock

  • Supports multiple sizes. eg : 2x2, 3x3, 4x4 -- 15x15.
  • Supports touch screens.
  • Many options to customize the input.

Edit n5j7knjo54

Installation

npm install react-pattern-lock

How to use

import React, { Component } from "react";
import PatternLock          from "react-pattern-lock";

// in you render method
<PatternLock
	width={ 300 }
	pointSize={ 15 }
	size={ 3 }
	path={ this.state.path }
	onChange={ (pattern) => {
		this.setState({ path : pattern });
	}}
	onFinish={() => {
		// check if the pattern is correct
	}}
/>

Props

PropTypeDefaultDefinition
sizeNumber3The size of the pattern input.
widthNumber, String"100%"The width of the pattern wrapper.
disabledBooleanfalseDisables the pattern input.
invisibleBooleanfalseMakes the lines that connect the points invisible.
noPopBooleanfalseDisables the pop animation when a point gets activated.
onChangeFunction(path: number[]) => voidA Function (the first argument is the drawn path).
pathnumber[][]The drawn path.
allowJumpingBooleanfalseSetting this to true would disable the auto activation on points that are in the middle of 2 already activated points (see details below).
allowOverlappingBooleanfalseAllows you to select the same point multiple times (Doesn't show the pop animation on the second time).
pointSizeNumber10The size of the pattern points (used for width and height) in pixels.
pointActiveSizeNumber30The size (in pixels) of the active area of the pattern points.
connectorThicknessNumber2The thickness (in pixels) of the lines that connect the points.
connectorRoundedCornersBooleanfalseSetting this to true makes the connector edges rounded.
classNameString""Any css classes that you might want to send to the wrapper.
successBooleanfalseWill add "success" class to the wrapper, it will also make the points and the connectors green
errorBooleanfalseWill add "error" class to the wrapper, it will also make the points and the connectors red
styleObject{}Any css styles that you might want to send to the wrapper.

Pattern Representation

A pattern path is represented as an array of numbers. for example :
in a 3x3 pattern the points are numbered starting from 0 top left, and ending in 8 bottom right.

react-pattern-lock

So for example :

react-pattern-lock

This would result in an array like this [1, 3, 4, 0].


Detailed Props

size Number default : 3

The size of the pattern input

  • 3 is 3x3 (9 points in total).
  • 4 is 4x4 (16 points in total).
  • etc.

allowJumping Boolean default : false

Setting this property to true would allow you to connect 2 points that have unselected points between them (diagonally, vertically or horizontally) without the points in the middle being auto selected for you (see image below).

react-pattern-lock

disabled Boolean default : false

Makes the pattern input disabled (turns gray and user input is disabled).

react-pattern-lock

invisible Boolean default : false

Hides the lines that connect the pattern points.

react-pattern-lock

noPop Boolean default : false

Disables the pop animation when a point gets activated.

react-pattern-lock

pointActiveSize Number default : 30

The active area of each of the points.
When the cursor enters this area the point will be activated.

Activate areas are indicated by the blue squares.

react-pattern-lock

Extra

You can override the default colors for (disabled, success, error) using css Check the codepen example for more info

Edit n5j7knjo54

License

MIT Licensed. Copyright (c) WinterCore 2019.

12.0.12

3 years ago

2.0.11

3 years ago

2.0.10

3 years ago

2.0.9

3 years ago

2.0.7

4 years ago

2.0.8

4 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago