primer_view_components 0.0.30 → 0.0.35

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +78 -0
  3. data/README.md +2 -2
  4. data/app/components/primer/auto_complete_component.rb +1 -1
  5. data/app/components/primer/auto_complete_item_component.rb +1 -1
  6. data/app/components/primer/avatar_stack_component.rb +1 -1
  7. data/app/components/primer/base_component.rb +115 -85
  8. data/app/components/primer/blankslate_component.html.erb +1 -1
  9. data/app/components/primer/blankslate_component.rb +0 -2
  10. data/app/components/primer/border_box_component.rb +0 -2
  11. data/app/components/primer/breadcrumb_component.rb +0 -1
  12. data/app/components/primer/button_component.rb +13 -11
  13. data/app/components/primer/button_group_component.rb +3 -5
  14. data/app/components/primer/button_marketing_component.rb +12 -12
  15. data/app/components/primer/component.rb +3 -0
  16. data/app/components/primer/details_component.rb +0 -1
  17. data/app/components/primer/dropdown/menu_component.rb +0 -2
  18. data/app/components/primer/dropdown_component.rb +1 -3
  19. data/app/components/primer/dropdown_menu_component.rb +1 -1
  20. data/app/components/primer/flash_component.html.erb +2 -2
  21. data/app/components/primer/flash_component.rb +10 -12
  22. data/app/components/primer/layout_component.rb +0 -2
  23. data/app/components/primer/link_component.rb +9 -9
  24. data/app/components/primer/menu_component.rb +2 -4
  25. data/app/components/primer/navigation/tab_component.html.erb +11 -0
  26. data/app/components/primer/navigation/tab_component.rb +126 -0
  27. data/app/components/primer/octicon_component.rb +5 -8
  28. data/app/components/primer/popover_component.rb +19 -3
  29. data/app/components/primer/progress_bar_component.rb +0 -1
  30. data/app/components/primer/spinner_component.html.erb +1 -3
  31. data/app/components/primer/spinner_component.rb +1 -0
  32. data/app/components/primer/state_component.rb +13 -13
  33. data/app/components/primer/subhead_component.rb +1 -3
  34. data/app/components/primer/tab_nav_component.html.erb +8 -10
  35. data/app/components/primer/tab_nav_component.rb +63 -76
  36. data/app/components/primer/time_ago_component.rb +2 -1
  37. data/app/components/primer/timeline_item_component.rb +1 -2
  38. data/app/components/primer/underline_nav_component.html.erb +19 -7
  39. data/app/components/primer/underline_nav_component.rb +114 -16
  40. data/app/lib/primer/classify.rb +5 -14
  41. data/app/lib/primer/classify/cache.rb +14 -4
  42. data/app/lib/primer/classify/spacing.rb +63 -0
  43. data/app/lib/primer/tabbed_component_helper.rb +39 -0
  44. data/app/lib/primer/view_helper.rb +2 -2
  45. data/lib/primer/view_components/version.rb +1 -1
  46. data/static/statuses.json +1 -1
  47. metadata +83 -22
  48. data/app/components/primer/slot.rb +0 -10
@@ -3,12 +3,11 @@
3
3
  module Primer
4
4
  # :nodoc:
5
5
  class Classify
6
- MARGIN_DIRECTION_KEYS = %i[mt ml mb mr].freeze
7
- SPACING_KEYS = (%i[m my mx p py px pt pl pb pr] + MARGIN_DIRECTION_KEYS).freeze
8
6
  DIRECTION_KEY = :direction
9
7
  JUSTIFY_CONTENT_KEY = :justify_content
10
8
  ALIGN_ITEMS_KEY = :align_items
11
9
  DISPLAY_KEY = :display
10
+ SPACING_KEYS = Primer::Classify::Spacing::KEYS
12
11
  RESPONSIVE_KEYS = ([DISPLAY_KEY, DIRECTION_KEY, JUSTIFY_CONTENT_KEY, ALIGN_ITEMS_KEY, :col, :float] + SPACING_KEYS).freeze
13
12
  BREAKPOINTS = ["", "-sm", "-md", "-lg", "-xl"].freeze
14
13
 
@@ -184,16 +183,10 @@ module Primer
184
183
  return if val.nil? || val == ""
185
184
 
186
185
  if SPACING_KEYS.include?(key)
