-
-
Notifications
You must be signed in to change notification settings - Fork 111
/
honeypot.tsx
68 lines (61 loc) · 1.45 KB
/
honeypot.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* eslint-disable jsx-a11y/autocomplete-valid */
import * as React from "react";
import type { HoneypotInputProps } from "../server/honeypot.js";
type HoneypotContextType = Partial<HoneypotInputProps>;
const HoneypotContext = React.createContext<HoneypotContextType>({});
export function HoneypotInputs({
label = "Please leave this field blank",
}: {
label?: string;
}): JSX.Element {
let context = React.useContext(HoneypotContext);
let {
nameFieldName = "name__confirm",
validFromFieldName = "from__confirm",
encryptedValidFrom,
} = context;
return (
<div
id={`${nameFieldName}_wrap`}
style={{ display: "none" }}
aria-hidden="true"
>
<label htmlFor={nameFieldName}>{label}</label>
<input
id={nameFieldName}
name={nameFieldName}
type="text"
defaultValue=""
autoComplete="nope"
tabIndex={-1}
/>
{validFromFieldName && encryptedValidFrom ? (
<>
<label htmlFor={validFromFieldName}>{label}</label>
<input
id={validFromFieldName}
name={validFromFieldName}
type="text"
value={encryptedValidFrom}
readOnly
autoComplete="off"
tabIndex={-1}
/>
</>
) : null}
</div>
);
}
export type HoneypotProviderProps = HoneypotContextType & {
children: React.ReactNode;
};
export function HoneypotProvider({
children,
...context
}: HoneypotProviderProps) {
return (
<HoneypotContext.Provider value={context}>
{children}
</HoneypotContext.Provider>
);
}