primer_view_components 0.0.115 → 0.0.116

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/app/assets/styles/primer_view_components.css +1 -1
  4. data/app/assets/styles/primer_view_components.css.map +1 -1
  5. data/app/components/primer/alpha/action_list/divider.rb +0 -2
  6. data/app/components/primer/alpha/action_list/heading.rb +0 -2
  7. data/app/components/primer/alpha/action_list/item.rb +0 -2
  8. data/app/components/primer/alpha/action_list.rb +0 -1
  9. data/app/components/primer/alpha/auto_complete/item.rb +0 -1
  10. data/app/components/primer/alpha/auto_complete.rb +8 -9
  11. data/app/components/primer/alpha/banner.rb +0 -1
  12. data/app/components/primer/alpha/button_marketing.rb +0 -2
  13. data/app/components/primer/alpha/dialog.rb +0 -1
  14. data/app/components/primer/alpha/dropdown/menu.rb +2 -0
  15. data/app/components/primer/alpha/dropdown.html.erb +3 -3
  16. data/app/components/primer/alpha/image.rb +0 -1
  17. data/app/components/primer/alpha/layout.rb +1 -1
  18. data/app/components/primer/alpha/octicon_symbols.rb +0 -2
  19. data/app/components/primer/alpha/segmented_control.css +1 -1
  20. data/app/components/primer/alpha/segmented_control.css.json +1 -1
  21. data/app/components/primer/alpha/segmented_control.css.map +1 -1
  22. data/app/components/primer/alpha/segmented_control.pcss +12 -0
  23. data/app/components/primer/alpha/segmented_control.rb +5 -5
  24. data/app/components/primer/alpha/tab_panels.rb +6 -6
  25. data/app/components/primer/alpha/text_field.rb +0 -1
  26. data/app/components/primer/alpha/toggle_switch.rb +6 -8
  27. data/app/components/primer/alpha/tooltip.rb +0 -2
  28. data/app/components/primer/alpha/underline_panels.rb +6 -6
  29. data/app/components/primer/beta/auto_complete/item.rb +1 -0
  30. data/app/components/primer/beta/auto_complete.rb +12 -10
  31. data/app/components/primer/beta/avatar.rb +0 -1
  32. data/app/components/primer/beta/avatar_stack.rb +2 -0
  33. data/app/components/primer/beta/base_button.rb +0 -1
  34. data/app/components/primer/beta/blankslate.rb +43 -42
  35. data/app/components/primer/beta/border_box/header.rb +2 -0
  36. data/app/components/primer/beta/border_box.rb +2 -0
  37. data/app/components/primer/beta/breadcrumbs.rb +1 -0
  38. data/app/components/primer/beta/button.css +1 -1
  39. data/app/components/primer/beta/button.css.json +1 -1
  40. data/app/components/primer/beta/button.css.map +1 -1
  41. data/app/components/primer/beta/button.pcss +5 -0
  42. data/app/components/primer/beta/button.rb +1 -0
  43. data/app/components/primer/beta/button_group.rb +3 -0
  44. data/app/components/primer/beta/clipboard_copy.rb +0 -1
  45. data/app/components/primer/beta/close_button.rb +0 -1
  46. data/app/components/primer/beta/counter.rb +0 -1
  47. data/app/components/primer/beta/details.rb +6 -3
  48. data/app/components/primer/beta/flash.rb +1 -0
  49. data/app/components/primer/beta/heading.rb +0 -1
  50. data/app/components/primer/beta/icon_button.rb +0 -1
  51. data/app/components/primer/beta/label.rb +0 -1
  52. data/app/components/primer/beta/link.rb +1 -0
  53. data/app/components/primer/beta/markdown.rb +0 -1
  54. data/app/components/primer/beta/octicon.rb +1 -0
  55. data/app/components/primer/beta/popover.rb +1 -0
  56. data/app/components/primer/beta/progress_bar.rb +7 -7
  57. data/app/components/primer/beta/relative_time.rb +0 -1
  58. data/app/components/primer/beta/spinner.rb +0 -1
  59. data/app/components/primer/beta/text.rb +0 -1
  60. data/app/components/primer/beta/truncate.rb +3 -2
  61. data/app/components/primer/box.rb +0 -1
  62. data/app/components/primer/button_component.rb +2 -2
  63. data/app/components/primer/component.rb +1 -0
  64. data/app/components/primer/conditional_wrapper.rb +0 -2
  65. data/app/components/primer/dropdown_menu_component.rb +3 -3
  66. data/app/components/primer/hellip_button.rb +0 -2
  67. data/app/components/primer/icon_button.rb +0 -1
  68. data/app/components/primer/layout_component.rb +0 -2
  69. data/app/components/primer/local_time.rb +0 -1
  70. data/app/components/primer/octicon_component.rb +0 -1
  71. data/app/components/primer/state_component.rb +0 -1
  72. data/app/components/primer/subhead_component.rb +0 -2
  73. data/app/components/primer/tab_container_component.rb +0 -2
  74. data/app/components/primer/time_ago_component.rb +0 -1
  75. data/app/components/primer/timeline_item_component.rb +0 -1
  76. data/app/components/primer/tooltip.rb +0 -1
  77. data/app/components/primer/truncate.rb +0 -2
  78. data/lib/primer/forms/builder.rb +2 -3
  79. data/lib/primer/forms/dsl/form_reference_input.rb +25 -2
  80. data/lib/primer/forms/dsl/input.rb +27 -0
  81. data/lib/primer/forms/form_reference.html.erb +1 -1
  82. data/lib/primer/forms/form_reference.rb +4 -0
  83. data/lib/primer/view_components/version.rb +1 -1
  84. data/previews/primer/alpha/tab_panels_preview.rb +8 -8
  85. data/previews/primer/beta/details_preview.rb +6 -6
  86. data/previews/primer/local_time_component_preview.rb +3 -0
  87. data/previews/primer/time_ago_component_preview.rb +3 -0
  88. data/previews/primer/url_helpers.rb +2 -2
  89. metadata +2 -2
