coveragebook_components 0.8.9 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/build/coco/app.css +255 -242
  3. data/app/assets/build/coco/app.js +71 -39
  4. data/app/assets/build/coco/book.css +23 -16
  5. data/app/assets/build/coco/book.js +50 -21
  6. data/app/assets/js/libs/alpine/directives/dropdown.js +5 -2
  7. data/app/components/coco/app/elements/alert/alert.css +1 -1
  8. data/app/components/coco/app/elements/button/button.css +38 -58
  9. data/app/components/coco/app/elements/button/button.rb +2 -3
  10. data/app/components/coco/app/elements/button_group/button_group.css +10 -2
  11. data/app/components/coco/app/elements/button_group/button_group.html.erb +2 -1
  12. data/app/components/coco/app/elements/button_group/button_group.js +35 -19
  13. data/app/components/coco/app/elements/button_to/button_to.css +4 -8
  14. data/app/components/coco/app/elements/color_picker_button/color_picker_button.css +1 -2
  15. data/app/components/coco/app/elements/image_picker_button/image_picker_button.css +1 -2
  16. data/app/components/coco/app/elements/layout_picker_button/layout_picker_button.css +1 -2
  17. data/app/components/coco/app/elements/menu/menu.css +7 -5
  18. data/app/components/coco/app/elements/menu_button/menu_button.css +1 -2
  19. data/app/components/coco/app/elements/snackbar/snackbar.css +3 -3
  20. data/app/components/coco/base/button/button.css +9 -9
  21. data/app/components/coco/base/button/button.html.erb +16 -18
  22. data/app/components/coco/base/button/button.js +6 -18
  23. data/app/components/coco/base/button/button.rb +38 -58
  24. data/app/components/coco/base/button/button_dropdown.js +27 -0
  25. data/lib/coco.rb +1 -1
  26. metadata +3 -6
  27. data/app/assets/build/coco/app.dev.css +0 -5535
  28. data/app/assets/build/coco/app.dev.js +0 -27473
  29. data/app/assets/build/coco/book.dev.css +0 -2009
  30. data/app/assets/build/coco/book.dev.js +0 -15801
@@ -16,10 +16,7 @@ module Coco
16
16
 
17
17
  DEFAULT_THEME = nil
18
18
 
19
- BUTTON_ATTRS = %i[type value name disabled href target]
20
-
21
- tag_name :button
22
- tag_attr(*BUTTON_ATTRS)
19
+ tag_attr :type, :value, :name, :disabled, :href, :target
23
20
 
24
21
  accepts_option :disabled, from: [true, false]
25
22
  accepts_option :confirm, from: [true, false, nil], default: nil
@@ -58,34 +55,22 @@ module Coco
58
55
  set_option_value(:state, "active")
59
56
  end
60
57
 
61
- @button_attrs = tag_attrs.slice(*BUTTON_ATTRS).merge(@button_element_attrs)
62
- tag_attrs.except!(*BUTTON_ATTRS)
63
-
64
- if disabled?
65
- button_attrs[:disabled] = true
66
- end
67
-
68
- if dropdown?
69
- set_option_value(:dropdown, :placement, "bottom-start") unless get_option(:dropdown, :placement).present?
70
- end
58
+ set_tag_attr(:disabled, true) if disabled?
59
+ set_tag_attr(:type, "button") unless tag_attr?(:type) || link?
71
60
 
72
- unless button_attrs[:type] || link?
73
- button_attrs[:type] = "button"
61
+ if dropdown? || confirm? && get_option(:dropdown, :placement).blank?
62
+ set_option_value(:dropdown, :placement, "bottom-start")
74
63
  end
75
64
  end
76
65
 
77
- attr_reader :on_click, :resize, :button_attrs
66
+ attr_reader :on_click, :resize
78
67
 
79
- def initialize(click: nil, resize: nil, states: nil, loading: false, active: false, button_element: {}, **kwargs)
68
+ def initialize(click: nil, resize: nil, states: nil, loading: false, active: false, tooltip: nil, **kwargs)
80
69
  @on_click = click
81
70
  @resize = resize.to_h
82
71
  @states = states.to_h
83
72
  @loading = loading
84
73
  @active = active
85
- @alpine_data = {}
86
- @button_element_attrs = button_element
87
-
88
- super(**kwargs)
89
74
  end
90
75
 
91
76
  def toggle?
@@ -96,8 +81,8 @@ module Coco
96
81
  get_option_value(:toggle)
97
82
  end
98
83
 
99
- def button_tag_name
100
- button_attrs[:href].present? ? :a : :button
84
+ def button_tag
85
+ tag_attr(:href).present? ? :a : :button
101
86
  end
102
87
 
103
88
  def button_text
@@ -121,11 +106,11 @@ module Coco
121
106
  end
