primer_view_components 0.0.116 → 0.0.117

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -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 +2 -2
  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/auto_complete/item.rb +4 -4
  11. data/app/components/primer/alpha/auto_complete.rb +6 -6
  12. data/app/components/primer/alpha/dialog.rb +0 -2
  13. data/app/components/primer/alpha/dropdown.rb +53 -53
  14. data/app/components/primer/alpha/hellip_button.rb +41 -0
  15. data/app/components/primer/alpha/hidden_text_expander.rb +1 -1
  16. data/app/components/primer/alpha/layout.rb +48 -48
  17. data/app/components/primer/alpha/menu.css +1 -1
  18. data/app/components/primer/alpha/menu.css.json +1 -1
  19. data/app/components/primer/alpha/menu.css.map +1 -1
  20. data/app/components/primer/alpha/menu.rb +5 -5
  21. data/app/components/primer/alpha/segmented_control.rb +20 -20
  22. data/app/components/primer/{tab_container_component.d.ts → alpha/tab_container.d.ts} +0 -0
  23. data/app/components/primer/{tab_container_component.js → alpha/tab_container.js} +0 -0
  24. data/app/components/primer/alpha/tab_container.rb +43 -0
  25. data/app/components/primer/{tab_container_component.ts → alpha/tab_container.ts} +0 -0
  26. data/app/components/primer/alpha/tab_nav.css +1 -1
  27. data/app/components/primer/alpha/tab_nav.css.json +1 -1
  28. data/app/components/primer/alpha/tab_nav.css.map +1 -1
  29. data/app/components/primer/alpha/tab_nav.rb +32 -32
  30. data/app/components/primer/alpha/tool_tip.js +3 -7
  31. data/app/components/primer/alpha/tool_tip.ts +3 -7
  32. data/app/components/primer/alpha/tooltip.rb +18 -18
  33. data/app/components/primer/alpha/underline_nav.css +1 -1
  34. data/app/components/primer/alpha/underline_nav.css.json +1 -1
  35. data/app/components/primer/alpha/underline_nav.css.map +1 -1
  36. data/app/components/primer/alpha/underline_nav.rb +18 -18
  37. data/app/components/primer/beta/auto_complete/item.rb +2 -3
  38. data/app/components/primer/beta/auto_complete.rb +14 -16
  39. data/app/components/primer/beta/avatar_stack.rb +12 -14
  40. data/app/components/primer/beta/blankslate.rb +0 -1
  41. data/app/components/primer/beta/border_box/header.rb +0 -2
  42. data/app/components/primer/beta/border_box.rb +0 -2
  43. data/app/components/primer/beta/breadcrumbs.css +1 -1
  44. data/app/components/primer/beta/breadcrumbs.css.json +1 -1
  45. data/app/components/primer/beta/breadcrumbs.css.map +1 -1
  46. data/app/components/primer/beta/breadcrumbs.rb +0 -1
  47. data/app/components/primer/beta/button.rb +9 -10
  48. data/app/components/primer/beta/button_group.rb +0 -1
  49. data/app/components/primer/beta/details.rb +0 -1
  50. data/app/components/primer/beta/flash.rb +0 -1
  51. data/app/components/primer/beta/link.rb +2 -3
  52. data/app/components/primer/beta/octicon.rb +0 -1
  53. data/app/components/primer/beta/popover.rb +0 -1
  54. data/app/components/primer/{state_component.css → beta/state.css} +0 -0
  55. data/app/components/primer/beta/state.css.json +1 -0
  56. data/app/components/primer/beta/state.css.map +1 -0
  57. data/app/components/primer/{state_component.pcss → beta/state.pcss} +0 -0
  58. data/app/components/primer/beta/state.rb +76 -0
  59. data/app/components/primer/{subhead_component.css → beta/subhead.css} +0 -0
  60. data/app/components/primer/beta/subhead.css.json +1 -0
  61. data/app/components/primer/beta/subhead.css.map +1 -0
  62. data/app/components/primer/{subhead_component.html.erb → beta/subhead.html.erb} +0 -0
  63. data/app/components/primer/{subhead_component.pcss → beta/subhead.pcss} +0 -0
  64. data/app/components/primer/beta/subhead.rb +135 -0
  65. data/app/components/primer/{timeline_item_component.css → beta/timeline_item.css} +0 -0
  66. data/app/components/primer/beta/timeline_item.css.json +1 -0
  67. data/app/components/primer/beta/timeline_item.css.map +1 -0
  68. data/app/components/primer/{timeline_item_component.html.erb → beta/timeline_item.html.erb} +0 -0
  69. data/app/components/primer/{timeline_item_component.pcss → beta/timeline_item.pcss} +0 -0
  70. data/app/components/primer/beta/timeline_item.rb +90 -0
  71. data/app/components/primer/beta/truncate.css +1 -1
  72. data/app/components/primer/beta/truncate.css.json +1 -1
  73. data/app/components/primer/beta/truncate.css.map +1 -1
  74. data/app/components/primer/beta/truncate.rb +0 -1
  75. data/app/components/primer/button_component.rb +9 -9
  76. data/app/components/primer/component.rb +0 -1
  77. data/app/components/primer/hellip_button.rb +2 -34
  78. data/app/components/primer/navigation/tab_component.rb +16 -16
  79. data/app/components/primer/primer.d.ts +1 -1
  80. data/app/components/primer/primer.js +1 -1
  81. data/app/components/primer/primer.pcss +3 -3
  82. data/app/components/primer/primer.ts +1 -1
  83. data/app/components/primer/state_component.rb +2 -69
  84. data/app/components/primer/subhead_component.rb +2 -128
  85. data/app/components/primer/tab_container_component.rb +2 -36
  86. data/app/components/primer/timeline_item_component.rb +5 -78
  87. data/app/forms/example_toggle_switch_form/example_field_caption.html.erb +1 -0
  88. data/app/forms/example_toggle_switch_form.rb +8 -0
  89. data/app/forms/submit_button_form.rb +4 -4
  90. data/app/lib/primer/tabbed_component_helper.rb +1 -1
  91. data/lib/primer/deprecations.rb +7 -13
  92. data/lib/primer/deprecations.yml +24 -0
  93. data/lib/primer/forms/button.html.erb +2 -2
  94. data/lib/primer/forms/dsl/toggle_switch_input.rb +35 -0
  95. data/lib/primer/forms/toggle_switch.html.erb +17 -0
  96. data/lib/primer/forms/toggle_switch.rb +19 -0
  97. data/lib/primer/forms/toggle_switch_form.rb +74 -0
  98. data/lib/primer/view_components/linters/subhead_component_migration_counter.rb +1 -1
  99. data/lib/primer/view_components/version.rb +1 -1
  100. data/lib/rubocop/cop/primer/component_name_migration.rb +2 -1
  101. data/lib/tasks/docs.rake +6 -6
  102. data/previews/primer/alpha/action_list_preview.rb +44 -44
  103. data/previews/primer/alpha/dropdown_preview.rb +97 -97
  104. data/previews/primer/alpha/hellip_button_preview.rb +24 -0
  105. data/previews/primer/alpha/layout_preview.rb +63 -63
  106. data/previews/primer/alpha/menu_preview/default.html.erb +5 -5
  107. data/previews/primer/alpha/menu_preview/playground.html.erb +5 -5
  108. data/previews/primer/alpha/segmented_control_preview.rb +60 -60
  109. data/previews/primer/alpha/tab_nav_preview.rb +22 -22
  110. data/previews/primer/alpha/tab_panels_preview.rb +2 -2
  111. data/previews/primer/alpha/tooltip_preview/with_multiple_on_a_page.html.erb +6 -6
  112. data/previews/primer/alpha/tooltip_preview.rb +12 -12
  113. data/previews/primer/alpha/underline_nav_preview.rb +4 -4
  114. data/previews/primer/alpha/underline_panels_preview.rb +8 -8
  115. data/previews/primer/beta/auto_complete_item_preview/default.html.erb +2 -2
  116. data/previews/primer/beta/auto_complete_item_preview/playground.html.erb +2 -2
  117. data/previews/primer/beta/auto_complete_item_preview/with_description.html.erb +3 -3
  118. data/previews/primer/beta/auto_complete_preview/with_submit_button.html.erb +2 -2
  119. data/previews/primer/beta/auto_complete_preview.rb +18 -18
  120. data/previews/primer/beta/avatar_stack_preview.rb +32 -32
  121. data/previews/primer/beta/blankslate_preview.rb +40 -40
  122. data/previews/primer/beta/border_box_preview.rb +38 -38
  123. data/previews/primer/beta/breadcrumbs_preview.rb +2 -2
  124. data/previews/primer/beta/button_group_preview.rb +10 -10
  125. data/previews/primer/beta/button_preview/all_schemes.html.erb +4 -4
  126. data/previews/primer/beta/button_preview/invisible_all_visuals.html.erb +16 -16
  127. data/previews/primer/beta/button_preview/leading_visual.html.erb +2 -2
  128. data/previews/primer/beta/button_preview/trailing_action.html.erb +2 -2
  129. data/previews/primer/beta/button_preview/trailing_visual.html.erb +2 -2
  130. data/previews/primer/beta/button_preview/with_tooltip.html.erb +2 -2
  131. data/previews/primer/beta/details_preview.rb +6 -6
  132. data/previews/primer/beta/state_preview.rb +66 -0
  133. data/previews/primer/beta/subhead_preview/actions.html.erb +14 -0
  134. data/previews/primer/beta/subhead_preview.rb +99 -0
  135. data/previews/primer/beta/timeline_item_preview.rb +30 -0
  136. data/previews/primer/forms/forms_preview/example_toggle_switch_form.html.erb +1 -0
  137. data/previews/primer/forms/forms_preview.rb +2 -0
  138. data/static/arguments.json +118 -118
  139. data/static/audited_at.json +6 -0
  140. data/static/constants.json +67 -54
  141. data/static/statuses.json +12 -6
  142. metadata +36 -23
  143. data/app/components/primer/state_component.css.json +0 -1
  144. data/app/components/primer/state_component.css.map +0 -1
  145. data/app/components/primer/subhead_component.css.json +0 -1
  146. data/app/components/primer/subhead_component.css.map +0 -1
  147. data/app/components/primer/timeline_item_component.css.json +0 -1
  148. data/app/components/primer/timeline_item_component.css.map +0 -1
  149. data/previews/primer/hellip_button_preview.rb +0 -22
  150. data/previews/primer/state_component_preview.rb +0 -26
  151. data/previews/primer/subhead_component_preview.rb +0 -40
  152. data/previews/primer/timeline_item_component_preview.rb +0 -28
@@ -1,133 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
- # Use `Subhead` as the start of a section. The `:heading` slot will render an `<h2>` font-sized text.
5
- #
6
- # - Optionally set the `:description` slot to render a short description and the `:actions` slot for a related action.
7
- # - Use a succinct, one-line description for the `:description` slot. For longer descriptions, omit the description slot and render a paragraph below the `Subhead`.
8
- # - Use the actions slot to render a related action to the right of the heading. Use <%= link_to_component(Primer::ButtonComponent) %> or <%= link_to_component(Primer::Beta::Link) %>.
9
- #
10
- # @accessibility
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
- # <%= link_to_heading_practices %>
13
- class SubheadComponent < Primer::Component
14
- status :beta
15
-
16
- DEFAULT_HEADING_TAG = :div
17
- HEADING_TAG_OPTIONS = [DEFAULT_HEADING_TAG, :h1, :h2, :h3, :h4, :h5, :h6].freeze
18
-
19
- # The heading
20
- #
21
- # @param tag [Symbol] <%= one_of(Primer::SubheadComponent::HEADING_TAG_OPTIONS)%>
22
- # @param danger [Boolean] Whether to style the heading as dangerous.
23
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
24
- renders_one :heading, lambda { |tag: DEFAULT_HEADING_TAG, danger: false, **system_arguments|
25
- system_arguments[:tag] = fetch_or_fallback(HEADING_TAG_OPTIONS, tag, DEFAULT_HEADING_TAG)
26
- system_arguments[:classes] = class_names(
27
- system_arguments[:classes],
28
- "Subhead-heading",
29
- "Subhead-heading--danger": danger
30
- )
31
-
32
- Primer::BaseComponent.new(**system_arguments)
33
- }
34
-
35
- # Actions
36
- #
37
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
38
- renders_one :actions, lambda { |**system_arguments|
39
- deny_tag_argument(**system_arguments)
40
- system_arguments[:tag] = :div
41
- system_arguments[:classes] = class_names(system_arguments[:classes], "Subhead-actions")
42
-
43
- Primer::BaseComponent.new(**system_arguments)
44
- }
45
-
46
- # The description
47
- #
48
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
49
- renders_one :description, lambda { |**system_arguments|
50
- deny_tag_argument(**system_arguments)
51
- system_arguments[:tag] = :div
52
- system_arguments[:classes] = class_names(system_arguments[:classes], "Subhead-description")
53
-
54
- Primer::BaseComponent.new(**system_arguments)
55
- }
56
-
57
- # @example Default
58
- # <%= render(Primer::SubheadComponent.new) do |component| %>
59
- # <% component.with_heading(tag: :h3) do %>
60
- # My Heading
61
- # <% end %>
62
- # <% component.with_description do %>
63
- # My Description
64
- # <% end %>
65
- # <% end %>
66
- #
67
- # @example With dangerous heading
68
- # <%= render(Primer::SubheadComponent.new) do |component| %>
69
- # <% component.with_heading(tag: :h3, danger: true) do %>
70
- # My Heading
71
- # <% end %>
72
- # <% component.with_description do %>
73
- # My Description
74
- # <% end %>
75
- # <% end %>
76
- #
77
- # @example With long description
78
- # <%= render(Primer::SubheadComponent.new) do |component| %>
79
- # <% component.with_heading(tag: :h3) do %>
80
- # My Heading
81
- # <% end %>
82
- # <% end %>
83
- # <p> This is a longer description that is sitting below the Subhead. It's much longer than a description that could sit comfortably in the Subhead. </p>
84
- #
85
- # @example Without border
86
- # <%= render(Primer::SubheadComponent.new(hide_border: true)) do |component| %>
87
- # <% component.with_heading do %>
88
- # My Heading
89
- # <% end %>
90
- # <% component.with_description do %>
91
- # My Description
92
- # <% end %>
93
- # <% end %>
94
- #
95
- # @example With actions
96
- # <%= render(Primer::SubheadComponent.new) do |component| %>
97
- # <% component.with_heading do %>
98
- # My Heading
99
- # <% end %>
100
- # <% component.with_description do %>
101
- # My Description
102
- # <% end %>
103
- # <% component.with_actions do %>
104
- # <%= render(
105
- # Primer::ButtonComponent.new(
106
- # tag: :a, href: "http://www.google.com", scheme: :danger
107
- # )
108
- # ) { "Action" } %>
109
- # <% end %>
110
- # <% end %>
111
- #
112
- # @param spacious [Boolean] Whether to add spacing to the Subhead.
113
- # @param hide_border [Boolean] Whether to hide the border under the heading.
114
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
115
- def initialize(spacious: false, hide_border: false, **system_arguments)
116
- @system_arguments = deny_tag_argument(**system_arguments)
117
-
118
- @system_arguments[:tag] = :div
119
- @system_arguments[:classes] =
120
- class_names(
121
- @system_arguments[:classes],
122
- "Subhead",
123
- "Subhead--spacious": spacious,
124
- "border-bottom-0": hide_border
125
- )
126
- @system_arguments[:mb] ||= hide_border ? 0 : nil
127
- end
128
-
129
- def render?
130
- heading.present?
131
- end
4
+ class SubheadComponent < Primer::Beta::Subhead
5
+ status :deprecated
132
6
  end
