ariadne_view_components 0.0.12-arm64-darwin → 0.0.13-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/ariadne.d.ts +1 -0
  3. data/app/assets/javascripts/ariadne_view_components.js +2 -2
  4. data/app/assets/javascripts/ariadne_view_components.js.map +1 -1
  5. data/app/assets/javascripts/tab-container-component.d.ts +1 -0
  6. data/app/assets/javascripts/tab-nav-component.d.ts +9 -0
  7. data/app/components/ariadne/ariadne.ts +3 -0
  8. data/app/components/ariadne/body_component.rb +1 -1
  9. data/app/components/ariadne/button_component.rb +2 -2
  10. data/app/components/ariadne/comment_component.html.erb +2 -6
  11. data/app/components/ariadne/comment_component.rb +1 -1
  12. data/app/components/ariadne/component.rb +3 -5
  13. data/app/components/ariadne/container_component.rb +1 -1
  14. data/app/components/ariadne/counter_component.rb +1 -1
  15. data/app/components/ariadne/flash_component.rb +1 -1
  16. data/app/components/ariadne/flex_component.rb +1 -1
  17. data/app/components/ariadne/footer_component.rb +1 -1
  18. data/app/components/ariadne/grid_component.html.erb +2 -2
  19. data/app/components/ariadne/grid_component.rb +10 -8
  20. data/app/components/ariadne/header_component.rb +1 -1
  21. data/app/components/ariadne/heroicon_component.html.erb +1 -1
  22. data/app/components/ariadne/heroicon_component.rb +1 -2
  23. data/app/components/ariadne/list_component.html.erb +3 -5
  24. data/app/components/ariadne/list_component.rb +5 -5
  25. data/app/components/ariadne/main_component.rb +1 -1
  26. data/app/components/ariadne/narrow_container_component.rb +1 -1
  27. data/app/components/ariadne/panel_bar_component.rb +2 -2
  28. data/app/components/ariadne/pill_component.rb +1 -1
  29. data/app/components/ariadne/rich_text_area_component.html.erb +1 -1
  30. data/app/components/ariadne/rich_text_area_component.rb +1 -1
  31. data/app/components/ariadne/slideover_component.rb +2 -2
  32. data/app/components/ariadne/tab-container-component.ts +24 -0
  33. data/app/components/ariadne/tab-nav-component.ts +34 -0
  34. data/app/components/ariadne/tab_component.html.erb +2 -6
  35. data/app/components/ariadne/tab_component.rb +77 -18
  36. data/app/components/ariadne/tab_container_component.erb +12 -0
  37. data/app/components/ariadne/tab_container_component.rb +61 -0
  38. data/app/components/ariadne/tab_nav_component.html.erb +7 -0
  39. data/app/components/ariadne/tab_nav_component.rb +72 -0
  40. data/app/components/ariadne/table_component.html.erb +17 -0
  41. data/app/components/ariadne/table_component.rb +281 -0
  42. data/app/components/ariadne/time_ago_component.rb +1 -1
  43. data/app/components/ariadne/timeline_component.rb +1 -1
  44. data/app/lib/ariadne/fetch_or_fallback_helper.rb +11 -3
  45. data/app/lib/ariadne/icon_helper.rb +17 -13
  46. data/lib/ariadne/view_components/constants.rb +2 -2
  47. data/lib/ariadne/view_components/statuses.rb +2 -2
  48. data/lib/ariadne/view_components/version.rb +1 -1
  49. data/lib/rubocop/config/default.yml +1 -1
  50. data/lib/tasks/docs.rake +5 -96
  51. data/static/arguments.yml +51 -15
  52. data/static/audited_at.json +9 -1
  53. data/static/classes.yml +157 -269
  54. data/static/constants.json +55 -15
  55. data/static/statuses.json +9 -1
  56. data/tailwind.config.js +11 -26
  57. metadata +13 -10
  58. data/app/components/ariadne/tab_bar_component.html.erb +0 -3
  59. data/app/components/ariadne/tab_bar_component.rb +0 -45
  60. data/app/lib/ariadne/join_style_arguments_helper.rb +0 -14
  61. data/app/lib/ariadne/tab_nav_helper.rb +0 -35
  62. data/app/lib/ariadne/tabbed_component_helper.rb +0 -39
  63. data/app/lib/ariadne/test_selector_helper.rb +0 -20
  64. data/app/lib/ariadne/underline_nav_helper.rb +0 -44
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ # A container for a row of tags. Keyboard support is provided.
5
+ # @accessibility This component requires you to pass in a `sr_label`
6
+ # attribute, which will be used to label the tabs for screen readers.
7
+ class TabContainerComponent < Ariadne::Component
8
+ DEFAULT_TAG = :"tab-container"
9
+
10
+ DEFAULT_CLASSES = ""
11
+
12
+ # Tabs and panels to be rendered.
13
+ #
14
+ # @param id [String] The unique ID of the tab.
15
+ # @param selected [Boolean] Whether the tab is selected.
16
+ # @param classes [String] <%= link_to_classes_docs %>
17
+ # @param attributes [Hash] <%= link_to_attributes_docs %>
18
+ renders_many :tabs, lambda { |id:, selected: false, href: "", classes: "", attributes: {}|
19
+ actual_classes = class_names(selected ? DEFAULT_SELECTED_CLASSES : DEFAULT_UNSELECTED_CLASSES, classes)
20
+ Ariadne::TabComponent.new(
21
+ id: id,
22
+ selected: selected,
23
+ href: href,
24
+ with_panel: true,
25
+
26
+ classes: actual_classes,
27
+ attributes: attributes,
28
+ )
29
+ }
30
+
31
+ # @example Default
32
+ #
33
+ # <%= render(Ariadne::TabContainerComponent.new(sr_label: "Comments")) do |tab_container| %>
34
+ # <%= render(Ariadne::TabComponent.new(id: "pub-comment")) do |tab| %>
35
+ # <% tab.text { "Tab 1" } %>
36
+ # <% tab.panel { "Panel 1" } %>
37
+ # <% end %>
38
+ # <%= render(Ariadne::TabComponent.new(id: "pub-comment")) do |tab| %>
39
+ # <% tab.text { "Tab 2" } %>
40
+ # <% tab.panel { "Panel 2" } %>
41
+ # <% end %>
42
+ # <% end %>
43
+ #
44
+ # %>
45
+ #
46
+ # @param sr_label [String] Sets an `aria-label` that helps assistive technology users understand the purpose of the tabs.
47
+ # @param classes [String] <%= link_to_classes_docs %>
48
+ # @param attributes [Hash] <%= link_to_attributes_docs %>
49
+ def initialize(sr_label:, classes: "", attributes: {})
50
+ @tag = DEFAULT_TAG
51
+ @classes = class_names(
52
+ DEFAULT_CLASSES,
53
+ classes,
54
+ )
55
+
56
+ @attributes = attributes
57
+ @attributes[:"aria-label"] = sr_label
58
+ @attributes[:role] = :presentation
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,7 @@
1
+ <%= render Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes) do |component| %>
2
+ <ul class="ariadne-list-none">
3
+ <% tabs.each do |tab| %>
4
+ <li class="inline-flex"><%= tab %></li>
5
+ <% end %>
6
+ </ul>
7
+ <% end %>
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ # Use `TabNavComponent` to style navigation links, typically placed at the top
5
+ # of the page.
6
+ #
7
+ # For panel navigation, use <%= link_to_component(Ariadne::TabContainerComponent) %> instead.
8
+ #
9
+ # @accessibility
10
+ # - By default, `TabNavComponent` renders links within a `<nav>` element. `<nav>` has an
11
+ # implicit landmark role of `navigation` which should be reserved for main links.
12
+ # For all other set of links, set tag to `:div`.
13
+ # - See <%= link_to_component(Ariadne::TabComponent) %> for additional
14
+ # accessibility considerations.
15
+ class TabNavComponent < Ariadne::Component
16
+ DEFAULT_TAG = :nav
17
+ TAG_OPTIONS = [DEFAULT_TAG, :div].freeze
18
+
19
+ BODY_TAG_DEFAULT = :ul
20
+
21
+ # keep this consistent with tab-container-component.ts
22
+ SELECTED_CLASSES = "ariadne-border-indigo-500 ariadne-text-indigo-600"
23
+ UNSELECTED_CLASSES = "ariadne-text-gray-500 hover:ariadne-text-gray-700 hover:ariadne-border-gray-300"
24
+
25
+ DEFAULT_CLASSES = ""
26
+
27
+ # Tabs to be rendered. Use the tabs to list page links.
28
+ #
29
+ # @param selected [Boolean] Whether the tab is selected.
30
+ # @param classes [String] <%= link_to_classes_docs %>
31
+ # @param attributes [Hash] <%= link_to_attributes_docs %>
32
+ renders_many :tabs, lambda { |selected: false, href: "", classes: "", attributes: {}|
33
+ attributes[:href] = href
34
+ attributes[:"data-tab-nav-component-target"] = "tab"
35
+ attributes[:"data-action"] = "click->tab-nav-component#toggle"
36
+
37
+ actual_classes = class_names(selected ? SELECTED_CLASSES : UNSELECTED_CLASSES, classes)
38
+ Ariadne::TabComponent.new(
39
+ selected: selected,
40
+
41
+ classes: actual_classes,
42
+ attributes: attributes,
43
+ )
44
+ }
45
+
46
+ # @example Default with `<nav>`
47
+ # @description
48
+ # `<nav>` is a landmark and should be reserved for main navigation links. See <%= link_to_accessibility %>.
49
+ # @code
50
+ # <%= render(Ariadne::TabNavComponent.new(label: "Nav")) do |c| %>
51
+ # <% c.tab(selected: true, href: "#") { "Tab 1" } %>
52
+ # <% c.tab(href: "#") { "Tab 2" } %>
53
+ # <% c.tab(href: "#") { "Tab 3" } %>
54
+ # <% end %>
55
+ #
56
+ # @param label [String] Sets an `aria-label` that helps assistive technology users understand the purpose of the links, and distinguish it from similar elements.
57
+ # @param tag [Symbol, String] The rendered tag name.
58
+ # @param classes [String] <%= link_to_classes_docs %>
59
+ # @param attributes [Hash] <%= link_to_attributes_docs %>
60
+ def initialize(label:, tag: DEFAULT_TAG, classes: "", attributes: {})
61
+ @tag = check_incoming_tag(DEFAULT_TAG, tag)
62
+ @classes = class_names(
63
+ DEFAULT_CLASSES,
64
+ classes,
65
+ )
66
+
67
+ @attributes = attributes
68
+ @attributes[:"aria-label"] = label
69
+ @attributes[:"data-controller"] = "tab-nav-component"
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,17 @@
1
+ <div class="ariadne-inline-block ariadne-min-w-full ariadne-py-2 ariadne-align-middle md:ariadne-px-6 lg:ariadne-px-8">
2
+ <div class="ariadne-overflow-hidden ariadne-shadow ariadne-ring-1 ariadne-ring-black ariadne-ring-opacity-5 md:ariadne-rounded-lg">
3
+ <%= render Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes) do |component| %>
4
+ <% if has_header_row? %>
5
+ <%= header_row %>
6
+ <% end %>
7
+ <ul class="ariadne-divide-y ariadne-divide-gray-200 ariadne-bg-white">
8
+ <% rows.each do |row| %>
9
+ <%= row %>
10
+ <% end %>
11
+ </ul>
12
+ <% end %>
13
+ </div>
14
+ <% if has_footer? %>
15
+ <%= footer %>
16
+ <% end %>
17
+ </div>
@@ -0,0 +1,281 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ # Add a general description of component here
5
+ # Add additional usage considerations or best practices that may aid the user to use the component correctly.
6
+ # @accessibility Add any accessibility considerations
7
+ class TableComponent < Ariadne::Component
8
+ DEFAULT_CLASSES = "ariadne-min-w-full ariadne-divide-y ariadne-divide-gray-300 flex flex-col"
9
+
10
+ renders_one :header_row, "HeaderRowItem"
11
+
12
+ renders_many :rows, "RowItem"
13
+
14
+ renders_one :footer, "FooterItem"
15
+
16
+ # @example Default
17
+ #
18
+ # <%= render(Ariadne::TableComponent.new) do |table| %>
19
+ # <%= table.header_row do |header_row| %>
20
+ # <% header_row.cell do %>
21
+ # State
22
+ # <% end %>
23
+ # <% end %>
24
+ # <%= table.row do |row| %>
25
+ # <% row.cell do %>
26
+ # "California"
27
+ # <% end %>
28
+ # <% end %>
29
+ # <%= table.row do |row| %>
30
+ # <% row.cell do %>
31
+ # "New York"
32
+ # <% end %>
33
+ # <% end %>
34
+ # <%= table.row do |row| %>
35
+ # <% row.cell do %>
36
+ # "Texas"
37
+ # <% end %>
38
+ # <% end %>
39
+ # <% end %>
40
+ # @param classes [String] <%= link_to_classes_docs %>
41
+ # @param attributes [Hash] <%= link_to_attributes_docs %>
42
+ def initialize(classes: "", attributes: {})
43
+ @tag = :div
44
+ @classes = class_names(
45
+ DEFAULT_CLASSES,
46
+ classes,
47
+ )
48
+
49
+ @attributes = attributes
50
+ end
51
+
52
+ def has_header_row?
53
+ header_row.present?
54
+ end
55
+
56
+ def has_footer?
57
+ footer.present?
58
+ end
59
+
60
+ # This component is part of `TableComponent` and should not be
61
+ # used as a standalone component.
62
+ class RowItem < Ariadne::Component
63
+ DEFAULT_ROW_CLASSES = "ariadne-whitespace-nowrap ariadne-py-4 ariadne-pl-4 ariadne-pr-3 ariadne-text-sm sm:ariadne-pl-6 flex flex-row"
64
+
65
+ renders_many :cells, lambda { |classes: "", attributes: {}|
66
+ if @header
67
+ Ariadne::TableComponent::RowItem::HeaderCellItem.new(classes: classes, attributes: attributes)
68
+ else
69
+ Ariadne::TableComponent::RowItem::CellItem.new(classes: classes, attributes: attributes)
70
+ end
71
+ }
72
+
73
+ # @param link [Hash] #TODO: link attributes
74
+ def initialize(link: "", classes: "", attributes: {})
75
+ @header = false
76
+ @link = link
77
+
78
+ @classes = if @link.present?
79
+ class_names(
80
+ DEFAULT_ROW_CLASSES,
81
+ "ariadne-cursor-pointer",
82
+ classes,
83
+ )
84
+ else
85
+ class_names(
86
+ DEFAULT_ROW_CLASSES,
87
+ classes,
88
+ )
89
+ end
90
+
91
+ @attributes = attributes
92
+ end
93
+
94
+ def call
95
+ render(Ariadne::BaseComponent.new(tag: :li, classes: @classes, attributes: @attributes)) do
96
+ if linked?
97
+ render(Ariadne::LinkComponent.new(href: @link[:href], classes: @link[:classes], attributes: @link[:attributes])) do
98
+ cells.each do |cell|
99
+ concat(cell)
100
+ end
101
+ end
102
+ else
103
+ cells.each do |cell|
104
+ concat(cell)
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ private def linked?
111
+ @link.present?
112
+ end
113
+
114
+ # This component is part of `TableComponent` and should not be
115
+ # used as a standalone component.
116
+ class HeaderCellItem < Ariadne::TableComponent::RowItem
117
+ DEFAULT_HEADER_CELL_CLASSES = "ariadne-py-3.5 ariadne-pl-4 pr-3 ariadne-text-left ariadne-text-sm ariadne-font-semibold ariadne-text-gray-900 ariadne-sm:pl-6"
118
+
119
+ def initialize(classes: "", attributes: {})
120
+ @classes = class_names(
121
+ DEFAULT_HEADER_CELL_CLASSES,
122
+ classes,
123
+ )
124
+
125
+ @attributes = attributes
126
+ end
127
+
128
+ def call
129
+ render(Ariadne::BaseComponent.new(tag: :span, classes: @classes, attributes: @attributes)) { content }
130
+ end
131
+ end
132
+
133
+ # This component is part of `TableComponent` and should not be
134
+ # used as a standalone component.
135
+ class CellItem < Ariadne::TableComponent::RowItem
136
+ DEFAULT_CELL_CLASSES = ""
137
+
138
+ def initialize(classes: "", attributes: {})
139
+ @classes = class_names(
140
+ DEFAULT_CELL_CLASSES,
141
+ classes,
142
+ )
143
+
144
+ @attributes = attributes
145
+ end
146
+
147
+ def call
148
+ render(Ariadne::BaseComponent.new(tag: :span, classes: @classes, attributes: @attributes)) { content }
149
+ end
150
+ end
151
+ end
152
+
153
+ # This component is part of `TableComponent` and should not be
154
+ # used as a standalone component.
155
+ class HeaderRowItem < Ariadne::TableComponent::RowItem
156
+ DEFAULT_HEADER_CLASSES = "ariadne-bg-gray-50 flex flex-row"
157
+
158
+ def initialize(classes: "", attributes: {})
159
+ @header = true
160
+
161
+ @classes = class_names(
162
+ DEFAULT_HEADER_CLASSES,
163
+ classes,
164
+ )
165
+
166
+ @attributes = attributes
167
+ end
168
+
169
+ def call
170
+ render(Ariadne::BaseComponent.new(tag: :div, classes: @classes, attributes: @attributes)) do
171
+ cells.each do |cell|
172
+ concat(cell)
173
+ end
174
+ end
175
+ end
176
+ end
177
+
178
+ # This component is part of `TableComponent` and should not be
179
+ # used as a standalone component.
180
+ class FooterItem < Ariadne::Component
181
+ DEFAULT_CLASSES = "ariadne-border-none ariadne-flex ariadne-items-center ariadne-justify-between ariadne-px-4 ariadne-py-3 sm:ariadne-px-6"
182
+
183
+ DEFAULT_RESULT_CLASSES = "ariadne-text-sm ariadne-text-gray-700"
184
+ renders_one :records_info, lambda { |classes: "", attributes: {}|
185
+ actual_classes = class_names(DEFAULT_RESULT_CLASSES, classes)
186
+ Ariadne::BaseComponent.new(tag: :p, classes: actual_classes, attributes: attributes)
187
+ }
188
+
189
+ renders_one :pagination_bar, "Ariadne::TableComponent::PaginationBarItem"
190
+
191
+ def initialize(classes: "", attributes: {})
192
+ @classes = class_names(
193
+ DEFAULT_CLASSES,
194
+ classes,
195
+ )
196
+
197
+ @attributes = attributes
198
+ end
199
+
200
+ def call
201
+ render(Ariadne::BaseComponent.new(tag: :div, classes: @classes, attributes: @attributes)) do
202
+ records_info.to_s + pagination_bar.to_s
203
+ end
204
+ end
205
+ end
206
+
207
+ # This component is part of `TableComponent` and should not be
208
+ # used as a standalone component.
209
+ class PaginationBarItem < Ariadne::Component
210
+ DEFAULT_PREV_PAGE_CLASSES = "ariadne-relative ariadne-inline-flex ariadne-items-center ariadne-rounded-l-md ariadne-border ariadne-border-gray-300 ariadne-bg-white ariadne-px-2 ariadne-py-2 ariadne-text-sm ariadne-font-medium ariadne-text-gray-500 focus:ariadne-z-20"
211
+ renders_one :prev_page, lambda { |disabled: false, href:, classes: "", attributes: {}|
212
+ if disabled
213
+ actual_classes = class_names(DEFAULT_PREV_PAGE_CLASSES, classes)
214
+
215
+ render(Ariadne::BaseComponent.new(tag: :span, classes: actual_classes, attributes: attributes)) do
216
+ render(Ariadne::HeroiconComponent.new(icon: "chevron-left", size: :sm, variant: :mini, text_attributes: { "aria-hidden": true }, text_classes: "ariadne-sr-only"))
217
+ end
218
+ else
219
+ actual_classes = class_names(DEFAULT_PREV_PAGE_CLASSES, "hover:ariadne-bg-gray-50", classes)
220
+ attributes[:"aria-label"] = "previous"
221
+
222
+ render(Ariadne::LinkComponent.new(href: href, classes: actual_classes, attributes: attributes)) do
223
+ render(Ariadne::HeroiconComponent.new(icon: "chevron-left", size: :sm, variant: :mini, text_attributes: { "aria-hidden": true }, text_classes: "ariadne-sr-only"))
224
+ end
225
+ end
226
+ }
227
+
228
+ renders_one :page_list, lambda { |disabled: false, href:, classes: "", attributes: {}|
229
+ if disabled
230
+ actual_classes = class_names(DEFAULT_NEXT_PAGE_CLASSES, classes)
231
+
232
+ render(Ariadne::BaseComponent.new(tag: :span, classes: actual_classes, attributes: attributes)) do
233
+ render(Ariadne::HeroiconComponent.new(icon: "chevron-left", size: :sm, variant: :mini, text_attributes: { "aria-hidden": true }, text_classes: "ariadne-sr-only"))
234
+ end
235
+ else
236
+ actual_classes = class_names(DEFAULT_NEXT_PAGE_CLASSES, "hover:ariadne-bg-gray-50", classes)
237
+ attributes[:"aria-label"] = "next"
238
+
239
+ render(Ariadne::LinkComponent.new(href: href, classes: actual_classes, attributes: attributes)) do
240
+ render(Ariadne::HeroiconComponent.new(icon: "chevron-right", size: :sm, variant: :mini, text_attributes: { "aria-hidden": true }, text_classes: "ariadne-sr-only"))
241
+ end
242
+ end
243
+ }
244
+
245
+ DEFAULT_NEXT_PAGE_CLASSES = " ariadne-relative ariadne-inline-flex ariadne-items-center ariadne-rounded-r-md ariadne-border ariadne-border-gray-300 ariadne-bg-white ariadne-px-2 ariadne-py-2 ariadne-text-sm ariadne-font-medium ariadne-text-gray-500 focus:ariadne-z-20"
246
+ renders_one :next_page, lambda { |disabled: false, href:, classes: "", attributes: {}|
247
+ if disabled
248
+ actual_classes = class_names(DEFAULT_NEXT_PAGE_CLASSES, classes)
249
+
250
+ render(Ariadne::BaseComponent.new(tag: :span, classes: actual_classes, attributes: attributes)) do
251
+ render(Ariadne::HeroiconComponent.new(icon: "chevron-left", size: :sm, variant: :mini, text_attributes: { "aria-hidden": true }, text_classes: "ariadne-sr-only"))
252
+ end
253
+ else
254
+ actual_classes = class_names(DEFAULT_NEXT_PAGE_CLASSES, "hover:ariadne-bg-gray-50", classes)
255
+ attributes[:"aria-label"] = "next"
256
+
257
+ render(Ariadne::LinkComponent.new(href: href, classes: actual_classes, attributes: attributes)) do
258
+ render(Ariadne::HeroiconComponent.new(icon: "chevron-right", size: :sm, variant: :mini, text_attributes: { "aria-hidden": true }, text_classes: "ariadne-sr-only"))
259
+ end
260
+ end
261
+ }
262
+
263
+ DEFAULT_PAGINATOR_CLASSES = "ariadne-flex ariadne-items-center ariadne-justify-between ariadne-m-10"
264
+ def initialize(classes: "", attributes: {})
265
+ @classes = class_names(
266
+ DEFAULT_PAGINATOR_CLASSES,
267
+ classes,
268
+ )
269
+
270
+ @attributes = attributes
271
+ @attributes[:"aria-label"] ||= "paginator"
272
+ end
273
+
274
+ def call
275
+ render(Ariadne::BaseComponent.new(tag: :nav, classes: @classes, attributes: @attributes)) do
276
+ prev_page.to_s + next_page.to_s
277
+ end
278
+ end
279
+ end
280
+ end
281
+ end
@@ -21,7 +21,7 @@ module Ariadne
21
21
  @tag = check_incoming_tag(DEFAULT_TAG, tag)