@@ -8,8 +8,6 @@ module Primer
8
8
  # * This button is displaying a hellip as its content (The three dots character). Therefore a label is needed for screen readers.
9
9
  # * Set the attribute `aria-label` on the system arguments. E.g. `Primer::HellipButton.new("aria-label": "Expand next part")`
10
10
  class HellipButton < Primer::Component
11
- warn_on_deprecated_slot_setter
12
-
13
11
  # @example Default
14
12
  # <%= render(Primer::HellipButton.new("aria-label": "No effect")) %>
15
13
  #
@@ -12,7 +12,6 @@ module Primer
12
12
  # Either `aria-label` or `aria-description` will be used for the `Tooltip` text, depending on which one is present.
13
13
  # [Learn more about best functional image practices (WAI Images)](https://www.w3.org/WAI/tutorials/images/functional)
14
14
  class IconButton < Primer::Component
15
- warn_on_deprecated_slot_setter
16
15
  status :deprecated
17
16
 
18
17
  DEFAULT_SCHEME = :default
@@ -3,8 +3,6 @@
3
3
  module Primer
4
4
  # Use `Layout` to build a main/sidebar layout.
5
5
  class LayoutComponent < Primer::Component
6
- warn_on_deprecated_slot_setter
7
-
8
6
  # The main content
9
7
  #
10
8
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
@@ -3,7 +3,6 @@
3
3
  module Primer
4
4
  # Use `LocalTime` to format a date and time in the user's preferred locale format. This component requires JavaScript.
5
5
  class LocalTime < Primer::Component
6
- warn_on_deprecated_slot_setter
7
6
  status :deprecated
8
7
 
9
8
  DEFAULT_DIGIT_TYPE = :numeric
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Primer
4
4
  class OcticonComponent < Primer::Beta::Octicon
5
- warn_on_deprecated_slot_setter
6
5
  status :deprecated
7
6
  end
8
7
  end
@@ -3,7 +3,6 @@
3
3
  module Primer
4
4
  # Use `State` for rendering the status of an item.
5
5
  class StateComponent < Primer::Component
6
- warn_on_deprecated_slot_setter
7
6
  status :beta
