primer_view_components 0.0.112 → 0.0.114

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -0
  3. data/app/assets/javascripts/primer_view_components.js +1 -1
  4. data/app/assets/javascripts/primer_view_components.js.map +1 -1
  5. data/app/assets/styles/primer_view_components.css +3 -1
  6. data/app/assets/styles/primer_view_components.css.map +1 -1
  7. data/app/components/primer/alpha/action_list.css +1 -1
  8. data/app/components/primer/alpha/action_list.css.json +1 -1
  9. data/app/components/primer/alpha/action_list.css.map +1 -1
  10. data/app/components/primer/alpha/action_list.pcss +0 -15
  11. data/app/components/primer/alpha/auto_complete.css +1 -1
  12. data/app/components/primer/alpha/auto_complete.css.map +1 -1
  13. data/app/components/primer/alpha/auto_complete.pcss +1 -1
  14. data/app/components/primer/alpha/banner.css +1 -1
  15. data/app/components/primer/alpha/banner.css.map +1 -1
  16. data/app/components/primer/alpha/banner.pcss +2 -2
  17. data/app/components/primer/alpha/dialog/body.rb +3 -0
  18. data/app/components/primer/alpha/dialog/footer.rb +3 -0
  19. data/app/components/primer/alpha/dialog/header.rb +3 -0
  20. data/app/components/primer/alpha/dialog.css +1 -0
  21. data/app/components/primer/alpha/dialog.css.json +1 -0
  22. data/app/components/primer/alpha/dialog.css.map +1 -0
  23. data/app/components/primer/alpha/dialog.pcss +484 -0
  24. data/app/components/primer/alpha/dialog.rb +3 -0
  25. data/app/components/primer/alpha/segmented_control.css +1 -1
  26. data/app/components/primer/alpha/segmented_control.css.map +1 -1
  27. data/app/components/primer/alpha/text_field.css +3 -0
  28. data/app/components/primer/alpha/text_field.css.json +1 -0
  29. data/app/components/primer/alpha/text_field.css.map +1 -0
  30. data/app/components/primer/alpha/text_field.pcss +683 -0
  31. data/app/components/primer/alpha/toggle_switch.d.ts +1 -1
  32. data/app/components/primer/alpha/toggle_switch.js +7 -4
  33. data/app/components/primer/alpha/toggle_switch.ts +7 -3
  34. data/app/components/primer/{clipboard_copy.d.ts → beta/clipboard_copy.d.ts} +0 -0
  35. data/app/components/primer/{clipboard_copy.html.erb → beta/clipboard_copy.html.erb} +0 -0
  36. data/app/components/primer/{clipboard_copy.js → beta/clipboard_copy.js} +0 -0
  37. data/app/components/primer/beta/clipboard_copy.rb +50 -0
  38. data/app/components/primer/{clipboard_copy.ts → beta/clipboard_copy.ts} +0 -0
  39. data/app/components/primer/beta/markdown.rb +290 -0
  40. data/app/components/primer/beta/popover.css.map +1 -1
  41. data/app/components/primer/beta/popover.pcss +5 -5
  42. data/app/components/primer/beta/relative_time.rb +160 -0
  43. data/app/components/primer/button_component.rb +1 -1
  44. data/app/components/primer/clipboard_copy.rb +2 -43
  45. data/app/components/primer/component.rb +4 -0
  46. data/app/components/primer/local_time.d.ts +1 -1
  47. data/app/components/primer/local_time.js +1 -1
  48. data/app/components/primer/local_time.rb +3 -1
  49. data/app/components/primer/local_time.ts +1 -1
  50. data/app/components/primer/markdown.rb +2 -283
  51. data/app/components/primer/primer.d.ts +1 -1
  52. data/app/components/primer/primer.js +1 -1
  53. data/app/components/primer/primer.pcss +8 -0
  54. data/app/components/primer/primer.ts +1 -1
  55. data/app/components/primer/time_ago_component.d.ts +1 -1
  56. data/app/components/primer/time_ago_component.js +1 -1
  57. data/app/components/primer/time_ago_component.rb +2 -1
  58. data/app/components/primer/time_ago_component.ts +1 -1
  59. data/app/forms/submit_button_form.rb +8 -2
  60. data/app/helpers/primer/form_helper.rb +12 -0
  61. data/lib/postcss_mixins/clearfix.pcss +12 -0
  62. data/lib/primer/deprecations.rb +96 -26
  63. data/lib/primer/deprecations.yml +72 -0
  64. data/lib/primer/forms/base.rb +7 -20
  65. data/lib/primer/forms/base_component.rb +15 -1
  66. data/lib/primer/forms/button.html.erb +4 -0
  67. data/lib/primer/forms/button.rb +68 -0
  68. data/lib/primer/forms/check_box.html.erb +2 -2
  69. data/lib/primer/forms/check_box.rb +1 -1
  70. data/lib/primer/forms/check_box_group.html.erb +2 -2
  71. data/lib/primer/forms/dsl/button_input.rb +29 -0
  72. data/lib/primer/forms/dsl/input_methods.rb +7 -2
  73. data/lib/primer/forms/dsl/submit_button_input.rb +1 -0
  74. data/lib/primer/forms/dsl/text_field_input.rb +0 -7
  75. data/lib/primer/forms/radio_button.html.erb +2 -2
  76. data/lib/primer/forms/radio_button.rb +1 -1
  77. data/lib/primer/forms/radio_button_group.html.erb +2 -2
  78. data/lib/primer/forms/select_list.html.erb +1 -1
  79. data/lib/primer/forms/select_list.rb +4 -1
  80. data/lib/primer/forms/submit_button.html.erb +1 -4
  81. data/lib/primer/forms/submit_button.rb +1 -37
  82. data/lib/primer/forms/text_area.html.erb +1 -1
  83. data/lib/primer/forms/text_area.rb +5 -1
  84. data/lib/primer/forms/text_field.html.erb +1 -1
  85. data/lib/primer/forms/text_field.rb +11 -0
  86. data/lib/primer/forms/utils.rb +28 -0
  87. data/lib/primer/view_components/audited.rb +14 -0
  88. data/lib/primer/view_components/engine.rb +1 -0
  89. data/lib/primer/view_components/linters/clipboard_copy_component_migration_counter.rb +2 -2
  90. data/lib/primer/view_components/linters/helpers/deprecated_components_helpers.rb +3 -18
  91. data/lib/primer/view_components/version.rb +1 -1
  92. data/lib/rubocop/cop/primer/component_name_migration.rb +2 -2
  93. data/lib/tasks/docs.rake +4 -3
  94. data/previews/primer/alpha/auto_complete_preview.rb +12 -0
  95. data/previews/primer/alpha/segmented_control_preview.rb +9 -6
  96. data/previews/primer/alpha/text_field_preview.rb +77 -52
  97. data/previews/primer/beta/clipboard_copy_preview/element.html.erb +2 -0
  98. data/previews/primer/beta/clipboard_copy_preview.rb +39 -0
  99. data/previews/primer/{markdown_preview.rb → beta/markdown_preview.rb} +14 -12
  100. data/previews/primer/beta/relative_time_preview.rb +271 -0
  101. data/previews/primer/forms/forms_preview.rb +1 -0
  102. data/static/arguments.json +163 -53
  103. data/static/audited_at.json +7 -4
  104. data/static/constants.json +132 -6
  105. data/static/statuses.json +6 -3
  106. metadata +28 -9
  107. data/previews/primer/clipboard_copy_preview/element.html.erb +0 -2
  108. data/previews/primer/clipboard_copy_preview.rb +0 -37