22
22
  @classes = class_names(
23
23
  DEFAULT_CLASSES,
24
- classes
24
+ classes,
25
25
  )
26
26
 
27
27
  @time = time
@@ -25,7 +25,7 @@ module Ariadne
25
25
  @tag = check_incoming_tag(DEFAULT_TAG, tag)
26
26
  @classes = class_names(
27
27
  DEFAULT_CLASSES,
28
- classes
28
+ classes,
29
29
  )
30
30
 
31
31
  @attributes = attributes
@@ -22,14 +22,17 @@ module Ariadne
22
22
 
23
23
  InvalidValueError = Class.new(StandardError)
24
24
 
25
- TRUE_OR_FALSE = [true, false].freeze
25
+ TRUE_OR_FALSE = Set.new([true, false]).freeze
26
26
 
27
- def fetch_or_raise(allowed_values, given_value)
27
+ INTEGER_TYPES = Set.new(["Integer"]).freeze
28
+
29
+ def fetch_or_raise(allowed_values, given_value, against: nil)
28
30
  if !allowed_values.is_a?(Array) && !allowed_values.is_a?(Set)
29
31
  raise ArgumentError, "allowed_values must be an array or a set; it was #{allowed_values.class}"
30
32
  end
31
33
 
32
- if allowed_values.include?(given_value)
34
+ check_against_given_value = against || given_value
35
+ if allowed_values.include?(check_against_given_value)
33
36
  given_value
