page.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package e15_vuetify_navigation_drawer
  2. // @snippet_begin(VuetifyNavigationDrawerSample)
  3. import (
  4. "fmt"
  5. "time"
  6. . "github.com/qor5/ui/vuetify"
  7. "github.com/qor5/web"
  8. h "github.com/theplant/htmlgo"
  9. )
  10. func VuetifyNavigationDrawer(ctx *web.EventContext) (pr web.PageResponse, err error) {
  11. pr.Body = VContainer(
  12. h.H2("A drawer that has close button"),
  13. VBtn("show").On("click", "vars.drawer1 = !vars.drawer1"),
  14. VNavigationDrawer(
  15. h.Text("Hi"),
  16. VBtn("Close").On("click", "vars.drawer1 = false"),
  17. ).Temporary(true).
  18. Attr("v-model", "vars.drawer1").
  19. Right(true).
  20. Bottom(true).
  21. Absolute(true).
  22. Width(600),
  23. h.H2("Load a drawer from remote and show it").Class("pt-8"),
  24. VBtn("Show Drawer 2").OnClick("showDrawer"),
  25. web.Portal().Name("drawer2UpdateContent"),
  26. web.Portal().Name("drawer2"),
  27. ).Attr(web.InitContextVars, `{drawer1: false, drawer2: false}`)
  28. return
  29. }
  30. func showDrawer(ctx *web.EventContext) (er web.EventResponse, err error) {
  31. er.UpdatePortals = append(er.UpdatePortals,
  32. &web.PortalUpdate{
  33. Name: "drawer2",
  34. Body: VNavigationDrawer(
  35. h.Text("Drawer 2"),
  36. web.Portal(
  37. textField(""),
  38. ).Name("InputPortal"),
  39. VBtn("Update parent and close").
  40. OnClick("updateParentAndClose"),
  41. ).Right(true).
  42. Attr("v-model", "vars.drawer2").
  43. Bottom(true).
  44. Temporary(true).
  45. Absolute(true).
  46. Value(true).
  47. Width(800),
  48. },
  49. )
  50. er.VarsScript = `setTimeout(function(){ vars.drawer2 = true }, 100)`
  51. return
  52. }
  53. func textField(value string, fieldErrors ...string) h.HTMLComponent {
  54. return VTextField().
  55. FieldName("Drawer2Input").
  56. ErrorMessages(fieldErrors...).
  57. Value(value)
  58. }
  59. func updateParentAndClose(ctx *web.EventContext) (er web.EventResponse, err error) {
  60. if len(ctx.R.FormValue("Drawer2Input")) < 10 {
  61. er.UpdatePortals = append(er.UpdatePortals, &web.PortalUpdate{
  62. Name: "InputPortal",
  63. Body: textField(ctx.R.FormValue("Drawer2Input"), "input more then 10 characters"),
  64. })
  65. return
  66. }
  67. er.UpdatePortals = append(er.UpdatePortals, &web.PortalUpdate{
  68. Name: "drawer2UpdateContent",
  69. Body: h.Text(fmt.Sprintf("Updated content at %s", time.Now())),
  70. })
  71. er.VarsScript = "vars.drawer2 = false"
  72. return
  73. }
  74. var VuetifyNavigationDrawerPB = web.Page(VuetifyNavigationDrawer).
  75. EventFunc("showDrawer", showDrawer).
  76. EventFunc("updateParentAndClose", updateParentAndClose)
  77. const VuetifyNavigationDrawerPath = "/samples/vuetify-navigation-drawer"
  78. // @snippet_end