primer_view_components 0.0.89 → 0.0.90
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/app/assets/javascripts/primer_view_components.js +1 -1
- data/app/assets/javascripts/primer_view_components.js.map +1 -1
- data/app/components/primer/alpha/auto_complete.rb +2 -2
- data/app/components/primer/alpha/layout.rb +34 -32
- data/app/components/primer/alpha/tab_nav.rb +20 -20
- data/app/components/primer/alpha/tab_panels.rb +2 -2
- data/app/components/primer/alpha/tool-tip-element.d.ts +1 -3
- data/app/components/primer/alpha/tool-tip-element.js +13 -19
- data/app/components/primer/alpha/tool-tip-element.ts +14 -22
- data/app/components/primer/alpha/tooltip.rb +1 -1
- data/app/components/primer/alpha/underline_nav.rb +16 -16
- data/app/components/primer/alpha/underline_panels.rb +3 -3
- data/app/components/primer/beta/auto_complete/item.rb +2 -2
- data/app/components/primer/beta/auto_complete.rb +2 -2
- data/app/components/primer/beta/avatar_stack.rb +9 -9
- data/app/components/primer/beta/border_box/header.rb +4 -2
- data/app/components/primer/beta/border_box.rb +13 -13
- data/app/components/primer/beta/breadcrumbs.rb +3 -3
- data/app/components/primer/beta/button_group.rb +9 -9
- data/app/components/primer/beta/close_button.rb +41 -0
- data/app/components/primer/beta/counter.rb +113 -0
- data/app/components/primer/beta/flash.rb +1 -1
- data/app/components/primer/beta/truncate.rb +17 -17
- data/app/components/primer/blankslate_component.rb +1 -1
- data/app/components/primer/button_component.rb +8 -8
- data/app/components/primer/close_button.rb +2 -34
- data/app/components/primer/counter_component.rb +2 -106
- data/app/components/primer/details_component.rb +2 -2
- data/app/components/primer/dropdown.rb +14 -14
- data/app/components/primer/image_crop.rb +1 -1
- data/app/components/primer/layout_component.rb +4 -4
- data/app/components/primer/link_component.rb +1 -1
- data/app/components/primer/menu_component.rb +5 -5
- data/app/components/primer/navigation/tab_component.rb +12 -12
- data/app/components/primer/popover_component.rb +8 -8
- data/app/components/primer/subhead_component.rb +10 -10
- data/app/components/primer/timeline_item_component.rb +3 -3
- data/app/lib/primer/join_style_arguments_helper.rb +1 -1
- data/lib/primer/view_components/linters/argument_mappers/close_button.rb +2 -2
- data/lib/primer/view_components/linters/close_button_component_migration_counter.rb +2 -2
- data/lib/primer/view_components/linters/helpers/deprecated_components_helpers.rb +2 -0
- data/lib/primer/view_components/version.rb +1 -1
- data/lib/rubocop/cop/primer/component_name_migration.rb +2 -0
- data/lib/tasks/docs.rake +2 -2
- data/static/arguments.yml +44 -44
- data/static/audited_at.json +2 -0
- data/static/constants.json +26 -22
- data/static/statuses.json +5 -3
- metadata +4 -2
@@ -5,8 +5,10 @@ module Primer
|
|
5
5
|
class BorderBox
|
6
6
|
# `BorderBox::Header` is used inside `BorderBox` to render its header slot.
|
7
7
|
#
|
8
|
-
# @accessibility When using `header.
|
8
|
+
# @accessibility When using `header.with_title`, set `tag` to one of `h1`, `h2`, `h3`, etc. based on what is appropriate for the page context. <%= link_to_heading_practices %>
|
9
9
|
class Header < Primer::Component
|
10
|
+
status :beta
|
11
|
+
|
10
12
|
TITLE_TAG_FALLBACK = :h2
|
11
13
|
TITLE_TAG_OPTIONS = [:h1, TITLE_TAG_FALLBACK, :h3, :h4, :h5, :h6].freeze
|
12
14
|
|
@@ -32,7 +34,7 @@ module Primer
|
|
32
34
|
#
|
33
35
|
# @example with title
|
34
36
|
# <%= render(Primer::Beta::BorderBox::Header.new) do |h| %>
|
35
|
-
# <% h.
|
37
|
+
# <% h.with_title(tag: :h3) do %>I am a title<% end %>
|
36
38
|
# <% end %>
|
37
39
|
#
|
38
40
|
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
@@ -72,55 +72,55 @@ module Primer
|
|
72
72
|
|
73
73
|
# @example Header with title, body, rows, and footer
|
74
74
|
# <%= render(Primer::Beta::BorderBox.new) do |component| %>
|
75
|
-
# <% component.
|
75
|
+
# <% component.with_header do |h| %>
|
76
76
|
# <% h.title(tag: :h2) do %>
|
77
77
|
# Header
|
78
78
|
# <% end %>
|
79
79
|
# <% end %>
|
80
|
-
# <% component.
|
80
|
+
# <% component.with_body do %>
|
81
81
|
# Body
|
82
82
|
# <% end %>
|
83
|
-
# <% component.
|
83
|
+
# <% component.with_row do %>
|
84
84
|
# <% if true %>
|
85
85
|
# Row one
|
86
86
|
# <% end %>
|
87
87
|
# <% end %>
|
88
|
-
# <% component.
|
88
|
+
# <% component.with_row do %>
|
89
89
|
# Row two
|
90
90
|
# <% end %>
|
91
|
-
# <% component.
|
91
|
+
# <% component.with_footer do %>
|
92
92
|
# Footer
|
93
93
|
# <% end %>
|
94
94
|
# <% end %>
|
95
95
|
#
|
96
96
|
# @example Padding density
|
97
97
|
# <%= render(Primer::Beta::BorderBox.new(padding: :condensed)) do |component| %>
|
98
|
-
# <% component.
|
98
|
+
# <% component.with_header do %>
|
99
99
|
# Header
|
100
100
|
# <% end %>
|
101
|
-
# <% component.
|
101
|
+
# <% component.with_body do %>
|
102
102
|
# Body
|
103
103
|
# <% end %>
|
104
|
-
# <% component.
|
104
|
+
# <% component.with_row do %>
|
105
105
|
# Row two
|
106
106
|
# <% end %>
|
107
|
-
# <% component.
|
107
|
+
# <% component.with_footer do %>
|
108
108
|
# Footer
|
109
109
|
# <% end %>
|
110
110
|
# <% end %>
|
111
111
|
#
|
112
112
|
# @example Row colors
|
113
113
|
# <%= render(Primer::Beta::BorderBox.new) do |component| %>
|
114
|
-
# <% component.
|
114
|
+
# <% component.with_row do %>
|
115
115
|
# Default
|
116
116
|
# <% end %>
|
117
|
-
# <% component.
|
117
|
+
# <% component.with_row(scheme: :neutral) do %>
|
118
118
|
# Neutral
|
119
119
|
# <% end %>
|
120
|
-
# <% component.
|
120
|
+
# <% component.with_row(scheme: :info) do %>
|
121
121
|
# Info
|
122
122
|
# <% end %>
|
123
|
-
# <% component.
|
123
|
+
# <% component.with_row(scheme: :warning) do %>
|
124
124
|
# Warning
|
125
125
|
# <% end %>
|
126
126
|
# <% end %>
|
@@ -33,9 +33,9 @@ module Primer
|
|
33
33
|
|
34
34
|
# @example Basic
|
35
35
|
# <%= render(Primer::Beta::Breadcrumbs.new) do |component| %>
|
36
|
-
# <% component.
|
37
|
-
# <% component.
|
38
|
-
# <% component.
|
36
|
+
# <% component.with_item(href: "/") do %>Home<% end %>
|
37
|
+
# <% component.with_item(href: "/about") do %>About<% end %>
|
38
|
+
# <% component.with_item(href: "/about/team") do %>Team<% end %>
|
39
39
|
# <% end %>
|
40
40
|
#
|
41
41
|
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
@@ -19,20 +19,20 @@ module Primer
|
|
19
19
|
# @example Default
|
20
20
|
#
|
21
21
|
# <%= render(Primer::Beta::ButtonGroup.new) do |component| %>
|
22
|
-
# <% component.
|
23
|
-
# <% component.
|
24
|
-
# <% component.
|
25
|
-
# <% component.
|
26
|
-
# <% component.
|
22
|
+
# <% component.with_button { "Default" } %>
|
23
|
+
# <% component.with_button(scheme: :primary) { "Primary" } %>
|
24
|
+
# <% component.with_button(scheme: :danger) { "Danger" } %>
|
25
|
+
# <% component.with_button(scheme: :outline) { "Outline" } %>
|
26
|
+
# <% component.with_button(classes: "custom-class") { "Custom class" } %>
|
27
27
|
# <% end %>
|
28
28
|
#
|
29
29
|
# @example Sizes
|
30
30
|
#
|
31
31
|
# <%= render(Primer::Beta::ButtonGroup.new(size: :small)) do |component| %>
|
32
|
-
# <% component.
|
33
|
-
# <% component.
|
34
|
-
# <% component.
|
35
|
-
# <% component.
|
32
|
+
# <% component.with_button { "Default" } %>
|
33
|
+
# <% component.with_button(scheme: :primary) { "Primary" } %>
|
34
|
+
# <% component.with_button(scheme: :danger) { "Danger" } %>
|
35
|
+
# <% component.with_button(scheme: :outline) { "Outline" } %>
|
36
36
|
# <% end %>
|
37
37
|
#
|
38
38
|
# @param variant [Symbol] DEPRECATED. <%= one_of(Primer::ButtonComponent::SIZE_OPTIONS) %>
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Primer
|
4
|
+
module Beta
|
5
|
+
# Use `CloseButton` to render an `×` without default button styles.
|
6
|
+
#
|
7
|
+
# @accessibility
|
8
|
+
# `CloseButton` has a default `aria-label` of "Close" to provides assistive technologies with an accessible label.
|
9
|
+
# You may choose to override this label with something more descriptive via [system_arguments][0].
|
10
|
+
# [0]: https://primer.style/view-components/system-arguments#html-attributes
|
11
|
+
class CloseButton < Primer::Component
|
12
|
+
status :beta
|
13
|
+
|
14
|
+
DEFAULT_TYPE = :button
|
15
|
+
TYPE_OPTIONS = [DEFAULT_TYPE, :submit].freeze
|
16
|
+
|
17
|
+
# @example Default
|
18
|
+
# <%= render(Primer::Beta::CloseButton.new) %>
|
19
|
+
#
|
20
|
+
# @param type [Symbol] <%= one_of(Primer::Beta::CloseButton::TYPE_OPTIONS) %>
|
21
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
22
|
+
def initialize(type: DEFAULT_TYPE, **system_arguments)
|
23
|
+
@system_arguments = deny_tag_argument(**system_arguments)
|
24
|
+
@system_arguments[:tag] = :button
|
25
|
+
@system_arguments[:block] = false
|
26
|
+
@system_arguments[:type] = fetch_or_fallback(TYPE_OPTIONS, type, DEFAULT_TYPE)
|
27
|
+
@system_arguments[:classes] = class_names(
|
28
|
+
"close-button",
|
29
|
+
system_arguments[:classes]
|
30
|
+
)
|
31
|
+
@system_arguments[:"aria-label"] ||= "Close"
|
32
|
+
end
|
33
|
+
|
34
|
+
def call
|
35
|
+
render(Primer::Beta::BaseButton.new(**@system_arguments)) do
|
36
|
+
render(Primer::OcticonComponent.new("x"))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -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
|
@@ -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.
|
45
|
+
# <% component.with_action do %>
|
46
46
|
# <%= render(Primer::ButtonComponent.new(size: :small)) { "Take action" } %>
|
47
47
|
# <% end %>
|
48
48
|
# <% 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.
|
23
|
-
# <% component.
|
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.
|
31
|
-
# <% component.
|
32
|
-
# <% component.
|
33
|
-
# <% component.
|
34
|
-
# <% component.
|
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.
|
42
|
-
# <% component.
|
43
|
-
# <% component.
|
44
|
-
# <% component.
|
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.
|
50
|
-
# <% component.
|
51
|
-
# <% component.
|
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.
|
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.
|
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.
|
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 %>
|
@@ -44,14 +44,14 @@ module Primer
|
|
44
44
|
#
|
45
45
|
# Use:
|
46
46
|
#
|
47
|
-
# - `trailing_visual_counter` for a <%= link_to_component(Primer::
|
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::
|
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::
|
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.
|
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.
|
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.
|
105
|
-
# <% c.
|
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.
|
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
|
-
|
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
|
-
|
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
|
@@ -40,10 +40,10 @@ module Primer
|
|
40
40
|
# @example Default
|
41
41
|
#
|
42
42
|
# <%= render Primer::DetailsComponent.new do |c| %>
|
43
|
-
# <% c.
|
43
|
+
# <% c.with_summary do %>
|
44
44
|
# Summary
|
45
45
|
# <% end %>
|
46
|
-
# <% c.
|
46
|
+
# <% c.with_body do %>
|
47
47
|
# Body
|
48
48
|
# <% end %>
|
49
49
|
# <% end %>
|