187
- if MARGIN_DIRECTION_KEYS.include?(key)
188
- raise ArgumentError, "value of #{key} must be between -6 and 6" if val < -6 || val > 6
189
- elsif !((key == :mx || key == :my) && val == :auto)
190
- raise ArgumentError, "value of #{key} must be between 0 and 6" if val.negative? || val > 6
191
- end
192
- end
193
-
194
- if BOOLEAN_MAPPINGS.key?(key)
195
- BOOLEAN_MAPPINGS[key][:mappings].map { |m| m[:css_class] if m[:value] == val }.compact.each do |css_class|
196
- memo[:classes] << css_class
186
+ memo[:classes] << Primer::Classify::Spacing.spacing(key, val, breakpoint)
187
+ elsif BOOLEAN_MAPPINGS.key?(key)
188
+ BOOLEAN_MAPPINGS[key][:mappings].each do |m|
189
+ memo[:classes] << m[:css_class] if m[:value] == val && m[:css_class].present?
197
190
  end
198
191
  elsif key == BG_KEY
199
192
  if val.to_s.start_with?("#")
@@ -248,8 +241,6 @@ module Primer
248
241
  memo[:classes] << "text-#{val.to_s.dasherize}"
249
242
  elsif TYPOGRAPHY_KEYS.include?(key)
250
243
  memo[:classes] << "f#{val.to_s.dasherize}"
251
- elsif MARGIN_DIRECTION_KEYS.include?(key) && val.negative?
252
- memo[:classes] << "#{key.to_s.dasherize}#{breakpoint}-n#{val.abs}"
253
244
  elsif key == BOX_SHADOW_KEY
254
245
  memo[:classes] << if val == true
255
246
  "color-shadow-small"
@@ -20,13 +20,23 @@ module Primer
20
20
 
21
21
  def preload!
22
22
  preload(
23
- keys: Primer::Classify::MARGIN_DIRECTION_KEYS,
24
- values: [-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]
23
+ keys: Primer::Classify::Spacing::MARGIN_DIRECTION_MAPPINGS.keys,
24
+ values: Primer::Classify::Spacing::MARGIN_DIRECTION_OPTIONS
25
25
  )
26
26
 
27
27
  preload(
28
- keys: (Primer::Classify::SPACING_KEYS - Primer::Classify::MARGIN_DIRECTION_KEYS),
29
- values: [0, 1, 2, 3, 4, 5, 6]
28
+ keys: Primer::Classify::Spacing::BASE_MAPPINGS.keys,
29
+ values: Primer::Classify::Spacing::BASE_OPTIONS
30
+ )
31
+
32
+ preload(
33
+ keys: Primer::Classify::Spacing::AUTO_MAPPINGS.keys,
34
+ values: Primer::Classify::Spacing::AUTO_OPTIONS
35
+ )
36
+
37
+ preload(
38
+ keys: Primer::Classify::Spacing::RESPONSIVE_MAPPINGS.keys,
39
+ values: Primer::Classify::Spacing::RESPONSIVE_OPTIONS
30
40
  )
31
41
 
