primer_view_components 0.0.54 → 0.0.55

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +37 -0
  3. data/app/components/primer/alpha/tab_nav.html.erb +11 -0
  4. data/app/components/primer/alpha/tab_nav.rb +130 -0
  5. data/app/components/primer/{tab_nav_component.html.erb → alpha/tab_panels.html.erb} +3 -8
  6. data/app/components/primer/alpha/tab_panels.rb +82 -0
  7. data/app/components/primer/alpha/underline_nav.rb +1 -7
  8. data/app/components/primer/alpha/underline_panels.html.erb +1 -1
  9. data/app/components/primer/base_component.rb +1 -1
  10. data/app/components/primer/beta/breadcrumbs.html.erb +2 -1
  11. data/app/components/primer/beta/breadcrumbs.rb +15 -13
  12. data/app/components/primer/navigation/tab_component.rb +2 -2
  13. data/app/components/primer/octicon_component.rb +6 -1
  14. data/app/components/primer/tab_container_component.rb +1 -1
  15. data/app/lib/primer/class_name_helper.rb +14 -13
  16. data/app/lib/primer/octicon/cache.rb +10 -2
  17. data/app/lib/primer/tab_nav_helper.rb +35 -0
  18. data/app/lib/primer/tabbed_component_helper.rb +3 -3
  19. data/lib/primer/classify/cache.rb +0 -6
  20. data/lib/primer/classify/utilities.rb +1 -1
  21. data/lib/primer/classify/utilities.yml +35 -0
  22. data/lib/primer/classify.rb +0 -5
  23. data/lib/primer/view_components/version.rb +1 -1
  24. data/lib/rubocop/cop/primer/base_cop.rb +28 -0
  25. data/lib/rubocop/cop/primer/deprecated_arguments.rb +1 -15
  26. data/lib/rubocop/cop/primer/system_argument_instead_of_class.rb +1 -15
  27. data/lib/tasks/docs.rake +5 -5
  28. data/lib/tasks/utilities.rake +2 -0
  29. data/static/arguments.yml +29 -36
  30. data/static/classes.yml +1 -0
  31. data/static/constants.json +16 -17
  32. data/static/statuses.json +2 -1
  33. metadata +22 -5
  34. data/app/components/primer/tab_nav_component.rb +0 -151
  35. data/lib/primer/classify/functional_text_colors.rb +0 -64
@@ -41,7 +41,12 @@ module Primer
41
41
  system_arguments.delete(:width)
42
42
  end
43
43
 
44
- cache_key = Primer::Octicon::Cache.get_key(symbol: icon_key, size: size, **system_arguments.slice(:height, :width))
44
+ cache_key = Primer::Octicon::Cache.get_key(
45
+ symbol: icon_key,
46
+ size: size,
47
+ height: system_arguments[:height],
48
+ width: system_arguments[:width]
49
+ )
45
50
 
46
51
  @system_arguments = system_arguments
47
52
  @system_arguments[:tag] = :svg
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Primer
4
4
  # Use `TabContainer` to create tabbed content with keyboard support. This component does not add any styles.
5
- # It only provides the tab functionality. If you want styled Tabs you can look at <%= link_to_component(Primer::TabNavComponent) %>.
5
+ # It only provides the tab functionality. If you want styled Tabs you can look at <%= link_to_component(Primer::Alpha::TabNav) %>.
6
6
  #
7
7
  # This component requires javascript.
8
8
  class TabContainerComponent < Primer::Component
@@ -7,22 +7,23 @@ module Primer
7
7
  # :nodoc:
8
8
  module ClassNameHelper
9
9
  def class_names(*args)
10
- classes = []
11
-
12
- args.each do |class_name|
13
- case class_name
14
- when String
15
- classes << class_name if class_name.present?
16
- when Hash
17
- class_name.each do |key, val|
18
- classes << key if val
10
+ [].tap do |classes|
11
+ args.each do |class_name|
12
+ case class_name
13
+ when String
14
+ classes << class_name if class_name.present?
15
+ when Hash
16
+ class_name.each do |key, val|
17
+ classes << key if val
18
+ end
19
+ when Array
20
+ classes << class_names(*class_name).presence
19
21
  end
20
- when Array
21
- classes << class_names(*class_name).presence
22
22
  end
