primer_view_components 0.0.88 → 0.0.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -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 +0 -0
  6. data/app/assets/styles/primer_view_components.css.map +1 -0
  7. data/app/components/primer/alpha/auto_complete.rb +2 -2
  8. data/app/components/primer/alpha/hidden_text_expander.rb +57 -0
  9. data/app/components/primer/alpha/layout.rb +34 -32
  10. data/app/components/primer/alpha/segmented-control-element.js +5 -4
  11. data/app/components/primer/alpha/tab_nav.rb +20 -20
  12. data/app/components/primer/alpha/tab_panels.rb +2 -2
  13. data/app/components/primer/alpha/tool-tip-element.d.ts +1 -3
  14. data/app/components/primer/alpha/tool-tip-element.js +13 -19
  15. data/app/components/primer/alpha/tool-tip-element.ts +14 -22
  16. data/app/components/primer/alpha/tooltip.rb +72 -53
  17. data/app/components/primer/alpha/underline_nav.rb +16 -16
  18. data/app/components/primer/alpha/underline_panels.rb +3 -3
  19. data/app/components/primer/base_component.rb +1 -1
  20. data/app/components/primer/beta/auto_complete/item.rb +2 -2
  21. data/app/components/primer/beta/auto_complete.rb +2 -2
  22. data/app/components/primer/beta/avatar_stack.rb +9 -9
  23. data/app/components/primer/beta/blankslate.rb +2 -2
  24. data/app/components/primer/beta/border_box/header.rb +4 -2
  25. data/app/components/primer/beta/border_box.rb +13 -13
  26. data/app/components/primer/beta/breadcrumbs.rb +3 -3
  27. data/app/components/primer/beta/button_group.rb +9 -9
  28. data/app/components/primer/beta/close_button.rb +41 -0
  29. data/app/components/primer/beta/counter.rb +113 -0
  30. data/app/components/primer/{details_component.html.erb → beta/details.html.erb} +0 -0
  31. data/app/components/primer/beta/details.rb +70 -0
  32. data/app/components/primer/beta/flash.rb +1 -1
  33. data/app/components/primer/beta/heading.rb +46 -0
  34. data/app/components/primer/beta/truncate.rb +17 -17
  35. data/app/components/primer/blankslate_component.rb +1 -1
  36. data/app/components/primer/button_component.rb +8 -8
  37. data/app/components/primer/close_button.rb +2 -34
  38. data/app/components/primer/counter_component.rb +2 -106
  39. data/app/components/primer/details_component.rb +2 -63
  40. data/app/components/primer/dropdown.html.erb +1 -1
  41. data/app/components/primer/dropdown.rb +15 -15
  42. data/app/components/primer/dropdown_menu_component.rb +1 -1
  43. data/app/components/primer/heading_component.rb +2 -39
  44. data/app/components/primer/hidden_text_expander.rb +2 -48
  45. data/app/components/primer/icon_button.html.erb +8 -2
  46. data/app/components/primer/icon_button.rb +7 -0
  47. data/app/components/primer/image_crop.rb +1 -1
  48. data/app/components/primer/label_component.rb +2 -1
  49. data/app/components/primer/layout_component.rb +4 -4
  50. data/app/components/primer/link_component.rb +1 -1
  51. data/app/components/primer/menu_component.rb +5 -5
  52. data/app/components/primer/navigation/tab_component.rb +12 -12
  53. data/app/components/primer/popover_component.rb +10 -10
  54. data/app/components/primer/primer.pcss +1 -0
  55. data/app/components/primer/subhead_component.rb +10 -10
  56. data/app/components/primer/timeline_item_component.rb +3 -3
  57. data/app/lib/primer/join_style_arguments_helper.rb +1 -1
  58. data/app/lib/primer/view_helper.rb +1 -1
  59. data/lib/primer/view_components/linters/argument_mappers/close_button.rb +2 -2
  60. data/lib/primer/view_components/linters/close_button_component_migration_counter.rb +2 -2
  61. data/lib/primer/view_components/linters/flash_migration_counter.rb +1 -1
  62. data/lib/primer/view_components/linters/helpers/deprecated_components_helpers.rb +5 -0
  63. data/lib/primer/view_components/version.rb +1 -1
  64. data/lib/rubocop/cop/primer/component_name_migration.rb +5 -0
  65. data/lib/tasks/docs.rake +5 -5
  66. data/static/arguments.yml +87 -87
  67. data/static/audited_at.json +5 -0
  68. data/static/constants.json +54 -44
  69. data/static/statuses.json +11 -6
  70. metadata +11 -3
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module Beta
5
+ # Use `Counter` to add a count to navigational elements and buttons.
6
+ #
7
+ # @accessibility
8
+ # Always use `Counter` with adjacent text that provides supplementary information regarding what the count is for. For instance, `Counter`
9
+ # should be accompanied with text such as `issues` or `pull requests`.
10
+ #
11
+ class Counter < Primer::Component
12
+ status :beta
13
+
14
+ DEFAULT_SCHEME = :default
15
+ SCHEME_MAPPINGS = {
16
+ DEFAULT_SCHEME => "",
17
+ :primary => "Counter--primary",
18
+ :secondary => "Counter--secondary",
19
+ # deprecated
20
+ :gray => "Counter--primary",
21
+ :light_gray => "Counter--secondary"
22
+ }.freeze
23
+ DEPRECATED_SCHEME_OPTIONS = [:gray, :light_gray].freeze
24
+ SCHEME_OPTIONS = (SCHEME_MAPPINGS.keys - DEPRECATED_SCHEME_OPTIONS).freeze
25
+
26
+ #
27
+ # @example Default
28
+ # <%= render(Primer::Beta::Counter.new(count: 25)) %>
29
+ #
30
+ # @example Schemes
31
+ # <%= render(Primer::Beta::Counter.new(count: 25, scheme: :primary)) %>
32
+ # <%= render(Primer::Beta::Counter.new(count: 25, scheme: :secondary)) %>
33
+ #
34
+ # @param count [Integer, Float::INFINITY, nil] The number to be displayed (e.x. # of issues, pull requests)
35
+ # @param scheme [Symbol] Color scheme. <%= one_of(Primer::Beta::Counter::SCHEME_OPTIONS) %>
36
+ # @param limit [Integer, nil] Maximum value to display. Pass `nil` for no limit. (e.x. if `count` == 6,000 and `limit` == 5000, counter will display "5,000+")
37
+ # @param hide_if_zero [Boolean] If true, a `hidden` attribute is added to the counter if `count` is zero.
38
+ # @param text [String] Text to display instead of count.
39
+ # @param round [Boolean] Whether to apply our standard rounding logic to value.
40
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
41
+ def initialize(
42
+ count: 0,
43
+ scheme: DEFAULT_SCHEME,
44
+ limit: 5_000,
45
+ hide_if_zero: false,
46
+ text: "",
47
+ round: false,
48
+ **system_arguments
49
+ )
50
+ @count = count
51
+ @limit = limit
52
+ @hide_if_zero = hide_if_zero
53
+ @text = text
54
+ @round = round
55
+ @system_arguments = deny_tag_argument(**system_arguments)
56
+
57
+ @has_limit = !@limit.nil?
58
+ @system_arguments[:title] = title
59
+ @system_arguments[:tag] = :span
60
+ @system_arguments[:classes] = class_names(
61
+ "Counter",
62
+ @system_arguments[:classes],
63
+ SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME, deprecated_values: DEPRECATED_SCHEME_OPTIONS)]
64
+ )
65
+ @system_arguments[:hidden] = true if count == 0 && hide_if_zero # rubocop:disable Style/NumericPredicate
66
+ end
67
+
68
+ def call
69
+ render(Primer::BaseComponent.new(**@system_arguments)) { value }
70
+ end
71
+
72
+ private
73
+
74
+ def title
75
+ if @text.present?
76
+ @text
77
+ elsif @count.nil?
78
+ "Not available"
79
+ elsif @count == Float::INFINITY
80
+ "Infinity"
81
+ else
82
+ count = @count.to_i
83
+ str = number_with_delimiter(@has_limit ? [count, @limit].min : count)
84
+ str += "+" if @has_limit && count > @limit
85
+ str
86
+ end
87
+ end
88
+
89
+ def value
90
+ if @text.present?
91
+ @text
92
+ elsif @count.nil?
93
+ "" # CSS will hide it
94
+ elsif @count == Float::INFINITY
95
+ "∞"
96
+ else
97
+ if @round
98
+ count = @has_limit ? [@count.to_i, @limit].min : @count.to_i
99
+ precision = count.between?(100_000, 999_999) ? 0 : 1
100
+ units = { thousand: "k", million: "m", billion: "b" }
101
+ str = number_to_human(count, precision: precision, significant: false, units: units, format: "%n%u")
102
+ else
103
+ @count = @count.to_i
104
+ str = number_with_delimiter(@has_limit ? [@count, @limit].min : @count)
105
+ end
106
+
107
+ str += "+" if @has_limit && @count.to_i > @limit
108
+ str
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module Beta
5
+ # Use `DetailsComponent` to reveal content after clicking a button.
6
+ class Details < Primer::Component
7
+ status :beta
8
+
9
+ BODY_TAG_DEFAULT = :div
10
+ BODY_TAG_OPTIONS = [:ul, :"details-menu", :"details-dialog", BODY_TAG_DEFAULT].freeze
11
+ NO_OVERLAY = :none
12
+ OVERLAY_MAPPINGS = {
13
+ NO_OVERLAY => "",
14
+ :default => "details-overlay",
15
+ :dark => "details-overlay details-overlay-dark"
16
+ }.freeze
17
+
18
+ # Use the Summary slot as a trigger to reveal the content.
19
+ #
20
+ # @param button [Boolean] (true) Whether to render the Summary as a button or not.
21
+ # @param kwargs [Hash] The same arguments as <%= link_to_system_arguments_docs %>.
22
+ renders_one :summary, lambda { |button: true, **system_arguments|
23
+ system_arguments[:tag] = :summary
24
+ system_arguments[:role] = "button"
25
+
26
+ return Primer::BaseComponent.new(**system_arguments) unless button
27
+
28
+ Primer::ButtonComponent.new(**system_arguments)
29
+ }
30
+
31
+ # Use the Body slot as the main content to be shown when triggered by the Summary.
32
+ #
33
+ # @param tag [Symbol] (Primer::Beta::Details::BODY_TAG_DEFAULT) <%= one_of(Primer::Beta::Details::BODY_TAG_OPTIONS) %>
34
+ # @param kwargs [Hash] The same arguments as <%= link_to_system_arguments_docs %>.
35
+ renders_one :body, lambda { |tag: BODY_TAG_DEFAULT, **system_arguments|
36
+ system_arguments[:tag] = fetch_or_fallback(BODY_TAG_OPTIONS, tag, BODY_TAG_DEFAULT)
37
+
38
+ Primer::BaseComponent.new(**system_arguments)
39
+ }
40
+
41
+ # @example Default
42
+ #
43
+ # <%= render Primer::Beta::Details.new do |c| %>
44
+ # <% c.with_summary do %>
45
+ # Summary
46
+ # <% end %>
47
+ # <% c.with_body do %>
48
+ # Body
49
+ # <% end %>
50
+ # <% end %>
51
+ #
52
+ # @param overlay [Symbol] Dictates the type of overlay to render with. <%= one_of(Primer::Beta::Details::OVERLAY_MAPPINGS.keys) %>
53
+ # @param reset [Boolean] Defaults to false. If set to true, it will remove the default caret and remove style from the summary element
54
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
55
+ def initialize(overlay: NO_OVERLAY, reset: false, **system_arguments)
56
+ @system_arguments = deny_tag_argument(**system_arguments)
57
+ @system_arguments[:tag] = :details
58
+ @system_arguments[:classes] = class_names(
59
+ system_arguments[:classes],
60
+ OVERLAY_MAPPINGS[fetch_or_fallback(OVERLAY_MAPPINGS.keys, overlay, NO_OVERLAY)],
61
+ "details-reset" => reset
62
+ )
63
+ end
64
+
65
+ def render?
66
+ summary.present? && body.present?
67
+ end
68
+ end
69
+ end
70
+ end
@@ -42,7 +42,7 @@ module Primer
42
42
  # @example With actions