@@ -0,0 +1,72 @@
1
+ # PVC Component Deprecations
2
+ # --------------------------
3
+ #
4
+ # All component deprecations for PVC must be listed here, and must have valid configurations.
5
+ # See 'docs/contributors/deprecations.md' for information on configuration options.
6
+
7
+ deprecations:
8
+ - component: "Primer::Alpha::AutoComplete"
9
+ autocorrect: true
10
+ replacement: "Primer::Beta::AutoComplete"
11
+
12
+ - component: "Primer::Alpha::AutoComplete::Item"
13
+ autocorrect: true
14
+ replacement: "Primer::Beta::AutoComplete::Item"
15
+
16
+ - component: "Primer::BlankslateComponent"
17
+ autocorrect: true
18
+ replacement: "Primer::Beta::Blankslate"
19
+
20
+ - component: "Primer::BoxComponent"
21
+ autocorrect: true
22
+ replacement: "Primer::Box"
23
+
24
+ - component: "Primer::ButtonComponent"
25
+ autocorrect: false
26
+ replacement: "Primer::Beta::Button"
27
+ guide: "https://primer.style/view-components/guides/primer_button_component"
28
+
29
+ - component: "Primer::ClipboardCopy"
30
+ autocorrect: true
31
+ replacement: "Primer::Beta::ClipboardCopy"
32
+
33
+ - component: "Primer::DropdownMenuComponent"
34
+ autocorrect: false
35
+ replacement: "Primer::Beta::Dropdown"
36
+ guide: "https://primer.style/view-components/guides/primer_dropdown_menu_component"
37
+
38
+ - component: "Primer::Dropdown"
39
+ autocorrect: true
40
+ replacement: "Primer::Alpha::Dropdown"
41
+
42
+ - component: "Primer::Dropdown::Menu"
43
+ autocorrect: true
44
+ replacement: "Primer::Alpha::Dropdown::Menu"
45
+
46
+ - component: "Primer::Dropdown::Menu::Item"
47
+ autocorrect: true
48
+ replacement: "Primer::Alpha::Dropdown::Menu::Item"
49
+
50
+ - component: "Primer::IconButton"
51
+ autocorrect: true
52
+ replacement: "Primer::Beta::IconButton"
53
+
54
+ - component: "Primer::LabelComponent"
55
+ autocorrect: true
56
+ replacement: "Primer::Beta::Label"
57
+
58
+ - component: "Primer::LinkComponent"
59
+ autocorrect: true
60
+ replacement: "Primer::Beta::Link"
61
+
62
+ - component: "Primer::Markdown"
63
+ autocorrect: true
64
+ replacement: "Primer::Beta::Markdown"
65
+
66
+ - component: "Primer::PopoverComponent"
67
+ autocorrect: true
68
+ replacement: "Primer::Beta::Popover"
69
+
70
+ - component: "Primer::Tooltip"
71
+ autocorrect: true
72
+ replacement: "Primer::Alpha::Tooltip"
@@ -29,7 +29,7 @@ module Primer
29
29
  end