23
- end
24
23
 
25
- classes.compact.uniq.join(" ")
24
+ classes.compact!
25
+ classes.uniq!
26
+ end.join(" ")
26
27
  end
27
28
  end
28
29
  end
@@ -9,8 +9,9 @@ module Primer
9
9
  PRELOADED_ICONS = [:alert, :check, :"chevron-down", :paste, :clock, :"dot-fill", :info, :"kebab-horizontal", :link, :lock, :mail, :pencil, :plus, :question, :repo, :search, :"shield-lock", :star, :trash, :x].freeze
10
10
 
11
11
  class << self
12
- def get_key(symbol:, size:, width: nil, height: nil)
13
- [symbol, size, width, height].join("_")
12
+ def get_key(**kwargs)
13
+ correct_key_args?(**kwargs)
14
+ kwargs.hash
14
15
  end
15
16
 
16
17
  def read(key)
@@ -36,6 +37,13 @@ module Primer
36
37
  def preload!
37
38
  PRELOADED_ICONS.each { |icon| Primer::OcticonComponent.new(icon: icon) }
38
39
  end
40
+
41
+ private
42
+
43
+ def correct_key_args?(symbol:, size:, width: nil, height: nil)
44
+ # This method does nothing but will raise an ArgumentError if the
45
+ # wrong args are passed.
46
+ end
39
47
  end
40
48
  end
41
49
  end
@@ -0,0 +1,35 @@
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 TabNavHelper
9
+ extend ActiveSupport::Concern
10
+
11
+ EXTRA_ALIGN_DEFAULT = :left
12
+ EXTRA_ALIGN_OPTIONS = [EXTRA_ALIGN_DEFAULT, :right].freeze
13
+
14
+ def tab_nav_tab_classes(classes)
15
+ class_names(
16
+ "tabnav-tab",
17
+ classes
18
+ )
19
+ end
20
+
21
+ def tab_nav_classes(classes)
22
+ class_names(
23
+ "tabnav",
24
+ classes
25
+ )
26
+ end
27
+
28
+ def tab_nav_body_classes(classes)
29
+ class_names(
30
+ "tabnav-tabs",
31
+ classes
32
+ )
33
+ end
34
+ end
35
+ end
@@ -16,11 +16,11 @@ module Primer
16
16
 
17
17
  private
18
18
 
19
- def navigation_tag(with_panel)
20
- with_panel ? :div : :nav
19
+ def aria_label_for_page_nav(label)
20
+ @system_arguments[:tag] == :nav ? @system_arguments[:"aria-label"] = label : @body_arguments[:"aria-label"] = label
21
21
  end
22
22
 
23
- def wrapper(with_panel:, **system_arguments)
23
+ def tab_container_wrapper(with_panel:, **system_arguments)
24
24
  return yield unless with_panel
25
25
 
26
26
  render Primer::TabContainerComponent.new(**system_arguments) do
@@ -3,7 +3,6 @@
3
3
  require_relative "flex"
4
4
  require_relative "functional_background_colors"
5
5
  require_relative "functional_border_colors"
6
- require_relative "functional_text_colors"
7
6
  require_relative "grid"
8
7
 
9
8
  module Primer
@@ -55,11 +54,6 @@ module Primer
55
54
  values: Primer::Classify::Grid::COL_VALUES
56
55
  )
57
56
 