43
43
  # <%= render(Primer::Beta::Flash.new) do |component| %>
44
44
  # This is a flash message with actions!
45
- # <% component.action do %>
45
+ # <% component.with_action do %>
46
46
  # <%= render(Primer::ButtonComponent.new(size: :small)) { "Take action" } %>
47
47
  # <% end %>
48
48
  # <% end %>
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module Beta
5
+ # `Heading` should be used to communicate page organization and hierarchy.
6
+ #
7
+ # - Set tag to one of `:h1`, `:h2`, `:h3`, `:h4`, `:h5`, `:h6` based on what is appropriate for the page context.
8
+ # - Use `Heading` as the title of a section or sub section.
9
+ # - Do not use `Heading` for styling alone. For simply styling text, consider using <%= link_to_component(Primer::Beta::Text) %> with relevant <%= link_to_typography_docs %>
10
+ # such as `font_size` and `font_weight`.
11
+ # - Do not jump heading levels. For instance, do not follow a `<h1>` with an `<h3>`. Heading levels should increase by one in ascending order.
12
+ #
13
+ # @accessibility
14
+ # While sighted users rely on visual cues such as font size changes to determine what the heading is, assistive technology users rely on programatic cues that can be read out.
15
+ # When text on a page is visually implied to be a heading, ensure that it is coded as a heading. Additionally, visually implied heading level and coded heading level should be
16
+ # consistent. [See WCAG success criteria: 1.3.1: Info and Relationships](https://www.w3.org/WAI/WCAG21/Understanding/info-and-relationships.html)
17
+ #
18
+ # Headings allow assistive technology users to quickly navigate around a page. Navigation to text that is not meant to be a heading can be a confusing experience.
19
+ # <%= link_to_heading_practices %>
20
+ class Heading < Primer::Component
21
+ status :beta
22
+
23
+ TAG_FALLBACK = :h2
24
+ TAG_OPTIONS = [:h1, TAG_FALLBACK, :h3, :h4, :h5, :h6].freeze
25
+
26
+ # @example Default
27
+ # <%= render(Primer::Beta::Heading.new(tag: :h1)) { "H1 Text" } %>
28
+ # <%= render(Primer::Beta::Heading.new(tag: :h2)) { "H2 Text" } %>
29
+ # <%= render(Primer::Beta::Heading.new(tag: :h3)) { "H3 Text" } %>
30
+ # <%= render(Primer::Beta::Heading.new(tag: :h4)) { "H4 Text" } %>
31
+ # <%= render(Primer::Beta::Heading.new(tag: :h5)) { "H5 Text" } %>
32
+ # <%= render(Primer::Beta::Heading.new(tag: :h6)) { "H6 Text" } %>
33
+ #
34
+ # @param tag [String] <%= one_of(Primer::Beta::Heading::TAG_OPTIONS) %>
35
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
36
+ def initialize(tag:, **system_arguments)
37
+ @system_arguments = system_arguments
38
+ @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_FALLBACK)
39
+ end
40
+
41
+ def call
42
+ render(Primer::BaseComponent.new(**@system_arguments)) { content }
43
+ end
44
+ end
45
+ end
46
+ end
@@ -19,49 +19,49 @@ module Primer
19
19
  #
