-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathControlCard.tsx
More file actions
158 lines (141 loc) · 5.81 KB
/
Copy pathControlCard.tsx
File metadata and controls
158 lines (141 loc) · 5.81 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"use client";
import { memo, useState } from "react";
import "./control.css";
import { Control, ControlData, ControlState } from "./types";
interface ControlCardProps {
control: Control;
data: ControlData;
onControlChange: (data: ControlData) => void;
}
const nextState: Record<ControlState, ControlState> = {
no: "yes",
yes: "partial",
partial: "na",
na: "no",
};
const stateLabels: Record<ControlState, string> = {
yes: "✓",
partial: "½",
na: "—",
no: "",
};
const stateActionLabels: Record<ControlState, string> = {
no: "Mark as completed",
yes: "Mark as partially implemented",
partial: "Mark as not applicable",
na: "Reset to incomplete",
};
export const ControlCard = memo(function ControlCard({
control,
data,
onControlChange
}: ControlCardProps) {
const [expanded, setExpanded] = useState(false);
const handleCycleState = () => {
const newState = nextState[data.state];
onControlChange({
...data,
state: newState,
});
};
const handleJustificationChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
onControlChange({
...data,
justification: e.target.value,
});
};
const handleEvidenceChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
onControlChange({
...data,
evidence: e.target.value,
});
};
const handleToggleExpanded = () => setExpanded(!expanded);
const handleExpandKeyDown = (e: React.KeyboardEvent) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
handleToggleExpanded();
}
};
const completedStyles = data.state === "yes" ? "line-through opacity-60" : "";
return (
<div className="border border-solid rounded-lg p-3 control-card">
<div className="flex items-start">
<div className="mr-3">
<button
type="button"
onClick={handleCycleState}
className={`mt-1 control-state-btn control-state-${data.state}`}
aria-label={`${stateActionLabels[data.state]}: ${control.title}`}
>
{stateLabels[data.state]}
</button>
</div>
<div className="flex-1">
<div className={`font-bold mb-1 control-title ${completedStyles}`}>
<span className="control-id">{control.id}</span>
<span className="control-id-sep"> · </span>
{control.title}
</div>
<div className={`text-md control-description ${completedStyles}`}>
{control.description}
</div>
{control.baselines && control.baselines.length > 0 && (
<div className={`control-baselines ${completedStyles}`}>
<div className="control-baselines-label">Baseline Requirements</div>
<ul className="control-baselines-list">
{control.baselines.map((baseline, idx) => (
<li key={idx}>{baseline}</li>
))}
</ul>
</div>
)}
</div>
<div className="ml-auto pl-3">
<button
type="button"
onClick={handleToggleExpanded}
onKeyDown={handleExpandKeyDown}
className="w-6 h-6 rounded-full border border-solid bg-transparent cursor-pointer flex items-center justify-center text-sm font-medium control-info-btn"
aria-label={`${expanded ? "Hide" : "Show"} justification for ${control.title}`}
aria-expanded={expanded}
aria-controls={`justification-${control.id}`}
>
{expanded ? "-" : "i"}
</button>
</div>
</div>
<div className={`control-expanded-content ${expanded ? "expanded" : ""}`}>
<div className="mt-3 pt-3 border-t border-solid control-inputs-section">
<div className="mb-3">
<label htmlFor={`justification-${control.id}`} className="block mb-1 text-sm font-medium control-label">
Justification
</label>
<textarea
id={`justification-${control.id}`}
value={data.justification}
onChange={handleJustificationChange}
placeholder={control.justification || "Enter implementation justification..."}
className="control-textarea"
rows={3}
/>
</div>
<div>
<label htmlFor={`evidence-${control.id}`} className="block mb-1 text-sm font-medium control-label">
Evidence / Notes
</label>
<textarea
id={`evidence-${control.id}`}
value={data.evidence}
onChange={handleEvidenceChange}
placeholder={control.evidence || "Enter evidence or notes..."}
className="control-textarea"
rows={3}
/>
</div>
</div>
</div>
</div>
);
});
ControlCard.displayName = "ControlCard";