primer_view_components 0.0.49 → 0.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43c27ddfb1f920ba9dfd9989d859cc61b3fd26bc3788a44873412c971ad58cc1
4
- data.tar.gz: 640aed54b2b1e68bb24c06989320f445da9e2e3c2981e959e693345f61fc92cf
3
+ metadata.gz: 81f226f5fd176e5a1565b2064ba3a85a8af1c11bfd7c3c9503714f3f5cd41dac
4
+ data.tar.gz: d655dc0cfa7260a09de3f1f662a1317eb2540914407f33cfdbc07b369a6cd5b0
5
5
  SHA512:
6
- metadata.gz: 7c6b6ce07b479c462a01cfe65ccda3da920689c5e6642231f897bf5f92f559836d30d6f01bfec2c7ae99545c391abe25b85e7cd45da18de8249f63176b00bedb
7
- data.tar.gz: ef88c518675d73c7c418fee48a11f173200f3a98ab4f10115fcfad5ccf5fa4ef0b3452da7bb9577a55a3d3286a3536f616f56aac4a07108421e8466abc76250b
6
+ metadata.gz: 07bc38eedefeae46a76d6f7a4b28892a4f01ab0018564c610d8143919c3fed93da3ad91c7970225fdfaac1fd12a294b51e245633f690e87b7392a21d3d3d65f8
7
+ data.tar.gz: c162cf3fca8accf0a92b9045e9e77bce16d3e646793a3fd479b12efd7e545e0cb9c56cc60884b39965ed7f41baf502d990cee3279170a3b896c845558a3ba714
data/CHANGELOG.md CHANGED
@@ -30,6 +30,44 @@ The category for changes related to documentation, testing and tooling. Also, fo
30
30
 
31
31
  ## main
32
32
 