20
20
  # @example Multiple items
21
21
  # <%= render(Primer::Beta::Truncate.new) do |component| %>
22
- # <% component.item do %>really-long-repository-owner-name<% end %>
23
- # <% component.item(font_weight: :bold) do %>
22
+ # <% component.with_item do %>really-long-repository-owner-name<% end %>
23
+ # <% component.with_item(font_weight: :bold) do %>
24
24
  # <%= render(Primer::BaseComponent.new(tag: :span, font_weight: :normal)) { "/" } %> really-long-repository-name
25
25
  # <% end %>
26
26
  # <% end %>
27
27
  #
28
28
  # @example Advanced multiple items
29
29
  # <%= render(Primer::Beta::Truncate.new(tag: :ol)) do |component| %>
30
- # <% component.item(tag: :li) do %>primer<% end %>
31
- # <% component.item(tag: :li, priority: true) do %>/ css<% end %>
32
- # <% component.item(tag: :li) do %>/ Issues<% end %>
33
- # <% component.item(tag: :li) do %>/ #123 —<% end %>
34
- # <% component.item(tag: :li, priority: true) do %>
30
+ # <% component.with_item(tag: :li) do %>primer<% end %>
31
+ # <% component.with_item(tag: :li, priority: true) do %>/ css<% end %>
32
+ # <% component.with_item(tag: :li) do %>/ Issues<% end %>
33
+ # <% component.with_item(tag: :li) do %>/ #123 —<% end %>
34
+ # <% component.with_item(tag: :li, priority: true) do %>
35
35
  # Visual bug on primer.style found in lists
