page.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package e23_vuetify_components_kitchen
  2. // @snippet_begin(VuetifyComponentsKitchen)
  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. var globalCities = []string{"Tokyo", "Hangzhou", "Shanghai"}
  10. type formVals struct {
  11. Cities1 []string
  12. Cities2 []string
  13. MyItem string
  14. }
  15. var fv = formVals{
  16. Cities1: []string{
  17. "TK",
  18. "LD",
  19. },
  20. Cities2: []string{
  21. "Hangzhou",
  22. "Shanghai",
  23. },
  24. MyItem: "VItem2",
  25. }
  26. func VuetifyComponentsKitchen(ctx *web.EventContext) (pr web.PageResponse, err error) {
  27. var chips h.HTMLComponents
  28. for _, city := range globalCities {
  29. chips = append(chips,
  30. VChip(h.Text(city)).
  31. Close(true).
  32. Attr("@click:close", web.POST().EventFunc("removeCity").Query("city", city).Go()),
  33. )
  34. }
  35. pr.Body = VContainer(
  36. utils.PrettyFormAsJSON(ctx),
  37. h.H1("Chips delete"),
  38. chips,
  39. h.H1("Chips group"),
  40. VChipGroup(
  41. VChip(
  42. h.Text("Hangzhou"),
  43. VIcon("star").Right(true),
  44. ).Value("HZ"),
  45. VChip(h.Text("Shanghai")).Value("SH").Filter(true).Label(true),
  46. VChip(h.Text("Tokyo")).Value("TK").Filter(true),
  47. VChip(h.Text("New York")).Value("NY"),
  48. VChip(h.Text("London")).Value("LD"),
  49. ).ActiveClass("indigo darken-3 white--text").
  50. // Mandatory(true).
  51. FieldName("Cities1").
  52. Value(fv.Cities1).
  53. Multiple(true),
  54. VAutocomplete().
  55. Items(globalCities).
  56. FieldName("Cities2").
  57. Value(fv.Cities2),
  58. h.H1("Items Group"),
  59. VItemGroup(
  60. VContainer(
  61. VRow(
  62. VCol(
  63. VItem(
  64. VCard(
  65. VCardTitle(h.Text("Item1")),
  66. ).Attr(":color", "active ? \"primary\" : \"\"").
  67. Attr("@click", "toggle"),
  68. ).Value("VItem1").Attr("v-slot", "{active, toggle}"),
  69. ),
  70. VCol(
  71. VItem(
  72. VCard(
  73. VCardTitle(h.Text("Item2")),
  74. ).Attr(":color", "active ? \"primary\" : \"\"").
  75. Attr("@click", "toggle"),
  76. ).Value("VItem2").Attr("v-slot", "{active, toggle}"),
  77. ),
  78. ),
  79. ),
  80. ).FieldName("MyItem").
  81. Value(fv.MyItem),
  82. VBtn("Submit").
  83. OnClick("submit"),
  84. )
  85. return
  86. }
  87. func submit(ctx *web.EventContext) (r web.EventResponse, err error) {
  88. fv = formVals{}
  89. ctx.MustUnmarshalForm(&fv)
  90. r.Reload = true
  91. return
  92. }
  93. func removeCity(ctx *web.EventContext) (r web.EventResponse, err error) {
  94. city := ctx.R.FormValue("city")
  95. var newCities []string
  96. for _, c := range globalCities {
  97. if c != city {
  98. newCities = append(newCities, c)
  99. }
  100. }
  101. globalCities = newCities
  102. r.Reload = true
  103. return
  104. }
  105. var VuetifyComponentsKitchenPB = web.Page(VuetifyComponentsKitchen).
  106. EventFunc("removeCity", removeCity).
  107. EventFunc("submit", submit)
  108. const VuetifyComponentsKitchenPath = "/samples/vuetify-components-kitchen"
  109. // @snippet_end