30
30
 
31
31
  def inherited(base)
32
- form_path = const_source_location(base.name)
32
+ form_path = Utils.const_source_location(base.name)
33
33
  return unless form_path
34
34
 
35
35
  base.template_root_path = File.join(File.dirname(form_path), base.name.demodulize.underscore)
@@ -54,25 +54,6 @@ module Primer
54
54
  def sanitize_field_name_for_template_path(field_name)
55
55
  field_name.to_s.delete_suffix("?").to_sym
56
56
  end
57
-
58
- private
59
-
60
- # Unfortunately this bug (https://github.com/ruby/ruby/pull/5646) prevents us from using
61
- # Ruby's native Module.const_source_location. Instead we have to fudge it by searching
62
- # for the file in the configured autoload paths. Doing so relies on Rails' autoloading
63
- # conventions, so it should work ok. Zeitwerk also has this information but lacks a
64
- # public API to map constants to source files.
65
- def const_source_location(class_name)
66
- # NOTE: underscore respects namespacing, i.e. will convert Foo::Bar to foo/bar.
67
- class_path = "#{class_name.underscore}.rb"
68
-
69
- ActiveSupport::Dependencies.autoload_paths.each do |autoload_path|
70
- absolute_path = File.join(autoload_path, class_path)
71
- return absolute_path if File.exist?(absolute_path)
72
- end
73
-
74
- nil
75
- end
76
57
  end
