-
Notifications
You must be signed in to change notification settings - Fork 354
Expand file tree
/
Copy pathjwt-editor.component.tsx
More file actions
84 lines (76 loc) · 2.23 KB
/
jwt-editor.component.tsx
File metadata and controls
84 lines (76 loc) · 2.23 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React from "react";
import { EditorComponent } from "@/features/common/components/code-editor/editor.component";
interface JwtEditorComponentProps {
token: string;
handleJwtChange: (value: string) => void;
autoFocus: boolean
}
export const JwtEditorComponent: React.FC<JwtEditorComponentProps> = ({
token,
autoFocus,
handleJwtChange,
}) => {
return (
<EditorComponent
aria-label="JWT editor input"
value={token}
autoFocus={autoFocus}
focusOnWindowFocus={autoFocus}
onValueChange={(code) => handleJwtChange(code)}
highlight={(code) => {
if (!code) {
return (
<React.Fragment>
<span className="ace_text"> </span>
</React.Fragment>
);
}
const parts = code.split(".");
const lastIndex = parts.length - 1;
return parts.map((part, index) => {
const text = part.trim();
const withDot = index !== lastIndex;
if (index === 0) {
return (
<React.Fragment key={index}>
<span className="ace_header">{text}</span>
{withDot && <span className="ace_dot">.</span>}
</React.Fragment>
);
}
if (index === 1) {
return (
<React.Fragment key={index}>
<span className="ace_payload">{text}</span>
{withDot && <span className="ace_dot">.</span>}
</React.Fragment>
);
}
if (index === 2) {
return (
<React.Fragment key={index}>
<span className="ace_signature">{text}</span>
{withDot && <span className="ace_dot">.</span>}
</React.Fragment>
);
}
return (
<React.Fragment key={index}>
<span className="ace_text">{text}</span>
{withDot && <span className="ace_dot">.</span>}
</React.Fragment>
);
});
}}
padding="1rem"
style={{
fontFamily: '"Roboto Mono", monospace',
fontSize: 14,
lineHeight: 1.4,
border: "none",
outline: "none",
minHeight: "4rem",
}}
/>
);
};