-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
81 lines (68 loc) · 2.29 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package gropdown
// Config represents a dropdown menu component.
type Config struct {
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.
}
// ConfigBuilder 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,
Placement: Bottom,
CloseOnOutsideClick: true,
Animation: true,
}
}
// 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
}
// 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 auto close when a click occurs outside of it..
func (b *ConfigBuilder) WithCloseOnOutsideClick(close bool) *ConfigBuilder {
b.config.CloseOnOutsideClick = close
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) Build() Config {
return b.config
}
// NewConfigMap 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
}