primer_view_components 0.0.50 → 0.0.54

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +136 -0
  3. data/app/components/primer/alpha/underline_nav.html.erb +15 -0
  4. data/app/components/primer/alpha/underline_nav.rb +143 -0
  5. data/app/components/primer/{underline_nav_component.html.erb → alpha/underline_panels.html.erb} +3 -8
  6. data/app/components/primer/alpha/underline_panels.rb +86 -0
  7. data/app/components/primer/base_component.rb +2 -2
  8. data/app/components/primer/beta/avatar_stack.rb +9 -9
  9. data/app/components/primer/{breadcrumb_component.html.erb → beta/breadcrumbs.html.erb} +0 -0
  10. data/app/components/primer/beta/breadcrumbs.rb +59 -0
  11. data/app/components/primer/beta/truncate.html.erb +5 -0
  12. data/app/components/primer/beta/truncate.rb +110 -0
  13. data/app/components/primer/border_box_component.rb +27 -1
  14. data/app/components/primer/clipboard_copy.rb +1 -1
  15. data/app/components/primer/dropdown.rb +7 -7
  16. data/app/components/primer/icon_button.rb +1 -1
  17. data/app/components/primer/navigation/tab_component.rb +7 -5
  18. data/app/components/primer/progress_bar_component.rb +0 -3
  19. data/app/components/primer/tab_nav_component.html.erb +1 -1
  20. data/app/components/primer/tab_nav_component.rb +1 -1
  21. data/app/lib/primer/fetch_or_fallback_helper.rb +2 -0
  22. data/app/lib/primer/tabbed_component_helper.rb +3 -3
  23. data/app/lib/primer/underline_nav_helper.rb +44 -0
  24. data/app/lib/primer/view_helper.rb +1 -0
  25. data/lib/primer/classify/flex.rb +1 -1
  26. data/lib/primer/classify/functional_colors.rb +1 -1
  27. data/lib/primer/classify/utilities.rb +19 -2
  28. data/lib/primer/classify/utilities.yml +2 -2
  29. data/lib/primer/classify/validation.rb +18 -0
  30. data/lib/primer/classify.rb +5 -15
  31. data/lib/primer/view_components/constants.rb +1 -1
  32. data/lib/primer/view_components/linters/argument_mappers/base.rb +34 -8
  33. data/lib/primer/view_components/linters/argument_mappers/button.rb +5 -6
  34. data/lib/primer/view_components/linters/argument_mappers/clipboard_copy.rb +4 -3
  35. data/lib/primer/view_components/linters/argument_mappers/close_button.rb +43 -0
  36. data/lib/primer/view_components/linters/argument_mappers/flash.rb +32 -0
  37. data/lib/primer/view_components/linters/argument_mappers/helpers/erb_block.rb +48 -5
  38. data/lib/primer/view_components/linters/argument_mappers/label.rb +3 -4
  39. data/lib/primer/view_components/linters/argument_mappers/system_arguments.rb +5 -7
  40. data/lib/primer/view_components/linters/autocorrectable.rb +6 -4
  41. data/lib/primer/view_components/linters/{helpers.rb → base_linter.rb} +69 -29
  42. data/lib/primer/view_components/linters/button_component_migration_counter.rb +4 -3
  43. data/lib/primer/view_components/linters/clipboard_copy_component_migration_counter.rb +3 -4
  44. data/lib/primer/view_components/linters/close_button_component_migration_counter.rb +110 -3
  45. data/lib/primer/view_components/linters/flash_component_migration_counter.rb +18 -3
  46. data/lib/primer/view_components/linters/label_component_migration_counter.rb +2 -3
  47. data/lib/primer/view_components/version.rb +1 -1
  48. data/lib/rubocop/config/default.yml +5 -0
  49. data/lib/rubocop/cop/primer/deprecated_arguments.rb +277 -0
  50. data/lib/rubocop/cop/primer/no_tag_memoize.rb +1 -0
  51. data/lib/rubocop/cop/primer/primer_octicon.rb +178 -0
  52. data/lib/rubocop/cop/primer/system_argument_instead_of_class.rb +12 -16
  53. data/lib/rubocop/cop/primer.rb +1 -2
  54. data/lib/tasks/coverage.rake +4 -0
  55. data/lib/tasks/docs.rake +7 -5
  56. data/lib/tasks/utilities.rake +5 -3
  57. data/lib/yard/docs_helper.rb +6 -3
  58. data/static/arguments.yml +62 -37
  59. data/static/classes.yml +9 -0
  60. data/static/constants.json +38 -23
  61. data/static/statuses.json +8 -5
  62. metadata +37 -15
  63. data/app/components/primer/auto_complete/auto_component.d.ts +0 -1
  64. data/app/components/primer/auto_complete/auto_component.js +0 -1
  65. data/app/components/primer/breadcrumb_component.rb +0 -57
  66. data/app/components/primer/underline_nav_component.rb +0 -187
