primer_view_components 0.0.40 → 0.0.45

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +239 -1
  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/components/primer/alpha/button_marketing.rb +70 -0
  6. data/app/components/primer/auto_complete.rb +99 -41
  7. data/app/components/primer/auto_complete/auto_complete.html.erb +1 -0
  8. data/app/components/primer/{auto_complete/auto_component.d.ts → auto_complete_component.d.ts} +0 -0
  9. data/app/components/primer/{auto_complete/auto_component.js → auto_complete_component.js} +0 -0
  10. data/app/components/primer/avatar_stack_component.rb +2 -2
  11. data/app/components/primer/base_component.rb +31 -21
  12. data/app/components/primer/beta/text.rb +27 -0
  13. data/app/components/primer/blankslate_component.html.erb +1 -0
  14. data/app/components/primer/blankslate_component.rb +65 -46
  15. data/app/components/primer/button_component.rb +3 -2
  16. data/app/components/primer/button_group.rb +1 -1
  17. data/app/components/primer/clipboard_copy.rb +25 -7
  18. data/app/components/primer/clipboard_copy_component.js +13 -2
  19. data/app/components/primer/clipboard_copy_component.ts +15 -2
  20. data/app/components/primer/component.rb +1 -1
  21. data/app/components/primer/details_component.rb +12 -1
  22. data/app/components/primer/details_menu_component.d.ts +1 -0
  23. data/app/components/primer/details_menu_component.js +1 -0
  24. data/app/components/primer/dropdown.d.ts +1 -0
  25. data/app/components/primer/{dropdown_component.html.erb → dropdown.html.erb} +2 -1
  26. data/app/components/primer/dropdown.js +1 -0
  27. data/app/components/primer/dropdown.rb +149 -0
  28. data/app/components/primer/dropdown.ts +1 -0
  29. data/app/components/primer/dropdown/menu.d.ts +1 -0
  30. data/app/components/primer/dropdown/menu.html.erb +25 -0
  31. data/app/components/primer/dropdown/menu.js +1 -0
  32. data/app/components/primer/dropdown/menu.rb +99 -0
  33. data/app/components/primer/dropdown/menu.ts +1 -0
  34. data/app/components/primer/flash_component.rb +2 -2
  35. data/app/components/primer/heading_component.rb +1 -1
  36. data/app/components/primer/hidden_text_expander.rb +2 -2
  37. data/app/components/primer/icon_button.rb +1 -1
  38. data/app/components/primer/image.rb +46 -0
  39. data/app/components/primer/image_crop.rb +2 -2
  40. data/app/components/primer/label_component.rb +6 -2
  41. data/app/components/primer/local_time.d.ts +1 -0
  42. data/app/components/primer/local_time.js +1 -0
  43. data/app/components/primer/local_time.rb +59 -0
  44. data/app/components/primer/local_time.ts +1 -0
  45. data/app/components/primer/markdown.rb +6 -2
  46. data/app/components/primer/navigation/tab_component.rb +10 -3
  47. data/app/components/primer/octicon_component.rb +15 -12
  48. data/app/components/primer/primer.d.ts +2 -0
  49. data/app/components/primer/primer.js +2 -0
  50. data/app/components/primer/primer.ts +2 -0
  51. data/app/components/primer/spinner_component.rb +2 -0
  52. data/app/components/primer/tab_nav_component.html.erb +5 -1
  53. data/app/components/primer/tab_nav_component.rb +62 -9
  54. data/app/components/primer/{tooltip_component.rb → tooltip.rb} +10 -8
  55. data/app/components/primer/truncate.rb +6 -2
  56. data/app/components/primer/underline_nav_component.html.erb +1 -1
  57. data/app/components/primer/underline_nav_component.rb +17 -1
  58. data/app/lib/primer/classify.rb +35 -12
  59. data/app/lib/primer/classify/cache.rb +12 -17
  60. data/app/lib/primer/classify/grid.rb +45 -0
  61. data/app/lib/primer/classify/utilities.rb +137 -0
  62. data/app/lib/primer/classify/utilities.yml +1147 -0
  63. data/app/lib/primer/tabbed_component_helper.rb +2 -2
  64. data/app/lib/primer/view_helper.rb +2 -1
  65. data/lib/primer/view_components/engine.rb +2 -0
  66. data/lib/primer/view_components/linters.rb +3 -0
  67. data/lib/primer/view_components/linters/argument_mappers/button.rb +82 -0
  68. data/lib/primer/view_components/linters/argument_mappers/conversion_error.rb +10 -0
  69. data/lib/primer/view_components/linters/argument_mappers/system_arguments.rb +48 -0
  70. data/lib/primer/view_components/linters/button_component_migration_counter.rb +39 -0
  71. data/lib/primer/view_components/linters/flash_component_migration_counter.rb +16 -0
  72. data/lib/primer/view_components/linters/helpers.rb +191 -0
  73. data/lib/primer/view_components/version.rb +1 -1
  74. data/lib/tasks/docs.rake +184 -109
  75. data/lib/tasks/utilities.rake +99 -0
  76. data/lib/yard/docs_helper.rb +12 -2
  77. data/static/statuses.json +10 -6
  78. metadata +65 -14
  79. data/app/components/primer/button_marketing_component.rb +0 -68
  80. data/app/components/primer/dropdown/menu_component.html.erb +0 -12
  81. data/app/components/primer/dropdown/menu_component.rb +0 -46
  82. data/app/components/primer/dropdown_component.rb +0 -73
  83. data/app/components/primer/text_component.rb +0 -25
  84. data/app/lib/primer/classify/spacing.rb +0 -63
