177 lines
6.7 KiB
Go
177 lines
6.7 KiB
Go
// Code generated by templ - DO NOT EDIT.
|
|
|
|
// templ: version: v0.3.977
|
|
package navigation
|
|
|
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
|
|
|
import "github.com/a-h/templ"
|
|
import templruntime "github.com/a-h/templ/runtime"
|
|
|
|
import (
|
|
"fmt"
|
|
// CHANGE TO WHATEVER DIRECTORY HAS YOUR TEMPLUI UTILS FOLDER
|
|
"blog/web/utils"
|
|
)
|
|
|
|
type Variant string
|
|
type Size string
|
|
|
|
const (
|
|
VariantDefault Variant = "default"
|
|
VariantOutline Variant = "outline"
|
|
VariantSecondary Variant = "secondary"
|
|
VariantGhost Variant = "ghost"
|
|
)
|
|
|
|
const (
|
|
SizeDefault Size = "default"
|
|
SizeSm Size = "sm"
|
|
SizeLg Size = "lg"
|
|
SizeIcon Size = "icon"
|
|
)
|
|
|
|
type Props struct {
|
|
ID string
|
|
Class string
|
|
Columns int
|
|
Attributes templ.Attributes
|
|
Variant Variant
|
|
Size Size
|
|
}
|
|
|
|
func Navigation(props ...Props) templ.Component {
|
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
|
return templ_7745c5c3_CtxErr
|
|
}
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|
if !templ_7745c5c3_IsBuffer {
|
|
defer func() {
|
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err == nil {
|
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
}
|
|
}()
|
|
}
|
|
ctx = templ.InitializeContext(ctx)
|
|
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
|
if templ_7745c5c3_Var1 == nil {
|
|
templ_7745c5c3_Var1 = templ.NopComponent
|
|
}
|
|
ctx = templ.ClearChildren(ctx)
|
|
var p Props
|
|
var cols string
|
|
if len(props) > 0 {
|
|
p = props[0]
|
|
}
|
|
if p.Columns == 0 {
|
|
cols = "grid-cols-1"
|
|
} else {
|
|
cols = fmt.Sprintf("grid-cols-%d", p.Columns)
|
|
}
|
|
var templ_7745c5c3_Var2 = []any{utils.TwMerge(
|
|
"w-full bg-card border-b border-b-secondary h-16 grid 2 text-lg items-center px-4 ",
|
|
cols,
|
|
),
|
|
}
|
|
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var2...)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<header class=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var3 string
|
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var2).String())
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/components/navigation/navigation.templ`, Line: 1, Col: 0}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templ.RenderAttributes(ctx, templ_7745c5c3_Buffer, p.Attributes)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, ">")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templ_7745c5c3_Var1.Render(ctx, templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</header>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func (p Props) variantClasses() string {
|
|
switch p.Variant {
|
|
case VariantGhost:
|
|
return "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent"
|
|
case VariantOutline:
|
|
return "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50"
|
|
case VariantSecondary:
|
|
return "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80"
|
|
default:
|
|
return "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90"
|
|
}
|
|
}
|
|
|
|
func (b Props) sizeClasses() string {
|
|
switch b.Size {
|
|
case SizeSm:
|
|
return "h-8 rounded-full aspect-square gap-1.5 px-3 has-[>svg]:px-2.5"
|
|
case SizeLg:
|
|
return "h-10 rounded-full aspect-square px-6 has-[>svg]:px-4"
|
|
case SizeIcon:
|
|
return "size-9"
|
|
default: // SizeDefault
|
|
return "h-9 px-4 py-2 has-[>svg]:px-3"
|
|
}
|
|
}
|
|
|
|
// Theme change script
|
|
func Script() templ.Component {
|
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
|
return templ_7745c5c3_CtxErr
|
|
}
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|
if !templ_7745c5c3_IsBuffer {
|
|
defer func() {
|
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err == nil {
|
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
}
|
|
}()
|
|
}
|
|
ctx = templ.InitializeContext(ctx)
|
|
templ_7745c5c3_Var4 := templ.GetChildren(ctx)
|
|
if templ_7745c5c3_Var4 == nil {
|
|
templ_7745c5c3_Var4 = templ.NopComponent
|
|
}
|
|
ctx = templ.ClearChildren(ctx)
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "<script>\n function ThemeToggle() {\n return {\n darkMode: false,\n \n init() {\n // Check localStorage for \"darkMode\" first, then use system preference\n const stored = localStorage.getItem(\"darkMode\")\n if (stored !== null) {\n this.darkMode = stored === \"true\"\n } else {\n this.darkMode = window.matchMedia('(prefers-color-scheme: dark)').matches\n }\n\n // Apply theme immediately\n this.updateTheme()\n\n // Watch for changes\n this.$watch(\"darkMode\", () => {\n this.updateTheme()\n localStorage.setItem('darkMode', this.darkMode) \n })\n },\n\n toggle() {\n this.darkMode = !this.darkMode\n },\n\n updateTheme() {\n if (this.darkMode) {\n document.body.classList.add(\"dark\")\n } else {\n document.body.classList.remove(\"dark\")\n }\n }\n }\n }\n </script>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
var _ = templruntime.GeneratedTemplate
|