1.0.1 • Published 1 year ago

@prkhch/react-pincode v1.0.1

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

Quick Start

PIN code Component for React

npm install @prkhch/react-pincode
import { Pincode } from "@prkhch/react-pincode";

export interface ON_COMPLETE_PROPS {
  inputValue: string;
  setMessage: (value: string | undefined) => void;
  setErrorMessage: (value: string | undefined) => void;
}

function App() {
  const onComplete = ({ inputValue, setMessage, setErrorMessage }: ON_COMPLETE_PROPS) => {
    // Request correct password from the server.
    // Example correct password : 0000
    if (inputValue === "0000") {
      setMessage("Correct!");
      setErrorMessage("");
    }

    if (inputValue !== "0000") {
      setMessage("");
      setErrorMessage("InCorrect!");
    }
  };

  return (
    <div>
      <Pincode
        onComplete={onComplete}
        // randomKeypad={true}
        length={4}
        defaultMessage="Enter PIN"
        // styleBottomLayout={true}
        styleBackgroundColor="#ffffff"
        styleBackgroundOpacity={1}
        styleMessageColor="#000000"
        styleErrorMessageColor="#ff0000"
        styleInputBoxColor="#efefef"
        styleInputCircleColor="#000000"
        styleNumberFontColor="#000000"
        styleNumberButtonColor="#efefef"
        styleResetButtonColor="#000000"
        styleDeleteButtonColor="#000000"
        styleHoverColor="#bbbbbb"
        style={{ width: "100%" }}
      />
    </div>
  );
}

export default App;

Options

* : Required
NameDescriptionDefaultType
*onCompleteCallback function when input is complete-function
randomKeypadRandomizes the number padfalseboolean
lengthLength of the password4 (4~8)number
defaultMessageDefault message displayed-string
styleBottomLayoutEnable/disable bottom layout stylefalseboolean
styleBackgroundColorBackground color of the component-string
styleBackgroundOpacityOpacity of the background1 (0~1)number
styleMessageColorText color for the message-string
styleErrorMessageColorText color for the error message-string
styleInputBoxColorColor of the input box-string
styleInputCircleColorColor of the input circles-string
styleNumberFontColorColor of the number fonts-string
styleNumberButtonColorColor of the number buttons-string
styleResetButtonColorColor of the reset button-string
styleDeleteButtonColorColor of the delete button-string
styleHoverColorHover color for the buttons-string
styleInline style-React.CSSProperties

onComplete Function

  • *inputValue: The PIN entered by the user.
  • setMessage: Function to display a message.
  • setErrorMessage: Function to display an error message.

The onComplete function is called when the user finishes entering their PIN. It checks the PIN and, depending on whether it's correct or not, executes a user-defined event.

Example

DefaultBottom Layout
DefaultBottomLayout
Random KeypadCustomizing
Random KeypadCustomizing