33
+ ## 0.0.50
34
+
35
+ ### New
36
+
37
+ * Add linter suggestions for `CloseButton` component.
38
+
39
+ *Manuel Puyol*
40
+
41
+ ### Breaking changes
42
+
43
+ * Update to `octicons` `v15`, removing open-ended dependency. See [https://github.com/primer/octicons/releases/tag/v15.0.0] for icon name changes in release.
44
+
45
+ *Joel Hawksley*
46
+
47
+ ### Updates
48
+
49
+ * Don't require `title` for `Label`.
50
+
51
+ *Manuel Puyol*
52
+
53
+ * Improve autocorrectable linters to convert known SystemArgument classes.
54
+
55
+ *Manuel Puyol*
56
+
57
+ * Add support for `width: :full` and `height: :full` to System Arguments.
58
+
59
+ *Joel Hawksley*
60
+
61
+ ### Bug fixes
62
+
63
+ * Update linters to not autocorrect attributes with ERB blocks.
64
+
65
+ *Manuel Puyol*
66
+
67
+ * Fix `:height` and `:width` docs to pull from Utilities
68
+
69
+ *Jon Rohan*
70
+
33
71
  ## 0.0.49
34
72
 
35
73
  ### New
@@ -79,7 +79,6 @@ module Primer
79
79
  # | `flex_shrink` | Integer | To enable, set to `0`. |
80
80
  # | `flex_wrap` | Symbol | <%= one_of(Primer::Classify::Flex::WRAP_MAPPINGS.keys) %> |
81
81
  # | `justify_content` | Symbol | <%= one_of(Primer::Classify::Flex::JUSTIFY_CONTENT_VALUES) %> |
82
- # | `width` | Symbol | <%= one_of([:fit]) %> |
83
82
  #
84
83
  # ## Grid
85
84
  #
@@ -94,7 +93,8 @@ module Primer
94
93
  # | Name | Type | Description |
95
94
  # | :- | :- | :- |
96
95
  # | `display` | Symbol | <%= one_of(Primer::Classify::Utilities.mappings(:display)) %> |
97
- # | `height` | Symbol | <%= one_of([:fit]) %> |
96
+ # | `width` | Symbol | <%= one_of(Primer::Classify::Utilities.mappings(:width)) %>. Also supports integer values. |
97
+ # | `height` | Symbol | <%= one_of(Primer::Classify::Utilities.mappings(:height)) %>. Also supports integer values. |
98
98
  # | `hide` | Symbol | Hide the element at a specific breakpoint. <%= one_of(Primer::Classify::Utilities.mappings(:hide)) %> |
99
99
  # | `visibility` | Symbol | Visibility. <%= one_of(Primer::Classify::Utilities.mappings(:visibility)) %> |
100
100
  # | `vertical_align` | Symbol | <%= one_of(Primer::Classify::Utilities.mappings(:vertical_align)) %> |
@@ -2,7 +2,7 @@
2
2
  <% if content.present? %>
3
3
  <%= content %>
4
4
  <% else %>
5
- <%= render Primer::OcticonComponent.new("clippy") %>
6
- <%= render Primer::OcticonComponent.new("check", color: :icon_success, style: "display: none;") %>
5
+ <%= render Primer::OcticonComponent.new(:paste) %>
6
+ <%= render Primer::OcticonComponent.new(:check, color: :icon_success, style: "display: none;") %>
7
7
  <% end %>
8
8
  <% end %>
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Primer
4
4
  # Use `Label` to add contextual metadata to a design.
5
+ #
6
+ # @accessibility
7
+ # Use `aria-label` if the `Label` or the context around it don't explain the label.
5
8
  class LabelComponent < Primer::Component
6
9
  status :beta
7
10
 
@@ -29,27 +32,25 @@ module Primer
29
32
  VARIANT_OPTIONS = VARIANT_MAPPINGS.keys << nil
30
33
 
31
34
  # @example Schemes
32
- # <%= render(Primer::LabelComponent.new(title: "Label: Label")) { "Default" } %>
33
- # <%= render(Primer::LabelComponent.new(title: "Label: Label", scheme: :primary)) { "Primary" } %>
34
- # <%= render(Primer::LabelComponent.new(title: "Label: Label", scheme: :secondary)) { "Secondary" } %>
35
- # <%= render(Primer::LabelComponent.new(title: "Label: Label", scheme: :info)) { "Info" } %>
36
- # <%= render(Primer::LabelComponent.new(title: "Label: Label", scheme: :success)) { "Success" } %>
37
- # <%= render(Primer::LabelComponent.new(title: "Label: Label", scheme: :warning)) { "Warning" } %>
38
- # <%= render(Primer::LabelComponent.new(title: "Label: Label", scheme: :danger)) { "Danger" } %>
35
+ # <%= render(Primer::LabelComponent.new) { "Default" } %>
36
+ # <%= render(Primer::LabelComponent.new( scheme: :primary)) { "Primary" } %>
37
+ # <%= render(Primer::LabelComponent.new( scheme: :secondary)) { "Secondary" } %>
38
+ # <%= render(Primer::LabelComponent.new( scheme: :info)) { "Info" } %>
39
+ # <%= render(Primer::LabelComponent.new( scheme: :success)) { "Success" } %>
40
+ # <%= render(Primer::LabelComponent.new( scheme: :warning)) { "Warning" } %>
41
+ # <%= render(Primer::LabelComponent.new( scheme: :danger)) { "Danger" } %>
39
42
  #
40
43
  # @example Variants
41
- # <%= render(Primer::LabelComponent.new(title: "Label: Label")) { "Default" } %>
42
- # <%= render(Primer::LabelComponent.new(title: "Label: Label", variant: :large)) { "Large" } %>
44
+ # <%= render(Primer::LabelComponent.new) { "Default" } %>
45
+ # <%= render(Primer::LabelComponent.new( variant: :large)) { "Large" } %>
43
46
  #
44
47
  # @param tag [Symbol] <%= one_of(Primer::LabelComponent::TAG_OPTIONS) %>
45
- # @param title [String] `title` attribute for the component element.
46
48
  # @param scheme [Symbol] <%= one_of(Primer::LabelComponent::SCHEME_MAPPINGS.keys) %>
47
49
  # @param variant [Symbol] <%= one_of(Primer::LabelComponent::VARIANT_OPTIONS) %>
48
50
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
49
- def initialize(tag: DEFAULT_TAG, title:, scheme: nil, variant: nil, **system_arguments)
51
+ def initialize(tag: DEFAULT_TAG, scheme: nil, variant: nil, **system_arguments)
50
52
  @system_arguments = system_arguments
51
53
  @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)