8
7
 
9
8
  SCHEME_DEFAULT = :default
@@ -11,8 +11,6 @@ module Primer
11
11
  # The `:heading` slot defaults to rendering a `<div>`. Update the tag to a heading element with the appropriate level to improve page navigation for assistive technologies.
12
12
  # <%= link_to_heading_practices %>
13
13
  class SubheadComponent < Primer::Component
14
- warn_on_deprecated_slot_setter
15
-
16
14
  status :beta
17
15
 
18
16
  DEFAULT_HEADING_TAG = :div
@@ -6,8 +6,6 @@ module Primer
6
6
  #
7
7
  # This component requires javascript.
8
8
  class TabContainerComponent < Primer::Component
9
- warn_on_deprecated_slot_setter
10
-
11
9
  # @example Default
12
10
  # <%= render(Primer::TabContainerComponent.new) do %>
13
11
  # <div role="tablist">
@@ -3,7 +3,6 @@
3
3
  module Primer
4
4
  # Use `TimeAgo` to display a time relative to how long ago it was. This component requires JavaScript.
5
5
  class TimeAgoComponent < Primer::Component
6
- warn_on_deprecated_slot_setter
7
6
  status :deprecated
8
7
 
9
8
  # @example Default
@@ -3,7 +3,6 @@
3
3
  module Primer
4
4
  # Use `TimelineItem` to display items on a vertical timeline, connected by badge elements.
5
5
  class TimelineItemComponent < Primer::Component
6
- warn_on_deprecated_slot_setter
7
6
  status :beta
8
7
 
9
8
  # Avatar to be rendered to the left of the Badge.
@@ -3,7 +3,6 @@
3
3
  module Primer
4
4
  # `Tooltip` is a wrapper component that will apply a tooltip to the provided content.
5
5
  class Tooltip < Primer::Component
6
- warn_on_deprecated_slot_setter
7
6
  status :deprecated
8
7
 
9
8
  DIRECTION_DEFAULT = :n
@@ -3,8 +3,6 @@
3
3
  module Primer
4
4
  # Use `Truncate` to shorten overflowing text with an ellipsis.
5
5
  class Truncate < Primer::Component
6
- warn_on_deprecated_slot_setter
7
-
8
6
  status :beta
9
7
 
10
8
  DEFAULT_TAG = :div
@@ -33,6 +33,8 @@ module Primer
33
33
 
34
34
  UTILITY_KEYS = Primer::Classify::Utilities::UTILITIES.keys.freeze
35
35
 
36
+ alias primer_fields_for fields_for
37
+
36
38
  def label(method, text = nil, **options, &block)
37
39
  super(method, text, classify(options).merge(generate_error_markup: false), &block)
38
40
  end
@@ -72,9 +74,6 @@ module Primer
72
74
  # is expected by Rails/HTML while the second is specific to Primer.
73
75
  # 3. Combines options[:class] and options[:classes] into options[:class]
74
76
  # so the options hash can be easily passed to Rails form builder methods.
75
- # 4. Sets generate_error_markup: false, which, in combination with the
76
- # monkeypatch at the top of this file, skips rendering any markup around
77
- # invalid fields.
78
77
  #
79
78
  def classify(options)
80
79
  options[:classes] = class_names(options.delete(:class), options[:classes])
@@ -5,11 +5,34 @@ module Primer
5
5
  module Dsl
6
6
  # :nodoc:
7
7
  class FormReferenceInput < Input
8
- attr_reader :ref_block, :fields_for_args, :fields_for_kwargs
8
+ attr_reader :ref_block, :fields_for_args, :fields_for_kwargs, :nested
9
+ alias nested? nested
9
10
 