@@ -0,0 +1 @@
1
+ import '@github/time-elements';
@@ -0,0 +1 @@
1
+ import '@github/time-elements';
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ # Use `LocalTime` to format a date and time in the user's preferred locale format. This component requires JavaScript.
5
+ class LocalTime < Primer::Component
6
+ DEFAULT_DIGIT_TYPE = :numeric
7
+ DIGIT_TYPE_OPTIONS = [DEFAULT_DIGIT_TYPE, :"2-digit"].freeze
8
+
9
+ DEFAULT_TEXT_TYPE = :short
10
+ TEXT_TYPE_OPTIONS = [DEFAULT_TEXT_TYPE, :long].freeze
11
+
12
+ # @example Default
13
+ # <%= render(Primer::LocalTime.new(datetime: DateTime.parse("2014-06-01T13:05:07Z"))) %>
14
+ #
15
+ # @example All the options
16
+ # <%= render(Primer::LocalTime.new(datetime: DateTime.parse("2014-06-01T13:05:07Z"), weekday: :long, year: :"2-digit", month: :long, day: :"2-digit", hour: :"2-digit", minute: :"2-digit", second: :"2-digit", time_zone_name: :long)) %>
17
+ #
18
+ # @example With initial content
19
+ # <%= render(Primer::LocalTime.new(datetime: DateTime.parse("2014-06-01T13:05:07Z"))) do %>
20
+ # <!-- This content will be replaced once the component connects -->
21
+ # 2014/06/01 13:05
22
+ # <% end %>
23
+ #
24
+ # @param datetime [DateTime] The date to parse
25
+ # @param initial_text [String] Text to render before component is initialized
26
+ # @param weekday [Symbol] <%= one_of(Primer::LocalTime::TEXT_TYPE_OPTIONS) %>
27
+ # @param year [Symbol] <%= one_of(Primer::LocalTime::DIGIT_TYPE_OPTIONS) %>
28
+ # @param month [Symbol] <%= one_of(Primer::LocalTime::TEXT_TYPE_OPTIONS) %>
29
+ # @param day [Symbol] <%= one_of(Primer::LocalTime::DIGIT_TYPE_OPTIONS) %>
30
+ # @param hour [Symbol] <%= one_of(Primer::LocalTime::DIGIT_TYPE_OPTIONS) %>
31
+ # @param minute [Symbol] <%= one_of(Primer::LocalTime::DIGIT_TYPE_OPTIONS) %>
32
+ # @param second [Symbol] <%= one_of(Primer::LocalTime::DIGIT_TYPE_OPTIONS) %>
33
+ # @param time_zone_name [Symbol] <%= one_of(Primer::LocalTime::TEXT_TYPE_OPTIONS) %>
34
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
35
+ def initialize(datetime:, initial_text: nil, weekday: DEFAULT_TEXT_TYPE, year: DEFAULT_DIGIT_TYPE, month: DEFAULT_TEXT_TYPE, day: DEFAULT_DIGIT_TYPE, hour: DEFAULT_DIGIT_TYPE, minute: DEFAULT_DIGIT_TYPE, second: DEFAULT_DIGIT_TYPE, time_zone_name: DEFAULT_TEXT_TYPE, **system_arguments)
36
+ @system_arguments = system_arguments
37
+
38
+ @datetime = datetime
39
+
40
+ @system_arguments[:tag] = "local-time"
41
+ @system_arguments[:datetime] = datetime
42
+
43
+ @initial_text = initial_text
44
+
45
+ @system_arguments[:weekday] = fetch_or_fallback(TEXT_TYPE_OPTIONS, weekday, DEFAULT_TEXT_TYPE)
46
+ @system_arguments[:year] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, year, DEFAULT_DIGIT_TYPE)
47
+ @system_arguments[:month] = fetch_or_fallback(TEXT_TYPE_OPTIONS, month, DEFAULT_TEXT_TYPE)
48
+ @system_arguments[:day] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, day, DEFAULT_DIGIT_TYPE)
49
+ @system_arguments[:hour] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, hour, DEFAULT_DIGIT_TYPE)
50
+ @system_arguments[:minute] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, minute, DEFAULT_DIGIT_TYPE)
51
+ @system_arguments[:second] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, second, DEFAULT_DIGIT_TYPE)
52
+ @system_arguments[:"time-zone-name"] = fetch_or_fallback(TEXT_TYPE_OPTIONS, time_zone_name, DEFAULT_TEXT_TYPE)
53
+ end
54
+
55
+ def call
56
+ render(Primer::BaseComponent.new(**@system_arguments).with_content(@initial_text || @datetime.strftime("%B %-d, %Y %H:%M %Z")))
57
+ end
58
+ end
59
+ end
@@ -0,0 +1 @@
1
+ import '@github/time-elements'
@@ -4,6 +4,9 @@ module Primer
4
4
  # Use `Markdown` to wrap markdown content