77
58
 
78
59
  def inputs
@@ -124,12 +105,18 @@ module Primer
124
105
  end
125
106
 
126
107
  def perform_render(&_block)
108
+ return "" unless render?
109
+
127
110
  Base.compile!
128
111
  self.class.compile!
129
112
 
130
113
  render_base_form
131
114
  end
132
115
 
116
+ def render?
117
+ true
118
+ end
119
+
133
120
  private
134
121
 
135
122
  def form_object
@@ -10,12 +10,22 @@ module Primer
10
10
  extend ActsAsComponent
11
11
 
12
12
  def self.inherited(base)
13
- base.renders_template File.join(__dir__, "#{base.name.demodulize.underscore}.html.erb"), :render_template
13
+ base_path = Utils.const_source_location(base.name)
14
+
15
+ unless base_path
16
+ warn "Could not identify the template for #{base}"
17
+ return
18
+ end
19
+
20
+ dir = File.dirname(base_path)
21
+ base.renders_template File.join(dir, "#{base.name.demodulize.underscore}.html.erb"), :render_template
14
22
  end
15
23
 
16
24
  delegate :required?, :disabled?, :hidden?, to: :@input
17
25
 
18
26
  def perform_render(&block)
27
+ return "" unless render?
28
+
19
29
  @__prf_content_block = block
20
30
  compile_and_render_template
21
31
  end
@@ -43,6 +53,10 @@ module Primer
43
53
  self
44
54
  end
45
55
 
56
+ def render?
57
+ true
58
+ end
59
+
46
60
  private
47
61
 
48
62
  def compile_and_render_template
@@ -0,0 +1,4 @@
1
+ <%= render(Primer::Beta::Button.new(**input_arguments)) do |c| %>
2
+ <% @input.block.call(c) if @input.block %>
3
+ <%= @input.label %>
4
+ <% end %>
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module Forms
5
+ # :nodoc:
6
+ class Button < BaseComponent
7
+ # :nodoc:
8
+ module ButtonAttributeGenerator
9
+ extend ActionView::Helpers::FormTagHelper
10
+
11
+ class << self
12
+ alias submit_tag_attributes submit_tag
13
+ alias button_tag_attributes button_tag
14
+
15
+ private
16
+
17
+ # FormTagHelper#submit_tag ultimately calls the #tag method. We return the options hash here instead
18
+ # of returning a string so it can be merged into the hash of options we pass to the Primer::ButtonComponent.
19
+ def tag(_name, options)
20
+ options
21
+ end
22
+
23
+ # FormTagHelper#button_tag ultimately calls the #content_tag method. We return the options hash here instead
24
+ # of returning a string so it can be merged into the hash of options we pass to the Primer::ButtonComponent.
25
+ def content_tag(_name, _content, options)
26
+ options
27
+ end
28
+ end
29
+ end
30
+
31
+ delegate :builder, :form, to: :@input
32
+
33
+ def initialize(input:, type: :button)
34
+ @input = input
35
+ @type = type
36
+
37
+ @input.add_input_classes("FormField-input flex-self-start")
38
+ @input.merge_input_arguments!(tag_attributes.deep_symbolize_keys)
39
+
40
+ # rails uses a string for this, but PVC wants a symbol
41
+ @input.merge_input_arguments!(type: type.to_sym)
42
+
43
+ # Never disable buttons. This overrides the global
44
+ # ActionView::Base.automatically_disable_submit_tag setting.
45
+ # Disabling buttons is not accessible.
46
+ @input.remove_input_data(:disable_with)
47
+ end
48
+
49
+ def input_arguments
50
+ @input_arguments ||= @input.input_arguments.deep_dup.tap do |args|
51
+ # rails uses :class but PVC wants :classes
52
+ args[:classes] = args.delete(:class)
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def tag_attributes
59
+ case @type
60
+ when :submit
61
+ ButtonAttributeGenerator.submit_tag_attributes(@input.label, name: @input.name)
62
+ else
63
+ ButtonAttributeGenerator.button_tag_attributes(@input.label, name: @input.name)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,4 +1,4 @@
1
- <div class="FormControl-checkbox-wrap">
1
+ <%= content_tag(:div, class: "FormControl-checkbox-wrap", hidden: @input.hidden?) do %>
2
2
  <%= builder.check_box(@input.name, @input.input_arguments, checked_value, unchecked_value) %>
