primer_view_components 0.0.115 → 0.0.117

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -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/divider.rb +0 -2
  8. data/app/components/primer/alpha/action_list/heading.rb +0 -2
  9. data/app/components/primer/alpha/action_list/item.rb +0 -2
  10. data/app/components/primer/alpha/action_list.css +1 -1
  11. data/app/components/primer/alpha/action_list.css.json +1 -1
  12. data/app/components/primer/alpha/action_list.css.map +1 -1
  13. data/app/components/primer/alpha/action_list.rb +0 -1
  14. data/app/components/primer/alpha/auto_complete/item.rb +4 -5
  15. data/app/components/primer/alpha/auto_complete.rb +12 -13
  16. data/app/components/primer/alpha/banner.rb +0 -1
  17. data/app/components/primer/alpha/button_marketing.rb +0 -2
  18. data/app/components/primer/alpha/dialog.rb +0 -3
  19. data/app/components/primer/alpha/dropdown/menu.rb +2 -0
  20. data/app/components/primer/alpha/dropdown.html.erb +3 -3
  21. data/app/components/primer/alpha/dropdown.rb +53 -53
  22. data/app/components/primer/alpha/hellip_button.rb +41 -0
  23. data/app/components/primer/alpha/hidden_text_expander.rb +1 -1
  24. data/app/components/primer/alpha/image.rb +0 -1
  25. data/app/components/primer/alpha/layout.rb +49 -49
  26. data/app/components/primer/alpha/menu.css +1 -1
  27. data/app/components/primer/alpha/menu.css.json +1 -1
  28. data/app/components/primer/alpha/menu.css.map +1 -1
  29. data/app/components/primer/alpha/menu.rb +5 -5
  30. data/app/components/primer/alpha/octicon_symbols.rb +0 -2
  31. data/app/components/primer/alpha/segmented_control.css +1 -1
  32. data/app/components/primer/alpha/segmented_control.css.json +1 -1
  33. data/app/components/primer/alpha/segmented_control.css.map +1 -1
  34. data/app/components/primer/alpha/segmented_control.pcss +12 -0
  35. data/app/components/primer/alpha/segmented_control.rb +20 -20
  36. data/app/components/primer/{tab_container_component.d.ts → alpha/tab_container.d.ts} +0 -0
  37. data/app/components/primer/{tab_container_component.js → alpha/tab_container.js} +0 -0
  38. data/app/components/primer/alpha/tab_container.rb +43 -0
  39. data/app/components/primer/{tab_container_component.ts → alpha/tab_container.ts} +0 -0
  40. data/app/components/primer/alpha/tab_nav.css +1 -1
  41. data/app/components/primer/alpha/tab_nav.css.json +1 -1
  42. data/app/components/primer/alpha/tab_nav.css.map +1 -1
  43. data/app/components/primer/alpha/tab_nav.rb +32 -32
  44. data/app/components/primer/alpha/tab_panels.rb +6 -6
  45. data/app/components/primer/alpha/text_field.rb +0 -1
  46. data/app/components/primer/alpha/toggle_switch.rb +6 -8
  47. data/app/components/primer/alpha/tool_tip.js +3 -7
  48. data/app/components/primer/alpha/tool_tip.ts +3 -7
  49. data/app/components/primer/alpha/tooltip.rb +18 -20
  50. data/app/components/primer/alpha/underline_nav.css +1 -1
  51. data/app/components/primer/alpha/underline_nav.css.json +1 -1
  52. data/app/components/primer/alpha/underline_nav.css.map +1 -1
  53. data/app/components/primer/alpha/underline_nav.rb +18 -18
  54. data/app/components/primer/alpha/underline_panels.rb +6 -6
  55. data/app/components/primer/beta/auto_complete/item.rb +2 -2
  56. data/app/components/primer/beta/auto_complete.rb +17 -17
  57. data/app/components/primer/beta/avatar.rb +0 -1
  58. data/app/components/primer/beta/avatar_stack.rb +12 -12
  59. data/app/components/primer/beta/base_button.rb +0 -1
  60. data/app/components/primer/beta/blankslate.rb +42 -42
  61. data/app/components/primer/beta/breadcrumbs.css +1 -1
  62. data/app/components/primer/beta/breadcrumbs.css.json +1 -1
  63. data/app/components/primer/beta/breadcrumbs.css.map +1 -1
  64. data/app/components/primer/beta/button.css +1 -1
  65. data/app/components/primer/beta/button.css.json +1 -1
  66. data/app/components/primer/beta/button.css.map +1 -1
  67. data/app/components/primer/beta/button.pcss +5 -0
  68. data/app/components/primer/beta/button.rb +9 -9
  69. data/app/components/primer/beta/button_group.rb +2 -0
  70. data/app/components/primer/beta/clipboard_copy.rb +0 -1
  71. data/app/components/primer/beta/close_button.rb +0 -1
  72. data/app/components/primer/beta/counter.rb +0 -1
  73. data/app/components/primer/beta/details.rb +5 -3
  74. data/app/components/primer/beta/heading.rb +0 -1
  75. data/app/components/primer/beta/icon_button.rb +0 -1
  76. data/app/components/primer/beta/label.rb +0 -1
  77. data/app/components/primer/beta/link.rb +2 -2
  78. data/app/components/primer/beta/markdown.rb +0 -1
  79. data/app/components/primer/beta/progress_bar.rb +7 -7
  80. data/app/components/primer/beta/relative_time.rb +0 -1
  81. data/app/components/primer/beta/spinner.rb +0 -1
  82. data/app/components/primer/{state_component.css → beta/state.css} +0 -0
  83. data/app/components/primer/beta/state.css.json +1 -0
  84. data/app/components/primer/beta/state.css.map +1 -0
  85. data/app/components/primer/{state_component.pcss → beta/state.pcss} +0 -0
  86. data/app/components/primer/beta/state.rb +76 -0
  87. data/app/components/primer/{subhead_component.css → beta/subhead.css} +0 -0
  88. data/app/components/primer/beta/subhead.css.json +1 -0
  89. data/app/components/primer/beta/subhead.css.map +1 -0
  90. data/app/components/primer/{subhead_component.html.erb → beta/subhead.html.erb} +0 -0
  91. data/app/components/primer/{subhead_component.pcss → beta/subhead.pcss} +0 -0
  92. data/app/components/primer/beta/subhead.rb +135 -0
  93. data/app/components/primer/beta/text.rb +0 -1
  94. data/app/components/primer/{timeline_item_component.css → beta/timeline_item.css} +0 -0
  95. data/app/components/primer/beta/timeline_item.css.json +1 -0
  96. data/app/components/primer/beta/timeline_item.css.map +1 -0
  97. data/app/components/primer/{timeline_item_component.html.erb → beta/timeline_item.html.erb} +0 -0
  98. data/app/components/primer/{timeline_item_component.pcss → beta/timeline_item.pcss} +0 -0
  99. data/app/components/primer/beta/timeline_item.rb +90 -0
  100. data/app/components/primer/beta/truncate.css +1 -1
  101. data/app/components/primer/beta/truncate.css.json +1 -1
  102. data/app/components/primer/beta/truncate.css.map +1 -1
  103. data/app/components/primer/beta/truncate.rb +2 -2
  104. data/app/components/primer/box.rb +0 -1
  105. data/app/components/primer/button_component.rb +11 -11
  106. data/app/components/primer/conditional_wrapper.rb +0 -2
  107. data/app/components/primer/dropdown_menu_component.rb +3 -3
  108. data/app/components/primer/hellip_button.rb +2 -36
  109. data/app/components/primer/icon_button.rb +0 -1
  110. data/app/components/primer/layout_component.rb +0 -2
  111. data/app/components/primer/local_time.rb +0 -1
  112. data/app/components/primer/navigation/tab_component.rb +16 -16
  113. data/app/components/primer/octicon_component.rb +0 -1
  114. data/app/components/primer/primer.d.ts +1 -1
  115. data/app/components/primer/primer.js +1 -1
  116. data/app/components/primer/primer.pcss +3 -3
  117. data/app/components/primer/primer.ts +1 -1
  118. data/app/components/primer/state_component.rb +2 -70
  119. data/app/components/primer/subhead_component.rb +2 -130
  120. data/app/components/primer/tab_container_component.rb +2 -38
  121. data/app/components/primer/time_ago_component.rb +0 -1
  122. data/app/components/primer/timeline_item_component.rb +5 -79
  123. data/app/components/primer/tooltip.rb +0 -1
  124. data/app/components/primer/truncate.rb +0 -2
  125. data/app/forms/example_toggle_switch_form/example_field_caption.html.erb +1 -0
  126. data/app/forms/example_toggle_switch_form.rb +8 -0
  127. data/app/forms/submit_button_form.rb +4 -4
  128. data/app/lib/primer/tabbed_component_helper.rb +1 -1
  129. data/lib/primer/deprecations.rb +7 -13
  130. data/lib/primer/deprecations.yml +24 -0
  131. data/lib/primer/forms/builder.rb +2 -3
  132. data/lib/primer/forms/button.html.erb +2 -2
  133. data/lib/primer/forms/dsl/form_reference_input.rb +25 -2
  134. data/lib/primer/forms/dsl/input.rb +27 -0
  135. data/lib/primer/forms/dsl/toggle_switch_input.rb +35 -0
  136. data/lib/primer/forms/form_reference.html.erb +1 -1
  137. data/lib/primer/forms/form_reference.rb +4 -0
  138. data/lib/primer/forms/toggle_switch.html.erb +17 -0
  139. data/lib/primer/forms/toggle_switch.rb +19 -0
  140. data/lib/primer/forms/toggle_switch_form.rb +74 -0
  141. data/lib/primer/view_components/linters/subhead_component_migration_counter.rb +1 -1
  142. data/lib/primer/view_components/version.rb +1 -1
  143. data/lib/rubocop/cop/primer/component_name_migration.rb +2 -1
  144. data/lib/tasks/docs.rake +6 -6
  145. data/previews/primer/alpha/action_list_preview.rb +44 -44
  146. data/previews/primer/alpha/dropdown_preview.rb +97 -97
  147. data/previews/primer/alpha/hellip_button_preview.rb +24 -0
  148. data/previews/primer/alpha/layout_preview.rb +63 -63
  149. data/previews/primer/alpha/menu_preview/default.html.erb +5 -5
  150. data/previews/primer/alpha/menu_preview/playground.html.erb +5 -5
  151. data/previews/primer/alpha/segmented_control_preview.rb +60 -60
  152. data/previews/primer/alpha/tab_nav_preview.rb +22 -22
  153. data/previews/primer/alpha/tab_panels_preview.rb +8 -8
  154. data/previews/primer/alpha/tooltip_preview/with_multiple_on_a_page.html.erb +6 -6
  155. data/previews/primer/alpha/tooltip_preview.rb +12 -12
  156. data/previews/primer/alpha/underline_nav_preview.rb +4 -4
  157. data/previews/primer/alpha/underline_panels_preview.rb +8 -8
  158. data/previews/primer/beta/auto_complete_item_preview/default.html.erb +2 -2
  159. data/previews/primer/beta/auto_complete_item_preview/playground.html.erb +2 -2
  160. data/previews/primer/beta/auto_complete_item_preview/with_description.html.erb +3 -3
  161. data/previews/primer/beta/auto_complete_preview/with_submit_button.html.erb +2 -2
  162. data/previews/primer/beta/auto_complete_preview.rb +18 -18
  163. data/previews/primer/beta/avatar_stack_preview.rb +32 -32
  164. data/previews/primer/beta/blankslate_preview.rb +40 -40
  165. data/previews/primer/beta/border_box_preview.rb +38 -38
  166. data/previews/primer/beta/breadcrumbs_preview.rb +2 -2
  167. data/previews/primer/beta/button_group_preview.rb +10 -10
  168. data/previews/primer/beta/button_preview/all_schemes.html.erb +4 -4
  169. data/previews/primer/beta/button_preview/invisible_all_visuals.html.erb +16 -16
  170. data/previews/primer/beta/button_preview/leading_visual.html.erb +2 -2
  171. data/previews/primer/beta/button_preview/trailing_action.html.erb +2 -2
  172. data/previews/primer/beta/button_preview/trailing_visual.html.erb +2 -2
  173. data/previews/primer/beta/button_preview/with_tooltip.html.erb +2 -2
  174. data/previews/primer/beta/details_preview.rb +12 -12
  175. data/previews/primer/beta/state_preview.rb +66 -0
  176. data/previews/primer/beta/subhead_preview/actions.html.erb +14 -0
  177. data/previews/primer/beta/subhead_preview.rb +99 -0
  178. data/previews/primer/beta/timeline_item_preview.rb +30 -0
  179. data/previews/primer/forms/forms_preview/example_toggle_switch_form.html.erb +1 -0
  180. data/previews/primer/forms/forms_preview.rb +2 -0
  181. data/previews/primer/local_time_component_preview.rb +3 -0
  182. data/previews/primer/time_ago_component_preview.rb +3 -0
  183. data/previews/primer/url_helpers.rb +2 -2
  184. data/static/arguments.json +118 -118
  185. data/static/audited_at.json +6 -0
  186. data/static/constants.json +67 -54
  187. data/static/statuses.json +12 -6
  188. metadata +36 -23
  189. data/app/components/primer/state_component.css.json +0 -1
  190. data/app/components/primer/state_component.css.map +0 -1
  191. data/app/components/primer/subhead_component.css.json +0 -1
  192. data/app/components/primer/subhead_component.css.map +0 -1
  193. data/app/components/primer/timeline_item_component.css.json +0 -1
  194. data/app/components/primer/timeline_item_component.css.map +0 -1
  195. data/previews/primer/hellip_button_preview.rb +0 -22
  196. data/previews/primer/state_component_preview.rb +0 -26
  197. data/previews/primer/subhead_component_preview.rb +0 -40
  198. data/previews/primer/timeline_item_component_preview.rb +0 -28
