primer_view_components 0.0.112 → 0.0.113

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -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/beta/button_group.css +1 -0
  35. data/app/components/primer/beta/button_group.css.json +1 -0
  36. data/app/components/primer/beta/button_group.css.map +1 -0
  37. data/app/components/primer/beta/button_group.pcss +92 -0
  38. data/app/components/primer/{clipboard_copy.d.ts → beta/clipboard_copy.d.ts} +0 -0
  39. data/app/components/primer/{clipboard_copy.html.erb → beta/clipboard_copy.html.erb} +0 -0
  40. data/app/components/primer/{clipboard_copy.js → beta/clipboard_copy.js} +0 -0
  41. data/app/components/primer/beta/clipboard_copy.rb +50 -0
  42. data/app/components/primer/{clipboard_copy.ts → beta/clipboard_copy.ts} +0 -0
  43. data/app/components/primer/beta/popover.css.map +1 -1
  44. data/app/components/primer/beta/popover.pcss +5 -5
  45. data/app/components/primer/beta/relative_time.rb +160 -0
  46. data/app/components/primer/button_component.css +1 -0
  47. data/app/components/primer/button_component.css.json +1 -0
  48. data/app/components/primer/button_component.css.map +1 -0
  49. data/app/components/primer/button_component.pcss +557 -0
  50. data/app/components/primer/button_component.rb +1 -1
  51. data/app/components/primer/clipboard_copy.rb +2 -43
  52. data/app/components/primer/component.rb +4 -0
  53. data/app/components/primer/local_time.d.ts +1 -1
  54. data/app/components/primer/local_time.js +1 -1
  55. data/app/components/primer/local_time.rb +3 -1
  56. data/app/components/primer/local_time.ts +1 -1
  57. data/app/components/primer/primer.d.ts +1 -1
  58. data/app/components/primer/primer.js +1 -1
  59. data/app/components/primer/primer.pcss +10 -0
  60. data/app/components/primer/primer.ts +1 -1
  61. data/app/components/primer/time_ago_component.d.ts +1 -1
  62. data/app/components/primer/time_ago_component.js +1 -1
  63. data/app/components/primer/time_ago_component.rb +2 -1
  64. data/app/components/primer/time_ago_component.ts +1 -1
  65. data/app/forms/submit_button_form.rb +8 -2
  66. data/app/helpers/primer/form_helper.rb +12 -0
  67. data/lib/postcss_mixins/clearfix.pcss +12 -0
  68. data/lib/primer/deprecations.rb +96 -26
  69. data/lib/primer/deprecations.yml +68 -0
  70. data/lib/primer/forms/base.rb +7 -20
  71. data/lib/primer/forms/base_component.rb +15 -1
  72. data/lib/primer/forms/button.html.erb +4 -0
  73. data/lib/primer/forms/button.rb +68 -0
  74. data/lib/primer/forms/check_box.html.erb +2 -2
  75. data/lib/primer/forms/check_box.rb +1 -1
  76. data/lib/primer/forms/check_box_group.html.erb +2 -2
  77. data/lib/primer/forms/dsl/button_input.rb +29 -0
  78. data/lib/primer/forms/dsl/input_methods.rb +7 -2
  79. data/lib/primer/forms/dsl/submit_button_input.rb +1 -0
  80. data/lib/primer/forms/dsl/text_field_input.rb +0 -7
  81. data/lib/primer/forms/radio_button.html.erb +2 -2
  82. data/lib/primer/forms/radio_button.rb +1 -1
  83. data/lib/primer/forms/radio_button_group.html.erb +2 -2
  84. data/lib/primer/forms/select_list.html.erb +1 -1
  85. data/lib/primer/forms/select_list.rb +4 -1
  86. data/lib/primer/forms/submit_button.html.erb +1 -4
  87. data/lib/primer/forms/submit_button.rb +1 -37
  88. data/lib/primer/forms/text_area.html.erb +1 -1
  89. data/lib/primer/forms/text_area.rb +5 -1
  90. data/lib/primer/forms/text_field.html.erb +1 -1
  91. data/lib/primer/forms/text_field.rb +11 -0
  92. data/lib/primer/forms/utils.rb +28 -0
  93. data/lib/primer/view_components/audited.rb +14 -0
  94. data/lib/primer/view_components/engine.rb +1 -0
  95. data/lib/primer/view_components/linters/clipboard_copy_component_migration_counter.rb +2 -2
  96. data/lib/primer/view_components/linters/helpers/deprecated_components_helpers.rb +3 -18
  97. data/lib/primer/view_components/version.rb +1 -1
  98. data/lib/rubocop/cop/primer/component_name_migration.rb +2 -2
  99. data/lib/tasks/docs.rake +3 -2
  100. data/previews/primer/alpha/auto_complete_preview.rb +12 -0
  101. data/previews/primer/alpha/segmented_control_preview.rb +9 -6
  102. data/previews/primer/alpha/text_field_preview.rb +77 -52
  103. data/previews/primer/beta/clipboard_copy_preview/element.html.erb +2 -0
  104. data/previews/primer/beta/clipboard_copy_preview.rb +39 -0
  105. data/previews/primer/beta/relative_time_preview.rb +271 -0
  106. data/previews/primer/forms/forms_preview.rb +1 -0
  107. data/static/arguments.json +143 -33
  108. data/static/audited_at.json +6 -4
  109. data/static/constants.json +124 -0
  110. data/static/statuses.json +4 -2
  111. metadata +34 -8
  112. data/previews/primer/clipboard_copy_preview/element.html.erb +0 -2
  113. data/previews/primer/clipboard_copy_preview.rb +0 -37