5
5
  class Markdown < Primer::Component
6
6
  status :beta
7
+
8
+ DEFAULT_TAG = :div
9
+ TAG_OPTIONS = [DEFAULT_TAG, :article, :td].freeze
7
10
  # @example Default
8
11
  # <%= render(Primer::Markdown.new) do %>
9
12
  # <p>Text can be <b>bold</b>, <i>italic</i>, or <s>strikethrough</s>. <a href="https://github.com">Links </a> should be blue with no underlines (unless hovered over).</p>
@@ -276,10 +279,11 @@ module Primer
276
279
  # <pre><code>This is the final element on the page and there should be no margin below this.</code></pre>
277
280
  # <% end %>
278
281
  #
282
+ # @param tag [Symbol] <%= one_of(Primer::Markdown::TAG_OPTIONS) %>
279
283
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
280
- def initialize(**system_arguments)
284
+ def initialize(tag: DEFAULT_TAG, **system_arguments)
281
285
  @system_arguments = system_arguments
282
- @system_arguments[:tag] ||= :div
286
+ @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)
283
287
 
284
288
  @system_arguments[:classes] = class_names(
285
289
  "markdown-body",
@@ -4,7 +4,13 @@ module Primer
4
4
  module Navigation
5
5
  # This component is part of navigation components such as `Primer::TabNavComponent`
6
6
  # and `Primer::UnderlineNavComponent` and should not be used by itself.
7
+ #
8
+ # @accessibility
9
+ # `TabComponent` renders the selected anchor tab with `aria-current="page"` by default.
10
+ # When the selected tab does not correspond to the current page, such as in a nested inner tab, make sure to use aria-current="true"
7
11
  class TabComponent < Primer::Component
12
+ DEFAULT_ARIA_CURRENT_FOR_ANCHOR = :page
13
+ ARIA_CURRENT_OPTIONS_FOR_ANCHOR = [true, DEFAULT_ARIA_CURRENT_FOR_ANCHOR].freeze
8
14
  # Panel controlled by the Tab. This will not render anything in the tab itself.
9
15
  # It will provide a accessor for the Tab's parent to call and render the panel
10
16
  # content in the appropriate place.
@@ -32,8 +38,8 @@ module Primer
32
38
 
33
39
  # The Tab's text.
34
40
  #
35
- # @param kwargs [Hash] The same arguments as <%= link_to_component(Primer::TextComponent) %>.
36
- renders_one :text, Primer::TextComponent
41
+ # @param kwargs [Hash] The same arguments as <%= link_to_component(Primer::Beta::Text) %>.
42
+ renders_one :text, Primer::Beta::Text
37
43
 
38
44
  # Counter to be rendered in the Tab right.
39
45
  #
@@ -105,7 +111,8 @@ module Primer
105
111
  return unless @selected
106
112
 
107
113
  if @system_arguments[:tag] == :a
108
- @system_arguments[:"aria-current"] = :page
114
+ aria_current = @system_arguments[:"aria-current"] || @system_arguments.dig(:aria, :current) || DEFAULT_ARIA_CURRENT_FOR_ANCHOR
115
+ @system_arguments[:"aria-current"] = fetch_or_fallback(ARIA_CURRENT_OPTIONS_FOR_ANCHOR, aria_current, DEFAULT_ARIA_CURRENT_FOR_ANCHOR)
109
116
  else
110
117
  @system_arguments[:"aria-selected"] = true
111
118
  end
@@ -10,34 +10,37 @@ module Primer
10
10
 
11
11
  SIZE_DEFAULT = :small
12
12
  SIZE_MEDIUM = :medium
13
- SIZE_LARGE = :large
14
13
 
15
14
  SIZE_MAPPINGS = {
16
15
  SIZE_DEFAULT => 16,
17
- SIZE_MEDIUM => 32,
18
- SIZE_LARGE => 64
16
+ SIZE_MEDIUM => 24
19
17
  }.freeze
20
18
  SIZE_OPTIONS = SIZE_MAPPINGS.keys
21
19
 
22
20
  # @example Default
23
- # <%= render(Primer::OcticonComponent.new("check")) %>
24
- # <%= render(Primer::OcticonComponent.new(icon: "check")) %>
21
+ # <%= render(Primer::OcticonComponent.new(:check)) %>
22
+ # <%= render(Primer::OcticonComponent.new(icon: :check)) %>
25
23
  #
26
24
  # @example Medium
27
- # <%= render(Primer::OcticonComponent.new("people", size: :medium)) %>
28
- #
29
- # @example Large
30
- # <%= render(Primer::OcticonComponent.new("x", size: :large)) %>
25
+ # <%= render(Primer::OcticonComponent.new(:people, size: :medium)) %>
31
26
  #
32
27
  # @example Helper
33
- # <%= primer_octicon("check") %>
28
+ # <%= primer_octicon(:check) %>
34
29
  #
35
- # @param icon [String] Name of <%= link_to_octicons %> to use.
36
- # @param size [Symbol] <%= one_of(Primer::OcticonComponent::SIZE_MAPPINGS) %>
30
+ # @param icon_name [Symbol, String] Name of <%= link_to_octicons %> to use.
31
+ # @param icon [Symbol, String] Name of <%= link_to_octicons %> to use.
32
+ # @param size [Symbol] <%= one_of(Primer::OcticonComponent::SIZE_MAPPINGS, sort: false) %>
37
33
  # @param use_symbol [Boolean] EXPERIMENTAL (May change or be removed) - Set to true when using with <%= link_to_component(Primer::OcticonSymbolsComponent) %>.
38
34
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
39
35
  def initialize(icon_name = nil, icon: nil, size: SIZE_DEFAULT, use_symbol: false, **system_arguments)
40
36
  icon_key = icon_name || icon
37
+
38
+ # Don't allow sizes under 16px
39
+ if system_arguments[:height].present? && system_arguments[:height].to_i < 16 || system_arguments[:width].present? && system_arguments[:width].to_i < 16
40
+ system_arguments.delete(:height)
41
+ system_arguments.delete(:width)
42
+ end
43
+
41
44
  cache_key = Primer::Octicon::Cache.get_key(symbol: icon_key, size: size, **system_arguments.slice(:height, :width))
42
45
 
43
46
  @system_arguments = system_arguments
@@ -2,4 +2,6 @@ import './auto_complete/auto_complete';
2
2
  import './clipboard_copy_component';
3
3
  import './tab_container_component';
4
4
  import './time_ago_component';
5
+ import './local_time';
5
6
  import './image_crop';
7
+ import './dropdown';
@@ -2,4 +2,6 @@ import './auto_complete/auto_complete';
2
2
  import './clipboard_copy_component';
3
3
  import './tab_container_component';
4
4
  import './time_ago_component';
5
+ import './local_time';
5
6
  import './image_crop';
7
+ import './dropdown';
@@ -2,4 +2,6 @@ import './auto_complete/auto_complete'
2
2
  import './clipboard_copy_component'
3
3
  import './tab_container_component'
4
4
  import './time_ago_component'
5
+ import './local_time'
5
6
  import './image_crop'
7
+ import './dropdown'
@@ -27,6 +27,8 @@ module Primer
27
27
  # <%= render(Primer::SpinnerComponent.new(size: :large)) %>
28
28
  #
29
29
  # @param size [Symbol] <%= one_of(Primer::SpinnerComponent::SIZE_MAPPINGS) %>
30
+ # @param style [String] Custom element styles.
31
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
30
32
  def initialize(size: DEFAULT_SIZE, style: DEFAULT_STYLE, **system_arguments)
31
33
  @system_arguments = system_arguments
32
34
  @system_arguments[:tag] = :svg
@@ -1,10 +1,14 @@
1
- <%= wrapper do %>
1
+ <%= wrapper(**@wrapper_arguments) do %>
2
2
  <%= render Primer::BaseComponent.new(**@system_arguments) do %>
3
+ <%= extra if @align == :left %>
4
+
3
5
  <%= render Primer::BaseComponent.new(**@body_arguments) do %>
4
6
  <% tabs.each do |tab| %>
5
7
  <%= tab %>
6
8
  <% end %>
7
9
  <% end %>
10
+
11
+ <%= extra if @align == :right %>
8
12
  <% end %>
9
13
 
10
14
  <% if @with_panel %>
@@ -5,6 +5,11 @@ module Primer
5
5
  class TabNavComponent < Primer::Component
6
6
  include Primer::TabbedComponentHelper
7
7
 
8
+ status :beta
9
+
10
+ DEFAULT_EXTRA_ALIGN = :left
11
+ EXTRA_ALIGN_OPTIONS = [DEFAULT_EXTRA_ALIGN, :right].freeze
12
+
8
13
  # Tabs to be rendered. For more information, refer to <%= link_to_component(Primer::Navigation::TabComponent) %>.
9
14
  #
10
15
  # @param selected [Boolean] Whether the tab is selected.
@@ -22,6 +27,15 @@ module Primer
22
27
  )