52
- @system_arguments[:title] = title
53
54
  @system_arguments[:classes] = class_names(
54
55
  "Label",
55
56
  system_arguments[:classes],
@@ -6,7 +6,7 @@ module Primer
6
6
  class Cache
7
7
  LOOKUP = {} # rubocop:disable Style/MutableConstant
8
8
  # Preload the top 20 used icons.
9
- PRELOADED_ICONS = [:alert, :check, :"chevron-down", :clippy, :clock, :"dot-fill", :info, :"kebab-horizontal", :link, :lock, :mail, :pencil, :plus, :question, :repo, :search, :"shield-lock", :star, :trash, :x].freeze
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
12
  def get_key(symbol:, size:, width: nil, height: nil)
@@ -170,7 +170,9 @@ module Primer
170
170
  def extract_value(memo, key, val, breakpoint)
171
171
  return if val.nil? || val == ""
172
172
 
173
- if Primer::Classify::Utilities.supported_key?(key)
173
+ if (key == WIDTH_KEY || key == HEIGHT_KEY) && !val.is_a?(Symbol)
174
+ memo[key] = val
175
+ elsif Primer::Classify::Utilities.supported_key?(key)
174
176
  memo[:classes] << Primer::Classify::Utilities.classname(key, val, breakpoint)
175
177
  elsif BOOLEAN_MAPPINGS.key?(key)
176
178
  BOOLEAN_MAPPINGS[key][:mappings].each do |m|
@@ -202,12 +204,6 @@ module Primer
202
204
  memo[:classes] << Primer::Classify::Flex.classes(key, val, breakpoint)
203
205
  elsif Primer::Classify::Grid::KEYS.include?(key)
204
206
  memo[:classes] << Primer::Classify::Grid.classes(key, val, breakpoint)
205
- elsif key == WIDTH_KEY || key == HEIGHT_KEY
206
- if val == :fit
207
- memo[:classes] << "#{key}-#{val}"
208
- else
209
- memo[key] = val
210
- end
211
207
  elsif TEXT_KEYS.include?(key)
212
208
  memo[:classes] << "text-#{val.to_s.dasherize}"
213
209
  elsif TYPOGRAPHY_KEYS.include?(key)
@@ -95,11 +95,6 @@ module Primer
95
95
  values: Primer::Classify::Flex::ALIGN_SELF_VALUES
96
96
  )
97
97
 
98
- preload(
99
- keys: [Primer::Classify::WIDTH_KEY, Primer::Classify::HEIGHT_KEY],
100
- values: [:fit]
101
- )
102
-
103
98
  preload(
104
99
  keys: Primer::Classify::BOX_SHADOW_KEY,
105
100
  values: [true, :small, :medium, :large, :extra_large, :none]
@@ -85,6 +85,22 @@
85
85
  - float-md-none
86
86
  - float-lg-none
87
87
  - float-xl-none
88
+ :width:
89
+ :fit:
90
+ - width-fit
91
+ :full:
92
+ - width-full
93
+ :auto:
94
+ - width-auto
95
+ - width-sm-auto
96
+ - width-md-auto
97
+ - width-lg-auto
98
+ - width-xl-auto
99
+ :height:
100
+ :fit:
101
+ - height-fit
102
+ :full:
103
+ - height-full
88
104
  :m:
89
105
  0:
90
106
  - m-0
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "primer/view_components/constants"
4
+ require "primer/classify/utilities"
3
5
  require_relative "conversion_error"
4
6
  require_relative "system_arguments"
5
- require "primer/view_components/constants"
7
+ require_relative "helpers/erb_block"
6
8
 
7
9
  module ERBLint
8
10
  module Linters
@@ -11,6 +13,7 @@ module ERBLint
11
13
  # Override attribute_to_args in a child class to customize its mapping behavior.
12
14
  class Base
13
15
  DEFAULT_TAG = nil
16
+ ATTRIBUTES = [].freeze
14
17
 
15
18
  def initialize(tag)
16
19
  @tag = tag
@@ -26,13 +29,45 @@ module ERBLint
26
29
  args[:tag] = ":#{@tag.name}" unless self.class::DEFAULT_TAG.nil? || @tag.name == self.class::DEFAULT_TAG
27
30
 
28
31
  @tag.attributes.each do |attribute|
29
- args.merge!(attribute_to_args(attribute))
32
+ attr_name = attribute.name
33
+
34
+ if self.class::ATTRIBUTES.include?(attr_name)
35
+ args.merge!(attribute_to_args(attribute))
36
+ elsif attr_name == "class"
37
+ args.merge!(map_classes(attribute))
38
+ else
39
+ # Assume the attribute is a system argument.
40
+ args.merge!(SystemArguments.new(attribute).to_args)
41
+ end
30
42
  end
31
43
 
32
44
  args
33
45
  end
34
46
 
35
47
  def attribute_to_args(attribute); end
48
+
49
+ def map_classes(classes)
50
+ system_arguments = system_arguments_to_args(classes.value)
51
+ args = classes_to_args(system_arguments[:classes])
52
+
53
+ args.merge(system_arguments.except(:classes))
54
+ end
55
+
56
+ # Override this with your component's mappings
57
+ def classes_to_args(classes)
58
+ raise ConversionError, "Cannot convert classes `#{classes}`" if classes.present?
59
+
60
+ {}
61
+ end
62
+
63
+ def system_arguments_to_args(classes)
64
+ system_arguments = Primer::Classify::Utilities.classes_to_hash(classes)
65
+
66
+ # need to transform symbols to strings with leading `:`
67
+ system_arguments.transform_values do |v|
68
+ v.is_a?(Symbol) ? ":#{v}" : v
69
+ end
70
+ end
36
71
  end
37
72
  end
38
73
  end
@@ -30,12 +30,12 @@ module ERBLint
30
30
  constant: "DEFAULT_TAG"
31
31
  ).freeze
