Skip to content

Commit

Permalink
feat: add error toast component
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Aug 15, 2024
1 parent e5bd03e commit 069207d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
15 changes: 15 additions & 0 deletions components/toasts/toasts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package toasts
import (
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/fiber-htmx/components/buttons"
"github.com/zeiss/pkg/errorx"
)

// ToastProps contains the properties for the toast component.
Expand All @@ -27,6 +28,20 @@ func Toast(p ToastProps, children ...htmx.Node) htmx.Node {
)
}

// Error is a component for the htmx toast extension.
func Error(props ToastsProps, err error) htmx.Node {
return htmx.If(
!errorx.Empty(err),
Toasts(
props,
ToastAlertError(
ToastProps{},
htmx.Text(err.Error()),
),
),
)
}

// ToastTopToastStart is a component for the htmx toast extension.
func ToastTopStart(props ToastProps, children ...htmx.Node) htmx.Node {
return htmx.Div(
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/yuin/goldmark v1.7.4
github.com/zeiss/fiber-authz v1.0.33
github.com/zeiss/fiber-goth v1.2.11
github.com/zeiss/pkg v0.1.7
github.com/zeiss/pkg v0.1.8-0.20240815072411-0766eb97f92e
gorm.io/gorm v1.25.11
mvdan.cc/gofumpt v0.6.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ github.com/zeiss/fiber-authz v1.0.33 h1:KZnVTxG+VoQLowoCqoMwam/5H4PVu89rn9ZJ2AGO
github.com/zeiss/fiber-authz v1.0.33/go.mod h1:oVkhY0X9/xFa0Pu3BuEU8ubE7pAQmIjFMUwUGD2pQqc=
github.com/zeiss/fiber-goth v1.2.11 h1:24EiIKF1iPrmlspbW/BylcqVyj4Ltwzmx9DM7pRs6R4=
github.com/zeiss/fiber-goth v1.2.11/go.mod h1:9NuXxIeKZgmk3dfl7HWbZK/eAfukvjMCHHacGo0m84Y=
github.com/zeiss/pkg v0.1.7 h1:P+kCMcZy/I7JgnXGWv/oidhj/47klSqk7xtF2/t02yc=
github.com/zeiss/pkg v0.1.7/go.mod h1:XQjoOM7oJAp065CC4Cd5lD2AXZ51cL9nYrNjs7mDmI4=
github.com/zeiss/pkg v0.1.8-0.20240815072411-0766eb97f92e h1:68fdAVp900gHeHAmC5QVOe9ft1o0t7q7X4w+T44Woxg=
github.com/zeiss/pkg v0.1.8-0.20240815072411-0766eb97f92e/go.mod h1:/AxmePnZ3bS4RtejU3NSHtG6DdIXkReaea8+wv0wY7o=
gitlab.com/bosi/decorder v0.4.2 h1:qbQaV3zgwnBZ4zPMhGLW4KZe7A7NwxEhJx39R3shffo=
gitlab.com/bosi/decorder v0.4.2/go.mod h1:muuhHoaJkA9QLcYHq4Mj8FJUwDZ+EirSHRiaTcTf6T8=
go-simpler.org/assert v0.9.0 h1:PfpmcSvL7yAnWyChSjOz6Sp6m9j5lyK8Ok9pEL31YkQ=
Expand Down

0 comments on commit 069207d

Please sign in to comment.