23
28
  }
24
29
 
30
+ # Renders extra content to the `TabNav`. This will be rendered after the tabs.
31
+ #
32
+ # @param align [Symbol] <%= one_of(Primer::TabNavComponent::EXTRA_ALIGN_OPTIONS) %>
33
+ renders_one :extra, lambda { |align: DEFAULT_EXTRA_ALIGN, &block|
34
+ @align = fetch_or_fallback(EXTRA_ALIGN_OPTIONS, align, DEFAULT_EXTRA_ALIGN)
35
+
36
+ view_context.capture { block&.call }
37
+ }
38
+
25
39
  # @example Default
26
40
  # <%= render(Primer::TabNavComponent.new(label: "Default")) do |c| %>
27
41
  # <% c.tab(selected: true, href: "#") { "Tab 1" }%>
@@ -68,12 +82,53 @@ module Primer
68
82
  # <% end %>
69
83
  # <% end %>
70
84
  #
85
+ # @example With extra content
86
+ # <%= render(Primer::TabNavComponent.new(label: "With extra content")) do |c| %>
87
+ # <% c.tab(selected: true, href: "#") { "Tab 1" }%>
88
+ # <% c.tab(href: "#") { "Tab 2" } %>
89
+ # <% c.tab(href: "#") { "Tab 3" } %>
90
+ # <% c.extra do %>
91
+ # <%= render(Primer::ButtonComponent.new(float: :right)) { "Button" } %>
92
+ # <% end %>
93
+ # <% end %>
94
+ #
95
+ # @example Adding extra content after the tabs
96
+ # <%= render(Primer::TabNavComponent.new(label: "Adding extra content after the tabs", display: :flex, body_arguments: { flex: 1 })) do |c| %>
97
+ # <% c.tab(selected: true, href: "#") { "Tab 1" }%>
98
+ # <% c.tab(href: "#") { "Tab 2" } %>
99
+ # <% c.tab(href: "#") { "Tab 3" } %>
100
+ # <% c.extra(align: :right) do %>
101
+ # <div>
102
+ # <%= render(Primer::ButtonComponent.new) { "Button" } %>
103
+ # </div>
104
+ # <% end %>
105
+ # <% end %>
106
+ #
107
+ # @example Customizing the body
108
+ # <%= render(Primer::TabNavComponent.new(label: "Default", body_arguments: { classes: "custom-class", border: true, border_color: :info })) do |c| %>
109
+ # <% c.tab(selected: true, href: "#") { "Tab 1" }%>
110
+ # <% c.tab(href: "#") { "Tab 2" } %>
111
+ # <% c.tab(href: "#") { "Tab 3" } %>
112
+ # <% end %>
113
+ #
114
+ # @example Customizing the wrapper
115
+ # <%= render(Primer::TabNavComponent.new(label: "Default", wrapper_arguments: { classes: "custom-class", border: true, border_color: :info })) do |c| %>
116
+ # <% c.tab(selected: true, href: "#") { "Tab 1" }%>
117
+ # <% c.tab(href: "#") { "Tab 2" } %>
118
+ # <% c.tab(href: "#") { "Tab 3" } %>
119
+ # <% end %>
120
+ #
71
121
  # @param label [String] Used to set the `aria-label` on the top level `<nav>` element.