32
32
 
33
+ ATTRIBUTES = %w[disabled type].freeze
34
+
33
35
  def attribute_to_args(attribute)
34
36
  attr_name = attribute.name
35
37
 
36
- if attr_name == "class"
37
- classes_to_args(attribute)
38
- elsif attr_name == "disabled"
38
+ if attr_name == "disabled"
39
39
  { disabled: true }
40
40
  elsif attr_name == "type"
41
41
  # button is the default type, so we don't need to do anything.
@@ -44,14 +44,11 @@ module ERBLint
44
44
  raise ConversionError, "Button component does not support type \"#{attribute.value}\"" unless TYPE_OPTIONS.include?(attribute.value)
45
45
 
46
46
  { type: ":#{attribute.value}" }
47
- else
48
- # Assume the attribute is a system argument.
49
- SystemArguments.new(attribute).to_args
50
47
  end
51
48
  end
52
49
 
53
50
  def classes_to_args(classes)
54
- classes.value.split(" ").each_with_object({}) do |class_name, acc|
51
+ classes.split(" ").each_with_object({}) do |class_name, acc|
55
52
  next if class_name == "btn"
56
53
 
57
54
  if SCHEME_MAPPINGS[class_name] && acc[:scheme].nil?
@@ -8,16 +8,11 @@ module ERBLint
8
8
  # Maps attributes in the clipboard-copy element to arguments for the ClipboardCopy component.
9
9
  class ClipboardCopy < Base
10
10
  DEFAULT_TAG = "clipboard-copy"
11
+ ATTRIBUTES = %w[value].freeze
11
12
 
12
13
  def attribute_to_args(attribute)
13
- attr_name = attribute.name
14
-
15
- if attr_name == "value"
16
- { value: attribute.value.to_json }
17
- else
18
- # Assume the attribute is a system argument.
19
- SystemArguments.new(attribute).to_args
20
- end
14
+ Helpers::ErbBlock.raise_if_erb_block(attribute)
15
+ { value: attribute.value.to_json }
21
16
  end
22
17
  end
23
18
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../conversion_error"
4
+
5
+ module ERBLint
6
+ module Linters
7
+ module ArgumentMappers
8
+ module Helpers
9
+ # provides helpers to identify and deal with ERB blocks.
10
+ class ErbBlock
11
+ class << self
12
+ def raise_if_erb_block(attribute)
13
+ raise ERBLint::Linters::ArgumentMappers::ConversionError, "Cannot convert attribute \"#{attribute.name}\" because its value contains an erb block" if any?(attribute)
14
+ end
15
+
16
+ def any?(attribute)
17
+ attribute.value_node&.children&.any? { |n| n.try(:type) == :erb }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -24,21 +24,15 @@ module ERBLint
24
24
  constant: "DEFAULT_TAG"
25
25
  ).freeze
26
26
 
27
+ ATTRIBUTES = %w[title].freeze
28
+
27
29
  def attribute_to_args(attribute)
28
- attr_name = attribute.name
29
-
30
- if attr_name == "class"
31
- classes_to_args(attribute)
32
- elsif attr_name == "title"
33
- { title: attribute.value.to_json }
34
- else
35
- # Assume the attribute is a system argument.
36
- SystemArguments.new(attribute).to_args
37
- end
30
+ Helpers::ErbBlock.raise_if_erb_block(attribute)
31
+ { title: attribute.value.to_json }
38
32
  end
