EditableTitle.tsx
Raw
1import config from "../config.ts";
2
3interface EditableTitleProps {
4 title: string;
5 canEdit: boolean;
6 editAction: string;
7 bodyFieldName: string;
8 bodyValue: string;
9}
10
11export function EditableTitle({
12 title,
13 canEdit,
14 editAction,
15 bodyFieldName,
16 bodyValue,
17}: EditableTitleProps) {
18 return (
19 <>
20 {canEdit && (
21 <input
22 type="checkbox"
23 id="title-edit-toggle"
24 class="title-edit-toggle"
25 />
26 )}
27 <div class="title-with-edit">
28 <h2 class="issue-detail-title">{title}</h2>
29 {canEdit && (
30 <>
31 <div class="title-edit-form-area">
32 <form
33 method="POST"
34 action={editAction}
35 class="title-edit-form"
36 >
37 <input
38 class="form-input"
39 name="title"
40 value={title}
41 required
42 maxlength={config.MAX_TITLE_BYTES}
43 />
44 <input
45 type="hidden"
46 name={bodyFieldName}
47 value={bodyValue}
48 />
49 <div class="title-edit-actions">
50 <button
51 type="submit"
52 class="btn btn-sm btn-primary"
53 >
54 Save
55 </button>
56 <label
57 for="title-edit-toggle"
58 class="btn btn-sm"
59 >
60 Cancel
61 </label>
62 </div>
63 </form>
64 </div>
65 <label
66 for="title-edit-toggle"
67 class="btn btn-xs title-edit-open"
68 >
69 Edit title
70 </label>
71 </>
72 )}
73 </div>
74 </>
75 );
76}
77