diff --git a/_examples/multiple-dropdowns/main.go b/_examples/multiple-dropdowns/main.go index 01504f3..08e9e04 100644 --- a/_examples/multiple-dropdowns/main.go +++ b/_examples/multiple-dropdowns/main.go @@ -10,7 +10,7 @@ import ( ) func HandleHome(w http.ResponseWriter, r *http.Request) { - configOne := gropdown.NewConfigBuilder().WithPosition(gropdown.Top).Build() + configOne := gropdown.NewConfigBuilder().WithPlacement(gropdown.Top).Build() configTwo := gropdown.NewConfigBuilder().WithCloseOnOutsideClick(false).Build() configMap := gropdown.NewConfigMap() configMap.Add("menu-1", configOne) diff --git a/_examples/positioning/main.go b/_examples/positioning/main.go index 286501c..580fdce 100644 --- a/_examples/positioning/main.go +++ b/_examples/positioning/main.go @@ -10,7 +10,7 @@ import ( ) func HandleHome(w http.ResponseWriter, r *http.Request) { - config := gropdown.NewConfigBuilder().WithPosition(gropdown.Top).Build() + config := gropdown.NewConfigBuilder().WithPlacement(gropdown.Top).Build() configMap := gropdown.NewConfigMap() configMap.Add("demo", config) diff --git a/config.go b/config.go index 07cdf57..79ec931 100644 --- a/config.go +++ b/config.go @@ -2,13 +2,13 @@ package gropdown // Config represents a dropdown menu component. type Config struct { - Open bool // Open indicates whether the dropdown menu is currently open. - Position Position // Position indicates the position of the dropdown content relative to the button. - Animation bool // Animation indicates whether the dropdown button should use animations on open and close. - CloseOnOutsideClick bool // CloseOnOutsideClick indicates whether the dropdown should be closes when a click occurs outside of it. + Open bool // Open indicates whether the dropdown menu is currently open. + Placement Placement // Placement indicates the position of the dropdown content relative to the button. + Animation bool // Animation indicates whether the dropdown button should use animations on open and close. + CloseOnOutsideClick bool // CloseOnOutsideClick indicates whether the dropdown should be closed when a click occurs outside of it. } -// DropdownBuilder is used to construct Dropdown instances with options. +// ConfigBuilder is used to construct Dropdown instances with options. type ConfigBuilder struct { config Config } @@ -21,7 +21,7 @@ type ConfigMap struct { func DefaultConfig() Config { return Config{ Open: false, - Position: Bottom, + Placement: Bottom, CloseOnOutsideClick: true, Animation: true, } @@ -40,13 +40,13 @@ func (b *ConfigBuilder) WithOpen(open bool) *ConfigBuilder { return b } -// WithPosition sets the opening position fro the dropdown menu. -func (b *ConfigBuilder) WithPosition(position Position) *ConfigBuilder { - b.config.Position = position +// WithPlacement sets the opening position for the dropdown menu. +func (b *ConfigBuilder) WithPlacement(position Placement) *ConfigBuilder { + b.config.Placement = position return b } -// WithCloseOnOutsideClick sets whether or not auto close when a click occurs outside of it.. +// WithCloseOnOutsideClick sets whether auto close when a click occurs outside of it.. func (b *ConfigBuilder) WithCloseOnOutsideClick(close bool) *ConfigBuilder { b.config.CloseOnOutsideClick = close return b @@ -62,7 +62,7 @@ func (b *ConfigBuilder) Build() Config { return b.config } -// Initialize a new ConfigMap instance +// NewConfigMap initialize a new ConfigMap instance func NewConfigMap() *ConfigMap { return &ConfigMap{ Data: make(map[string]Config), diff --git a/constants.go b/constants.go index 834b455..b98d01f 100644 --- a/constants.go +++ b/constants.go @@ -3,10 +3,10 @@ package gropdown // ConfigContextKey is a context key for the dropdown component configurations. var ConfigContextKey = contextKey("gropdown-config-ctx") -// Position constants define where the dropdown content will appear on the screen. +// Placement constants define where the dropdown content will appear on the screen. const ( - Top Position = "top" - Right Position = "right" - Bottom Position = "bottom" - Left Position = "left" + Top Placement = "top" + Right Placement = "right" + Bottom Placement = "bottom" + Left Placement = "left" ) diff --git a/context.go b/context.go index fb989d1..7dbc333 100644 --- a/context.go +++ b/context.go @@ -25,15 +25,15 @@ func GetConfigFromContextById(ctx context.Context, id string) *Config { return &Config{} } -// getPositionFromContextById retrieves the configured tab position from the context. -func getPositionFromContextById(ctx context.Context, id string) Position { +// getPlacementFromContextById retrieves the configured tab position from the context. +func getPlacementFromContextById(ctx context.Context, id string) Placement { if config, ok := GetConfigMapFromContext(ctx).Get(id); ok { - return config.Position + return config.Placement } - return DefaultConfig().Position + return DefaultConfig().Placement } -// getPositionAsStringFromContextById retrieves the configured tab position from the context. -func getPositionAsStringFromContextById(ctx context.Context, id string) string { - return getPositionFromContextById(ctx, id).String() +// getPlacementAsStringFromContextById retrieves the configured tab position from the context. +func getPlacementAsStringFromContextById(ctx context.Context, id string) string { + return getPlacementFromContextById(ctx, id).String() } diff --git a/gropdown-css_templ.go b/gropdown-css_templ.go index f8628c3..395691c 100644 --- a/gropdown-css_templ.go +++ b/gropdown-css_templ.go @@ -23,7 +23,7 @@ func GropdownCSS() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/gropdown-js_templ.go b/gropdown-js_templ.go index dae2d3e..f14605b 100644 --- a/gropdown-js_templ.go +++ b/gropdown-js_templ.go @@ -9,8 +9,8 @@ import "github.com/a-h/templ" func GropdownJS(configMap *ConfigMap) templ.ComponentScript { return templ.ComponentScript{ - Name: `__templ_GropdownJS_3b6c`, - Function: `function __templ_GropdownJS_3b6c(configMap){// Utility function to check if a value is null or undefined + Name: `__templ_GropdownJS_e3ae`, + Function: `function __templ_GropdownJS_e3ae(configMap){// Utility function to check if a value is null or undefined function isNullish(value) { return value === null || value === undefined; } @@ -553,7 +553,7 @@ func GropdownJS(configMap *ConfigMap) templ.ComponentScript { }); }`, - Call: templ.SafeScript(`__templ_GropdownJS_3b6c`, configMap), - CallInline: templ.SafeScriptInline(`__templ_GropdownJS_3b6c`, configMap), + Call: templ.SafeScript(`__templ_GropdownJS_e3ae`, configMap), + CallInline: templ.SafeScriptInline(`__templ_GropdownJS_e3ae`, configMap), } } diff --git a/gropdown.templ b/gropdown.templ index 02f180e..d8a8dc2 100644 --- a/gropdown.templ +++ b/gropdown.templ @@ -6,7 +6,7 @@ templ Root(id string) {