npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-captchafy

v1.0.1

Published

A customizable CAPTCHA component for React applications, designed to enhance form security with a canvas-based CAPTCHA challenge.

Downloads

127

Readme

react-captchafy

A customizable, lightweight CAPTCHA component for React applications. react-captchafy provides an easy way to integrate CAPTCHA into your forms, helping you protect your app against spam and automated submissions.

✨ Features

  • 🔐 Enhanced Security: Protects your forms from bots and automated scripts.
  • 🎨 Highly Customizable: Customize the appearance, font, colors, and more.
  • 🖥️ Canvas-based CAPTCHA: Renders CAPTCHA using HTML5 Canvas for better performance.
  • 📦 Lightweight: Minimal dependencies to keep your bundle size small.
  • ⚙️ Flexible API: Easy integration with just a few props.

📦 Installation

To get started, install the package via npm:

npm install react-captchafy

Or, if you're using yarn:

yarn add react-captchafy

🚀 Quick Start

Here's a basic example of how to use the Captcha component in your React application:

import React from "react";
import Captcha from "react-captchafy";

const App = () => {
  const handleCaptchaValid = () => alert("Captcha is valid!");
  const handleCaptchaInvalid = () => alert("Captcha is invalid!");

  return (
    <div style={{ padding: "20px" }}>
      <h2>React Captcha Example</h2>
      <Captcha
        onCaptchaValid={handleCaptchaValid}
        onCaptchaInvalid={handleCaptchaInvalid}
        errorMessage="The CAPTCHA you entered is incorrect."
        captchaLength={6}
        buttonLabel="Verify"
        customStyles={{
          input: {
            padding: "8px",
            border: "1px solid #ccc",
            borderRadius: "4px",
          },
          button: {
            marginTop: "10px",
            backgroundColor: "#4CAF50",
            color: "#fff",
          },
          resetIcon: { color: "#d9534f", cursor: "pointer" },
        }}
      />
    </div>
  );
};

export default App;

🔧 Props

| Prop Name | Type | Default Value | Description | | ------------------ | ---------- | --------------------------------- | ------------------------------------------------- | | onCaptchaValid | function | Required | Callback when CAPTCHA is successfully validated. | | onCaptchaInvalid | function | Required | Callback when CAPTCHA validation fails. | | captchaLength | number | 6 | Number of characters in the CAPTCHA. | | canvasWidth | number | 375 | Width of the CAPTCHA canvas. | | canvasHeight | number | 40 | Height of the CAPTCHA canvas. | | fontStyle | string | '30px Brush Script MT, cursive' | Font style for the CAPTCHA text. | | textColor | string | 'black' | Color of the CAPTCHA text. | | backgroundColor | string | '#f5f5f5' | Background color of the CAPTCHA canvas. | | buttonLabel | string | 'PROCEED' | Label for the verification button. | | customStyles | object | {} | Custom styles for the component elements. | | isLoading | boolean | false | Disables the button and shows a loader when true. |

📋 Usage Examples

1. Simple Usage

<Captcha
  onCaptchaValid={() => console.log("Success!")}
  onCaptchaInvalid={() => console.log("Failed!")}
/>

2. Custom Styles and Captcha Length

<Captcha
  onCaptchaValid={() => alert("Correct!")}
  onCaptchaInvalid={() => alert("Try Again!")}
  captchaLength={8}
  customStyles={{
    input: { padding: "10px", border: "2px solid blue" },
    button: { backgroundColor: "green", color: "white" },
  }}
/>

🎨 Custom Styling

You can style the CAPTCHA using the customStyles prop, which accepts an object:

  • input: Style for the CAPTCHA input field.
  • button: Style for the CAPTCHA verification button.
  • resetIcon: Style for the reset icon.
  • canvas: Style for the CAPTCHA canvas.

Example:

customStyles={{
  input: { width: '50%', padding: '10px' },
  button: { backgroundColor: '#007bff', color: 'white' },
  resetIcon: { fontSize: '20px' },
}}

🔍 Browser Support

The library is compatible with the latest versions of Chrome, Firefox, Safari, and Edge.

🛠️ Development

If you want to contribute to this project or run it locally:

git clone https://github.com/dpgaire/react-captchafy.git
cd react-captchafy
npm install
npm run build

Running the Demo

npm start

📄 License

MIT License. See the LICENSE file for more details.

🙌 Contribution

Feel free to submit issues, feature requests, or pull requests. Contributions are always welcome!

📬 Contact

For any questions or feedback, please reach out at [email protected].