72
122
  # @param with_panel [Boolean] Whether the TabNav should navigate through pages or panels.
123
+ # @param body_arguments [Hash] <%= link_to_system_arguments_docs %> for the body wrapper.
124
+ # @param wrapper_arguments [Hash] <%= link_to_system_arguments_docs %> for the `TabContainer` wrapper. Only applies if `with_panel` is `true`.
73
125
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
74
- def initialize(label:, with_panel: false, **system_arguments)
126
+ def initialize(label:, with_panel: false, body_arguments: {}, wrapper_arguments: {}, **system_arguments)
127
+ @align = DEFAULT_EXTRA_ALIGN
75
128
  @with_panel = with_panel
76
129
  @system_arguments = system_arguments
130
+ @body_arguments = body_arguments
131
+ @wrapper_arguments = wrapper_arguments
77
132
 
78
133
  @system_arguments[:tag] ||= :div
79
134
  @system_arguments[:classes] = class_names(
@@ -81,15 +136,13 @@ module Primer
81
136
  system_arguments[:classes]
82
137
  )
83
138
 
84
- @body_arguments = {
85
- tag: navigation_tag(with_panel),
86
- classes: "tabnav-tabs",
87
- aria: {
88
- label: label
89
- }
90
- }
91
-
139
+ @body_arguments[:tag] = navigation_tag(with_panel)
140
+ @body_arguments[:"aria-label"] = label
92
141
  @body_arguments[:role] = :tablist if @with_panel
