shortcut.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package e00_basics
  2. // @snippet_begin(ShortCutSample)
  3. import (
  4. . "github.com/qor5/ui/vuetify"
  5. "github.com/qor5/web"
  6. h "github.com/theplant/htmlgo"
  7. )
  8. func ShortCutSample(ctx *web.EventContext) (pr web.PageResponse, err error) {
  9. clickEvent := "locals.count += 1"
  10. pr.Body = VContainer(
  11. web.Scope(
  12. VRow(
  13. VCol(
  14. VRow(
  15. VBtn("count+1").Attr("@click", clickEvent).Class("mr-4"),
  16. h.Text("Shortcut: enter"),
  17. ).Class("mb-10"),
  18. VRow(
  19. VBtn("toggle shortcut").Attr("@click", "locals.shortCutEnabled = !locals.shortCutEnabled"),
  20. ),
  21. ),
  22. VCol(
  23. VCard(
  24. VCardTitle(h.Text("Shortcut Enabled")),
  25. VCardText().Attr("v-text", "locals.shortCutEnabled"),
  26. ).Class("mb-10"),
  27. VCard(
  28. VCardTitle(h.Text("Count")),
  29. VCardText().Attr("v-text", "locals.count"),
  30. ),
  31. ),
  32. ).Class("mt-10"),
  33. // Add shortcut for this button. only available when drawer is opened
  34. web.GlobalEvents().Attr(":filter", `(event, handler, eventName) => locals.shortCutEnabled == true`).Attr("@keydown.enter", clickEvent),
  35. ).Init(`{ shortCutEnabled: true, count: 0 }`).
  36. VSlot("{ locals }"),
  37. )
  38. return
  39. }
  40. var ShortCutSamplePB = web.Page(ShortCutSample)
  41. const ShortCutSamplePath = "/samples/shortcut-sample"
  42. // @snippet_end