header.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package containers
  2. import (
  3. "fmt"
  4. "github.com/iancoleman/strcase"
  5. "github.com/jinzhu/inflection"
  6. "github.com/qor5/admin/pagebuilder"
  7. "github.com/qor5/admin/presets"
  8. "github.com/qor5/ui/vuetify"
  9. "github.com/qor5/web"
  10. . "github.com/theplant/htmlgo"
  11. )
  12. type WebHeader struct {
  13. ID uint
  14. Color string
  15. }
  16. func (*WebHeader) TableName() string {
  17. return "container_headers"
  18. }
  19. func RegisterHeader(pb *pagebuilder.Builder) {
  20. header := pb.RegisterContainer("Header").
  21. RenderFunc(func(obj interface{}, input *pagebuilder.RenderInput, ctx *web.EventContext) HTMLComponent {
  22. header := obj.(*WebHeader)
  23. return HeaderTemplate(header, input)
  24. })
  25. ed := header.Model(&WebHeader{}).URIName(inflection.Plural(strcase.ToKebab("Header"))).Editing("Color")
  26. ed.Field("Color").ComponentFunc(func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) HTMLComponent {
  27. return vuetify.VSelect().
  28. Items([]string{"black", "white"}).
  29. Value(field.Value(obj)).
  30. Label(field.Label).
  31. FieldName(field.FormKey)
  32. })
  33. }
  34. func HeaderTemplate(data *WebHeader, input *pagebuilder.RenderInput) (body HTMLComponent) {
  35. //bc := data.Color
  36. style := "color: #fff;background: #000;"
  37. //if input.IsEditor && (input.Device == "phone" || input.Device == "tablet") {
  38. // bc = "black"
  39. //}
  40. if data.Color == "white" {
  41. style = "color: #000;background: #fff;"
  42. }
  43. body = ContainerWrapper(
  44. fmt.Sprintf(inflection.Plural(strcase.ToKebab("Header"))+"_%v", data.ID), "", "container-header", "", "", "",
  45. "", false, false, input.IsEditor, input.IsReadonly, style,
  46. Div(RawHTML(`
  47. <a href="/" class="container-header-logo"><svg viewBox="0 0 29 30" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M14.399 10.054V0L0 10.054V29.73h28.792V0L14.4 10.054z" fill="currentColor"><title>The Plant</title></path></svg></a>
  48. <ul data-list-unset="true" class="container-header-links">
  49. <li>
  50. <a href="/what-we-do/">What we do</a>
  51. </li>
  52. <li>
  53. <a href="/projects/">Projects</a>
  54. </li>
  55. <li>
  56. <a href="/why-clients-choose-us/">Why clients choose us</a>
  57. </li>
  58. <li>
  59. <a href="/our-company/">Our company</a>
  60. </li>
  61. </ul>
  62. <button class="container-header-menu">
  63. <span class="container-header-menu-icon"></span>
  64. </button>`)).Class("container-wrapper"),
  65. )
  66. return
  67. }