page.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package e14_vuetify_menu
  2. // @snippet_begin(VuetifyMenuSample)
  3. import (
  4. "github.com/qor5/docs/docsrc/utils"
  5. . "github.com/qor5/ui/vuetify"
  6. "github.com/qor5/web"
  7. h "github.com/theplant/htmlgo"
  8. )
  9. type formData struct {
  10. EnableMessages bool
  11. EnableHints bool
  12. }
  13. var globalFavored bool
  14. const favoredIconPortalName = "favoredIcon"
  15. func HelloVuetifyMenu(ctx *web.EventContext) (pr web.PageResponse, err error) {
  16. var fv formData
  17. err = ctx.UnmarshalForm(&fv)
  18. if err != nil {
  19. return
  20. }
  21. pr.Body = VContainer(
  22. utils.PrettyFormAsJSON(ctx),
  23. VMenu(
  24. web.Slot(
  25. VBtn("Menu as Popover").
  26. On("click", "vars.myMenuShow = true").
  27. Dark(true).
  28. Color("indigo"),
  29. ).Name("activator"),
  30. VCard(
  31. VList(
  32. VListItem(
  33. VListItemAvatar(
  34. h.Img("https://cdn.vuetifyjs.com/images/john.jpg").Alt("John"),
  35. ),
  36. VListItemContent(
  37. VListItemTitle(h.Text("John Leider")),
  38. VListItemSubtitle(h.Text("Founder of Vuetify.js")),
  39. ),
  40. VListItemAction(
  41. web.Portal(
  42. favoredIcon(),
  43. ).Name(favoredIconPortalName),
  44. ),
  45. ),
  46. ),
  47. VDivider(),
  48. VList(
  49. VListItem(
  50. VListItemAction(
  51. VSwitch().Color("purple").
  52. FieldName("EnableMessages").
  53. InputValue(fv.EnableMessages),
  54. ),
  55. VListItemTitle(h.Text("Enable messages")),
  56. ),
  57. VListItem(
  58. VListItemAction(
  59. VSwitch().Color("purple").
  60. FieldName("EnableHints").
  61. InputValue(fv.EnableHints),
  62. ),
  63. VListItemTitle(h.Text("Enable hints")),
  64. ),
  65. ),
  66. VCardActions(
  67. VSpacer(),
  68. VBtn("Cancel").Text(true).
  69. On("click", "vars.myMenuShow = false"),
  70. VBtn("Save").Color("primary").
  71. Text(true).OnClick("submit"),
  72. ),
  73. ),
  74. ).CloseOnContentClick(false).
  75. NudgeWidth(200).
  76. OffsetY(true).
  77. Attr("v-model", "vars.myMenuShow"),
  78. ).Attr(web.InitContextVars, `{myMenuShow: false}`)
  79. return
  80. }
  81. func favoredIcon() h.HTMLComponent {
  82. color := ""
  83. if globalFavored {
  84. color = "red"
  85. }
  86. return VBtn("").Icon(true).Children(
  87. VIcon("favorite").Color(color),
  88. ).OnClick("toggleFavored")
  89. }
  90. func toggleFavored(ctx *web.EventContext) (er web.EventResponse, err error) {
  91. globalFavored = !globalFavored
  92. er.UpdatePortals = append(er.UpdatePortals, &web.PortalUpdate{
  93. Name: favoredIconPortalName,
  94. Body: favoredIcon(),
  95. })
  96. return
  97. }
  98. func submit(ctx *web.EventContext) (er web.EventResponse, err error) {
  99. er.Reload = true
  100. er.VarsScript = "vars.myMenuShow = false"
  101. return
  102. }
  103. var HelloVuetifyMenuPB = web.Page(HelloVuetifyMenu).
  104. EventFunc("submit", submit).
  105. EventFunc("toggleFavored", toggleFavored)
  106. const HelloVuetifyMenuPath = "/samples/hello-vuetify-menu"
  107. // @snippet_end