58
- preload(
59
- keys: [Primer::Classify::COLOR_KEY],
60
- values: Primer::Classify::FunctionalTextColors::OPTIONS
61
- )
62
-
63
57
  preload(
64
58
  keys: [Primer::Classify::BG_KEY],
65
59
  values: Primer::Classify::FunctionalBackgroundColors::OPTIONS
@@ -175,7 +175,7 @@ module Primer
175
175
  unless supported_value?(key, val)
176
176
  raise ArgumentError, "#{val} is not a valid value for :#{key}. Use one of #{mappings(key)}" unless ENV["RAILS_ENV"] == "production"
177
177
 
178
- return ""
178
+ return "#{key.to_s.dasherize}-#{val.to_s.dasherize}"
179
179
  end
180
180
 
181
181
  nil
@@ -22,6 +22,39 @@
22
22
  - anim-hover-grow
23
23
  :rotate:
24
24
  - anim-rotate
25
+ :color:
26
+ :text_primary:
27
+ - color-text-primary
28
+ :text_secondary:
29
+ - color-text-secondary
30
+ :text_tertiary:
31
+ - color-text-tertiary
32
+ :text_link:
33
+ - color-text-link
34
+ :text_success:
35
+ - color-text-success
36
+ :text_warning:
37
+ - color-text-warning
38
+ :text_danger:
39
+ - color-text-danger
40
+ :text_inverse:
41
+ - color-text-inverse
42
+ :text_white:
43
+ - color-text-white
44
+ :icon_primary:
45
+ - color-icon-primary
46
+ :icon_secondary:
47
+ - color-icon-secondary
48
+ :icon_tertiary:
49
+ - color-icon-tertiary
50
+ :icon_info:
51
+ - color-icon-info
52
+ :icon_danger:
53
+ - color-icon-danger
54
+ :icon_success:
55
+ - color-icon-success
56
+ :icon_warning:
57
+ - color-icon-warning
25
58
  :position:
26
59
  :static:
27
60
  - position-static
@@ -1220,6 +1253,8 @@
1220
1253
  - py-lg-12
1221
1254
  - py-xl-12
1222
1255
  :word_break:
1256
+ :break_word:
1257
+ - wb-break-word
1223
1258
  :break_all:
1224
1259
  - wb-break-all
1225
1260
  :display:
@@ -4,7 +4,6 @@ require_relative "classify/cache"
4
4
  require_relative "classify/flex"
5
5
  require_relative "classify/functional_background_colors"
6
6
  require_relative "classify/functional_border_colors"
7
- require_relative "classify/functional_text_colors"
8
7
  require_relative "classify/grid"
9
8
  require_relative "classify/utilities"
10
9
  require_relative "classify/validation"
@@ -15,7 +14,6 @@ module Primer
15
14
  # Keys where we can simply translate { key: value } into ".key-value"
16
15
  CONCAT_KEYS = %i[text box_shadow].freeze
17
16
 
18
- COLOR_KEY = :color
19
17
  BG_KEY = :bg
20
18
  TEXT_KEYS = %i[font_family font_style font_weight text_align text_transform].freeze
21
19
  BOX_SHADOW_KEY = :box_shadow
@@ -88,7 +86,6 @@ module Primer
88
86
  BORDER_KEY,
89
87
  BORDER_COLOR_KEY,
90
88
  BORDER_RADIUS_KEY,
91
- COLOR_KEY,
92
89
  BG_KEY,
93
90
  BOX_SHADOW_KEY,
94
91
  CONTAINER_KEY
@@ -176,8 +173,6 @@ module Primer
176
173
  else
177
174
  memo[:classes] << Primer::Classify::FunctionalBackgroundColors.color(val)
178
175
  end
179
- elsif key == COLOR_KEY
180
- memo[:classes] << Primer::Classify::FunctionalTextColors.color(val)
181
176
  elsif key == BORDER_KEY
182
177
  border_value = if val == true
183
178
  "border"
@@ -5,7 +5,7 @@ module Primer
5
5
  module VERSION
6
6
  MAJOR = 0
7
7
  MINOR = 0
8
- PATCH = 54
8
+ PATCH = 55
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
11
11
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+ require "primer/view_components/statuses"
5
+ require_relative "../../../../app/lib/primer/view_helper"
6
+
7
+ module RuboCop
8
+ module Cop
9
+ module Primer
10
+ # :nodoc:
11
+ class BaseCop < RuboCop::Cop::Cop
12
+ # We only verify SystemArguments if it's a `.new` call on a component or
13
+ # a ViewHeleper call.
14
+ def valid_node?(node)
15
+ return if node.nil?
16
+
17
+ view_helpers.include?(node.method_name) || (node.method_name == :new && !node.receiver.nil? && ::Primer::ViewComponents::STATUSES.key?(node.receiver.const_name))
18
+ end
19
+
20
+ private
21
+
22
+ def view_helpers
23
+ ::Primer::ViewHelper::HELPERS.keys.map { |key| "primer_#{key}".to_sym }
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rubocop"
4
- require "primer/view_components/statuses"
5
- require_relative "../../../../app/lib/primer/view_helper"
6
4
 
7
5
  # :nocov:
8
6
  module RuboCop
@@ -15,7 +13,7 @@ module RuboCop
15
13
  #
16
14
  # good
17
15
  # Component.new(foo: :bar)
18
- class DeprecatedArguments < RuboCop::Cop::Cop
16
+ class DeprecatedArguments < BaseCop
19
17
  INVALID_MESSAGE = <<~STR
20
18
  Avoid using deprecated arguments: https://primer.style/view-components/deprecated.
21
19
  STR
@@ -259,18 +257,6 @@ module RuboCop
259
257
  corrector.replace(node, replacement) if replacement.present?
260
258
  end
261
259
  end
262
-
263
- private
264
-
265
- # We only verify SystemArguments if it's a `.new` call on a component or
266
- # a ViewHleper call.
267
- def valid_node?(node)
268
- view_helpers.include?(node.method_name) || (node.method_name == :new && ::Primer::ViewComponents::STATUSES.key?(node.receiver.const_name))
269
- end
270
-
271
- def view_helpers
272
- ::Primer::ViewHelper::HELPERS.keys.map { |key| "primer_#{key}".to_sym }
273
- end
274
260
  end
275
261
  end
276
262
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  require "rubocop"
4
4
  require "primer/classify/utilities"
5
- require "primer/view_components/statuses"
6
- require_relative "../../../../app/lib/primer/view_helper"
7
5
 
8
6
  # :nocov:
9
7
  module RuboCop
@@ -16,7 +14,7 @@ module RuboCop
16
14
  #
17
15
  # good
18
16
  # Component.new(mr: 1)
19
- class SystemArgumentInsteadOfClass < RuboCop::Cop::Cop
17
+ class SystemArgumentInsteadOfClass < BaseCop
20
18
  INVALID_MESSAGE = <<~STR
21
19
  Avoid using CSS classes when you can use System Arguments: https://primer.style/view-components/system-arguments.
22
20
  STR
@@ -53,18 +51,6 @@ module RuboCop
53
51
  corrector.replace(node.loc.expression, args)
54
52
  end
55
53
  end
56
-
57
- private
58
-
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
64
-
65
- def view_helpers
66
- ::Primer::ViewHelper::HELPERS.keys.map { |key| "primer_#{key}".to_sym }
67
- end
68
54
  end
69
55
  end
70
56
  end
data/lib/tasks/docs.rake CHANGED
@@ -68,7 +68,6 @@ namespace :docs do
68
68
  Primer::SpinnerComponent,
69
69
  Primer::SubheadComponent,
70
70
  Primer::TabContainerComponent,
71
- Primer::TabNavComponent,
72
71
  Primer::Beta::Text,
73
72
  Primer::TimeAgoComponent,
74
73
  Primer::TimelineItemComponent,
@@ -76,7 +75,8 @@ namespace :docs do
76
75
  Primer::Truncate,
77
76
  Primer::Beta::Truncate,
78
77
  Primer::Alpha::UnderlineNav,
79
- Primer::Alpha::UnderlinePanels
78
+ Primer::Alpha::TabNav,
79
+ Primer::Alpha::TabPanels
80
80
  ]