133
7
  end
@@ -1,41 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
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::Alpha::TabNav) %>.
6
- #
7
- # This component requires javascript.
8
- class TabContainerComponent < Primer::Component
9
- # @example Default
10
- # <%= render(Primer::TabContainerComponent.new) do %>
11
- # <div role="tablist">
12
- # <button type="button" role="tab" aria-selected="true">Tab one</button>
13
- # <button type="button" role="tab" tabindex="-1">Tab two</button>
14
- # <button type="button" role="tab" tabindex="-1">Tab three</button>
15
- # </div>
16
- # <div role="tabpanel">
17
- # Panel 1
18
- # </div>
19
- # <div role="tabpanel" hidden>
20
- # Panel 2
21
- # </div>
22
- # <div role="tabpanel" hidden>
23
- # Panel 3
24
- # </div>
25
- # <% end %>
26
- #
27
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
28
- def initialize(**system_arguments)
29
- @system_arguments = deny_tag_argument(**system_arguments)
30
- @system_arguments[:tag] = "tab-container"
31
- end
32
-
33
- def call
34
- render(Primer::BaseComponent.new(**@system_arguments)) { content }
35
- end
36
-
37
- def render?
38
- content.present?
39
- end
4
+ class TabContainerComponent < Primer::Alpha::TabContainer
5
+ status :deprecated
40
6
  end