36
36
  # <% end %>
37
37
  # <% end %>
38
38
  #
39
39
  # @example Expand on hover or focus
40
40
  # <%= render(Primer::Beta::Truncate.new) do |component| %>
41
- # <% component.item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
42
- # <% component.item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
43
- # <% component.item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
44
- # <% component.item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
41
+ # <% component.with_item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
42
+ # <% component.with_item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
43
+ # <% component.with_item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
44
+ # <% component.with_item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
45
45
  # <% end %>
46
46
  #
47
47
  # @example Max widths
48
48
  # <%= render(Primer::Beta::Truncate.new) do |component| %>
49
- # <% component.item(max_width: 300, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
50
- # <% component.item(max_width: 200, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
51
- # <% component.item(max_width: 100, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
49
+ # <% component.with_item(max_width: 300, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
50
+ # <% component.with_item(max_width: 200, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
51
+ # <% component.with_item(max_width: 100, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
52
52
  # <% end %>
53
53
  #
54
54
  # @example Max widths on new lines
55
55
  # <%= render(Primer::Beta::Truncate.new) do |component| %>
56
- # <% component.item(max_width: 300, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
56
+ # <% component.with_item(max_width: 300, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
57
57
  # <% end %>
58
58
  # <br/>
59
59
  # <%= render(Primer::Beta::Truncate.new) do |component| %>