@@ -3,7 +3,9 @@
3
3
  require "rubocop"
4
4
  require "primer/classify/utilities"
5
5
  require "primer/view_components/statuses"
6
+ require_relative "../../../../app/lib/primer/view_helper"
6
7
 
8
+ # :nocov:
7
9
  module RuboCop
8
10
  module Cop
9
11
  module Primer
@@ -20,8 +22,7 @@ module RuboCop
20
22
  STR
21
23
 
22
24
  def on_send(node)
23
- return unless node.method_name == :new
24
- return unless ::Primer::ViewComponents::STATUSES.key?(node.receiver.const_name)
25
+ return unless valid_node?(node)
25
26
  return unless node.arguments?
26
27
 
27
28
  # we are looking for hash arguments and they are always last
@@ -48,26 +49,21 @@ module RuboCop
48
49
 
49
50
  def autocorrect(node)
50
51
  lambda do |corrector|
51
- system_arguments = ::Primer::Classify::Utilities.classes_to_hash(node.value.value)
52
- corrector.replace(node.loc.expression, arguments_as_string(system_arguments))
52
+ args = ::Primer::Classify::Utilities.classes_to_args(node.value.value)
53
+ corrector.replace(node.loc.expression, args)
53
54
  end
54
55
  end
55
56
 
56
57
  private
57
58
 
58
- def arguments_as_string(system_arguments)
59
- system_arguments.map do |key, value|
60
- val = case value
61
- when Symbol
62
- ":#{value}"
63
- when String
64
- value.to_json
65
- else
66
- value
67
- end
59
+ # We only verify SystemArguments if it's a `.new` call on a component or
60
+ # a ViewHleper call.
61
+ def valid_node?(node)
62
+ view_helpers.include?(node.method_name) || (node.method_name == :new && ::Primer::ViewComponents::STATUSES.key?(node.receiver.const_name))
63
+ end
68
64
 
69
- "#{key}: #{val}"
70
- end.join(", ")
65
+ def view_helpers
66
+ ::Primer::ViewHelper::HELPERS.keys.map { |key| "primer_#{key}".to_sym }
71
67
  end
72
68
  end
73
69
  end
@@ -1,4 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rubocop/cop/primer/no_tag_memoize"
4
- require "rubocop/cop/primer/system_argument_instead_of_class"
3
+ Dir[File.join(__dir__, "primer", "*.rb")].sort.each { |file| require file }
@@ -9,6 +9,10 @@ namespace :coverage do
9
9
 
10
10
  SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"], "rails" do
11
11
  formatter SimpleCov::Formatter::Console
12
+
13
+ add_group "Ignored Code" do |src_file|
14
+ File.readlines(src_file.filename).grep(/:nocov:/).any?
15
+ end
12
16
  end
13
17
  end
14
18
  end
data/lib/tasks/docs.rake CHANGED
@@ -40,7 +40,7 @@ namespace :docs do
40
40
  Primer::BlankslateComponent,
41
41
  Primer::BorderBoxComponent,
42
42
  Primer::BoxComponent,
43
- Primer::BreadcrumbComponent,
43
+ Primer::Beta::Breadcrumbs,
44
44
  Primer::ButtonComponent,
45
45
  Primer::ButtonGroup,