34
37
  else
35
38
  raise InvalidValueError, <<~MSG
@@ -41,10 +44,15 @@ module Ariadne
41
44
  end
42
45
  end
43
46
 
47
+ # TODO: use these two more
44
48
  def fetch_or_raise_boolean(given_value)
45
49
  fetch_or_raise(TRUE_OR_FALSE, given_value)
46
50
  end
47
51
 
52
+ def fetch_or_raise_integer(given_value)
53
+ fetch_or_raise(INTEGER_TYPES, given_value, against: given_value.class.name)
54
+ end
55
+
48
56
  # TODO: test this
49
57
  def check_incoming_tag(preferred_tag, given_tag)
50
58
  return preferred_tag if given_tag.blank? || preferred_tag == given_tag
@@ -1,18 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Ariadne::FetchOrFallbackHelper
4
- # A little helper to enable graceful fallbacks
3
+ # Ariadne::IconHelper
4
+ # A helper that insists on certain values when
5
+ # checking herocions and their varients.
5
6
  #
6
- # Use this helper to quietly ensure a value is
7
- # one that you expect:
8
- #
9
- # allowed_values - allowed options for *value*
10
- # given_value - input being coerced
11
- # fallback - returned if *given_value* is not included in *allowed_values*
12
- #
13
- # fetch_or_raise([1,2,3], 5) => 2
14
- # fetch_or_raise([1,2,3], 1) => 1
15
- # fetch_or_raise([1,2,3], nil) => 2
7
+ # Use this helper to loudly ensure a value is
8
+ # one that you expect.
16
9
  module Ariadne