60
- # <% component.item(max_width: 200, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
60
+ # <% component.with_item(max_width: 200, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
61
61
  # <% end %>
62
62
  # <br/>
63
63
  # <%= render(Primer::Beta::Truncate.new) do |component| %>
64
- # <% component.item(max_width: 100, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
64
+ # <% component.with_item(max_width: 100, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
65
65
  # <% end %>
66
66
  #
67
67
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
@@ -41,7 +41,7 @@ module Primer
41
41
  # title: "Title",
42
42
  # description: "Description",
43
43
  # ) do |component| %>
44
- # <% component.spinner(size: :large) %>
44
+ # <% component.with_spinner(size: :large) %>
45
45
  # <% end %>
46
46
  #
47
47
  # @example Custom content
@@ -44,14 +44,14 @@ module Primer
44
44
  #
45
45
  # Use:
46
46
  #
47
- # - `trailing_visual_counter` for a <%= link_to_component(Primer::CounterComponent) %>.
47
+ # - `trailing_visual_counter` for a <%= link_to_component(Primer::Beta::Counter) %>.
48
48
  #
49
- # @param system_arguments [Hash] Same arguments as <%= link_to_component(Primer::CounterComponent) %>.
49
+ # @param system_arguments [Hash] Same arguments as <%= link_to_component(Primer::Beta::Counter) %>.
50
50
  renders_one :trailing_visual, types: {
51
51
  counter: lambda { |**system_arguments|
52
52
  system_arguments[:ml] = 2
53
53
 
54
- Primer::CounterComponent.new(**system_arguments)
54
+ Primer::Beta::Counter.new(**system_arguments)
55
55
  }
56
56
  }