@@ -1,135 +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
- warn_on_deprecated_slot_setter
15
-
16
- status :beta
17
-
18
- DEFAULT_HEADING_TAG = :div
19
- HEADING_TAG_OPTIONS = [DEFAULT_HEADING_TAG, :h1, :h2, :h3, :h4, :h5, :h6].freeze
20
-
21
- # The heading
22
- #
23
- # @param tag [Symbol] <%= one_of(Primer::SubheadComponent::HEADING_TAG_OPTIONS)%>
24
- # @param danger [Boolean] Whether to style the heading as dangerous.
25
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
26
- renders_one :heading, lambda { |tag: DEFAULT_HEADING_TAG, danger: false, **system_arguments|
27
- system_arguments[:tag] = fetch_or_fallback(HEADING_TAG_OPTIONS, tag, DEFAULT_HEADING_TAG)
28
- system_arguments[:classes] = class_names(
29
- system_arguments[:classes],
30
- "Subhead-heading",
31
- "Subhead-heading--danger": danger
32
- )
33
-
34
- Primer::BaseComponent.new(**system_arguments)
35
- }
36
-
37
- # Actions
38
- #
39
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
40
- renders_one :actions, lambda { |**system_arguments|
41
- deny_tag_argument(**system_arguments)
42
- system_arguments[:tag] = :div
43
- system_arguments[:classes] = class_names(system_arguments[:classes], "Subhead-actions")
44
-
45
- Primer::BaseComponent.new(**system_arguments)
46
- }
47
-
48
- # The description
49
- #
50
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
51
- renders_one :description, lambda { |**system_arguments|
52
- deny_tag_argument(**system_arguments)
53
- system_arguments[:tag] = :div
54
- system_arguments[:classes] = class_names(system_arguments[:classes], "Subhead-description")
55
-
56
- Primer::BaseComponent.new(**system_arguments)
57
- }
58
-
59
- # @example Default
60
- # <%= render(Primer::SubheadComponent.new) do |component| %>
61
- # <% component.with_heading(tag: :h3) do %>
62
- # My Heading
63
- # <% end %>
64
- # <% component.with_description do %>
65
- # My Description
66
- # <% end %>
67
- # <% end %>
68
- #
69
- # @example With dangerous heading
70
- # <%= render(Primer::SubheadComponent.new) do |component| %>
71
- # <% component.with_heading(tag: :h3, danger: true) do %>
72
- # My Heading
73
- # <% end %>
74
- # <% component.with_description do %>
75
- # My Description
76
- # <% end %>
77
- # <% end %>
78
- #
79
- # @example With long description
80
- # <%= render(Primer::SubheadComponent.new) do |component| %>
81
- # <% component.with_heading(tag: :h3) do %>
82
- # My Heading
83
- # <% end %>
84
- # <% end %>
85
- # <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>
86
- #
87
- # @example Without border
88
- # <%= render(Primer::SubheadComponent.new(hide_border: true)) do |component| %>
89
- # <% component.with_heading do %>
90
- # My Heading
91
- # <% end %>
92
- # <% component.with_description do %>
93
- # My Description
94
- # <% end %>
95
- # <% end %>
96
- #
97
- # @example With actions
98
- # <%= render(Primer::SubheadComponent.new) do |component| %>
99
- # <% component.with_heading do %>
100
- # My Heading
101
- # <% end %>
102
- # <% component.with_description do %>
103
- # My Description
104
- # <% end %>
105
- # <% component.with_actions do %>
106
- # <%= render(
107
- # Primer::ButtonComponent.new(
108
- # tag: :a, href: "http://www.google.com", scheme: :danger
109
- # )
110
- # ) { "Action" } %>
111
- # <% end %>
112
- # <% end %>
113
- #
114
- # @param spacious [Boolean] Whether to add spacing to the Subhead.
115
- # @param hide_border [Boolean] Whether to hide the border under the heading.
116
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
117
- def initialize(spacious: false, hide_border: false, **system_arguments)
118
- @system_arguments = deny_tag_argument(**system_arguments)
119
-
120
- @system_arguments[:tag] = :div
121
- @system_arguments[:classes] =
122
- class_names(
123
- @system_arguments[:classes],
124
- "Subhead",
125
- "Subhead--spacious": spacious,
126
- "border-bottom-0": hide_border
127
- )
128
- @system_arguments[:mb] ||= hide_border ? 0 : nil
129
- end
130
-
131
- def render?
132
- heading.present?
133
- end
4
+ class SubheadComponent < Primer::Beta::Subhead
5
+ status :deprecated
134
6
  end
