package containers import ( "fmt" "github.com/iancoleman/strcase" "github.com/jinzhu/inflection" "github.com/qor5/admin/pagebuilder" "github.com/qor5/admin/presets" "github.com/qor5/ui/vuetify" "github.com/qor5/web" . "github.com/theplant/htmlgo" ) type WebHeader struct { ID uint Color string } func (*WebHeader) TableName() string { return "container_headers" } func RegisterHeader(pb *pagebuilder.Builder) { header := pb.RegisterContainer("Header"). RenderFunc(func(obj interface{}, input *pagebuilder.RenderInput, ctx *web.EventContext) HTMLComponent { header := obj.(*WebHeader) return HeaderTemplate(header, input) }) ed := header.Model(&WebHeader{}).URIName(inflection.Plural(strcase.ToKebab("Header"))).Editing("Color") ed.Field("Color").ComponentFunc(func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) HTMLComponent { return vuetify.VSelect(). Items([]string{"black", "white"}). Value(field.Value(obj)). Label(field.Label). FieldName(field.FormKey) }) } func HeaderTemplate(data *WebHeader, input *pagebuilder.RenderInput) (body HTMLComponent) { //bc := data.Color style := "color: #fff;background: #000;" //if input.IsEditor && (input.Device == "phone" || input.Device == "tablet") { // bc = "black" //} if data.Color == "white" { style = "color: #000;background: #fff;" } body = ContainerWrapper( fmt.Sprintf(inflection.Plural(strcase.ToKebab("Header"))+"_%v", data.ID), "", "container-header", "", "", "", "", false, false, input.IsEditor, input.IsReadonly, style, Div(RawHTML(` `)).Class("container-wrapper"), ) return }