57
57
  alias counter trailing_visual_counter # remove alias when all buttons are migrated to new slot names
@@ -89,20 +89,20 @@ module Primer
89
89
  #
90
90
  # @example With leading visual
91
91
  # <%= render(Primer::ButtonComponent.new) do |c| %>
92
- # <% c.leading_visual_icon(icon: :star) %>
92
+ # <% c.with_leading_visual_icon(icon: :star) %>
93
93
  # Button
94
94
  # <% end %>
95
95
  #
96
96
  # @example With trailing visual
97
97
  # <%= render(Primer::ButtonComponent.new) do |c| %>
98
- # <% c.trailing_visual_counter(count: 15) %>
98
+ # <% c.with_trailing_visual_counter(count: 15) %>
99
99
  # Button
100
100
  # <% end %>
101
101
  #
102
102
  # @example With leading and trailing visuals
103
103
  # <%= render(Primer::ButtonComponent.new) do |c| %>
104
- # <% c.leading_visual_icon(icon: :star) %>
105
- # <% c.trailing_visual_counter(count: 15) %>
104
+ # <% c.with_leading_visual_icon(icon: :star) %>
105
+ # <% c.with_trailing_visual_counter(count: 15) %>
106
106
  # Button
107
107
  # <% end %>
108
108
  #
@@ -116,7 +116,7 @@ module Primer
116
116
  # Use tooltips sparingly and as a last resort. Consult the <%= link_to_component(Primer::Alpha::Tooltip) %> documentation for more information.
117
117
  # @code
118
118
  # <%= render(Primer::ButtonComponent.new(id: "button-with-tooltip")) do |c| %>
119
- # <% c.tooltip(text: "Tooltip text") %>
119
+ # <% c.with_tooltip(text: "Tooltip text") %>
120
120
  # Button
121
121
  # <% end %>
122
122
  #
@@ -1,39 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
- # Use `CloseButton` to render an `×` without default button styles.
5
- #
6
- # @accessibility
7
- # `CloseButton` has a default `aria-label` of "Close" to provides assistive technologies with an accessible label.
8
- # You may choose to override this label with something more descriptive via [system_arguments][0].
9
- # [0]: https://primer.style/view-components/system-arguments#html-attributes
10
- class CloseButton < Primer::Component
11
- status :beta
12
-
13
- DEFAULT_TYPE = :button
14
- TYPE_OPTIONS = [DEFAULT_TYPE, :submit].freeze
15
-
16
- # @example Default
17
- # <%= render(Primer::CloseButton.new) %>
18
- #
19
- # @param type [Symbol] <%= one_of(Primer::CloseButton::TYPE_OPTIONS) %>
20
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
21
- def initialize(type: DEFAULT_TYPE, **system_arguments)
22
- @system_arguments = deny_tag_argument(**system_arguments)
23
- @system_arguments[:tag] = :button
24
- @system_arguments[:block] = false
25
- @system_arguments[:type] = fetch_or_fallback(TYPE_OPTIONS, type, DEFAULT_TYPE)
26
- @system_arguments[:classes] = class_names(
27
- "close-button",
28
- system_arguments[:classes]
29
- )
30
- @system_arguments[:"aria-label"] ||= "Close"
31
- end
32
-
33
- def call
34
- render(Primer::Beta::BaseButton.new(**@system_arguments)) do
35
- render(Primer::OcticonComponent.new("x"))
36
- end
37
- end
4
+ class CloseButton < Primer::Beta::CloseButton
5
+ status :deprecated
38
6
  end
39
7
  end