41
7
  end
@@ -1,86 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
- # Use `TimelineItem` to display items on a vertical timeline, connected by badge elements.
5
- class TimelineItemComponent < Primer::Component
6
- status :beta
4
+ # nodoc
5
+ class TimelineItemComponent < Primer::Beta::TimelineItem
6
+ status :deprecated
7
7
 
8
- # Avatar to be rendered to the left of the Badge.
9
- #
10
- # @param kwargs [Hash] The same arguments as <%= link_to_component(Primer::Beta::Avatar) %>.
11
- renders_one :avatar, lambda { |src:, size: 40, shape: :square, **system_arguments|
12
- system_arguments[:classes] = class_names(
13
- "TimelineItem-avatar",
14
- system_arguments[:classes]
15
- )
16
-
17
- Primer::Beta::Avatar.new(src: src, size: size, shape: shape, **system_arguments)
18
- }
19
-
20
- # Badge that will be connected to other TimelineItems.
21
- #
22
- # @param icon [String] Name of <%= link_to_octicons %> to use.
23
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
24
- renders_one :badge, "BadgeComponent"
25
-
26
- # Body to be rendered to the left of the Badge.
27
- #
28
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
29
- renders_one :body, lambda { |**system_arguments|
30
- deny_tag_argument(**system_arguments)
31
- system_arguments[:tag] = :div
32
- system_arguments[:classes] = class_names(
33
- "TimelineItem-body",
34
- system_arguments[:classes]
35
- )
36
-
37
- Primer::BaseComponent.new(**system_arguments)
38
- }
39
-
40
- # @example Default
41
- # <div style="padding-left: 60px">
42
- # <%= render(Primer::TimelineItemComponent.new) do |component| %>
43
- # <% component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "github") %>
44
- # <% component.with_badge(bg: :success_emphasis, color: :on_emphasis, icon: :check) %>
45
- # <% component.with_body { "Success!" } %>
46
- # <% end %>
47
- # </div>
48
- #
49
- # @param condensed [Boolean] Reduce the vertical padding and remove the background from the badge item. Most commonly used in commits.
50
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
51
- def initialize(condensed: false, **system_arguments)
52
- @system_arguments = deny_tag_argument(**system_arguments)
53
- @system_arguments[:tag] = :div
54
- @system_arguments[:classes] = class_names(
55
- "TimelineItem",
56
- condensed ? "TimelineItem--condensed" : "",
57
- system_arguments[:classes]
58
- )
59
- end
60
-
61
- def render?
62
- avatar? || badge? || body?
63
- end
64
-
65
- # This component is part of `Primer::TimelineItemComponent` and should not be
66
- # used as a standalone component.
8
+ # nodoc
67
9
  class BadgeComponent < Primer::Component
