Skip to content

Commit

Permalink
Merge pull request #392 from qor5/fix-go-hooks
Browse files Browse the repository at this point in the history
fix: Refactor VXBtn and VXChip components for improved attribute hand…
  • Loading branch information
danni-cool authored Dec 20, 2024
2 parents fb3bab9 + e8ca58a commit dff9295
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 97 deletions.
2 changes: 1 addition & 1 deletion ui/vuetifyx/vuetifyxjs/dist/assets/vuetifyx.min.css

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions ui/vuetifyx/vuetifyxjs/dist/vuetifyx.min.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion ui/vuetifyx/vuetifyxjs/src/lib/Common/VXBtn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
<slot name="prepend" />
</template>

<slot />
<template v-if="!isDefaultSlotReallyEmpty" #default>
<slot />
</template>

<template v-if="slots.append" #append>
<slot name="append" />
Expand All @@ -35,6 +37,10 @@ const props = defineProps({
}
})
const isDefaultSlotReallyEmpty = computed(() => {
return !slots.default || !slots.default().length
})
const presetsSizeOptions = computed(() => {
const obj: { color: string; width: string; size: string } = {
color: 'primary',
Expand Down
2 changes: 1 addition & 1 deletion ui/vuetifyx/vx-btn-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (b *VXBtnGroupBuilder) BaseColor(v string) (r *VXBtnGroupBuilder) {
}

func (b *VXBtnGroupBuilder) DividerColor(v string) (r *VXBtnGroupBuilder) {
b.tag.Attr(":divider-color", v)
b.tag.Attr("divider-color", v)
return b
}

Expand Down
12 changes: 6 additions & 6 deletions ui/vuetifyx/vx-btn.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package vuetifyx

import (
"github.com/qor5/web/v3"
"fmt"
"context"
"fmt"

"github.com/qor5/web/v3"
h "github.com/theplant/htmlgo"
)

type VXBtnBuilder struct {
tag *h.HTMLTagBuilder
}


func VXBtn(children ...h.HTMLComponent) (r *VXBtnBuilder) {
func VXBtn(name string) (r *VXBtnBuilder) {
r = &VXBtnBuilder{
tag: h.Tag("vx-btn").Children(children...),
tag: h.Tag("vx-btn").Text(name),
}

return
}

Expand Down Expand Up @@ -267,7 +268,6 @@ func (b *VXBtnBuilder) MarshalHTML(ctx context.Context) (r []byte, err error) {
return b.tag.MarshalHTML(ctx)
}


func (b *VXBtnBuilder) OnClick(eventFuncId string) (r *VXBtnBuilder) {
b.tag.Attr("@click", web.POST().EventFunc(eventFuncId).Go())
return b
Expand Down
124 changes: 44 additions & 80 deletions ui/vuetifyx/vx-chip.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,47 @@ import (
"context"
"fmt"

"github.com/qor5/web/v3"
h "github.com/theplant/htmlgo"
)

type VXChipBuilder struct {
tag *h.HTMLTagBuilder
}

func VXChip(children ...h.HTMLComponent) (r *VXChipBuilder) {
func VXChip(text string) (r *VXChipBuilder) {
r = &VXChipBuilder{
tag: h.Tag("vx-btn").Children(children...),
tag: h.Tag("vx-chip").Children(h.Text(text)),
}
return
}

func (b *VXChipBuilder) Presets(v string) (r *VXChipBuilder) {
b.tag.Attr("presets", v)
return b
}

func (b *VXChipBuilder) Round(v bool) (r *VXChipBuilder) {
b.tag.Attr(":round", fmt.Sprint(v))
func (b *VXChipBuilder) Label(v bool) (r *VXChipBuilder) {
b.tag.Attr(":label", fmt.Sprint(v))
return b
}

func (b *VXChipBuilder) Symbol(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":symbol", h.JSONString(v))
func (b *VXChipBuilder) Filter(v bool) (r *VXChipBuilder) {
b.tag.Attr(":filter", fmt.Sprint(v))
return b
}

func (b *VXChipBuilder) Flat(v bool) (r *VXChipBuilder) {
b.tag.Attr(":flat", fmt.Sprint(v))
func (b *VXChipBuilder) Round(v bool) (r *VXChipBuilder) {
b.tag.Attr(":round", fmt.Sprint(v))
return b
}

func (b *VXChipBuilder) Active(v bool) (r *VXChipBuilder) {
b.tag.Attr(":active", fmt.Sprint(v))
func (b *VXChipBuilder) Presets(v string) (r *VXChipBuilder) {
b.tag.Attr("presets", v)
return b
}

func (b *VXChipBuilder) BaseColor(v string) (r *VXChipBuilder) {
b.tag.Attr("base-color", v)
func (b *VXChipBuilder) ActiveClass(v string) (r *VXChipBuilder) {
b.tag.Attr("active-class", v)
return b
}

func (b *VXChipBuilder) PrependIcon(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":prepend-icon", h.JSONString(v))
func (b *VXChipBuilder) AppendAvatar(v string) (r *VXChipBuilder) {
b.tag.Attr("append-avatar", v)
return b
}

Expand All @@ -59,78 +53,78 @@ func (b *VXChipBuilder) AppendIcon(v interface{}) (r *VXChipBuilder) {
return b
}

func (b *VXChipBuilder) Block(v bool) (r *VXChipBuilder) {
b.tag.Attr(":block", fmt.Sprint(v))
func (b *VXChipBuilder) Closable(v bool) (r *VXChipBuilder) {
b.tag.Attr(":closable", fmt.Sprint(v))
return b
}

func (b *VXChipBuilder) Readonly(v bool) (r *VXChipBuilder) {
b.tag.Attr(":readonly", fmt.Sprint(v))
func (b *VXChipBuilder) CloseIcon(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":close-icon", h.JSONString(v))
return b
}

func (b *VXChipBuilder) Slim(v bool) (r *VXChipBuilder) {
b.tag.Attr(":slim", fmt.Sprint(v))
func (b *VXChipBuilder) CloseLabel(v string) (r *VXChipBuilder) {
b.tag.Attr("close-label", v)
return b
}

func (b *VXChipBuilder) Stacked(v bool) (r *VXChipBuilder) {
b.tag.Attr(":stacked", fmt.Sprint(v))
func (b *VXChipBuilder) Draggable(v bool) (r *VXChipBuilder) {
b.tag.Attr(":draggable", fmt.Sprint(v))
return b
}

func (b *VXChipBuilder) Ripple(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":ripple", h.JSONString(v))
func (b *VXChipBuilder) FilterIcon(v string) (r *VXChipBuilder) {
b.tag.Attr("filter-icon", v)
return b
}

func (b *VXChipBuilder) Value(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":value", h.JSONString(v))
func (b *VXChipBuilder) Link(v bool) (r *VXChipBuilder) {
b.tag.Attr(":link", fmt.Sprint(v))
return b
}

func (b *VXChipBuilder) Text(v string) (r *VXChipBuilder) {
b.tag.Attr("text", v)
func (b *VXChipBuilder) Pill(v bool) (r *VXChipBuilder) {
b.tag.Attr(":pill", fmt.Sprint(v))
return b
}

func (b *VXChipBuilder) Border(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":border", h.JSONString(v))
func (b *VXChipBuilder) PrependAvatar(v string) (r *VXChipBuilder) {
b.tag.Attr("prepend-avatar", v)
return b
}

func (b *VXChipBuilder) Density(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":density", h.JSONString(v))
func (b *VXChipBuilder) PrependIcon(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":prepend-icon", h.JSONString(v))
return b
}

func (b *VXChipBuilder) Height(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":height", h.JSONString(v))
func (b *VXChipBuilder) Ripple(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":ripple", h.JSONString(v))
return b
}

func (b *VXChipBuilder) MaxHeight(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":max-height", h.JSONString(v))
func (b *VXChipBuilder) Value(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":value", h.JSONString(v))
return b
}

func (b *VXChipBuilder) MaxWidth(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":max-width", h.JSONString(v))
func (b *VXChipBuilder) Text(v string) (r *VXChipBuilder) {
b.tag.Attr("text", v)
return b
}

func (b *VXChipBuilder) MinHeight(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":min-height", h.JSONString(v))
func (b *VXChipBuilder) ModelValue(v bool) (r *VXChipBuilder) {
b.tag.Attr(":model-value", fmt.Sprint(v))
return b
}

func (b *VXChipBuilder) MinWidth(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":min-width", h.JSONString(v))
func (b *VXChipBuilder) Border(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":border", h.JSONString(v))
return b
}

func (b *VXChipBuilder) Width(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":width", h.JSONString(v))
func (b *VXChipBuilder) Density(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":density", h.JSONString(v))
return b
}

Expand All @@ -149,21 +143,6 @@ func (b *VXChipBuilder) SelectedClass(v string) (r *VXChipBuilder) {
return b
}

func (b *VXChipBuilder) Loading(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":loading", h.JSONString(v))
return b
}

func (b *VXChipBuilder) Location(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":location", h.JSONString(v))
return b
}

func (b *VXChipBuilder) Position(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":position", h.JSONString(v))
return b
}

func (b *VXChipBuilder) Rounded(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":rounded", h.JSONString(v))
return b
Expand Down Expand Up @@ -219,11 +198,6 @@ func (b *VXChipBuilder) Variant(v interface{}) (r *VXChipBuilder) {
return b
}

func (b *VXChipBuilder) Icon(v interface{}) (r *VXChipBuilder) {
b.tag.Attr(":icon", h.JSONString(v))
return b
}

func (b *VXChipBuilder) SetAttr(k string, v interface{}) {
b.tag.SetAttr(k, v)
}
Expand Down Expand Up @@ -271,13 +245,3 @@ func (b *VXChipBuilder) Bind(name string, value string) (r *VXChipBuilder) {
func (b *VXChipBuilder) MarshalHTML(ctx context.Context) (r []byte, err error) {
return b.tag.MarshalHTML(ctx)
}

func (b *VXChipBuilder) OnClick(eventFuncId string) (r *VXChipBuilder) {
b.tag.Attr("@click", web.POST().EventFunc(eventFuncId).Go())
return b
}

func (b *VXChipBuilder) AttrIf(key, value interface{}, add bool) (r *VXChipBuilder) {
b.tag.AttrIf(key, value, add)
return b
}

0 comments on commit dff9295

Please sign in to comment.