(DOC): Updated documentation

This commit is contained in:
Hayden Hargreaves 2025-09-03 22:25:13 -07:00
parent 47b8386844
commit 6b030adf02
2 changed files with 37 additions and 41 deletions

View File

@ -3,39 +3,27 @@ package components
import "github.com/gin-gonic/gin" import "github.com/gin-gonic/gin"
templ errorIcon() { templ errorIcon() {
<svg class="h-6 text-red-500" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg class="h-6 text-red-500" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path <path
d="M12 16.99V17M12 7V14M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12Z" d="M12 16.99V17M12 7V14M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12Z"
stroke="currentColor" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
stroke-width="1.5" </svg>
stroke-linecap="round"
stroke-linejoin="round"
></path>
</svg>
} }
templ closeButton() { templ closeButton() {
<button <button onclick="hideError();"
onclick="hideError();" class="text-red-500 ml-auto hover:bg-red-200 p-1 rounded-sm transition-all duration-300 cursor-pointer">
class="text-red-500 ml-auto hover:bg-red-200 p-1 rounded-sm transition-all duration-300 cursor-pointer"
>
<svg class="h-4" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg class="h-4" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path <path fill-rule="evenodd" clip-rule="evenodd"
fill-rule="evenodd"
clip-rule="evenodd"
d="M19.207 6.207a1 1 0 0 0-1.414-1.414L12 10.586 6.207 4.793a1 1 0 0 0-1.414 1.414L10.586 12l-5.793 5.793a1 1 0 1 0 1.414 1.414L12 13.414l5.793 5.793a1 1 0 0 0 1.414-1.414L13.414 12l5.793-5.793z" d="M19.207 6.207a1 1 0 0 0-1.414-1.414L12 10.586 6.207 4.793a1 1 0 0 0-1.414 1.414L10.586 12l-5.793 5.793a1 1 0 1 0 1.414 1.414L12 13.414l5.793 5.793a1 1 0 0 0 1.414-1.414L13.414 12l5.793-5.793z"
fill="currentColor" fill="currentColor"></path>
></path>
</svg> </svg>
</button> </button>
} }
templ errorBanner(message string) { templ errorBanner(message string) {
<div <div id="error-toast" hx-swap-oob="outerHTML"
id="error-toast" class="fixed z-20 border border-red-500 rounded-sm right-0 top-0 m-4 p-4 bg-red-100 shadow shadow-red-200 transition-all duration-300 text-sm md:w-1/3">
hx-swap-oob="outerHTML"
class="fixed z-20 border border-red-500 rounded-sm right-0 top-0 m-4 p-4 bg-red-100 shadow shadow-red-200 transition-all duration-300 text-sm md:w-1/3"
>
<div class="flex items-center gap-x-2 pb-1"> <div class="flex items-center gap-x-2 pb-1">
@errorIcon() @errorIcon()
<h1 class="text-red-500 font-semibold">Error</h1> <h1 class="text-red-500 font-semibold">Error</h1>
@ -46,13 +34,17 @@ templ errorBanner(message string) {
{ message } { message }
</p> </p>
</div> </div>
</div> </div>
} }
// RenderErrorBanner renders the error banner. However, this function must ONLY be called by an // RenderErrorBanner renders the error banner. However, this function must ONLY be called by an
// HTMX route. Otherwise, there is no promise it will work (may result in undefined behavior). // HTMX route. Otherwise, there is no promise it will work (may result in undefined behavior).
// Just writes a piece of content to the response. // Just writes a piece of content to the response.
//
// If this is called from an NON-HTMX request, it will display (and functionality seems to work)
// but it will be loaded at an unknown position in the DOM. It will not swap with the proper
// element.
func RenderErrorBanner(ctx *gin.Context, message string) { func RenderErrorBanner(ctx *gin.Context, message string) {
ctx.Writer.Header().Set("Content-Type", "text/html") ctx.Writer.Header().Set("Content-Type", "text/html")
errorBanner(message).Render(ctx.Request.Context(), ctx.Writer) errorBanner(message).Render(ctx.Request.Context(), ctx.Writer)
} }

View File

@ -112,7 +112,7 @@ func errorBanner(message string) templ.Component {
var templ_7745c5c3_Var4 string var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(message) templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(message)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/components/error.templ`, Line: 46, Col: 13} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/components/error.templ`, Line: 34, Col: 15}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
@ -129,6 +129,10 @@ func errorBanner(message string) templ.Component {
// RenderErrorBanner renders the error banner. However, this function must ONLY be called by an // RenderErrorBanner renders the error banner. However, this function must ONLY be called by an
// HTMX route. Otherwise, there is no promise it will work (may result in undefined behavior). // HTMX route. Otherwise, there is no promise it will work (may result in undefined behavior).
// Just writes a piece of content to the response. // Just writes a piece of content to the response.
//
// If this is called from an NON-HTMX request, it will display (and functionality seems to work)
// but it will be loaded at an unknown position in the DOM. It will not swap with the proper
// element.
func RenderErrorBanner(ctx *gin.Context, message string) { func RenderErrorBanner(ctx *gin.Context, message string) {
ctx.Writer.Header().Set("Content-Type", "text/html") ctx.Writer.Header().Set("Content-Type", "text/html")
errorBanner(message).Render(ctx.Request.Context(), ctx.Writer) errorBanner(message).Render(ctx.Request.Context(), ctx.Writer)