135
7
  end
@@ -1,43 +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
- warn_on_deprecated_slot_setter
10
-
11
- # @example Default
12
- # <%= render(Primer::TabContainerComponent.new) do %>
13
- # <div role="tablist">
14
- # <button type="button" role="tab" aria-selected="true">Tab one</button>
15
- # <button type="button" role="tab" tabindex="-1">Tab two</button>
16
- # <button type="button" role="tab" tabindex="-1">Tab three</button>
17
- # </div>
18
- # <div role="tabpanel">
19
- # Panel 1
20
- # </div>
21
- # <div role="tabpanel" hidden>
22
- # Panel 2
23
- # </div>
24
- # <div role="tabpanel" hidden>
25
- # Panel 3
26
- # </div>
27
- # <% end %>
28
- #
29
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
30
- def initialize(**system_arguments)
31
- @system_arguments = deny_tag_argument(**system_arguments)
32
- @system_arguments[:tag] = "tab-container"
33
- end
34
-
35
- def call
36
- render(Primer::BaseComponent.new(**@system_arguments)) { content }
37
- end
38
-
39
- def render?
40
- content.present?
41
- end
4
+ class TabContainerComponent < Primer::Alpha::TabContainer
5
+ status :deprecated
42
6
  end
43
7
  end
@@ -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
@@ -1,87 +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
- warn_on_deprecated_slot_setter
7
- status :beta
4
+ # nodoc
5
+ class TimelineItemComponent < Primer::Beta::TimelineItem
6
+ status :deprecated
8
7
 