68
- def initialize(icon: nil, **system_arguments)
69
- @icon = icon
70
-
71
- @system_arguments = deny_tag_argument(**system_arguments)
72
- @system_arguments[:tag] = :div
73
- @system_arguments[:classes] = class_names(
74
- "TimelineItem-badge",
75
- system_arguments[:classes]
76
- )
77
- end
78
-
79
- def call
80
- render(Primer::BaseComponent.new(**@system_arguments)) do
81
- render(Primer::Beta::Octicon.new(@icon))
82
- end
83
- end
10
+ status :deprecated
84
11
  end
85
12
  end
86
13
  end
@@ -0,0 +1 @@
1
+ My <em>favorite</em> caption.
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ class ExampleToggleSwitchForm < Primer::Forms::ToggleSwitchForm
5
+ def initialize(**system_arguments)
6
+ super(name: :example_field, label: "Example", **system_arguments)
7
+ end
8
+ end
@@ -14,12 +14,12 @@ class SubmitButtonForm < ApplicationForm
14
14
  )
15
15
 
16
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")
17
+ button_group.submit(name: :submit, label: "Submit", scheme: :primary, mb: 3) do |component|
18
+ component.with_leading_visual_icon(icon: :"check-circle")
19
19
  end
20
20
 
21
- button_group.button(name: :button, label: "Click me", mb: 3) do |c|
22
- c.with_leading_visual_icon(icon: :alert)
21
+ button_group.button(name: :button, label: "Click me", mb: 3) do |component|
22
+ component.with_leading_visual_icon(icon: :alert)
23
23
  end
24
24
  end
25
25
  end
@@ -23,7 +23,7 @@ module Primer
23
23
  def tab_container_wrapper(with_panel:, **system_arguments)
24
24
  return yield unless with_panel
25
25
 
26
- render Primer::TabContainerComponent.new(**system_arguments) do
26
+ render Primer::Alpha::TabContainer.new(**system_arguments) do
27
27
  yield if block_given?
28
28
  end
29
29
  end
@@ -74,19 +74,13 @@ module Primer
74
74
  # more information on what is and is not valid, see the
75
75
  # documentation here: docs/contributors/deprecations.md
76
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
77
+ if replacement?(component_name)
78
+ msg << "Please update your code to use '#{replacement(component_name)}'."
79
+ msg << "Use Rubocop's auto-correct, or replace it yourself." if correctable?(component_name)
80
+ msg << "See #{guide(component_name)} for more information." if guide?(component_name)
81
+ else # if there is no replacement, it must have a guide. this is enforced through tests
82
+ msg << "Unfortunately, there is no direct replacement."
83
+ msg << "See #{guide(component_name)} for more information and available options."
90
84
  end
91
85
 
92
86
  msg.join(" ")
@@ -47,6 +47,10 @@ deprecations:
47
47
  autocorrect: true
48
48
  replacement: "Primer::Alpha::Dropdown::Menu::Item"
49
49
 
50
+ - component: "Primer::HellipButton"
51
+ autocorrect: true
52
+ replacement: "Primer::Alpha::HellipButton"
53
+
50
54
  - component: "Primer::IconButton"
51
55
  autocorrect: true
52
56
  replacement: "Primer::Beta::IconButton"
@@ -88,11 +92,31 @@ deprecations:
88
92
  autocorrect: true
89
93
  replacement: "Primer::Beta::Spinner"
90
94
 
95
+ - component: "Primer::StateComponent"
96
+ autocorrect: true
97
+ replacement: "Primer::Beta::State"
98
+
99
+ - component: "Primer::SubheadComponent"
100
+ autocorrect: true
101
+ replacement: "Primer::Beta::Subhead"
102
+
103
+ - component: "Primer::TabContainerComponent"
104
+ autocorrect: true
105
+ replacement: "Primer::Alpha::TabContainer"
106
+
91
107
  - component: "Primer::TimeAgoComponent"
92
108
  autocorrect: false
93
109
  replacement: "Primer::Beta::RelativeTime"
94
110
  guide: "https://primer.style/view-components/guides/primer_time_ago"
95
111
 
112
+ - component: "Primer::TimelineItemComponent"
113
+ autocorrect: true
114
+ replacement: "Primer::Beta::TimelineItem"
115
+
116
+ - component: "Primer::TimelineItemComponent::BadgeComponent"
117
+ autocorrect: true
118
+ replacement: "Primer::Beta::TimelineItem::Badge"
119
+
96
120
  - component: "Primer::Tooltip"
97
121
  autocorrect: true
98
122
  replacement: "Primer::Alpha::Tooltip"
@@ -1,4 +1,4 @@
1
- <%= render(Primer::Beta::Button.new(**input_arguments)) do |c| %>
2
- <% @input.block.call(c) if @input.block %>
1
+ <%= render(Primer::Beta::Button.new(**input_arguments)) do |component| %>
2
+ <% @input.block.call(component) if @input.block %>
3
3
  <%= @input.label %>
4
4
  <% end %>
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module Forms
5
+ module Dsl
6
+ # :nodoc:
7
+ class ToggleSwitchInput < Input
8
+ attr_reader :name, :label, :src, :csrf
9
+
10
+ def initialize(
11
+ name:,
12
+ label:,
13
+ src:,
14
+ csrf: nil,
15
+ **system_arguments
16
+ )
17
+ @name = name
18
+ @label = label
19
+ @src = src
20
+ @csrf = csrf
21
+
22
+ super(**system_arguments)
23
+ end
24
+
25
+ def to_component
26
+ ToggleSwitch.new(input: self)
27
+ end
28
+
29
+ def type
30
+ :toggle_switch
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ <%= content_tag(:div, **@form_group_arguments) do %>
2
+ <span style="flex-grow: 1">
3
+ <%= builder.label(@input.name, **@input.label_arguments) do %>
4
+ <%= @input.label %>
5
+ <% end %>
6
+ <%= render(Caption.new(input: @input)) %>
7
+ </span>
8
+ <%
9
+ csrf = @input.csrf || @view_context.form_authenticity_token(
10
+ form_options: {
11
+ method: :post,
12
+ action: @input.src
13
+ }
14
+ )
15
+ %>
16
+ <%= render(Primer::Alpha::ToggleSwitch.new(src: @input.src, csrf: csrf)) %>
17
+ <% end %>
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module Forms
5
+ # :nodoc:
6
+ class ToggleSwitch < BaseComponent
7
+ delegate :builder, :form, to: :@input
8
+
9
+ def initialize(input:)
10
+ @input = input
11
+ @input.add_label_classes("FormControl-label")
12
+
13
+ @form_group_arguments = { class: "d-flex" }
14
+
15
+ @form_group_arguments[:hidden] = "hidden" if @input.hidden?
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module Forms
5
+ # Toggle switches are designed to submit an on/off value to the server immediately
6
+ # upon click. For that reason they are not designed to be used in "regular" forms
7
+ # that have other fields, etc. Instead they should be used independently via this
8
+ # class.
9
+ #
10
+ # ToggleSwitchForm can be used directly or via inheritance.
11
+ #
12
+ # Via inheritance:
13
+ #
14
+ # # app/forms/my_toggle_form.rb
15
+ # class MyToggleForm < Primer::Forms::ToggleSwitchForm
16
+ # def initialize(**system_arguments)
17
+ # super(name: :foo, label: "Foo", src: "/foo", **system_arguments)
18
+ # end
19
+ # end
20
+ #
21
+ # # app/views/some_view.html.erb
22
+ # <%= render(MyToggleForm.new) %>
23
+ #
24
+ # Directly:
25
+ #
26
+ # # app/views/some_view.html.erb
27
+ # <%= render(
28
+ # Primer::Forms::ToggleSwitchForm.new(
29
+ # name: :foo, label: "Foo", src: "/foo"
30
+ # )
31
+ # ) %>
32
+ #
33
+ class ToggleSwitchForm < Primer::Forms::Base
34
+ # Define the form on subclasses so render(Subclass.new) works as expected.
35
+ def self.inherited(base)
36
+ base.form do |toggle_switch_form|
37
+ input = Dsl::ToggleSwitchInput.new(
38
+ builder: toggle_switch_form.builder, form: self, **@system_arguments
39
+ )
40
+
41
+ toggle_switch_form.send(:add_input, input)
42
+ end
43
+ end
44
+
45
+ # Define the form on self so render(ToggleSwitchForm.new) works as expected.
46
+ inherited(self)
47
+
48
+ # Override to avoid accepting a builder argument. We create our own builder
49
+ # on render. See the implementation of render_in below.
50
+ def self.new(**options)
51
+ allocate.tap { |obj| obj.send(:initialize, **options) }
52
+ end
53
+
54
+ def initialize(**system_arguments)
55
+ @system_arguments = system_arguments
56
+ end
57
+
58
+ # Unlike other instances of Base, ToggleSwitchForm defines its own form and
59
+ # is not given a Rails form builder on instantiation. We do this mostly for
60
+ # ergonomic reasons; it's much less verbose than if you were required to
61
+ # call form_with/form_for, etc. That said, the rest of the forms framework
62
+ # assumes the presence of a builder so we create our own here. A builder
63
+ # cannot be constructed without a corresponding view context, which is why
64
+ # we have to override render_in and can't create it in the initializer.
65
+ def render_in(view_context, &block)
66
+ @builder = Primer::Forms::Builder.new(
67
+ nil, nil, view_context, {}
68
+ )
69
+
70
+ super
71
+ end
72
+ end
73
+ end
74
+ end
@@ -6,7 +6,7 @@ module ERBLint
6
6
  module Linters