@@ -7,7 +7,7 @@ import './alpha/toggle_switch'
7
7
  import './alpha/tool_tip'
8
8
  import './alpha/x_banner'
9
9
  import './beta/auto_complete/auto_complete'
10
- import './clipboard_copy'
10
+ import './beta/clipboard_copy'
11
11
  import './local_time'
12
12
  import './tab_container_component'
13
13
  import './time_ago_component'
@@ -1 +1 @@
1
- import '@github/time-elements';
1
+ import '@github/relative-time-element';
@@ -1 +1 @@
1
- import '@github/time-elements';
1
+ import '@github/relative-time-element';
@@ -15,7 +15,8 @@ module Primer
15
15
  @system_arguments = deny_tag_argument(**system_arguments)
16
16
  @system_arguments[:datetime] = time.utc.iso8601
17
17
  @system_arguments[:classes] = class_names("no-wrap", @system_arguments[:classes])
18
- @system_arguments[:tag] = "time-ago"
18
+ @system_arguments[:tag] = "relative-time"
19
+ @system_arguments[:tense] = "past"
19
20
  @system_arguments[:format] = "micro" if micro
20
21
  @time = time
21
22
  @micro = micro
@@ -1 +1 @@
1
- import '@github/time-elements'
1
+ import '@github/relative-time-element'
@@ -13,8 +13,14 @@ class SubmitButtonForm < ApplicationForm
13
13
  color: :success
14
14
  )
15
15
 
16
- my_form.submit(name: :submit, label: "Submit", scheme: :primary, mr: 3) do |c|
17
- c.with_leading_visual_icon(icon: :"check-circle")
16
+ my_form.group(layout: :horizontal) do |button_group|
17
+ button_group.submit(name: :submit, label: "Submit", scheme: :primary, mb: 3) do |c|
18
+ c.with_leading_visual_icon(icon: :"check-circle")
19
+ end
20
+
21
+ button_group.button(name: :button, label: "Click me", mb: 3) do |c|
22
+ c.with_leading_visual_icon(icon: :alert)
23
+ end
18
24
  end
19
25
  end
20
26
  end
@@ -7,5 +7,17 @@ module Primer
7
7
  def primer_form_with(**kwargs, &block)
8
8
  form_with(**kwargs, skip_default_ids: false, builder: Primer::Forms::Builder, &block)
9
9
  end
10
+
11
+ def primer_fields_for(record_name, record_object = nil, options = {}, &block)
12
+ fields_for(
13
+ record_name,
14
+ record_object,
15
+ options.merge(
16
+ skip_default_ids: false,
17
+ builder: Primer::Forms::Builder
18
+ ),
19
+ &block
20
+ )
21
+ end
10
22
  end
11
23
  end
@@ -0,0 +1,12 @@
1
+ @define-mixin clearfix {
2
+ &::before {
3
+ display: table;
4
+ content: '';
5
+ }
6
+
7
+ &::after {
8
+ display: table;
9
+ clear: both;
10
+ content: '';
11
+ }
12
+ }
@@ -1,35 +1,105 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "yaml"
4
+
3
5
  module Primer
4
6
  # :nodoc:
5
- module Deprecations
6
- # If there is no alternative to suggest, set the value to nil
7
- DEPRECATED_COMPONENTS = {
8
- "Primer::LabelComponent" => "Primer::Beta::Label",
9
- "Primer::LinkComponent" => "Primer::Beta::Link",
10
- "Primer::Alpha::AutoComplete" => "Primer::Beta::AutoComplete",
11
- "Primer::Alpha::AutoComplete::Item" => "Primer::Beta::AutoComplete::Item",
12
- "Primer::BlankslateComponent" => "Primer::Beta::Blankslate",
13
- "Primer::BoxComponent" => "Primer::Box",
14
- "Primer::DropdownMenuComponent" => nil,
15
- "Primer::Dropdown" => "Primer::Alpha::Dropdown",
16
- "Primer::Dropdown::Menu" => "Primer::Alpha::Dropdown::Menu",
17
- "Primer::Dropdown::Menu::Item" => "Primer::Alpha::Dropdown::Menu::Item",
18
- "Primer::IconButton" => "Primer::Beta::IconButton",
19
- "Primer::Tooltip" => "Primer::Alpha::Tooltip",
20
- "Primer::PopoverComponent" => "Primer::Beta::Popover"
21
- }.freeze
22
-
23
- def self.deprecated?(name)
24
- DEPRECATED_COMPONENTS.key?(name)
25
- end
7
+ class Deprecations
8
+ class << self
9
+ def register(file_path)
10
+ data = YAML.load_file(file_path)
11
+ data["deprecations"].each do |dep|
12
+ register_deprecation(dep["component"], {
13
+ autocorrect: dep["autocorrect"],
14
+ guide: dep["guide"],
15
+ replacement: dep["replacement"]
16
+ })
17
+ end
18
+ end
26
19
 
27
- def self.suggested_component(name)
28
- DEPRECATED_COMPONENTS[name]
29
- end
20
+ def register_deprecation(component, options)
21
+ registered_deprecations[component] = {
22
+ autocorrect: options[:autocorrect],
23
+ guide: options[:guide],
24
+ replacement: options[:replacement]
25
+ }
26
+ end
27
+
28
+ def deprecated_components
29
+ registered_deprecations.keys.sort
30
+ end
31
+
32
+ def deprecated?(component_name)
33
+ # if the component is registered, it is deprecated
34
+ registered_deprecations.key?(component_name)
35
+ end
36
+
37
+ def replacement?(component_name)
38
+ !replacement(component_name).nil?
39
+ end
40
+
41
+ def replacement(component_name)
42
+ dep = registered_deprecations[component_name]
43
+ return nil if dep.nil?
44
+
45
+ dep[:replacement]
46
+ end
47
+
48
+ def correctable?(component_name)
49
+ dep = registered_deprecations[component_name]
50
+ return false if dep.nil?
51
+
52
+ dep[:autocorrect]
53
+ end
30
54
 
31
- def self.correctable?(name)
32
- !suggested_component(name).nil?
55
+ def guide?(component_name)
56
+ !guide(component_name).nil?
57
+ end
58
+
59
+ def guide(component_name)
60
+ dep = registered_deprecations[component_name]
61
+ return nil if dep.nil?
62
+
63
+ dep[:guide]
64
+ end
65
+
66
+ def deprecation_message(component_name)
67
+ return nil unless deprecated?(component_name)
68
+
69
+ msg = ["'#{component_name}' has been deprecated."]
70
+
71
+ # this nested structure is complex, because it has to
72
+ # match all of the valid scenarios for a component being
73
+ # replaceable, auto-correctable, and having a guide. for
74
+ # more information on what is and is not valid, see the
75
+ # documentation here: docs/contributors/deprecations.md
76
+
77
+ if replacement?(component_name) # has replacement
78
+ if correctable?(component_name) # is autocorrectable
79
+ msg << "Please update your code to use '#{replacement(component_name)}'"
80
+ msg << "or use rubocop's auto-correct option to do it for you."
81
+ msg << "See #{guide(component_name)} for more information." if guide?(component_name) # has a guide
82
+ elsif guide?(component_name) # not autocorrectable
83
+ msg << "See #{guide(component_name)} for information on replacing this component in your code." # has a guide
84
+ end
85
+ elsif !correctable?(component_name) # no replacement
86
+ if guide?(component_name) # has a guide
87
+ msg << "Unfortunately, there is no direct replacement."
88
+ msg << "See #{guide(component_name)} for available options to update your code."
89
+ end
90
+ end
91
+
92
+ msg.join(" ")
93
+ end
94
+
95
+ private
96
+
97
+ def registered_deprecations
98
+ @registered_deprecations ||= {}
99
+ end
33
100
  end
101
+
102
+ # auto-load PVC's deprecations
103
+ register(File.expand_path("deprecations.yml", __dir__))
34
104
  end
35
105
  end
@@ -0,0 +1,68 @@
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::PopoverComponent"
63
+ autocorrect: true
64
+ replacement: "Primer::Beta::Popover"
65
+
66
+ - component: "Primer::Tooltip"
67
+ autocorrect: true
68
+ 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) %>