32
42
  preload(
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ class Classify
5
+ # Handler for PrimerCSS spacing classes.
6
+ class Spacing
7
+ BASE_OPTIONS = (0..6).to_a.freeze
8
+ BASE_MAPPINGS = {
9
+ my: BASE_OPTIONS,
10
+ pb: BASE_OPTIONS,
11
+ pl: BASE_OPTIONS,
12
+ pr: BASE_OPTIONS,
13
+ pt: BASE_OPTIONS,
14
+ px: BASE_OPTIONS,
15
+ py: BASE_OPTIONS
16
+ }.freeze
17
+
18
+ MARGIN_DIRECTION_OPTIONS = [*(-6..-1), *BASE_OPTIONS].freeze
19
+ MARGIN_DIRECTION_MAPPINGS = {
20
+ mb: MARGIN_DIRECTION_OPTIONS,
21
+ ml: MARGIN_DIRECTION_OPTIONS,
22
+ mr: MARGIN_DIRECTION_OPTIONS,
23
+ mt: MARGIN_DIRECTION_OPTIONS
24
+ }.freeze
25
+
26
+ AUTO_OPTIONS = [*BASE_OPTIONS, :auto].freeze
27
+ AUTO_MAPPINGS = {
28
+ m: AUTO_OPTIONS,
29
+ mx: AUTO_OPTIONS
30
+ }.freeze
31
+
32
+ RESPONSIVE_OPTIONS = [*BASE_OPTIONS, :responsive].freeze
33
+ RESPONSIVE_MAPPINGS = {
34
+ p: RESPONSIVE_OPTIONS
35
+ }.freeze
36
+
37
+ MAPPINGS = {
38
+ **BASE_MAPPINGS,
39
+ **MARGIN_DIRECTION_MAPPINGS,
40
+ **AUTO_MAPPINGS,
41
+ **RESPONSIVE_MAPPINGS
42
+ }.freeze
43
+ KEYS = MAPPINGS.keys.freeze
44
+
45
+ class << self
46
+ def spacing(key, val, breakpoint)
47
+ validate(key, val) unless Rails.env.production?
48
+
49
+ return "#{key.to_s.dasherize}#{breakpoint}-n#{val.abs}" if val.is_a?(Numeric) && val.negative?
50
+
51
+ "#{key.to_s.dasherize}#{breakpoint}-#{val.to_s.dasherize}"
52
+ end
53
+
54
+ private
55
+
56
+ def validate(key, val)
57
+ raise ArgumentError, "#{key} is not a spacing key" unless KEYS.include?(key)
58
+ raise ArgumentError, "#{val} is not a valid value for :#{key}. Use one of #{MAPPINGS[key]}" unless MAPPINGS[key].include?(val)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Primer
6
+ # Helper to share tab validation logic between components.
7
+ # The component will raise an error if there are 0 or 2+ selected tabs.
8
+ module TabbedComponentHelper
9
+ extend ActiveSupport::Concern
10
+
11
+ class MultipleSelectedTabsError < StandardError; end
12
+
13
+ def before_render
14
+ validate_single_selected_tab unless Rails.env.production?
15
+ end
16
+
17
+ private
18
+
19
+ def navigation_tag(with_panel)
20
+ with_panel ? :div : :nav
21
+ end
22
+
23
+ def wrapper
24
+ return yield unless @with_panel
25
+
26
+ render Primer::TabContainerComponent.new do
27
+ yield
28
+ end
29
+ end
30
+
31
+ def validate_single_selected_tab
32
+ raise MultipleSelectedTabsError, "only one tab can be selected" if selected_tabs_count > 1
33
+ end
34
+
35
+ def selected_tabs_count
36
+ @selected_tabs_count ||= tabs.count(&:selected)
37
+ end
38
+ end
39
+ end
@@ -12,8 +12,8 @@ module Primer
12
12
  }.freeze
13
13
 
14
14
  HELPERS.each do |name, component|
15
- define_method "primer_#{name}" do |**component_args, &block|
16
- render component.constantize.new(**component_args), &block
15
+ define_method "primer_#{name}" do |*args, **kwargs, &block|
16
+ render component.constantize.new(*args, **kwargs), &block
17
17
  end
18
18
  end
19
19
  end
@@ -5,7 +5,7 @@ module Primer
5
5
  module VERSION
6
6
  MAJOR = 0
7
7
  MINOR = 0
8
- PATCH = 30
8
+ PATCH = 35
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
11
11
  end
data/static/statuses.json CHANGED
@@ -1 +1 @@
1
- {"Primer::AutoCompleteComponent":"alpha","Primer::AutoCompleteItemComponent":"alpha","Primer::AvatarComponent":"beta","Primer::AvatarStackComponent":"alpha","Primer::BaseComponent":"beta","Primer::BlankslateComponent":"beta","Primer::BorderBoxComponent":"beta","Primer::BoxComponent":"stable","Primer::BreadcrumbComponent":"beta","Primer::BreadcrumbComponent::ItemComponent":"alpha","Primer::ButtonComponent":"alpha","Primer::ButtonGroupComponent":"alpha","Primer::ButtonMarketingComponent":"alpha","Primer::CounterComponent":"beta","Primer::DetailsComponent":"beta","Primer::Dropdown::MenuComponent":"alpha","Primer::DropdownComponent":"alpha","Primer::DropdownMenuComponent":"deprecated","Primer::FlashComponent":"beta","Primer::FlexComponent":"alpha","Primer::FlexItemComponent":"alpha","Primer::HeadingComponent":"beta","Primer::LabelComponent":"beta","Primer::LayoutComponent":"alpha","Primer::LinkComponent":"beta","Primer::MarkdownComponent":"alpha","Primer::MenuComponent":"alpha","Primer::OcticonComponent":"beta","Primer::PopoverComponent":"beta","Primer::ProgressBarComponent":"beta","Primer::SpinnerComponent":"beta","Primer::StateComponent":"beta","Primer::SubheadComponent":"beta","Primer::TabContainerComponent":"alpha","Primer::TabNavComponent":"alpha","Primer::TabNavComponent::TabComponent":"alpha","Primer::TextComponent":"beta","Primer::TimeAgoComponent":"alpha","Primer::TimelineItemComponent":"beta","Primer::TimelineItemComponent::BadgeComponent":"alpha","Primer::TooltipComponent":"alpha","Primer::TruncateComponent":"alpha","Primer::UnderlineNavComponent":"alpha"}
1
+ {"Primer::AutoCompleteComponent":"beta","Primer::AutoCompleteItemComponent":"beta","Primer::AvatarComponent":"beta","Primer::AvatarStackComponent":"beta","Primer::BaseComponent":"beta","Primer::BlankslateComponent":"beta","Primer::BorderBoxComponent":"beta","Primer::BoxComponent":"stable","Primer::BreadcrumbComponent":"beta","Primer::BreadcrumbComponent::ItemComponent":"alpha","Primer::ButtonComponent":"beta","Primer::ButtonGroupComponent":"alpha","Primer::ButtonMarketingComponent":"alpha","Primer::CounterComponent":"beta","Primer::DetailsComponent":"beta","Primer::Dropdown::MenuComponent":"alpha","Primer::DropdownComponent":"alpha","Primer::DropdownMenuComponent":"deprecated","Primer::FlashComponent":"beta","Primer::FlexComponent":"alpha","Primer::FlexItemComponent":"alpha","Primer::HeadingComponent":"beta","Primer::LabelComponent":"beta","Primer::LayoutComponent":"alpha","Primer::LinkComponent":"beta","Primer::MarkdownComponent":"alpha","Primer::MenuComponent":"alpha","Primer::Navigation::TabComponent":"alpha","Primer::OcticonComponent":"beta","Primer::PopoverComponent":"beta","Primer::ProgressBarComponent":"beta","Primer::SpinnerComponent":"beta","Primer::StateComponent":"beta","Primer::SubheadComponent":"beta","Primer::TabContainerComponent":"alpha","Primer::TabNavComponent":"alpha","Primer::TextComponent":"beta","Primer::TimeAgoComponent":"beta","Primer::TimelineItemComponent":"beta","Primer::TimelineItemComponent::BadgeComponent":"alpha","Primer::TooltipComponent":"alpha","Primer::TruncateComponent":"alpha","Primer::UnderlineNavComponent":"alpha"}
metadata CHANGED
@@ -1,45 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primer_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.30
4
+ version: 0.0.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-12 00:00:00.000000000 Z
11
+ date: 2021-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: octicons_helper
14
+ name: actionview
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 9.0.0
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: 13.0.0
19
+ version: 5.0.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 9.0.0
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: 13.0.0
26
+ version: 5.0.0
33
27
  - !ruby/object:Gem::Dependency
34
- name: rails
28
+ name: activesupport
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - ">="
38
32
  - !ruby/object:Gem::Version
39
33
  version: 5.0.0
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '7.0'
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
@@ -47,9 +38,20 @@ dependencies:
47
38
  - - ">="
48
39
  - !ruby/object:Gem::Version
49
40
  version: 5.0.0
50
- - - "<"
41
+ - !ruby/object:Gem::Dependency
42
+ name: octicons_helper
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
51
46
  - !ruby/object:Gem::Version
52
- version: '7.0'
47
+ version: 13.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 13.0.0
53
55
  - !ruby/object:Gem::Dependency
54
56
  name: view_component
55
57
  requirement: !ruby/object:Gem::Requirement
@@ -98,6 +100,34 @@ dependencies:
98
100
  - - "~>"
99
101
  - !ruby/object:Gem::Version
100
102
  version: 2.8.4