81
81
 
82
82
  js_components = [
@@ -86,9 +86,9 @@ namespace :docs do
86
86
  Primer::Beta::AutoComplete,
87
87
  Primer::ClipboardCopy,
88
88
  Primer::TabContainerComponent,
89
- Primer::TabNavComponent,
90
89
  Primer::TimeAgoComponent,
91
- Primer::Alpha::UnderlinePanels
90
+ Primer::Alpha::UnderlinePanels,
91
+ Primer::Alpha::TabPanels
92
92
  ]
93
93
 
94
94
  all_components = Primer::Component.descendants - [Primer::BaseComponent]
@@ -206,7 +206,7 @@ namespace :docs do
206
206
  f.puts
207
207
  f.puts("### `#{slot_documentation.name.to_s.capitalize}`")
208
208
 
209
- if slot_documentation.base_docstring.present?
209
+ if slot_documentation.base_docstring.to_s.present?
210
210
  f.puts
211
211
  f.puts(view_context.render(inline: slot_documentation.base_docstring))
212
212
  end
@@ -11,6 +11,8 @@ namespace :utilities do
11
11
  # rubocop:disable Lint/ConstantDefinitionInBlock
12
12
  SUPPORTED_KEYS = %i[
13
13
  anim
14
+ color-icon
15
+ color-text
14
16
  d
15
17
  float
16
18
  height
data/static/arguments.yml CHANGED
@@ -22,8 +22,8 @@
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
25
+ - component: TabNav
26
+ source: https://github.com/primer/view_components/tree/main/app/components/primer/alpha/tab_nav.rb
27
27
  parameters:
28
28
  - name: tag
29
29
  type: Symbol
@@ -34,10 +34,6 @@
34
34
  default: N/A
35
35
  description: Sets an `aria-label` that helps assistive technology users understand
36
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
37
  - name: body_arguments
42
38
  type: Hash
43
39
  default: "`{}`"
@@ -46,8 +42,8 @@
46
42
  type: Hash
47
43
  default: N/A
48
44
  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
45
+ - component: TabPanels
46
+ source: https://github.com/primer/view_components/tree/main/app/components/primer/alpha/tab_panels.rb
51
47
  parameters:
52
48
  - name: label
53
49
  type: String
@@ -56,7 +52,7 @@
56
52
  the purpose of the tabs.
57
53
  - name: align
58
54
  type: Symbol
59
- default: "`:left`"
55
+ default: N/A
60
56
  description: One of `:left` and `:right`. - Defaults to left
61
57
  - name: body_arguments
62
58
  type: Hash
@@ -70,6 +66,30 @@
70
66
  type: Hash
71
67
  default: N/A
72
68
  description: "[System arguments](/system-arguments)"
69
+ - component: UnderlineNav
70
+ source: https://github.com/primer/view_components/tree/main/app/components/primer/alpha/underline_nav.rb
71
+ parameters:
72
+ - name: tag
73
+ type: Symbol
74
+ default: "`:nav`"
75
+ description: One of `:div` and `:nav`.
76
+ - name: label
77
+ type: String
78
+ default: N/A
79
+ description: Sets an `aria-label` that helps assistive technology users understand
80
+ the purpose of the links, and distinguish it from similar elements.
81
+ - name: align
82
+ type: Symbol
83
+ default: "`:left`"
84
+ description: One of `:left` and `:right`. - Defaults to left
85
+ - name: body_arguments
86
+ type: Hash
87
+ default: "`{}`"
88
+ description: "[System arguments](/system-arguments) for the body wrapper."
89
+ - name: system_arguments
90
+ type: Hash
91
+ default: N/A
92
+ description: "[System arguments](/system-arguments)"
73
93
  - component: BaseButton
74
94
  source: https://github.com/primer/view_components/tree/main/app/components/primer/base_button.rb
75
95
  parameters:
@@ -886,33 +906,6 @@
886
906
  type: Hash
887
907
  default: N/A
888
908
  description: "[System arguments](/system-arguments)"
889
- - component: TabNav
890
- source: https://github.com/primer/view_components/tree/main/app/components/primer/tab_nav_component.rb
891
- parameters:
892
- - name: label
893
- type: String
894
- default: N/A
895
- description: Used to set the `aria-label` on the top level `<nav>` element.
896
- - name: with_panel
897
- type: Boolean
898
- default: "`false`"
899
- description: Whether the TabNav should navigate through pages or panels. When
900
- true, [TabContainer](/components/tabcontainer) is rendered along with JavaScript
901
- behavior. Additionally, the `tab` slot will render as a button as opposed to
902
- an anchor.
903
- - name: body_arguments
904
- type: Hash
905
- default: "`{}`"
906
- description: "[System arguments](/system-arguments) for the body wrapper."
907
- - name: wrapper_arguments
908
- type: Hash
909
- default: "`{}`"
910
- description: "[System arguments](/system-arguments) for the `TabContainer` wrapper.
911
- Only applies if `with_panel` is `true`."
912
- - name: system_arguments
913
- type: Hash
914
- default: N/A
915
- description: "[System arguments](/system-arguments)"
916
909
  - component: TimeAgo
917
910
  source: https://github.com/primer/view_components/tree/main/app/components/primer/time_ago_component.rb
918
911
  parameters: