
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
drag-puzzle-captcha
Advanced tools
A beautiful, modern drag-and-drop puzzle CAPTCHA component for React applications
A beautiful, modern drag-and-drop puzzle CAPTCHA component for React applications. This component provides an interactive slider puzzle that users must solve to verify they are human.
npm install drag-puzzle-captcha
import React, { useState } from 'react';
import DragPuzzleCaptcha from 'drag-puzzle-captcha';
import 'drag-puzzle-captcha/DragPuzzleCaptcha.css';
function App() {
const [isVerified, setIsVerified] = useState(false);
const handleVerification = (success) => {
setIsVerified(success);
if (success) {
console.log('CAPTCHA verified successfully!');
}
};
return (
<div>
<h1>My Form</h1>
<DragPuzzleCaptcha onVerify={handleVerification} />
{isVerified && <p>✅ Verification successful!</p>}
</div>
);
}
export default App;
For Vite projects, you can import styles in multiple ways:
// Method 1: Import CSS directly
import 'drag-puzzle-captcha/DragPuzzleCaptcha.css';
// Method 2: Import as style (alias)
import 'drag-puzzle-captcha/style';
// Method 3: Import in your CSS file
/* In your main CSS file */
@import 'drag-puzzle-captcha/DragPuzzleCaptcha.css';
import React, { useState } from 'react';
import dynamic from 'next/dynamic';
import 'drag-puzzle-captcha/DragPuzzleCaptcha.css';
// Dynamic import to avoid SSR issues
const DragPuzzleCaptcha = dynamic(
() => import('drag-puzzle-captcha'),
{ ssr: false }
);
export default function MyPage() {
const [isVerified, setIsVerified] = useState(false);
return (
<div>
<h1>Secure Form</h1>
<DragPuzzleCaptcha onVerify={setIsVerified} />
{isVerified && <p>✅ Verified!</p>}
</div>
);
}
import React, { useState } from 'react';
import DragPuzzleCaptcha from 'drag-puzzle-captcha';
import 'drag-puzzle-captcha/DragPuzzleCaptcha.css';
function App() {
const [showCaptcha, setShowCaptcha] = useState(false);
const [isVerified, setIsVerified] = useState(false);
const handleVerification = (success) => {
setIsVerified(success);
if (success) {
setShowCaptcha(false);
}
};
return (
<div>
<button onClick={() => setShowCaptcha(true)}>
Verify Identity
</button>
{showCaptcha && (
<DragPuzzleCaptcha
showModal={true}
onVerify={handleVerification}
onCloseModal={() => setShowCaptcha(false)}
/>
)}
</div>
);
}
import React, { useState, useRef } from 'react';
import DragPuzzleCaptcha, {
DragPuzzleCaptchaProps,
DragPuzzleCaptchaRef
} from 'drag-puzzle-captcha';
import 'drag-puzzle-captcha/DragPuzzleCaptcha.css';
const MyComponent: React.FC = () => {
const [isVerified, setIsVerified] = useState<boolean>(false);
const captchaRef = useRef<DragPuzzleCaptchaRef>(null);
const handleVerification = (success: boolean) => {
setIsVerified(success);
};
const resetCaptcha = () => {
captchaRef.current?.reset();
};
return (
<div>
<DragPuzzleCaptcha
ref={captchaRef}
onVerify={handleVerification}
language="eng"
/>
<button onClick={resetCaptcha}>Reset</button>
</div>
);
};
Prop | Type | Default | Description |
---|---|---|---|
onVerify | (success: boolean) => void | - | Callback function called when verification completes |
language | 'eng' | 'fr' | 'eng' | Language for component text |
showModal | boolean | false | Whether to display the component in a modal |
onCloseModal | () => void | - | Callback when modal is closed |
Method | Type | Description |
---|---|---|
reset | () => void | Reset the puzzle to initial state |
isVerified | () => boolean | Check if puzzle is currently verified |
The component comes with default styles, but you can customize the appearance:
/* Override default styles */
.drag-puzzle-container {
--primary-color: #your-color;
--background-color: #your-bg;
}
.drag-puzzle-piece {
border-radius: 12px; /* Custom border radius */
}
.drag-puzzle-track {
background: your-custom-gradient;
}
Currently supports:
'eng'
)'fr'
)<DragPuzzleCaptcha language="fr" onVerify={handleVerify} />
ssr: false
for Next.js to avoid hydration issuesMIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues or have questions, please open an issue on GitHub.
FAQs
A beautiful, modern drag-and-drop puzzle CAPTCHA component for React applications
We found that drag-puzzle-captcha demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.