editabletitle.go
| 1 | package views |
| 2 | |
| 3 | import ( |
| 4 | "strconv" |
| 5 | |
| 6 | "hearthforge/internal/config" |
| 7 | |
| 8 | g "maragu.dev/gomponents" |
| 9 | . "maragu.dev/gomponents/html" |
| 10 | ) |
| 11 | |
| 12 | // EditableTitle renders a title with a CSS-only inline edit form. |
| 13 | // bodyFieldName and bodyValue resubmit the unchanged body with the title. |
| 14 | func EditableTitle(cfg *config.Config, title string, canEdit bool, editAction, bodyFieldName, bodyValue string) g.Node { |
| 15 | return g.Group{ |
| 16 | g.If(canEdit, Input(Type("checkbox"), ID("title-edit-toggle"), Class("title-edit-toggle"))), |
| 17 | Div(Class("title-with-edit"), |
| 18 | H2(Class("issue-detail-title"), g.Text(title)), |
| 19 | g.If(canEdit, g.Group{ |
| 20 | Div(Class("title-edit-form-area"), |
| 21 | Form(Method("POST"), Action(editAction), Class("title-edit-form"), |
| 22 | Input(Class("form-input"), Name("title"), Value(title), Required(), |
| 23 | MaxLength(strconv.Itoa(cfg.MaxTitleBytes))), |
| 24 | Input(Type("hidden"), Name(bodyFieldName), Value(bodyValue)), |
| 25 | Div(Class("title-edit-actions"), |
| 26 | Button(Type("submit"), Class("btn btn-sm btn-primary"), g.Text("Save")), |
| 27 | Label(For("title-edit-toggle"), Class("btn btn-sm"), g.Text("Cancel")), |
| 28 | ), |
| 29 | ), |
| 30 | ), |
| 31 | Label(For("title-edit-toggle"), Class("btn btn-xs title-edit-open"), g.Text("Edit title")), |
| 32 | }), |
| 33 | ), |
| 34 | } |
| 35 | } |
| 36 |