@@ -1,111 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
- # Use `Counter` to add a count to navigational elements and buttons.
5
- #
6
- # @accessibility
7
- # Always use `Counter` with adjacent text that provides supplementary information regarding what the count is for. For instance, `Counter`
8
- # should be accompanied with text such as `issues` or `pull requests`.
9
- #
10
- class CounterComponent < Primer::Component
11
- status :beta
12
-
13
- DEFAULT_SCHEME = :default
14
- SCHEME_MAPPINGS = {
15
- DEFAULT_SCHEME => "",
16
- :primary => "Counter--primary",
17
- :secondary => "Counter--secondary",
18
- # deprecated
19
- :gray => "Counter--primary",
20
- :light_gray => "Counter--secondary"
21
- }.freeze
22
- DEPRECATED_SCHEME_OPTIONS = [:gray, :light_gray].freeze
23
- SCHEME_OPTIONS = (SCHEME_MAPPINGS.keys - DEPRECATED_SCHEME_OPTIONS).freeze
24
-
25
- #
26
- # @example Default
27
- # <%= render(Primer::CounterComponent.new(count: 25)) %>
28
- #
29
- # @example Schemes
30
- # <%= render(Primer::CounterComponent.new(count: 25, scheme: :primary)) %>
31
- # <%= render(Primer::CounterComponent.new(count: 25, scheme: :secondary)) %>
32
- #
33
- # @param count [Integer, Float::INFINITY, nil] The number to be displayed (e.x. # of issues, pull requests)
34
- # @param scheme [Symbol] Color scheme. <%= one_of(Primer::CounterComponent::SCHEME_OPTIONS) %>
35
- # @param limit [Integer, nil] Maximum value to display. Pass `nil` for no limit. (e.x. if `count` == 6,000 and `limit` == 5000, counter will display "5,000+")
36
- # @param hide_if_zero [Boolean] If true, a `hidden` attribute is added to the counter if `count` is zero.
37
- # @param text [String] Text to display instead of count.
38
- # @param round [Boolean] Whether to apply our standard rounding logic to value.
39
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
40
- def initialize(
41
- count: 0,
42
- scheme: DEFAULT_SCHEME,
43
- limit: 5_000,
44
- hide_if_zero: false,
45
- text: "",
46
- round: false,
47
- **system_arguments
48
- )
49
- @count = count
50
- @limit = limit
51
- @hide_if_zero = hide_if_zero
52
- @text = text
53
- @round = round
54
- @system_arguments = deny_tag_argument(**system_arguments)
55
-
56
- @has_limit = !@limit.nil?
57
- @system_arguments[:title] = title
58
- @system_arguments[:tag] = :span
59
- @system_arguments[:classes] = class_names(
60
- "Counter",
61
- @system_arguments[:classes],
62
- SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME, deprecated_values: DEPRECATED_SCHEME_OPTIONS)]
63
- )
64
- @system_arguments[:hidden] = true if count == 0 && hide_if_zero # rubocop:disable Style/NumericPredicate
65
- end
66
-
67
- def call
68
- render(Primer::BaseComponent.new(**@system_arguments)) { value }
69
- end
70
-
71
- private
72
-
73
- def title
74
- if @text.present?
75
- @text
76
- elsif @count.nil?
77
- "Not available"
78
- elsif @count == Float::INFINITY
79
- "Infinity"
80
- else
81
- count = @count.to_i
82
- str = number_with_delimiter(@has_limit ? [count, @limit].min : count)
83
- str += "+" if @has_limit && count > @limit
84
- str
85
- end
86
- end
87
-
88
- def value
89
- if @text.present?
90
- @text
91
- elsif @count.nil?
92
- "" # CSS will hide it
93
- elsif @count == Float::INFINITY
94
- "∞"
95
- else
96
- if @round
97
- count = @has_limit ? [@count.to_i, @limit].min : @count.to_i
98
- precision = count.between?(100_000, 999_999) ? 0 : 1
99
- units = { thousand: "k", million: "m", billion: "b" }
100
- str = number_to_human(count, precision: precision, significant: false, units: units, format: "%n%u")
101
- else
102
- @count = @count.to_i
103
- str = number_with_delimiter(@has_limit ? [@count, @limit].min : @count)
104
- end
105
-
106
- str += "+" if @has_limit && @count.to_i > @limit
107
- str
108
- end
109
- end
4
+ class CounterComponent < Primer::Beta::Counter
5
+ status :deprecated
110
6
  end