46
46
  Primer::Alpha::ButtonMarketing,
@@ -74,7 +74,9 @@ namespace :docs do
74
74
  Primer::TimelineItemComponent,
75
75
  Primer::Tooltip,
76
76
  Primer::Truncate,
77
- Primer::UnderlineNavComponent
77
+ Primer::Beta::Truncate,
78
+ Primer::Alpha::UnderlineNav,
79
+ Primer::Alpha::UnderlinePanels
78
80
  ]
79
81
 
80
82
  js_components = [
@@ -86,7 +88,7 @@ namespace :docs do
86
88
  Primer::TabContainerComponent,
87
89
  Primer::TabNavComponent,
88
90
  Primer::TimeAgoComponent,
89
- Primer::UnderlineNavComponent
91
+ Primer::Alpha::UnderlinePanels
90
92
  ]
91
93
 
92
94
  all_components = Primer::Component.descendants - [Primer::BaseComponent]
@@ -238,7 +240,7 @@ namespace :docs do
238
240
  f.puts
239
241
  html = view_context.render(inline: code)
240
242
  html.scan(/class="([^"]*)"/) do |classnames|
241
- classes_found_in_examples.concat(classnames[0].split(" ").reject { |c| c.starts_with?("octicon", "js", "my-") }.map { ".#{_1}"})
243
+ classes_found_in_examples.concat(classnames[0].split.reject { |c| c.starts_with?("octicon", "js", "my-") }.map { ".#{_1}" })
242
244
  end
