card.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package vuetifyx
  2. import (
  3. "context"
  4. v "github.com/qor5/ui/vuetify"
  5. h "github.com/theplant/htmlgo"
  6. )
  7. type CardBuilder struct {
  8. children []h.HTMLComponent
  9. systemBar []h.HTMLComponent
  10. header []h.HTMLComponent
  11. actions []h.HTMLComponent
  12. classNames []string
  13. }
  14. func Card(children ...h.HTMLComponent) (r *CardBuilder) {
  15. r = &CardBuilder{}
  16. r.Children(children...)
  17. return
  18. }
  19. func (b *CardBuilder) Children(comps ...h.HTMLComponent) (r *CardBuilder) {
  20. b.children = comps
  21. return b
  22. }
  23. func (b *CardBuilder) Actions(actions ...h.HTMLComponent) (r *CardBuilder) {
  24. b.actions = actions
  25. return b
  26. }
  27. func (b *CardBuilder) Header(header ...h.HTMLComponent) (r *CardBuilder) {
  28. b.header = header
  29. return b
  30. }
  31. func (b *CardBuilder) HeaderTitle(title string) (r *CardBuilder) {
  32. b.header = []h.HTMLComponent{h.Text(title)}
  33. return b
  34. }
  35. func (b *CardBuilder) SystemBar(systemBar ...h.HTMLComponent) (r *CardBuilder) {
  36. b.systemBar = systemBar
  37. return b
  38. }
  39. func (b *CardBuilder) Class(names ...string) (r *CardBuilder) {
  40. b.classNames = names
  41. return b
  42. }
  43. func (b *CardBuilder) MarshalHTML(ctx context.Context) (r []byte, err error) {
  44. var sb h.HTMLComponent
  45. if len(b.systemBar) > 0 {
  46. sb = v.VSystemBar(b.systemBar...).Class("mx-2 pt-4").Color("white").Height(32)
  47. }
  48. return v.VCard(
  49. sb,
  50. v.VToolbar(
  51. v.VToolbarTitle("").Children(b.header...),
  52. v.VSpacer(),
  53. ).Flat(true).AppendChildren(b.actions...),
  54. v.VDivider(),
  55. ).Class(b.classNames...).AppendChildren(b.children...).MarshalHTML(ctx)
  56. }