Skip to content

First point color through props, updated to latest React version. #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 38 additions & 36 deletions demos/src/Components/Demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import * as React from "react";
import PatternLock from "../../../src/index";

type IDemoState = {
path : number[],
isLoading : boolean,
error : boolean,
success : boolean,
disabled : boolean,
size : number,
path: number[],
isLoading: boolean,
error: boolean,
success: boolean,
disabled: boolean,
size: number,
}

class Demo extends React.Component<{}, IDemoState> {
state = {
path : [] as number[],
isLoading : false,
error : false,
success : false,
disabled : false,
size : 3
path: [] as number[],
isLoading: false,
error: false,
success: false,
disabled: false,
size: 3
};

errorTimeout: number = 0;
Expand All @@ -28,41 +28,41 @@ class Demo extends React.Component<{}, IDemoState> {
const { key } = e;
if (key === "ArrowUp") {
e.preventDefault();
this.setState({ size : this.state.size >= 10 ? 10 : this.state.size + 1 });
this.setState({ size: this.state.size >= 10 ? 10 : this.state.size + 1 });
} else if (key === "ArrowDown") {
e.preventDefault();
this.setState({ size : this.state.size > 3 ? this.state.size - 1 : 3 });
this.setState({ size: this.state.size > 3 ? this.state.size - 1 : 3 });
}
});
}

onReset = () => {
this.setState({
path : [],
success : false,
error : false,
disabled : false
path: [],
success: false,
error: false,
disabled: false
});
};

onChange = (path: number[]) => {
this.setState({ path : [...path] });
this.setState({ path: [...path] });
};

onFinish = () => {
this.setState({ isLoading : true });
this.setState({ isLoading: true });
// an imaginary api call
setTimeout(() => {
if (this.state.path.join("-") === "0-1-2") {
this.setState({ isLoading : false, success : true, disabled : true });
this.setState({ isLoading: false, success: true, disabled: true });
} else {
this.setState({ disabled : true, error : true });
this.setState({ disabled: true, error: true });
this.errorTimeout = window.setTimeout(() => {
this.setState({
disabled : false,
error : false,
isLoading : false,
path : []
disabled: false,
error: false,
isLoading: false,
path: []
});
}, 3000);
}
Expand All @@ -76,24 +76,26 @@ class Demo extends React.Component<{}, IDemoState> {
<React.Fragment>
<div className="center">
<PatternLock
size={ size }
onChange={ this.onChange }
path={ path }
error={ error }
onFinish={ this.onFinish }
connectorThickness={ 5 }
disabled={ disabled || isLoading }
success={ success }
size={size}
onChange={this.onChange}
path={path}
error={error}
onFinish={this.onFinish}
connectorThickness={5}
disabled={disabled || isLoading}
success={success}
firstPointColorEnabled={true}
firstPointColor={"green"}
/>
</div>
<div className="output">
Select the top 3 points starting from the left
</div>
<div className="output">
Output : { this.state.path.join(", ") }
Output : {this.state.path.join(", ")}
</div>
{
success && <button style={{ margin : "0 auto", display : "block" }} onClick={ this.onReset }>Click here to reset</button>
success && <button style={{ margin: "0 auto", display: "block" }} onClick={this.onReset}>Click here to reset</button>
}
<div className="output">
Press the up/down arrow keys to increase/decrease the size of the input
Expand Down
Loading