10
- def initialize(*fields_for_args, builder:, form:, **fields_for_kwargs, &block)
11
+ # Pass `nested: false` to prevent the referenced form fields from being treated as nested
12
+ # under the parent form's model. For example, consider these models:
13
+
14
+ # class User < ActiveRecord::Base
15
+ # has_many :addresses
16
+ # end
17
+
18
+ # class Address < ActiveRecord::Base
19
+ # belongs_to :user
20
+ # end
21
+
22
+ # A sign-up form might include fields from `User` as well as `Address`. Since addresses are
23
+ # associated with users, it's perfectly natural to accept the address fields as nested
24
+ # attributes. Rails will name each field accordingly. For example, the `street` field on
25
+ # `Address` will be named `user[address][street]`.
26
+
27
+ # For situations like this where an association exists between two models, the nested
28
+ # attributes approach works great. However sometimes all you want is to compose two forms
29
+ # together that aren't connected by an association. In such cases the fields will still
30
+ # include the name of the parent model, eg. `user[address][street]` instead of what we want,
31
+ # `address[street]`. To render the form independent of the parent, pass `nested: false`.
32
+ def initialize(*fields_for_args, builder:, form:, nested: true, **fields_for_kwargs, &block)
11
33
  @fields_for_args = fields_for_args
12
34
  @fields_for_kwargs = fields_for_kwargs
35
+ @nested = nested
13
36
  @ref_block = block
14
37
 
15
38
  super(builder: builder, form: form, **fields_for_kwargs)
@@ -43,6 +43,33 @@ module Primer
43
43
  @full_width = @input_arguments.delete(:full_width)
44
44
  @size = @input_arguments.delete(:size)
45
45
 
46
+ # If scope_name_to_model is false, the name of the input for eg. `my_field`
47
+ # will be `my_field` instead of the Rails default of `model[my_field]`.
48
+ #
49
+ # We achieve this by passing the `name` option to Rails form builder
50
+ # methods. These methods will use the passed name if provided instead
51
+ # of generating a scoped one.
52
+ #
53
+ # rubocop:disable Style/IfUnlessModifier
54
+ unless @input_arguments.delete(:scope_name_to_model) { true }
55
+ @input_arguments[:name] = name
56
+ end
57
+ # rubocop:enable Style/IfUnlessModifier
58
+
59
+ # If scope_id_to_model is false, the name of the input for eg. `my_field`
60
+ # will be `my_field` instead of the Rails default of `model_my_field`.
61
+ #
62
+ # We achieve this by passing the `id` option to Rails form builder
63
+ # methods. These methods will use the passed id if provided instead
64
+ # of generating a scoped one. The id is the name of the field unless
65
+ # explicitly provided in system_arguments.
66
+ #
67
+ # rubocop:disable Style/IfUnlessModifier
68
+ unless @input_arguments.delete(:scope_id_to_model) { true }
69
+ @input_arguments[:id] = @input_arguments.delete(:id) { name }
70
+ end
71
+ # rubocop:enable Style/IfUnlessModifier
72
+
46
73
  # Whether or not to wrap the component in a FormControl, which renders a
47
74
  # label above and validation message beneath the input.
48
75
  @form_control = @input_arguments.delete(:form_control) { true }
@@ -1,3 +1,3 @@
1
- <%= builder.fields_for(*@input.fields_for_args, **@input.fields_for_kwargs) do |fields| %>
1
+ <%= builder_or_view.primer_fields_for(*@input.fields_for_args, **@input.fields_for_kwargs) do |fields| %>
2
2
  <%= render(@input.ref_block.call(fields)) %>
3
3
  <% end %>
@@ -9,6 +9,10 @@ module Primer
9
9
  def initialize(input:)
10
10
  @input = input
11
11
  end
12
+
13
+ def builder_or_view
14
+ @input.nested? ? builder : @view_context
15
+ end
12
16
  end
13
17
  end
14
18
  end
@@ -6,7 +6,7 @@ module Primer
6
6
  module VERSION
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- PATCH = 115
9
+ PATCH = 116
10
10
 
11
11
  STRING = [MAJOR, MINOR, PATCH].join(".")
12
12
  end
@@ -9,11 +9,11 @@ module Primer
9
9
  # @param number_of_panels [Integer] number
10
10
  # @param align [Symbol] select [left, right]
11
11
  def playground(number_of_panels: 3, align: :left)