243
245
  f.puts("<Example src=\"#{html.tr('"', "\'").delete("\n")}\" />")
244
246
  f.puts
@@ -382,7 +384,7 @@ namespace :docs do
382
384
  end
383
385
 
384
386
  def pretty_default_value(tag, component)
385
- params = tag.object.parameters.find { |param| [tag.name.to_s, tag.name.to_s + ":"].include?(param[0]) }
387
+ params = tag.object.parameters.find { |param| [tag.name.to_s, "#{tag.name}:"].include?(param[0]) }
386
388
  default = tag.defaults&.first || params&.second
387
389
 
388
390
  return "N/A" unless default
@@ -8,6 +8,7 @@ namespace :utilities do
8
8
  require "primer/classify/utilities"
9
9
 
10
10
  # Keys that are looked for to be included in the utilities.yml file
11
+ # rubocop:disable Lint/ConstantDefinitionInBlock
11
12
  SUPPORTED_KEYS = %i[
12
13
  anim
13
14
  d
@@ -23,6 +24,7 @@ namespace :utilities do
23
24
  ].freeze
24
25
 
25
26
  BREAKPOINTS = [nil, "sm", "md", "lg", "xl"].freeze
27
+ # rubocop:enable Lint/ConstantDefinitionInBlock
26
28
 
27
29
  css_data =
28
30
  JSON.parse(
@@ -38,7 +40,7 @@ namespace :utilities do
38
40
  css_data.each do |selector|
39
41
  selector.sub!(/^./, "")
40
42
  # Next if selector has ancestors or sibling selectors
41
- next if selector.match?(/[:><~\[\.]/)
43
+ next if selector.match?(/[:><~\[.]/)
42
44
  next unless SUPPORTED_KEYS.any? { |key| selector.start_with?("#{key}-") }
43
45
 
44
46
  # Dupe so we still have the selector at the end of slicing it up
@@ -50,7 +52,7 @@ namespace :utilities do
50
52
  next unless classname.match?(Regexp.new(k))
51
53
 
52
54
  key = v
53
- classname.sub!(Regexp.new(k + "-"), "")
55
+ classname.sub!(Regexp.new("#{k}-"), "")
54
56
  end
55
57
 
56
58
  # If we didn't find a replacement, grab the first text before hyphen
@@ -66,7 +68,7 @@ namespace :utilities do
66
68
  end
67
69
 
68
70
  # Change the rest from hypens to underscores
69
- classname.sub!(/\-/, "_")
71
+ classname.sub!(/-/, "_")
70
72
 
71
73
  # convert padding/margin negative values ie n7 to -7
72
74
  classname.sub!(/^n/, "-") if classname.match?(/^n[0-9]/)
@@ -1,13 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :nocov:
4
+
3
5
  module YARD
4
6
  # Helper methods to use for yard documentation
5
7
  module DocsHelper
6
8
  def one_of(enumerable, lower: false, sort: true)
7
9
  # Sort the array if requested
8
10
  if sort
9
- compare = ->(a, b) { a.class == b.class ? a <=> b : a.class.to_s <=> b.class.to_s }
10
- enumerable = enumerable.sort { |a, b| compare.call(a, b) }
11
+ enumerable = enumerable.sort do |a, b|
12
+ a.instance_of?(b.class) ? a <=> b : a.class.to_s <=> b.class.to_s
13
+ end
11
14
  end
12
15
 
13
16
  values =
@@ -58,7 +61,7 @@ module YARD
58
61
  def status_module_and_short_name(component)
59
62
  name_with_status = component.name.gsub(/Primer::|Component/, "")
60
63
 
61
- m = name_with_status.match(/(?<status>Beta|Alpha|Deprecated)?(::)?(?<name>.*)/)
64
+ m = name_with_status.match(/(?<status>Beta|Alpha|Deprecated)?(?<_colons>::)?(?<name>.*)/)
62
65
  [m[:status]&.downcase, m[:name].gsub("::", "")]
63
66
  end
64
67
 
data/static/arguments.yml CHANGED
@@ -22,6 +22,54 @@
22
22
  type: Hash
23
23
  default: N/A
24
24
  description: "[System arguments](/system-arguments)"
25
+ - component: UnderlineNav
26
+ source: https://github.com/primer/view_components/tree/main/app/components/primer/alpha/underline_nav.rb
27
+ parameters:
28
+ - name: tag
29
+ type: Symbol
30
+ default: "`:nav`"
31
+ description: One of `:div` and `:nav`.
32
+ - name: label
33
+ type: String
34
+ default: N/A
35
+ description: Sets an `aria-label` that helps assistive technology users understand
36
+ the purpose of the links, and distinguish it from similar elements.
37
+ - name: align
38
+ type: Symbol
39
+ default: "`:left`"
40
+ description: One of `:left` and `:right`. - Defaults to left
41
+ - name: body_arguments
42
+ type: Hash
43
+ default: "`{}`"
44
+ description: "[System arguments](/system-arguments) for the body wrapper."
45
+ - name: system_arguments
46
+ type: Hash
47
+ default: N/A
48
+ description: "[System arguments](/system-arguments)"
49
+ - component: UnderlinePanels
50
+ source: https://github.com/primer/view_components/tree/main/app/components/primer/alpha/underline_panels.rb
51
+ parameters:
52
+ - name: label
53
+ type: String
54
+ default: N/A
55
+ description: Sets an `aria-label` that helps assistive technology users understand
56
+ the purpose of the tabs.
57
+ - name: align
58
+ type: Symbol
59
+ default: "`:left`"
60
+ description: One of `:left` and `:right`. - Defaults to left
61
+ - name: body_arguments
62
+ type: Hash
63
+ default: "`{}`"
64
+ description: "[System arguments](/system-arguments) for the body wrapper."
65
+ - name: wrapper_arguments
66
+ type: Hash
67
+ default: "`{}`"
68
+ description: "[System arguments](/system-arguments) for the `TabContainer` wrapper."
69
+ - name: system_arguments
70
+ type: Hash
71
+ default: N/A
72
+ description: "[System arguments](/system-arguments)"
25
73
  - component: BaseButton
26
74
  source: https://github.com/primer/view_components/tree/main/app/components/primer/base_button.rb
27
75
  parameters:
@@ -132,6 +180,13 @@
132
180
  type: Hash
133
181
  default: N/A
134
182
  description: "[System arguments](/system-arguments)"
183
+ - component: Breadcrumbs
184
+ source: https://github.com/primer/view_components/tree/main/app/components/primer/beta/breadcrumbs.rb
185
+ parameters:
186
+ - name: system_arguments
187
+ type: Hash
188
+ default: N/A
189
+ description: "[System arguments](/system-arguments)"
135
190
  - component: Text
136
191
  source: https://github.com/primer/view_components/tree/main/app/components/primer/beta/text.rb
137
192
  parameters:
@@ -143,6 +198,13 @@
143
198
  type: Hash
144
199
  default: N/A
145
200
  description: "[System arguments](/system-arguments)"
201
+ - component: Truncate
202
+ source: https://github.com/primer/view_components/tree/main/app/components/primer/beta/truncate.rb
203
+ parameters:
204
+ - name: system_arguments
205
+ type: Hash
206
+ default: N/A
207
+ description: "[System arguments](/system-arguments)"
146
208
  - component: Blankslate
147
209
  source: https://github.com/primer/view_components/tree/main/app/components/primer/blankslate_component.rb
148
210
  parameters:
@@ -228,13 +290,6 @@
228
290
  type: Hash
229
291
  default: N/A
230
292
  description: "[System arguments](/system-arguments)"
231
- - component: Breadcrumb
232
- source: https://github.com/primer/view_components/tree/main/app/components/primer/breadcrumb_component.rb
233
- parameters:
234
- - name: system_arguments
235
- type: Hash
236
- default: N/A
237
- description: "[System arguments](/system-arguments)"
238
293
  - component: Button
239
294
  source: https://github.com/primer/view_components/tree/main/app/components/primer/button_component.rb
240
295
  parameters:
@@ -941,33 +996,3 @@
941
996
  type: Hash
942
997
  default: N/A
943
998
  description: "[System arguments](/system-arguments)"
944
- - component: UnderlineNav
945
- source: https://github.com/primer/view_components/tree/main/app/components/primer/underline_nav_component.rb
946
- parameters:
947
- - name: label
948
- type: String
949
- default: N/A
950
- description: The `aria-label` on top level `<nav>` element.
951
- - name: with_panel
952
- type: Boolean
953
- default: "`false`"
954
- description: Whether the `UnderlineNav` should navigate through pages or panels.
955
- When true, [TabContainer](/components/tabcontainer) is rendered along with JavaScript
956
- behavior.
957
- - name: align
958
- type: Symbol
959
- default: "`:left`"
960
- description: One of `:left` and `:right`. - Defaults to left
961
- - name: body_arguments
962
- type: Hash
963
- default: "`{ tag: BODY_TAG_DEFAULT }`"
964
- description: "[System arguments](/system-arguments) for the body wrapper."
965
- - name: wrapper_arguments
966
- type: Hash
967
- default: "`{}`"
968
- description: "[System arguments](/system-arguments) for the `TabContainer` wrapper.
969
- Only applies if `with_panel` is `true`."
970
- - name: system_arguments
971
- type: Hash
972
- default: N/A
973
- description: "[System arguments](/system-arguments)"
data/static/classes.yml CHANGED
@@ -10,6 +10,9 @@
10
10
  - ".Box-footer"
11
11
  - ".Box-header"
12
12
  - ".Box-row"
13
+ - ".Box-row--blue"
14
+ - ".Box-row--gray"
15
+ - ".Box-row--yellow"
13
16
  - ".BtnGroup"
14
17
  - ".BtnGroup-item"
15
18
  - ".Counter"
@@ -49,6 +52,10 @@
49
52
  - ".TimelineItem-avatar"
50
53
  - ".TimelineItem-badge"
51
54
  - ".TimelineItem-body"
55
+ - ".Truncate"
56
+ - ".Truncate-text"
57
+ - ".Truncate-text--expandable"
58
+ - ".Truncate-text--primary"
52
59
  - ".UnderlineNav"
53
60
  - ".UnderlineNav--right"
54
61
  - ".UnderlineNav-actions"
@@ -107,6 +114,7 @@
107
114
  - ".custom-class"
108
115
  - ".d-flex"
109
116
  - ".d-inline-block"
117
+ - ".d-inline-flex"
110
118
  - ".details-overlay"
111
119
  - ".details-reset"
112
120
  - ".dropdown"
@@ -168,6 +176,7 @@
168
176
  - ".tabnav-tabs"
169
177
  - ".text-bold"
170
178
  - ".text-left"
179
+ - ".text-normal"
171
180
  - ".tooltipped"
172
181
  - ".tooltipped-n"
173
182
  - ".tooltipped-no-delay"
@@ -33,6 +33,26 @@
33
33
  "large"
34
34
  ]
35
35
  },
36
+ "Primer::Alpha::UnderlineNav": {
37
+ "ACTIONS_TAG_DEFAULT": "div",
38
+ "ACTIONS_TAG_OPTIONS": [
39
+ "div",
40
+ "span"
41
+ ],
42
+ "ALIGN_DEFAULT": "left",
43
+ "ALIGN_OPTIONS": [
44
+ "left",
45
+ "right"
46
+ ],
47
+ "BODY_TAG_DEFAULT": "ul",
48
+ "TAG_DEFAULT": "nav",
49
+ "TAG_OPTIONS": [
50
+ "nav",
51
+ "div"
52
+ ]
53
+ },
54
+ "Primer::Alpha::UnderlinePanels": {
55
+ },
36
56
  "Primer::BaseButton": {
37
57
  "DEFAULT_TAG": "button",
38
58
  "DEFAULT_TYPE": "button",
@@ -82,27 +102,39 @@
82
102
  "span"
83
103
  ]
84
104
  },
105
+ "Primer::Beta::Breadcrumbs": {
106
+ "Item": "Primer::Beta::Breadcrumbs::Item"
107
+ },
108
+ "Primer::Beta::Breadcrumbs::Item": {
109
+ },
85
110
  "Primer::Beta::Text": {
86
111
  "DEFAULT_TAG": "span"
87
112
  },
113
+ "Primer::Beta::Truncate": {
114
+ "TruncateText": "Primer::Beta::Truncate::TruncateText"
115
+ },
116
+ "Primer::Beta::Truncate::TruncateText": {
117
+ },
88
118
  "Primer::BlankslateComponent": {
89
119
  },
90
120
  "Primer::BorderBoxComponent": {
91
121
  "DEFAULT_PADDING": "default",
122
+ "DEFAULT_ROW_SCHEME": "default",
92
123
  "PADDING_MAPPINGS": {
93
124
  "default": "",
94
125
  "condensed": "Box--condensed",
95
126
  "spacious": "Box--spacious"
96
127
  },
97
- "PADDING_SUGGESTION": "Perhaps you could consider using :padding options of default, condensed, and spacious?"
128
+ "PADDING_SUGGESTION": "Perhaps you could consider using :padding options of default, condensed, and spacious?",
129
+ "ROW_SCHEME_MAPPINGS": {
130
+ "default": "",
131
+ "neutral": "Box-row--gray",
132
+ "info": "Box-row--blue",
133
+ "warning": "Box-row--yellow"
134
+ }
98
135
  },
99
136
  "Primer::BoxComponent": {
100
137
  },
101
- "Primer::BreadcrumbComponent": {
102
- "ItemComponent": "Primer::BreadcrumbComponent::ItemComponent"
103
- },
104
- "Primer::BreadcrumbComponent::ItemComponent": {
105
- },
106
138
  "Primer::ButtonComponent": {
107
139
  "DEFAULT_SCHEME": "default",
108
140
  "DEFAULT_VARIANT": "medium",
@@ -607,22 +639,5 @@
607
639
  "p",
608
640
  "strong"
609
641
  ]
610
- },
611
- "Primer::UnderlineNavComponent": {
612
- "ACTIONS_TAG_DEFAULT": "div",
613
- "ACTIONS_TAG_OPTIONS": [
614
- "div",
615
- "span"
616
- ],
617
- "ALIGN_DEFAULT": "left",
618
- "ALIGN_OPTIONS": [
619
- "left",
620
- "right"
621
- ],
622
- "BODY_TAG_DEFAULT": "div",
623
- "BODY_TAG_OPTIONS": [
624
- "div",
625
- "ul"
626
- ]
627
642
  }
628
643
  }