142
+ @body_arguments[:classes] = class_names(
143
+ "tabnav-tabs",
144
+ body_arguments[:classes]
145
+ )
93
146
  end
94
147
  end
95
148
  end
@@ -2,7 +2,9 @@
2
2
 
3
3
  module Primer
4
4
  # `Tooltip` is a wrapper component that will apply a tooltip to the provided content.
5
- class TooltipComponent < Primer::Component
5
+ class Tooltip < Primer::Component
6
+ status :beta
7
+
6
8
  DIRECTION_DEFAULT = :n
7
9
  ALIGN_DEFAULT = :default
8
10
  MULTILINE_DEFAULT = false
@@ -28,34 +30,34 @@ module Primer
28
30
 
29
31
  # @example Default
30
32
  # <div class="pt-5">
31
- # <%= render(Primer::TooltipComponent.new(label: "Even bolder")) { "Default Bold Text" } %>
33
+ # <%= render(Primer::Tooltip.new(label: "Even bolder")) { "Default Bold Text" } %>
32
34
  # </div>
33
35
  #
34
36
  # @example Wrapping another component
35
37
  # <div class="pt-5">
36
- # <%= render(Primer::TooltipComponent.new(label: "Even bolder")) do %>
38
+ # <%= render(Primer::Tooltip.new(label: "Even bolder")) do %>
37
39
  # <%= render(Primer::ButtonComponent.new) { "Bold Button" } %>