103
+ - !ruby/object:Gem::Dependency
104
+ name: capybara
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '3'
117
+ - !ruby/object:Gem::Dependency
118
+ name: cuprite
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '='
122
+ - !ruby/object:Gem::Version
123
+ version: '0.11'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '='
129
+ - !ruby/object:Gem::Version
130
+ version: '0.11'
101
131
  - !ruby/object:Gem::Dependency
102
132
  name: listen
103
133
  requirement: !ruby/object:Gem::Requirement
@@ -116,16 +146,16 @@ dependencies:
116
146
  name: minitest
117
147
  requirement: !ruby/object:Gem::Requirement
118
148
  requirements:
119
- - - '='
149
+ - - "~>"
120
150
  - !ruby/object:Gem::Version
121
- version: 5.6.0
151
+ version: '5.0'
122
152
  type: :development
123
153
  prerelease: false
124
154
  version_requirements: !ruby/object:Gem::Requirement
125
155
  requirements:
126
- - - '='
156
+ - - "~>"
127
157
  - !ruby/object:Gem::Version
128
- version: 5.6.0
158
+ version: '5.0'
129
159
  - !ruby/object:Gem::Dependency
130
160
  name: mocha
131
161
  requirement: !ruby/object:Gem::Requirement
@@ -224,6 +254,34 @@ dependencies:
224
254
  - - "~>"
225
255
  - !ruby/object:Gem::Version
226
256
  version: 0.7.2
257
+ - !ruby/object:Gem::Dependency
258
+ name: sprockets
259
+ requirement: !ruby/object:Gem::Requirement
260
+ requirements:
261
+ - - ">="
262
+ - !ruby/object:Gem::Version
263
+ version: '0'
264
+ type: :development
265
+ prerelease: false
266
+ version_requirements: !ruby/object:Gem::Requirement
267
+ requirements:
268
+ - - ">="
269
+ - !ruby/object:Gem::Version
270
+ version: '0'
271
+ - !ruby/object:Gem::Dependency
272
+ name: sprockets-rails
273
+ requirement: !ruby/object:Gem::Requirement
274
+ requirements:
275
+ - - ">="
276
+ - !ruby/object:Gem::Version
277
+ version: '0'
278
+ type: :development
279
+ prerelease: false
280
+ version_requirements: !ruby/object:Gem::Requirement
281
+ requirements:
282
+ - - ">="
283
+ - !ruby/object:Gem::Version
284
+ version: '0'
227
285
  - !ruby/object:Gem::Dependency
228
286
  name: yard
229
287
  requirement: !ruby/object:Gem::Requirement
@@ -295,6 +353,8 @@ files:
295
353
  - app/components/primer/markdown_component.rb
296
354
  - app/components/primer/menu_component.html.erb
297
355
  - app/components/primer/menu_component.rb
356
+ - app/components/primer/navigation/tab_component.html.erb
357
+ - app/components/primer/navigation/tab_component.rb
298
358
  - app/components/primer/octicon_component.rb
299
359
  - app/components/primer/popover_component.html.erb
300
360
  - app/components/primer/popover_component.rb
@@ -303,7 +363,6 @@ files:
303
363
  - app/components/primer/primer.ts
304
364
  - app/components/primer/progress_bar_component.html.erb
305
365
  - app/components/primer/progress_bar_component.rb
306
- - app/components/primer/slot.rb
307
366
  - app/components/primer/spinner_component.html.erb
308
367
  - app/components/primer/spinner_component.rb
309
368
  - app/components/primer/state_component.rb
@@ -333,9 +392,11 @@ files:
333
392
  - app/lib/primer/classify/functional_border_colors.rb
334
393
  - app/lib/primer/classify/functional_colors.rb
335
394
  - app/lib/primer/classify/functional_text_colors.rb
395
+ - app/lib/primer/classify/spacing.rb
336
396
  - app/lib/primer/fetch_or_fallback_helper.rb
337
397
  - app/lib/primer/join_style_arguments_helper.rb
338
398
  - app/lib/primer/status/dsl.rb
399
+ - app/lib/primer/tabbed_component_helper.rb
339
400
  - app/lib/primer/test_selector_helper.rb
340
401
  - app/lib/primer/view_helper.rb
341
402
  - lib/primer/view_components.rb
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Primer
4
- # @private
5
- class Slot < ViewComponent::Slot
6
- include ClassNameHelper
7
- include FetchOrFallbackHelper
8
- include JoinStyleArgumentsHelper
9
- end
10
- end