12
- render(Primer::Alpha::TabPanels.new(label: "label", align: align)) do |c|
12
+ render(Primer::Alpha::TabPanels.new(label: "label", align: align)) do |component|
13
13
  Array.new(number_of_panels || 3) do |i|
14
- c.tab(selected: i.zero?, id: "tab-#{i + 1}") do |t|
15
- t.panel { "Panel #{i + 1}" }
16
- t.text { "Tab #{i + 1}" }
14
+ component.tab(selected: i.zero?, id: "tab-#{i + 1}") do |tab|
15
+ tab.with_panel { "Panel #{i + 1}" }
16
+ tab.with_text { "Tab #{i + 1}" }
17
17
  end
18
18
  end
19
19
  end
@@ -24,11 +24,11 @@ module Primer
24
24
  # @param number_of_panels [Integer] number
25
25
  # @param align [Symbol] select [left, right]
26
26
  def default(number_of_panels: 3, align: :left)
27
- render(Primer::Alpha::TabPanels.new(label: "label", align: align)) do |c|
27
+ render(Primer::Alpha::TabPanels.new(label: "label", align: align)) do |component|
28
28
  Array.new(number_of_panels || 3) do |i|
29
- c.tab(selected: i.zero?, id: "tab-#{i + 1}") do |t|
30
- t.panel { "Panel #{i + 1}" }
31
- t.text { "Tab #{i + 1}" }
29
+ component.tab(selected: i.zero?, id: "tab-#{i + 1}") do |tab|
30
+ tab.with_panel { "Panel #{i + 1}" }
31
+ tab.with_text { "Tab #{i + 1}" }
32
32
  end
33
33
  end
34
34
  end
@@ -39,9 +39,9 @@ module Primer
39
39
  # @param overlay [Symbol] select [none, default, dark]
40
40
  # @param reset [Boolean] toggle
41
41
  def custom_button(reset: false, overlay: :default)
42
- render Primer::Beta::Details.new(reset: reset, overlay: overlay) do |c|
43
- c.summary(size: :small, scheme: :primary) { "Click me" }
44
- c.body { "Body" }
42
+ render Primer::Beta::Details.new(reset: reset, overlay: overlay) do |component|
43
+ component.with_summary(size: :small, scheme: :primary) { "Click me" }
44
+ component.with_body { "Body" }
45
45
  end
46
46
  end
47
47
 
@@ -50,9 +50,9 @@ module Primer
50
50
  # @param overlay [Symbol] select [none, default, dark]
51
51
  # @param reset [Boolean] toggle
52
52
  def without_button(reset: false, overlay: :default)
53
- render Primer::Beta::Details.new(reset: reset, overlay: overlay) do |c|
54
- c.summary(button: false) { "Click me" }
55
- c.body { "Body" }
53
+ render Primer::Beta::Details.new(reset: reset, overlay: overlay) do |component|
54
+ component.with_summary(button: false) { "Click me" }
55
+ component.with_body { "Body" }
56
56
  end
57
57
  end
58
58
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Primer/ComponentNameMigration
4
+
3
5
  module Primer
4
6
  # @label LocalTime
5
7
  class LocalTimeComponentPreview < ViewComponent::Preview
@@ -52,3 +54,4 @@ module Primer
52
54
  end
53
55
  end
54
56
  end
57
+ # rubocop:enable Primer/ComponentNameMigration
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Primer/ComponentNameMigration
4
+
3
5
  module Primer
4
6
  # @label TimeAgoComponent
5
7
  class TimeAgoComponentPreview < ViewComponent::Preview
@@ -22,3 +24,4 @@ module Primer
22
24
  end
23
25
  end
24
26
  end
27
+ # rubocop:enable Primer/ComponentNameMigration
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
+ # :nodoc:
4
5
  module URLHelpers
5
6
  class << self
6
7
  # use send to avoid yard warning
@@ -8,8 +9,7 @@ module Primer
8
9
 
9
10
  private
10
11
 
11
- def controller
12
- end
12
+ def controller; end
13
13
  end
14
14
  end
15
15
  end
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.115
4
+ version: 0.0.116
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: 2022-12-13 00:00:00.000000000 Z
11
+ date: 2022-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview