-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: first step to new api, multiple components and simplified s…
…tyles
- Loading branch information
Showing
26 changed files
with
722 additions
and
1,248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package gropdown | ||
|
||
// Config represents a dropdown menu component. | ||
type Config struct { | ||
Open bool // Open indicates whether the dropdown menu is currently open. | ||
Animation bool // Animation indicates whether the dropdown button should use animations on open and close. | ||
Position Position // Position indicates the position of the dropdown content relative to the button. | ||
} | ||
|
||
// DropdownBuilder is used to construct Dropdown instances with options. | ||
type ConfigBuilder struct { | ||
config Config | ||
} | ||
|
||
type ConfigMap struct { | ||
Data map[string]Config | ||
} | ||
|
||
// DefaultConfig returns the default configuration. | ||
func DefaultConfig() Config { | ||
return Config{ | ||
Open: false, | ||
Animation: true, | ||
Position: Bottom, | ||
} | ||
} | ||
|
||
// NewConfigBuilder creates a new ConfigBuilder instance with default settings. | ||
func NewConfigBuilder() *ConfigBuilder { | ||
return &ConfigBuilder{ | ||
config: DefaultConfig(), | ||
} | ||
} | ||
|
||
// WithOpen sets the Open field of the dropdown. | ||
func (b *ConfigBuilder) WithOpen(open bool) *ConfigBuilder { | ||
b.config.Open = open | ||
return b | ||
} | ||
|
||
// WithAnimation sets the animations for the dropdown button icon when open/close. | ||
func (b *ConfigBuilder) WithAnimation(animation bool) *ConfigBuilder { | ||
b.config.Animation = animation | ||
return b | ||
} | ||
|
||
func (b *ConfigBuilder) WithPosition(position Position) *ConfigBuilder { | ||
b.config.Position = position | ||
return b | ||
} | ||
|
||
func (b *ConfigBuilder) Build() Config { | ||
return b.config | ||
} | ||
|
||
// Initialize a new ConfigMap instance | ||
func NewConfigMap() *ConfigMap { | ||
return &ConfigMap{ | ||
Data: make(map[string]Config), | ||
} | ||
} | ||
|
||
// Add adds a configuration to the map. | ||
func (m *ConfigMap) Add(key string, config Config) { | ||
m.Data[key] = config | ||
} | ||
|
||
// Get retrieves a configuration from the map. | ||
func (m *ConfigMap) Get(key string) (Config, bool) { | ||
config, ok := m.Data[key] | ||
return config, ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package gropdown | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// Define the context key type. | ||
type contextKey string | ||
|
||
// GetConfigMapFromContext retrieves the tab configuration from the context. | ||
func GetConfigMapFromContext(ctx context.Context) *ConfigMap { | ||
if opts, ok := ctx.Value(ConfigContextKey).(*ConfigMap); ok { | ||
return opts | ||
} | ||
return &ConfigMap{ | ||
Data: make(map[string]Config), | ||
} | ||
} | ||
|
||
// GetConfigFromContextById retrieves the tab configuration from the context. | ||
func GetConfigFromContextById(ctx context.Context, id string) *Config { | ||
if config, ok := GetConfigMapFromContext(ctx).Get(id); ok { | ||
return &config | ||
} | ||
return &Config{} | ||
} | ||
|
||
// getOpenFromContextById retrieves the configured tab position from the context. | ||
func getOpenFromContextById(ctx context.Context, id string) Position { | ||
if config, ok := GetConfigMapFromContext(ctx).Get(id); ok { | ||
return config.Position | ||
} | ||
return DefaultConfig().Position | ||
} | ||
|
||
// getOpenAsStringFromContextById retrieves the configured tab position from the context. | ||
func getOpenAsStringFromContextById(ctx context.Context, id string) string { | ||
return getOpenFromContextById(ctx, id).String() | ||
} | ||
|
||
// getAnimationFromContextById retrieves the configured tab position from the context. | ||
func getAnimationFromContextById(ctx context.Context, id string) Position { | ||
if config, ok := GetConfigMapFromContext(ctx).Get(id); ok { | ||
return config.Position | ||
} | ||
return DefaultConfig().Position | ||
} | ||
|
||
// getAnimationAsStringFromContextById retrieves the configured tab position from the context. | ||
func getAnimationAsStringFromContextById(ctx context.Context, id string) string { | ||
return getAnimationFromContextById(ctx, id).String() | ||
} | ||
|
||
// getPositionFromContextById retrieves the configured tab position from the context. | ||
func getPositionFromContextById(ctx context.Context, id string) Position { | ||
if config, ok := GetConfigMapFromContext(ctx).Get(id); ok { | ||
return config.Position | ||
} | ||
return DefaultConfig().Position | ||
} | ||
|
||
// getPositionAsStringFromContextById retrieves the configured tab position from the context. | ||
func getPositionAsStringFromContextById(ctx context.Context, id string) string { | ||
return getPositionFromContextById(ctx, id).String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.