Skip to content

Commit f6c65b6

Browse files
committed
refactor: update toast notification constants for clarity and add icons.go
1 parent 1962337 commit f6c65b6

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

constants.go

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package goaster
22

3-
// Constants for different levels of toast notifications.
3+
// Predefined toast levels
44
const (
55
DefaultLevel Level = "default"
66
SuccessLevel Level = "success"
@@ -9,29 +9,19 @@ const (
99
InfoLevel Level = "info"
1010
)
1111

12-
// Default SVG icons for each level of toast notifications.
13-
// These are inline SVGs for default icons, which can be replaced by the user.
12+
// Predefined toast positions
1413
const (
15-
defaultDefaultIcon = `<svg xmlns="http://www.w3.org/2000/svg" style="stroke: currentColor;" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>`
16-
defaultSuccessIcon = `<svg xmlns="http://www.w3.org/2000/svg" style="stroke: currentColor;" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>`
17-
defaultErrorIcon = `<svg xmlns="http://www.w3.org/2000/svg" style="stroke: currentColor;" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>`
18-
defaultWarningIcon = `<svg xmlns="http://www.w3.org/2000/svg" style="stroke: currentColor;" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path></svg>`
19-
defaultInfoIcon = `<svg xmlns="http://www.w3.org/2000/svg" style="stroke: currentColor;" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>`
14+
TopRight = Position("top-right")
15+
TopLeft = Position("top-left")
16+
TopCenter = Position("top-center")
17+
BottomRight = Position("bottom-right")
18+
BottomLeft = Position("bottom-left")
19+
BottomCenter = Position("bottom-center")
2020
)
2121

22-
// Position constants define where the toast will appear on the screen.
23-
var (
24-
TopRight = Position{Name: "top-right", CSS: gttContainerTopRight()}
25-
TopLeft = Position{Name: "top-left", CSS: gttContainerTopLeft()}
26-
TopCenter = Position{Name: "top-center", CSS: gttContainerTopCenter()}
27-
BottomRight = Position{Name: "bottom-right", CSS: gttContainerBottomRight()}
28-
BottomLeft = Position{Name: "bottom-left", CSS: gttContainerBottomLeft()}
29-
BottomCenter = Position{Name: "bottom-center", CSS: gttContainerBottomCenter()}
30-
)
31-
32-
// Variant constants define the style variant to be used for the toast.
22+
// Predefined style variants
3323
const (
34-
Accent = "accent"
35-
AccentLight = "accent_light"
36-
AccentDark = "accent_dark"
24+
Accent = Variant("accent")
25+
AccentLight = Variant("accent_light")
26+
AccentDark = Variant("accent_dark")
3727
)

icons.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package goaster
2+
3+
// Inline SVGs for default toast icons
4+
const (
5+
defaultIconDefault = `<svg xmlns="http://www.w3.org/2000/svg" style="stroke: currentColor;" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>`
6+
defaultIconSuccess = `<svg xmlns="http://www.w3.org/2000/svg" style="stroke: currentColor;" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>`
7+
defaultIconError = `<svg xmlns="http://www.w3.org/2000/svg" style="stroke: currentColor;" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>`
8+
defaultIconWarning = `<svg xmlns="http://www.w3.org/2000/svg" style="stroke: currentColor;" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path></svg>`
9+
defaultIconInfo = `<svg xmlns="http://www.w3.org/2000/svg" style="stroke: currentColor;" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>`
10+
)
11+
12+
// defaultIcons returns a map of default SVG icons for each toast level.
13+
func defaultIcons() map[Level]string {
14+
return map[Level]string{
15+
DefaultLevel: defaultIconDefault,
16+
SuccessLevel: defaultIconSuccess,
17+
ErrorLevel: defaultIconError,
18+
WarningLevel: defaultIconWarning,
19+
InfoLevel: defaultIconInfo,
20+
}
21+
}

0 commit comments

Comments
 (0)