7
7
  # Counts the number of times a HTML Subhead is used instead of the component.
8
8
  class SubheadComponentMigrationCounter < BaseLinter
9
- MESSAGE = "We are migrating Subhead to use [Primer::SubheadComponent](https://primer.style/view-components/components/subhead), please try to use that instead of raw HTML."
9
+ MESSAGE = "We are migrating Subhead to use [Primer::Beta::Subhead](https://primer.style/view-components/components/subhead), please try to use that instead of raw HTML."
10
10
  CLASSES = %w[Subhead].freeze
11
11
  TAGS = %w[div].freeze
12
12
  end
@@ -6,7 +6,7 @@ module Primer
6
6
  module VERSION
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- PATCH = 116
9
+ PATCH = 117
10
10
 
11
11
  STRING = [MAJOR, MINOR, PATCH].join(".")
12
12
  end
@@ -18,7 +18,8 @@ module RuboCop
18
18
  def on_send(node)
19
19
  return unless node.method_name == :new && !node.receiver.nil? && ::Primer::Deprecations.deprecated?(node.receiver.const_name)
20
20
 
21
- add_offense(node.receiver, message: "Don't use deprecated names")
21
+ message = ::Primer::Deprecations.deprecation_message(node.receiver.const_name)
22
+ add_offense(node.receiver, message: message)
22
23
  end
23
24
 
24
25
  def autocorrect(node)
data/lib/tasks/docs.rake CHANGED
@@ -34,7 +34,7 @@ namespace :docs do
34
34
  Primer::Beta::Button,
35
35
  Primer::Alpha::SegmentedControl,
36
36
  Primer::Alpha::Layout,
37
- Primer::HellipButton,
37
+ Primer::Alpha::HellipButton,
38
38
  Primer::Alpha::Image,
39
39
  Primer::LocalTime,
40
40
  Primer::Alpha::OcticonSymbols,
@@ -73,14 +73,14 @@ namespace :docs do
73
73
  Primer::Beta::Octicon,
74
74
  Primer::Beta::Popover,
75
75
  Primer::Beta::ProgressBar,
76
- Primer::StateComponent,
76
+ Primer::Beta::State,
77
77
  Primer::Beta::Spinner,
78
- Primer::SubheadComponent,
79
- Primer::TabContainerComponent,
78
+ Primer::Beta::Subhead,
79
+ Primer::Alpha::TabContainer,
80
80
  Primer::Beta::Text,
81
81
  Primer::Alpha::TextField,
82
82
  Primer::TimeAgoComponent,
83
- Primer::TimelineItemComponent,
83
+ Primer::Beta::TimelineItem,
84
84
  Primer::Tooltip,
85
85
  Primer::Truncate,
86
86
  Primer::Beta::Truncate,
@@ -106,7 +106,7 @@ namespace :docs do
106
106
  Primer::Beta::AutoComplete,
107
107
  Primer::Alpha::Banner,
108
108
  Primer::Beta::ClipboardCopy,
109
- Primer::TabContainerComponent,
109
+ Primer::Alpha::TabContainer,
110
110
  Primer::TimeAgoComponent,
111
111
  Primer::Alpha::UnderlinePanels,
112
112
  Primer::Alpha::TabPanels,