@the_disreputable_doggo/password-gate 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +6 -2
- package/index.tsx +0 -139
- package/tsconfig.json +0 -14
package/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @the_disreputable_doggo/password-gate
|
|
2
2
|
|
|
3
3
|
A React component that provides a full-screen password gate for early access or pre-launch sites.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @
|
|
8
|
+
npm install @the_disreputable_doggo/password-gate
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```tsx
|
|
14
|
-
import PasswordGate from '@
|
|
14
|
+
import PasswordGate from '@the_disreputable_doggo/password-gate';
|
|
15
15
|
|
|
16
16
|
function App() {
|
|
17
17
|
return (
|
package/package.json
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the_disreputable_doggo/password-gate",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Password Gate component for Pier & Pixel templates",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
8
12
|
"scripts": {
|
|
9
13
|
"build": "tsup index.tsx --format cjs,esm --dts"
|
|
10
14
|
},
|
|
11
15
|
"repository": {
|
|
12
16
|
"type": "git",
|
|
13
|
-
"url": "git
|
|
17
|
+
"url": "git+https://github.com/HadleySwello/password-gate.git"
|
|
14
18
|
},
|
|
15
19
|
"peerDependencies": {
|
|
16
20
|
"react": "^19.0.0",
|
package/index.tsx
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
export interface PasswordGateProps {
|
|
4
|
-
title: string;
|
|
5
|
-
subtitle: string;
|
|
6
|
-
datePrefix: string;
|
|
7
|
-
underConstruction: string;
|
|
8
|
-
placeholder: string;
|
|
9
|
-
buttonText: string;
|
|
10
|
-
enabled?: boolean;
|
|
11
|
-
password?: string;
|
|
12
|
-
releaseDate?: string;
|
|
13
|
-
onUnlock?: () => void;
|
|
14
|
-
showPasswordLabel?: string;
|
|
15
|
-
hidePasswordLabel?: string;
|
|
16
|
-
unlockBodyClass?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default function PasswordGate({
|
|
20
|
-
title,
|
|
21
|
-
subtitle,
|
|
22
|
-
datePrefix,
|
|
23
|
-
underConstruction,
|
|
24
|
-
placeholder,
|
|
25
|
-
buttonText,
|
|
26
|
-
enabled = true,
|
|
27
|
-
password = '',
|
|
28
|
-
releaseDate = '',
|
|
29
|
-
onUnlock,
|
|
30
|
-
showPasswordLabel = 'Show password',
|
|
31
|
-
hidePasswordLabel = 'Hide password',
|
|
32
|
-
unlockBodyClass = 'locked'
|
|
33
|
-
}: PasswordGateProps) {
|
|
34
|
-
const [passwordInput, setPasswordInput] = useState('');
|
|
35
|
-
const [showPassword, setShowPassword] = useState(false);
|
|
36
|
-
const [error, setError] = useState(false);
|
|
37
|
-
const [unlocked, setUnlocked] = useState(false);
|
|
38
|
-
const [shouldRender, setShouldRender] = useState(() => {
|
|
39
|
-
if (typeof window !== 'undefined') {
|
|
40
|
-
return localStorage.getItem('site_unlocked') !== 'true';
|
|
41
|
-
}
|
|
42
|
-
return true;
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// If password protection is disabled, we don't render anything
|
|
46
|
-
if (!enabled) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (!shouldRender) return null;
|
|
51
|
-
|
|
52
|
-
const handleSubmit = (e: React.FormEvent) => {
|
|
53
|
-
e.preventDefault();
|
|
54
|
-
if (passwordInput === password) {
|
|
55
|
-
setError(false);
|
|
56
|
-
setUnlocked(true);
|
|
57
|
-
localStorage.setItem('site_unlocked', 'true');
|
|
58
|
-
|
|
59
|
-
if (unlockBodyClass && typeof document !== 'undefined') {
|
|
60
|
-
document.documentElement.classList.remove(unlockBodyClass);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (onUnlock) {
|
|
64
|
-
onUnlock();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Allow fade out animation to finish before removing from DOM
|
|
68
|
-
setTimeout(() => {
|
|
69
|
-
setShouldRender(false);
|
|
70
|
-
}, 500);
|
|
71
|
-
} else {
|
|
72
|
-
setError(true);
|
|
73
|
-
// Reset error after animation
|
|
74
|
-
setTimeout(() => setError(false), 500);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<div
|
|
80
|
-
className={`fixed inset-0 z-50 flex items-center justify-center bg-base transition-opacity duration-500 ${unlocked ? 'opacity-0 pointer-events-none' : 'opacity-100'}`}
|
|
81
|
-
>
|
|
82
|
-
<div className="max-w-2xl px-6 text-center">
|
|
83
|
-
<h1 className="text-4xl md:text-5xl font-bold text-heading mb-6">
|
|
84
|
-
{title}
|
|
85
|
-
</h1>
|
|
86
|
-
<p className="text-lg text-body mb-8">
|
|
87
|
-
{subtitle}
|
|
88
|
-
</p>
|
|
89
|
-
<div className="bg-surface p-8 rounded-xl shadow-lg inline-block border border-accent-muted">
|
|
90
|
-
<p className="text-accent-muted font-bold mb-4">
|
|
91
|
-
{datePrefix} {releaseDate} {underConstruction}
|
|
92
|
-
</p>
|
|
93
|
-
<form onSubmit={handleSubmit} className="flex flex-col items-center gap-4">
|
|
94
|
-
<div className="relative w-full">
|
|
95
|
-
<input
|
|
96
|
-
type={showPassword ? "text" : "password"}
|
|
97
|
-
placeholder={placeholder}
|
|
98
|
-
value={passwordInput}
|
|
99
|
-
onChange={(e) => setPasswordInput(e.target.value)}
|
|
100
|
-
className={`w-full px-4 py-2 pr-10 bg-base border rounded text-body focus:outline-none focus:ring-2 focus:ring-accent transition-transform ${error ? 'border-red-500 animate-[shake_0.5s_ease-in-out]' : 'border-accent-muted'}`}
|
|
101
|
-
/>
|
|
102
|
-
<button
|
|
103
|
-
type="button"
|
|
104
|
-
onClick={() => setShowPassword(!showPassword)}
|
|
105
|
-
className="absolute inset-y-0 right-0 pr-3 flex items-center text-body hover:text-heading"
|
|
106
|
-
aria-label={showPassword ? hidePasswordLabel : showPasswordLabel}
|
|
107
|
-
>
|
|
108
|
-
{showPassword ? (
|
|
109
|
-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-5 h-5">
|
|
110
|
-
<path strokeLinecap="round" strokeLinejoin="round" d="M3.98 8.223A10.477 10.477 0 001.934 12C3.226 16.338 7.244 19.5 12 19.5c.993 0 1.953-.138 2.863-.395M6.228 6.228A10.45 10.45 0 0112 4.5c4.756 0 8.773 3.162 10.065 7.498a10.523 10.523 0 01-4.293 5.774M6.228 6.228L3 3m3.228 3.228l3.65 3.65m7.894 7.894L21 21m-3.228-3.228l-3.65-3.65m0 0a3 3 0 10-4.243-4.243m4.242 4.242L9.88 9.88" />
|
|
111
|
-
</svg>
|
|
112
|
-
) : (
|
|
113
|
-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-5 h-5">
|
|
114
|
-
<path strokeLinecap="round" strokeLinejoin="round" d="M2.036 12.322a1.012 1.012 0 010-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178z" />
|
|
115
|
-
<path strokeLinecap="round" strokeLinejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
|
116
|
-
</svg>
|
|
117
|
-
)}
|
|
118
|
-
</button>
|
|
119
|
-
</div>
|
|
120
|
-
<button
|
|
121
|
-
type="submit"
|
|
122
|
-
className="px-6 py-2 bg-accent-muted text-white rounded font-semibold transition-colors"
|
|
123
|
-
>
|
|
124
|
-
{buttonText}
|
|
125
|
-
</button>
|
|
126
|
-
</form>
|
|
127
|
-
</div>
|
|
128
|
-
</div>
|
|
129
|
-
<style>{`
|
|
130
|
-
@keyframes shake {
|
|
131
|
-
0%, 100% { transform: translateX(0); }
|
|
132
|
-
25% { transform: translateX(-5px); }
|
|
133
|
-
50% { transform: translateX(5px); }
|
|
134
|
-
75% { transform: translateX(-5px); }
|
|
135
|
-
}
|
|
136
|
-
`}</style>
|
|
137
|
-
</div>
|
|
138
|
-
);
|
|
139
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"jsx": "react",
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"forceConsistentCasingInFileNames": true,
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"emitDeclarationOnly": true
|
|
12
|
-
},
|
|
13
|
-
"include": ["index.tsx"]
|
|
14
|
-
}
|