38
40
  # <% end %>
39
41
  # </div>
40
42
  #
41
43
  # @example With a direction
42
44
  # <div class="pt-5">
43
- # <%= render(Primer::TooltipComponent.new(label: "Even bolder", direction: :s)) { "Bold Text With a Direction" } %>
45
+ # <%= render(Primer::Tooltip.new(label: "Even bolder", direction: :s)) { "Bold Text With a Direction" } %>
44
46
  # </div>
45
47
  #
46
48
  # @example With an alignment
47
49
  # <div class="pt-5">
48
- # <%= render(Primer::TooltipComponent.new(label: "Even bolder", direction: :s, alignment: :right_1)) { "Bold Text With an Alignment" } %>
50
+ # <%= render(Primer::Tooltip.new(label: "Even bolder", direction: :s, alignment: :right_1)) { "Bold Text With an Alignment" } %>
49
51
  # </div>
50
52
  #
51
53
  # @example Without a delay
52
54
  # <div class="pt-5">
53
- # <%= render(Primer::TooltipComponent.new(label: "Even bolder", direction: :s, no_delay: true)) { "Bold Text without a delay" } %>
55
+ # <%= render(Primer::Tooltip.new(label: "Even bolder", direction: :s, no_delay: true)) { "Bold Text without a delay" } %>
54
56
  # </div>
55
57
  #
56
58
  # @param label [String] the text to appear in the tooltip
57
- # @param direction [String] Direction of the tooltip. <%= one_of(Primer::TooltipComponent::DIRECTION_OPTIONS) %>
58
- # @param align [String] Align tooltips to the left or right of an element, combined with a `direction` to specify north or south. <%= one_of(Primer::TooltipComponent::ALIGN_MAPPING.keys) %>
59
+ # @param direction [String] Direction of the tooltip. <%= one_of(Primer::Tooltip::DIRECTION_OPTIONS) %>
60
+ # @param align [String] Align tooltips to the left or right of an element, combined with a `direction` to specify north or south. <%= one_of(Primer::Tooltip::ALIGN_MAPPING.keys) %>
59
61
  # @param multiline [Boolean] Use this when you have long content
60
62
  # @param no_delay [Boolean] By default the tooltips have a slight delay before appearing. Set true to override this
61
63
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
@@ -5,6 +5,9 @@ module Primer
5
5
  class Truncate < Primer::Component
6
6
  status :beta
7
7
 
8
+ DEFAULT_TAG = :div
9
+ TAG_OPTIONS = [DEFAULT_TAG, :span, :p].freeze
10
+
8
11
  # @example Default
9
12
  # <div class="col-2">
