Skip to content

Commit

Permalink
refactor: rename Position to Placement
Browse files Browse the repository at this point in the history
  • Loading branch information
indaco committed May 5, 2024
1 parent bf8f69d commit 65c17d5
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion _examples/multiple-dropdowns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion _examples/positioning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 11 additions & 11 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -21,7 +21,7 @@ type ConfigMap struct {
func DefaultConfig() Config {
return Config{
Open: false,
Position: Bottom,
Placement: Bottom,
CloseOnOutsideClick: true,
Animation: true,
}
Expand All @@ -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
Expand All @@ -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),
Expand Down
10 changes: 5 additions & 5 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
14 changes: 7 additions & 7 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
2 changes: 1 addition & 1 deletion gropdown-css_templ.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions gropdown-js_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gropdown.templ
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ templ Root(id string) {
<div
id={ toSlug(fmt.Sprintf("gropdown-container-%s", id)) }
class="gdd_gropdown_container"
data-position={ getPositionAsStringFromContextById(ctx, id) }
data-position={ getPlacementAsStringFromContextById(ctx, id) }
>
{ children... }
</div>
Expand Down
4 changes: 2 additions & 2 deletions gropdown_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package gropdown

import "github.com/a-h/templ"

// Position represents a position on the screen.
type Position string
// Placement represents a position on the screen.
type Placement string

func (p Position) String() string {
func (p Placement) String() string {
return string(p)
}

Expand Down

0 comments on commit 65c17d5

Please sign in to comment.