122
107
 
123
108
  def link?
124
- button_tag_name == :a
109
+ button_tag == :a
125
110
  end
126
111
 
127
112
  def button?
128
- button_tag_name == :button
113
+ button_tag == :button
129
114
  end
130
115
 
131
116
  def icon_only?
@@ -136,25 +121,17 @@ module Coco
136
121
  false
137
122
  end
138
123
 
139
- def dropdown_opts
140
- if dropdown?
141
- jsify_data({
142
- appendTo: "parent",
143
- offset: [0, 1],
144
- placement: get_option_value(:dropdown, :placement)
145
- }.compact)
146
- end
147
- end
148
-
149
- def component_classes
150
- [
151
- "coco-button",
152
- tag_attrs[:class],
124
+ def alpine_wrapper_attrs
125
+ if dropdown? || confirm?
153
126
  {
154
- "icon-only": icon_only?,
155
- "with-icon": (icon? && !icon_only?)
127
+ data: x_data("buttonDropdown"),
128
+ dropdown: jsify_data({offset: [0, 1], placement: get_option_value(:dropdown, :placement)}.compact),
129
+ "@dropdown:show": ("button.setState('active')" if dropdown?),
130
+ "@dropdown:hide": ("button.resetState()" if dropdown?),
131
+ "@confirmation:confirm": ("button.approveAndRun($event)" if confirm?),
132
+ "@confirmation:cancel": ("button.cancelConfirmation($event)" if confirm?)
156
133
  }
157
- ]
134
+ end
158
135
  end
159
136
 
160
137
  def states
@@ -188,23 +165,26 @@ module Coco
188
165
  private
189
166
 
190
167
  def default_states
191
- states = {
192
- default: {
193
- text: button_text,
194
- icon: icon,
195
- tooltip: get_option_value(:tooltip, :content)
196
- }
197
- }
168
+ {
169
+ default: default_state,
170
+ loading: (loading_state if @states&.key?(:loading))
171
+ }.compact
172
+ end
198
173
 
199
- if @states.key?(:loading)
200
- states[:loading] = {
201
- text: "Loading...",
202
- icon: :loader_2,
203
- tooltip: nil
204
- }
205
- end
174
+ def default_state
175
+ {
176
+ text: button_text,
177
+ icon: icon,
178
+ tooltip: get_option_value(:tooltip, :content)
179
+ }
180
+ end
206
181
 
207
- states
182
+ def loading_state
183
+ {
184
+ text: "Loading...",
185
+ icon: :loader_2,
186
+ tooltip: nil
187
+ }
208
188
  end
209
189
 
210
190
  def render_icon(icon)
@@ -0,0 +1,27 @@
1
+ import { CocoComponent } from "@js/coco.js";
2
+ import { getComponent } from "@helpers/alpine";
3
+
4
+ export default CocoComponent("buttonDropdown", (data = {}) => {
5
+ return {
6
+ dropdown: null,
7
+ button: null,
8
+
9
+ init() {
10
+ this.$nextTick(() => {
11
+ this.button = getComponent(this.$el.querySelector(".coco-button"));
12
+ });
13
+ },
14
+
15
+ hideDropdown() {
16
+ if (this.dropdown) {
17
+ this.dropdown.hide();
18
+ }
19
+ },
20
+
21
+ showDropdown() {
22
+ if (this.dropdown) {
23
+ this.dropdown.show();
24
+ }
25
+ },
26
+ };
27
+ });
data/lib/coco.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Coco
2
- VERSION = "0.8.9"
2
+ VERSION = "0.9.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coveragebook_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.9
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Perkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-17 00:00:00.000000000 Z
11
+ date: 2023-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -74,12 +74,8 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - app/assets/build/coco/app.css
77
- - app/assets/build/coco/app.dev.css
78
- - app/assets/build/coco/app.dev.js
79
77
  - app/assets/build/coco/app.js
80
78
  - app/assets/build/coco/book.css
81
- - app/assets/build/coco/book.dev.css
82
- - app/assets/build/coco/book.dev.js
83
79
  - app/assets/build/coco/book.js
84
80
  - app/assets/build/coco/icons/accessibility.svg
85
81
  - app/assets/build/coco/icons/activity-square.svg
@@ -1622,6 +1618,7 @@ files:
1622
1618
  - app/components/coco/base/button/button.html.erb
1623
1619
  - app/components/coco/base/button/button.js
1624
1620
  - app/components/coco/base/button/button.rb
1621
+ - app/components/coco/base/button/button_dropdown.js
1625
1622
  - app/components/coco/base/content/content.rb
1626
1623
  - app/components/coco/base/dropdown/dropdown.css
1627
1624
  - app/components/coco/base/dropdown/dropdown.html.erb