3
3
  <span class="FormControl-checkbox-labelWrap">
4
4
  <%= builder.label(@input.name, **@input.label_arguments) do %>
@@ -6,7 +6,7 @@
6
6
  <% end %>
7
7
  <%= render(Caption.new(input: @input)) %>
8
8
  </span>
9
- </div>
9
+ <% end %>
10
10
  <% if @input.nested_form_block %>
11
11
  <%= content_tag(:div, nested_form_arguments) do %>
12
12
  <%= render(@input.nested_form_block.call(builder)) %>
@@ -20,7 +20,7 @@ module Primer
20
20
  def nested_form_arguments
21
21
  return @nested_form_arguments if defined?(@nested_form_arguments)
22
22
 
23
- @nested_form_arguments = { **@input.nested_form_arguments }
23
+ @nested_form_arguments = { hidden: @input.hidden?, **@input.nested_form_arguments }
24
24
  @nested_form_arguments[:class] = class_names(
25
25
  @nested_form_arguments[:class],
26
26
  @nested_form_arguments.delete(:classes),
@@ -1,4 +1,4 @@
1
- <fieldset>
1
+ <%= content_tag(:fieldset, hidden: @input.hidden?) do %>
2
2
  <% if @input.label %>
3
3
  <%= content_tag(:legend, **@input.label_arguments) do %>
4
4
  <%= @input.label %>
@@ -9,4 +9,4 @@
9
9
  <%= render(check_box.to_component) %>
10
10
  <% end %>
11
11
  <% end %>
12
- </fieldset>
12
+ <% end %>
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module Forms
5
+ module Dsl
6
+ # :nodoc:
7
+ class ButtonInput < Input
8
+ attr_reader :name, :label, :block
9
+
10
+ def initialize(name:, label:, **system_arguments, &block)
11
+ @name = name
12
+ @label = label
13
+ @block = block
14
+
15
+ super(**system_arguments)
16
+ end
17
+
18
+ def to_component
19
+ Button.new(input: self)
20
+ end
21
+
22
+ # :nocov:
23
+ def type
24
+ :button
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -17,8 +17,8 @@ module Primer
17
17
  add_input HiddenInput.new(builder: builder, form: form, **options)
18
18
  end
19
19
 
20
- def check_box(**options)
21
- add_input CheckBoxInput.new(builder: builder, form: form, **options)
20
+ def check_box(**options, &block)
21
+ add_input CheckBoxInput.new(builder: builder, form: form, **options, &block)
22
22
  end
23
23
 
24
24
  def radio_button_group(**options, &block)
@@ -63,6 +63,11 @@ module Primer
63
63
  add_input SubmitButtonInput.new(builder: builder, form: form, **options, &block)
64
64
  end
65
65
 
66
+ def button(**options, &block)
67
+ options = decorate_options(**options)
68
+ add_input ButtonInput.new(builder: builder, form: form, **options, &block)
69
+ end
70
+
66
71
  # END button input methods
67
72
 
68
73
  def inputs
@@ -19,6 +19,7 @@ module Primer
19
19
  SubmitButton.new(input: self)
20
20
  end
21
21
 
22
+ # :nocov:
22
23
  def type
23
24
  :submit_button
24
25
  end
@@ -31,13 +31,6 @@ module Primer
31
31
 
32
32
  add_input_classes("FormControl-inset") if inset?
33
33
  add_input_classes("FormControl-monospace") if monospace?
34
-
35
- @field_wrap_classes = class_names(
36
- "FormControl-input-wrap",
37
- Primer::Forms::Dsl::Input::SIZE_MAPPINGS[size],
38
- "FormControl-input-wrap--trailingAction": show_clear_button?,
39
- "FormControl-input-wrap--leadingVisual": leading_visual?
40
- )
41
34
  end
42
35
 
43
36
  alias show_clear_button? show_clear_button
@@ -1,4 +1,4 @@
1
- <div class="FormControl-radio-wrap">
1
+ <%= content_tag(:div, class: "FormControl-radio-wrap", hidden: @input.hidden?) do %>
2
2
  <%= builder.radio_button(@input.name, @input.value, **@input.input_arguments) %>
3
3
  <span class="FormControl-radio-labelWrap">
4
4
  <%= builder.label(@input.name, value: @input.value, **@input.label_arguments) do %>
@@ -6,7 +6,7 @@
6
6
  <% end %>
7
7
  <%= render(Caption.new(input: @input)) %>
8
8
  </span>
9
- </div>
9
+ <% end %>
10
10
  <% if @input.nested_form_block %>
11
11
  <%= content_tag(:div, nested_form_arguments) do %>
12
12
  <%= render(@input.nested_form_block.call(builder)) %>
@@ -15,7 +15,7 @@ module Primer
15
15
  def nested_form_arguments
16
16
  return @nested_form_arguments if defined?(@nested_form_arguments)
17
17
 
18
- @nested_form_arguments = { **@input.nested_form_arguments }
18
+ @nested_form_arguments = { hidden: @input.hidden?, **@input.nested_form_arguments }
19
19
  @nested_form_arguments[:class] = class_names(
20
20
  @nested_form_arguments[:class],
21
21
  @nested_form_arguments.delete(:classes),
@@ -1,4 +1,4 @@
1
- <fieldset>
1
+ <%= content_tag(:fieldset, hidden: @input.hidden?) do %>
2
2
  <% if @input.label %>
3
3
  <%= content_tag(:legend, **@input.label_arguments) do %>
4
4
  <%= @input.label %>
@@ -9,4 +9,4 @@
9
9
  <%= render(radio_button.to_component) %>
10
10
  <% end %>
11
11
  <% end %>
12
- </fieldset>
12
+ <% end %>
@@ -1,5 +1,5 @@
1
1
  <%= render(FormControl.new(input: @input)) do %>
2
- <%= content_tag(:div, class: @field_wrap_classes) do %>
2
+ <%= content_tag(:div, **@field_wrap_arguments) do %>
3
3
  <%= builder.select(@input.name, options, @input.select_arguments, **@input.input_arguments) %>
4
4
  <% end %>
5
5
  <% end %>
@@ -13,7 +13,10 @@ module Primer
13
13
  "FormControl--medium"
14
14
  )
15
15
 
16
- @field_wrap_classes = class_names("FormControl-select-wrap")
16
+ @field_wrap_arguments = {
17
+ class: "FormControl-select-wrap",
18
+ hidden: @input.hidden?
19
+ }
17
20
  end
18
21
 
19
22
  def options
@@ -1,4 +1 @@
1
- <%= render(Primer::ButtonComponent.new(**input_arguments)) do |c| %>
2
- <% @input.block.call(c) if @input.block %>
3
- <%= @input.label %>
4
- <% end %>
1
+ <%= render(@button) %>
@@ -4,46 +4,10 @@ module Primer
4
4
  module Forms
5
5
  # :nodoc:
6
6
  class SubmitButton < BaseComponent
7
- # :nodoc:
8
- module SubmitAttributeGenerator
9
- extend ActionView::Helpers::FormTagHelper
10
-
11
- class << self
12
- alias submit_tag_attributes submit_tag
13
-
14
- private
15
-
16
- # FormTagHelper#submit_tag ultimately calls the #tag method. We return the options hash here instead
17
- # of returning a string so it can be merged into the hash of options we pass to the Primer::ButtonComponent.
18
- def tag(_name, options)
19
- options
20
- end
21
- end
22
- end
23
-
24
7
  delegate :builder, :form, to: :@input
25
8
 
26
9
  def initialize(input:)
27
- @input = input
28
- @input.add_input_classes("FormField-input flex-self-start")
29
- @input.merge_input_arguments!(
30
- SubmitAttributeGenerator.submit_tag_attributes(input.label, name: input.name).deep_symbolize_keys
31
- )
32
-
33
- # rails uses a string for this, but PVC wants a symbol
34
- @input.merge_input_arguments!(type: :submit)
35
-
36
- # Never disable submit buttons. This overrides the global
37
- # ActionView::Base.automatically_disable_submit_tag setting.
38
- # Disabling the submit button is not accessible.
39
- @input.remove_input_data(:disable_with)
40
- end
41
-
42
- def input_arguments
43
- @input_arguments ||= @input.input_arguments.deep_dup.tap do |args|
44
- # rails uses :class but PVC wants :classes
45
- args[:classes] = args.delete(:class)
46
- end
10
+ @button = Button.new(input: input, type: :submit)
47
11
  end
48
12
  end
49
13
  end
@@ -1,5 +1,5 @@
1
1
  <%= render(FormControl.new(input: @input)) do %>
2
- <%= content_tag(:div, class: @field_wrap_classes) do %>
2
+ <%= content_tag(:div, **@field_wrap_arguments) do %>
3
3
  <%= builder.text_area(@input.name, **@input.input_arguments) %>
4
4
  <% end %>
5
5
  <% end %>
@@ -9,7 +9,11 @@ module Primer
9
9
  def initialize(input:)
10
10
  @input = input
11
11
  @input.add_input_classes("FormControl-input", "FormControl--medium")
12
- @field_wrap_classes = class_names("FormControl-input-wrap")
12
+
13
+ @field_wrap_arguments = {
14
+ class: class_names("FormControl-input-wrap"),
15
+ hidden: @input.hidden?
16
+ }
13
17
  end
14
18
  end
15
19
  end
@@ -1,6 +1,6 @@
1
1
  <%= render(FormControl.new(input: @input)) do %>
2
2
  <% if @input.leading_visual || @input.show_clear_button? %>
3
- <%= content_tag(:div, class: @input.field_wrap_classes) do %>
3
+ <%= content_tag(:div, **@field_wrap_arguments) do %>
4
4
  <% if @input.leading_visual %>
5
5
  <span class="FormControl-input-leadingVisualWrap">
6
6
  <%= render(Primer::OcticonComponent.new(**@input.leading_visual)) %>
@@ -8,6 +8,17 @@ module Primer
8
8
 
9
9
  def initialize(input:)
10
10
  @input = input
11
+
12
+ @field_wrap_arguments = {
13
+ class: class_names(
14
+ "FormControl-input-wrap",
15
+ Primer::Forms::Dsl::Input::SIZE_MAPPINGS[@input.size],
16
+ "FormControl-input-wrap--trailingAction": @input.show_clear_button?,
17
+ "FormControl-input-wrap--leadingVisual": @input.leading_visual?
18
+ ),
19
+
20
+ hidden: @input.hidden?
21
+ }
11
22
  end
12
23
  end
13
24
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ # :nodoc:
5
+ module Forms
6
+ # :nodoc:
7
+ module Utils
8
+ # Unfortunately this bug (https://github.com/ruby/ruby/pull/5646) prevents us from using
9
+ # Ruby's native Module.const_source_location. Instead we have to fudge it by searching
10
+ # for the file in the configured autoload paths. Doing so relies on Rails' autoloading
11
+ # conventions, so it should work ok. Zeitwerk also has this information but lacks a
12
+ # public API to map constants to source files.
13
+ def const_source_location(class_name)
14
+ # NOTE: underscore respects namespacing, i.e. will convert Foo::Bar to foo/bar.
15
+ class_path = "#{class_name.underscore}.rb"
16
+
17
+ ActiveSupport::Dependencies.autoload_paths.each do |autoload_path|
18
+ absolute_path = File.join(autoload_path, class_path)
19
+ return absolute_path if File.exist?(absolute_path)
20
+ end
21
+
22
+ nil
23
+ end
24
+ end
25
+
26
+ Utils.extend(Utils)
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Primer
6
+ # :nodoc:
7
+ module ViewComponents
8
+ AUDITED = JSON.parse(
9
+ File.read(
10
+ File.join(File.dirname(__FILE__), "../../../static/audited_at.json")
11
+ )
12
+ ).freeze
13
+ end
14
+ end
@@ -57,6 +57,7 @@ module Primer
57
57
  autoloader.ignore(Engine.root.join("lib", "primer", "view_components", "linters.rb"))
58
58
  autoloader.ignore(Engine.root.join("lib", "primer", "view_components", "linters", "**", "*.rb"))
59
59
  autoloader.ignore(Engine.root.join("lib", "primer", "view_components", "statuses.rb"))
60
+ autoloader.ignore(Engine.root.join("lib", "primer", "view_components", "audited.rb"))
60
61
  end
61
62
  end
62
63
 
@@ -12,9 +12,9 @@ module ERBLint
12
12
 
13
13
  TAGS = %w[clipboard-copy].freeze
14
14
  REQUIRED_ARGUMENTS = [/for|value/, "aria-label"].freeze
15
- MESSAGE = "We are migrating clipboard-copy to use [Primer::ClipboardCopy](https://primer.style/view-components/components/clipboardcopy), please try to use that instead of raw HTML."
15
+ MESSAGE = "We are migrating clipboard-copy to use [Primer::Beta::ClipboardCopy](https://primer.style/view-components/components/clipboardcopy), please try to use that instead of raw HTML."
16
16
  ARGUMENT_MAPPER = ArgumentMappers::ClipboardCopy
17
- COMPONENT = "Primer::ClipboardCopy"
17
+ COMPONENT = "Primer::Beta::ClipboardCopy"
18
18
  end
19
19
  end
20
20
  end
@@ -7,27 +7,12 @@ module ERBLint
7
7
  module Helpers
8
8
  # Helpers to share between DeprecatedComponents ERB lint and Rubocop cop
9
9
  module DeprecatedComponentsHelpers
10
- def message(component)
11
- message = "#{component} has been deprecated and should not be used."
12
-
13
- if Primer::Deprecations.correctable?(component)
14
- suggested_component = Primer::Deprecations.suggested_component(component)
15
- message += " Try #{suggested_component} instead."
16
- end
17
-
18
- message
19
- end
20
-
21
- def statuses_json
22
- JSON.parse(
23
- File.read(
24
- File.join(File.dirname(__FILE__), "../../../../../static/statuses.json")
25
- )
26
- ).freeze
10
+ def message(component_name)
11
+ Primer::Deprecations.deprecation_message(component_name)
27
12
  end
28
13
 
29
14
  def deprecated_components
30
- @deprecated_components ||= statuses_json.select { |_, value| value == "deprecated" }.keys
15
+ Primer::Deprecations.deprecated_components
31
16
  end
32
17
  end
33
18
  end
@@ -6,7 +6,7 @@ module Primer
6
6
  module VERSION
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- PATCH = 112
9
+ PATCH = 114
10
10
 
11
11
  STRING = [MAJOR, MINOR, PATCH].join(".")
12
12
  end
@@ -26,8 +26,8 @@ module RuboCop
26
26
  component_name = node.const_name
27
27
  return unless ::Primer::Deprecations.correctable?(component_name)
28
28
 
29
- suggested_component = ::Primer::Deprecations.suggested_component(component_name)
30
- corrector.replace(node, suggested_component) if suggested_component.present?
29
+ replacement = ::Primer::Deprecations.replacement(component_name)
30
+ corrector.replace(node, replacement) if replacement.present?
31
31
  end
32
32
  end
33
33
  end