10
13
  # <%= render(Primer::Truncate.new(tag: :p)) { "branch-name-that-is-really-long" } %>
@@ -19,13 +22,14 @@ module Primer
19
22
  # @example Custom size
20
23
  # <%= render(Primer::Truncate.new(tag: :span, inline: true, expandable: true, max_width: 100)) { "branch-name-that-is-really-long" } %>
21
24
  #
25
+ # @param tag [Symbol] <%= one_of(Primer::Truncate::TAG_OPTIONS) %>
22
26
  # @param inline [Boolean] Whether the element is inline (or inline-block).
23
27
  # @param expandable [Boolean] Whether the entire string should be revealed on hover. Can only be used in conjunction with `inline`.
24
28
  # @param max_width [Integer] Sets the max-width of the text.
25
29
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
26
- def initialize(inline: false, expandable: false, max_width: nil, **system_arguments)
30
+ def initialize(tag: DEFAULT_TAG, inline: false, expandable: false, max_width: nil, **system_arguments)
27
31
  @system_arguments = system_arguments
28
- @system_arguments[:tag] ||= :div
32
+ @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)
29
33
  @system_arguments[:classes] = class_names(
30
34
  @system_arguments[:classes],
31
35
  "css-truncate",
@@ -1,4 +1,4 @@
1
- <%= wrapper do %>
1
+ <%= wrapper(**@wrapper_arguments) do %>
2
2
  <%= render Primer::BaseComponent.new(**@system_arguments) do %>
3
3
  <% if @align == :right %>
4
4
  <%= actions %>
@@ -116,14 +116,30 @@ module Primer
116
116
  # <% end %>
117
117
  # <% end %>
118
118
  #
119
+ # @example Customizing the body
120
+ # <%= render(Primer::UnderlineNavComponent.new(label: "Default", body_arguments: { tag: :ul, classes: "custom-class", border: true, border_color: :info })) do |c| %>
121
+ # <% c.tab(selected: true, href: "#") { "Tab 1" }%>
122
+ # <% c.tab(href: "#") { "Tab 2" } %>
123
+ # <% c.tab(href: "#") { "Tab 3" } %>
124
+ # <% end %>
125
+ #
126
+ # @example Customizing the wrapper
127
+ # <%= render(Primer::UnderlineNavComponent.new(label: "Default", wrapper_arguments: { classes: "custom-class", border: true, border_color: :info })) do |c| %>
128
+ # <% c.tab(selected: true, href: "#") { "Tab 1" }%>
129
+ # <% c.tab(href: "#") { "Tab 2" } %>
130
+ # <% c.tab(href: "#") { "Tab 3" } %>
131
+ # <% end %>
132
+ #
119
133
  # @param label [String] The `aria-label` on top level `<nav>` element.
120
134
  # @param with_panel [Boolean] Whether the TabNav should navigate through pages or panels.
121
135
  # @param align [Symbol] <%= one_of(Primer::UnderlineNavComponent::ALIGN_OPTIONS) %> - Defaults to <%= Primer::UnderlineNavComponent::ALIGN_DEFAULT %>
122
136
  # @param body_arguments [Hash] <%= link_to_system_arguments_docs %> for the body wrapper.
137
+ # @param wrapper_arguments [Hash] <%= link_to_system_arguments_docs %> for the `TabContainer` wrapper. Only applies if `with_panel` is `true`.
123
138
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
124
- def initialize(label:, with_panel: false, align: ALIGN_DEFAULT, body_arguments: { tag: BODY_TAG_DEFAULT }, **system_arguments)
139
+ def initialize(label:, with_panel: false, align: ALIGN_DEFAULT, body_arguments: { tag: BODY_TAG_DEFAULT }, wrapper_arguments: {}, **system_arguments)
125
140
  @with_panel = with_panel
126
141
  @align = fetch_or_fallback(ALIGN_OPTIONS, align, ALIGN_DEFAULT)
142
+ @wrapper_arguments = wrapper_arguments
127
143
 
128
144
  @system_arguments = system_arguments
129
145
  @system_arguments[:tag] = navigation_tag(with_panel)