17
10
  # :nodoc:
18
11
  module IconHelper
@@ -23,11 +16,22 @@ module Ariadne
23
16
 
24
17
  icon_presence!(icon, variant)
25
18
  variant_presence!(icon, variant)
26
- fetch_or_raise(HeroiconsHelper::Icon::VALID_VARIANTS, variant)
19
+ ensure_valid_variant(variant)
27
20
 
28
21
  true
29
22
  end
30
23
 
24
+ def ensure_valid_variant(variant)
25
+ check_variant = if variant.blank? || !variant.respond_to?(:to_s)
26
+ ""
27
+ else
28
+ variant.to_s
29
+ end
30
+
31
+ fetch_or_raise(HeroiconsHelper::Icon::VALID_VARIANTS, check_variant)
32
+ end
33
+ module_function :ensure_valid_variant
34
+
31
35
  def has_partial_icon?(icon, variant)
32
36
  icon.present? || variant.present?
33
37
  end
@@ -8,8 +8,8 @@ module Ariadne
8
8
  class Constants
9
9
  CONSTANTS = JSON.parse(
10
10
  File.read(
11
- File.join(File.dirname(__FILE__), "../../../static/constants.json")
12
- )
11
+ File.join(File.dirname(__FILE__), "../../../static/constants.json"),
12
+ ),
13
13
  ).freeze
14
14
 
15
15
  class << self
@@ -7,8 +7,8 @@ module Ariadne
7
7
  module ViewComponents
8
8
  STATUSES = JSON.parse(
9
9
  File.read(
10
- File.join(File.dirname(__FILE__), "../../../static/statuses.json")
11
- )
10
+ File.join(File.dirname(__FILE__), "../../../static/statuses.json"),
11
+ ),
12
12
  ).freeze
13
13
  end
14
14
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ariadne
4
4
  module ViewComponents
5
- VERSION = "0.0.12"
5
+ VERSION = "0.0.13"
6
6
  end
7
7
  end
@@ -5,4 +5,4 @@ AllCops:
5
5
  DisabledByDefault: true
6
6
 
7
7
  Ariadne/NoTagMemoize:
8
- Enabled: true
8
+ Enabled: false