39
33
 
40
34
  def classes_to_args(classes)
41
- classes.value.split(" ").each_with_object({}) do |class_name, acc|
35
+ classes.split(" ").each_with_object({}) do |class_name, acc|
42
36
  next if class_name == "Label"
43
37
 
44
38
  if SCHEME_MAPPINGS[class_name] && acc[:scheme].nil?
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "conversion_error"
4
+ require_relative "helpers/erb_block"
4
5
 
5
6
  module ERBLint
6
7
  module Linters
@@ -28,9 +29,11 @@ module ERBLint
28
29
 
29
30
  { test_selector: m[:selector].tr("'", '"') }
30
31
  elsif attr_name == "data-test-selector"
32
+ Helpers::ErbBlock.raise_if_erb_block(attribute)
33
+
31
34
  { test_selector: attribute.value.to_json }
32
35
  elsif attr_name.start_with?(*STRING_PARAMETERS)
33
- raise ConversionError, "Cannot convert attribute \"#{attr_name}\" because its value contains an erb block" if attribute.value_node&.children&.any? { |n| n.try(:type) == :erb }
36
+ Helpers::ErbBlock.raise_if_erb_block(attribute)
34
37
 
35
38
  { "\"#{attr_name}\"" => attribute.value.to_json }
36
39
  else
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "helpers"
4
+
5
+ module ERBLint
6
+ module Linters
7
+ # Counts the number of times a HTML clipboard-copy is used instead of the component.
8
+ class CloseButtonComponentMigrationCounter < Linter
9
+ include Helpers
10
+
11
+ TAGS = %w[button].freeze
12
+ CLASSES = %w[close-button].freeze
13
+ MESSAGE = "We are migrating close-button to use [Primer::CloseButton](https://primer.style/view-components/components/closebutton), please try to use that instead of raw HTML."
14
+ end
15
+ end
16
+ end
@@ -5,7 +5,7 @@ module Primer
5
5
  module VERSION
6
6
  MAJOR = 0
7
7
  MINOR = 0
8
- PATCH = 49
8
+ PATCH = 50
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
11
11
  end
@@ -12,11 +12,13 @@ namespace :utilities do
12
12
  anim
13
13
  d
14
14
  float
15
+ height
15
16
  hide
16
17
  m mt mr mb ml mx my
17
18
  p pt pr pb pl px py
18
19
  position
19
20
  wb
21
+ width
20
22
  v
21
23
  ].freeze
22
24
 
data/static/arguments.yml CHANGED
@@ -562,10 +562,6 @@
562
562
  type: Symbol
563
563
  default: "`:span`"
564
564
  description: One of `:a`, `:div`, `:span`, or `:summary`.
565
- - name: title
566
- type: String
567
- default: N/A
568
- description: "`title` attribute for the component element."
569
565
  - name: scheme
570
566
  type: Symbol
571
567
  default: "`nil`"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primer_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.49
4
+ version: 0.0.50
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-07-27 00:00:00.000000000 Z
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: octicons
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 13.0.0
47
+ version: '15'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 13.0.0
54
+ version: '15'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: view_component
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -484,11 +484,13 @@ files:
484
484
  - lib/primer/view_components/linters/argument_mappers/button.rb
485
485
  - lib/primer/view_components/linters/argument_mappers/clipboard_copy.rb
486
486
  - lib/primer/view_components/linters/argument_mappers/conversion_error.rb
487
+ - lib/primer/view_components/linters/argument_mappers/helpers/erb_block.rb
487
488
  - lib/primer/view_components/linters/argument_mappers/label.rb
488
489
  - lib/primer/view_components/linters/argument_mappers/system_arguments.rb
489
490
  - lib/primer/view_components/linters/autocorrectable.rb
490
491
  - lib/primer/view_components/linters/button_component_migration_counter.rb
491
492
  - lib/primer/view_components/linters/clipboard_copy_component_migration_counter.rb
493
+ - lib/primer/view_components/linters/close_button_component_migration_counter.rb
492
494
  - lib/primer/view_components/linters/flash_component_migration_counter.rb
493
495
  - lib/primer/view_components/linters/helpers.rb
494
496
  - lib/primer/view_components/linters/label_component_migration_counter.rb