111
7
  end
@@ -1,68 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
- # Use `DetailsComponent` to reveal content after clicking a button.
5
- class DetailsComponent < Primer::Component
6
- status :beta
7
-
8
- BODY_TAG_DEFAULT = :div
9
- BODY_TAG_OPTIONS = [:ul, :"details-menu", :"details-dialog", BODY_TAG_DEFAULT].freeze
10
- NO_OVERLAY = :none
11
- OVERLAY_MAPPINGS = {
12
- NO_OVERLAY => "",
13
- :default => "details-overlay",
14
- :dark => "details-overlay details-overlay-dark"
15
- }.freeze
16
-
17
- # Use the Summary slot as a trigger to reveal the content.
18
- #
19
- # @param button [Boolean] (true) Whether to render the Summary as a button or not.
20
- # @param kwargs [Hash] The same arguments as <%= link_to_system_arguments_docs %>.
21
- renders_one :summary, lambda { |button: true, **system_arguments|
22
- system_arguments[:tag] = :summary
23
- system_arguments[:role] = "button"
24
-
25
- return Primer::BaseComponent.new(**system_arguments) unless button
26
-
27
- Primer::ButtonComponent.new(**system_arguments)
28
- }
29
-
30
- # Use the Body slot as the main content to be shown when triggered by the Summary.
31
- #
32
- # @param tag [Symbol] (Primer::DetailsComponent::BODY_TAG_DEFAULT) <%= one_of(Primer::DetailsComponent::BODY_TAG_OPTIONS) %>
33
- # @param kwargs [Hash] The same arguments as <%= link_to_system_arguments_docs %>.
34
- renders_one :body, lambda { |tag: BODY_TAG_DEFAULT, **system_arguments|
35
- system_arguments[:tag] = fetch_or_fallback(BODY_TAG_OPTIONS, tag, BODY_TAG_DEFAULT)
36
-
37
- Primer::BaseComponent.new(**system_arguments)
38
- }
39
-
40
- # @example Default
41
- #
42
- # <%= render Primer::DetailsComponent.new do |c| %>
43
- # <% c.summary do %>
44
- # Summary
45
- # <% end %>
46
- # <% c.body do %>
47
- # Body
48
- # <% end %>
49
- # <% end %>
50
- #
51
- # @param overlay [Symbol] Dictates the type of overlay to render with. <%= one_of(Primer::DetailsComponent::OVERLAY_MAPPINGS.keys) %>
52
- # @param reset [Boolean] Defaults to false. If set to true, it will remove the default caret and remove style from the summary element
53
- # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
54
- def initialize(overlay: NO_OVERLAY, reset: false, **system_arguments)
55
- @system_arguments = deny_tag_argument(**system_arguments)
56
- @system_arguments[:tag] = :details
57
- @system_arguments[:classes] = class_names(
58
- system_arguments[:classes],
59
- OVERLAY_MAPPINGS[fetch_or_fallback(OVERLAY_MAPPINGS.keys, overlay, NO_OVERLAY)],
60
- "details-reset" => reset
61
- )
62
- end
63
-
64
- def render?
65
- summary.present? && body.present?
66
- end
4
+ class DetailsComponent < Primer::Beta::Details
5
+ status :deprecated
67
6
  end
68
7
  end
@@ -1,4 +1,4 @@
1
- <%= render(Primer::DetailsComponent.new(**@system_arguments)) do |c| %>
1
+ <%= render(Primer::Beta::Details.new(**@system_arguments)) do |c| %>
2
2
  <% c.summary(**@button_arguments) do %>
3
3
  <%= button %>
4
4
  <% end %>