EditableTitle.tsx
| 1 | import config from "../config.ts"; |
| 2 | |
| 3 | interface EditableTitleProps { |
| 4 | title: string; |
| 5 | canEdit: boolean; |
| 6 | editAction: string; |
| 7 | bodyFieldName: string; |
| 8 | bodyValue: string; |
| 9 | } |
| 10 | |
| 11 | export 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" safe> |
| 29 | {title} |
| 30 | </h2> |
| 31 | {canEdit && ( |
| 32 | <> |
| 33 | <div class="title-edit-form-area"> |
| 34 | <form |
| 35 | method="POST" |
| 36 | action={editAction} |
| 37 | class="title-edit-form" |
| 38 | > |
| 39 | <input |
| 40 | class="form-input" |
| 41 | name="title" |
| 42 | value={title} |
| 43 | required |
| 44 | maxlength={config.MAX_TITLE_BYTES} |
| 45 | /> |
| 46 | <input |
| 47 | type="hidden" |
| 48 | name={bodyFieldName} |
| 49 | value={bodyValue} |
| 50 | /> |
| 51 | <div class="title-edit-actions"> |
| 52 | <button |
| 53 | type="submit" |
| 54 | class="btn btn-sm btn-primary" |
| 55 | > |
| 56 | Save |
| 57 | </button> |
| 58 | <label |
| 59 | for="title-edit-toggle" |
| 60 | class="btn btn-sm" |
| 61 | > |
| 62 | Cancel |
| 63 | </label> |
| 64 | </div> |
| 65 | </form> |
| 66 | </div> |
| 67 | <label |
| 68 | for="title-edit-toggle" |
| 69 | class="btn btn-xs title-edit-open" |
| 70 | > |
| 71 | Edit title |
| 72 | </label> |
| 73 | </> |
| 74 | )} |
| 75 | </div> |
| 76 | </> |
| 77 | ); |
| 78 | } |
| 79 |