feat: extract reusable layout components

This commit is contained in:
Prad Nukala
2024-10-07 20:14:46 -04:00
parent c608a067ed
commit d0dddbfe01
4 changed files with 233 additions and 243 deletions
+60 -1
View File
@@ -1,6 +1,33 @@
package styles
import "github.com/onsonr/sonr/pkg/nebula/global/cdn"
import (
"github.com/onsonr/sonr/pkg/nebula/global/cdn"
"strings"
)
type Icon interface {
Render() templ.Component
}
type Variant interface {
Attributes() templ.Attributes
}
templ Spacer() {
<br/>
}
templ Rows() {
<div class="flex flex-row w-full gap-2 md:gap-4">
{ children... }
</div>
}
templ Columns() {
<div class="flex flex-col h-full w-full gap-3 md:gap-6 md:flex-row">
{ children... }
</div>
}
templ Layout(title string, remote bool) {
<!DOCTYPE html>
@@ -98,3 +125,35 @@ templ OpenModal(title, description string) {
</template>
</div>
}
func clsxMerge(variants ...Variant) templ.Attributes {
combinedAttrs := templ.Attributes{}
var classElements []string
for _, variant := range variants {
attrs := variant.Attributes()
if class, ok := attrs["class"].(string); ok {
classElements = append(classElements, strings.Fields(class)...)
}
for key, value := range attrs {
if key != "class" {
combinedAttrs[key] = value
}
}
}
if len(classElements) > 0 {
combinedAttrs["class"] = strings.Join(classElements, " ")
}
return combinedAttrs
}
func clsxBuilder(classes ...string) templ.Attributes {
if len(classes) == 0 {
return templ.Attributes{}
}
class := strings.Join(classes, " ")
return templ.Attributes{
"class": class,
}
}