key-info.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package vuetifyx
  2. import (
  3. "context"
  4. h "github.com/theplant/htmlgo"
  5. )
  6. type KeyFieldBuilder struct {
  7. label string
  8. icon h.HTMLComponent
  9. children []h.HTMLComponent
  10. }
  11. func KeyField(children ...h.HTMLComponent) (r *KeyFieldBuilder) {
  12. r = &KeyFieldBuilder{}
  13. r.Children(children...)
  14. return
  15. }
  16. func (b *KeyFieldBuilder) Label(v string) (r *KeyFieldBuilder) {
  17. b.label = v
  18. return b
  19. }
  20. func (b *KeyFieldBuilder) Icon(v h.HTMLComponent) (r *KeyFieldBuilder) {
  21. b.icon = v
  22. return b
  23. }
  24. func (b *KeyFieldBuilder) Children(comps ...h.HTMLComponent) (r *KeyFieldBuilder) {
  25. b.children = comps
  26. return b
  27. }
  28. func (b *KeyFieldBuilder) MarshalHTML(ctx context.Context) (r []byte, err error) {
  29. return h.Div(
  30. h.Label(b.label).Class("blue-grey--text lighten-3"),
  31. h.Div(b.children...).PrependChildren(b.icon),
  32. ).Class("px-4 my-4").Style("border-right: 1px solid #E0E0E0").
  33. MarshalHTML(ctx)
  34. }
  35. type KeyInfoBuilder struct {
  36. children []h.HTMLComponent
  37. }
  38. func KeyInfo(children ...h.HTMLComponent) (r *KeyInfoBuilder) {
  39. r = &KeyInfoBuilder{}
  40. r.Children(children...)
  41. return
  42. }
  43. func (b *KeyInfoBuilder) Children(comps ...h.HTMLComponent) (r *KeyInfoBuilder) {
  44. b.children = comps
  45. return b
  46. }
  47. func (b *KeyInfoBuilder) Append(label string, comp h.HTMLComponent) (r *KeyInfoBuilder) {
  48. b.children = append(b.children, KeyField(comp).Label(label))
  49. return b
  50. }
  51. func (b *KeyInfoBuilder) AppendIcon(label string, icon h.HTMLComponent, comp h.HTMLComponent) (r *KeyInfoBuilder) {
  52. b.children = append(b.children, KeyField(comp).Label(label).Icon(icon))
  53. return b
  54. }
  55. func (b *KeyInfoBuilder) MarshalHTML(ctx context.Context) (r []byte, err error) {
  56. return h.Div(b.children...).
  57. Class("grey lighten-5 d-flex").
  58. MarshalHTML(ctx)
  59. }