9
- # Avatar to be rendered to the left of the Badge.
10
- #
11
- # @param kwargs [Hash] The same arguments as <%= link_to_component(Primer::Beta::Avatar) %>.
12
- renders_one :avatar, lambda { |src:, size: 40, shape: :square, **system_arguments|
13
- system_arguments[:classes] = class_names(
14
- "TimelineItem-avatar",
15
- system_arguments[:classes]
16
- )
17
-
18
- Primer::Beta::Avatar.new(src: src, size: size, shape: shape, **system_arguments)
19
- }
20
-
21
- # Badge that will be connected to other TimelineItems.
22
- #
23
- # @param icon [String] Name of <%= link_to_octicons %> to use.
24
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
25
- renders_one :badge, "BadgeComponent"
26
-
27
- # Body to be rendered to the left of the Badge.
28
- #
29
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
30
- renders_one :body, lambda { |**system_arguments|
31
- deny_tag_argument(**system_arguments)
32
- system_arguments[:tag] = :div
33
- system_arguments[:classes] = class_names(
34
- "TimelineItem-body",
35
- system_arguments[:classes]
36
- )
37
-
38
- Primer::BaseComponent.new(**system_arguments)
39
- }
40
-
41
- # @example Default
42
- # <div style="padding-left: 60px">
43
- # <%= render(Primer::TimelineItemComponent.new) do |component| %>
44
- # <% component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "github") %>
45
- # <% component.with_badge(bg: :success_emphasis, color: :on_emphasis, icon: :check) %>
46
- # <% component.with_body { "Success!" } %>
47
- # <% end %>
48
- # </div>
49
- #
50
- # @param condensed [Boolean] Reduce the vertical padding and remove the background from the badge item. Most commonly used in commits.
51
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
52
- def initialize(condensed: false, **system_arguments)
53
- @system_arguments = deny_tag_argument(**system_arguments)
54
- @system_arguments[:tag] = :div
55
- @system_arguments[:classes] = class_names(
56
- "TimelineItem",
57
- condensed ? "TimelineItem--condensed" : "",
58
- system_arguments[:classes]
59
- )
60
- end
61
-
62
- def render?
63
- avatar? || badge? || body?
64
- end
65
-
66
- # This component is part of `Primer::TimelineItemComponent` and should not be
67
- # used as a standalone component.
8
+ # nodoc
68
9
  class BadgeComponent < Primer::Component
69
- def initialize(icon: nil, **system_arguments)
70
- @icon = icon
71
-
72
- @system_arguments = deny_tag_argument(**system_arguments)
73
- @system_arguments[:tag] = :div
74
- @system_arguments[:classes] = class_names(
75
- "TimelineItem-badge",
76
- system_arguments[:classes]
77
- )
78
- end
79
-
80
- def call
81
- render(Primer::BaseComponent.new(**@system_arguments)) do
82
- render(Primer::Beta::Octicon.new(@icon))
83
- end
84
- end
10
+ status :deprecated
85
11
  end
86
12
  end
87
13
  end
@@ -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
@@ -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"
@@ -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])
@@ -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 %>
@@ -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 }
@@ -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
@@ -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
@@ -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