primer_view_components 0.0.8 → 0.0.13
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 +66 -37
- data/README.md +2 -161
- data/app/components/primer/avatar_component.rb +22 -11
- data/app/components/primer/base_component.rb +56 -11
- data/app/components/primer/blankslate_component.html.erb +2 -2
- data/app/components/primer/blankslate_component.rb +71 -116
- data/app/components/primer/border_box_component.html.erb +5 -5
- data/app/components/primer/border_box_component.rb +45 -33
- data/app/components/primer/box_component.rb +6 -4
- data/app/components/primer/breadcrumb_component.html.erb +2 -2
- data/app/components/primer/breadcrumb_component.rb +23 -30
- data/app/components/primer/button_component.rb +28 -11
- data/app/components/primer/component.rb +1 -0
- data/app/components/primer/counter_component.rb +14 -9
- data/app/components/primer/details_component.html.erb +1 -1
- data/app/components/primer/details_component.rb +18 -18
- data/app/components/primer/dropdown_menu_component.html.erb +1 -1
- data/app/components/primer/dropdown_menu_component.rb +6 -6
- data/app/components/primer/flash_component.html.erb +2 -2
- data/app/components/primer/flash_component.rb +43 -13
- data/app/components/primer/flex_component.rb +5 -5
- data/app/components/primer/flex_item_component.rb +5 -5
- data/app/components/primer/heading_component.rb +4 -4
- data/app/components/primer/label_component.rb +25 -8
- data/app/components/primer/layout_component.html.erb +1 -1
- data/app/components/primer/layout_component.rb +23 -6
- data/app/components/primer/link_component.rb +17 -7
- data/app/components/primer/octicon_component.rb +23 -5
- data/app/components/primer/popover_component.html.erb +1 -1
- data/app/components/primer/popover_component.rb +61 -23
- data/app/components/primer/progress_bar_component.html.erb +2 -2
- data/app/components/primer/progress_bar_component.rb +40 -30
- data/app/components/primer/slot.rb +1 -0
- data/app/components/primer/spinner_component.html.erb +6 -0
- data/app/components/primer/spinner_component.rb +39 -0
- data/app/components/primer/state_component.rb +26 -14
- data/app/components/primer/subhead_component.html.erb +4 -4
- data/app/components/primer/subhead_component.rb +68 -43
- data/app/components/primer/text_component.rb +10 -4
- data/app/components/primer/timeline_item_component.html.erb +4 -4
- data/app/components/primer/timeline_item_component.rb +48 -24
- data/app/components/primer/underline_nav_component.html.erb +1 -1
- data/app/components/primer/underline_nav_component.rb +5 -5
- data/app/components/primer/view_components.rb +1 -0
- data/lib/primer/classify.rb +2 -4
- data/lib/primer/view_components/version.rb +1 -1
- metadata +22 -6
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= render(Primer::FlexComponent.new(**@
|
1
|
+
<%= render(Primer::FlexComponent.new(**@system_arguments)) do %>
|
2
2
|
<% if @side == :left %>
|
3
3
|
<%= render Primer::BaseComponent.new(tag: :div, classes: "flex-shrink-0", col: (@responsive ? [12, nil, @sidebar_col] : @sidebar_col), mb: (@responsive ? [4, nil, 0] : nil)) do %>
|
4
4
|
<%= sidebar %>
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
+
# Use Layout to build a main/sidebar layout.
|
4
5
|
class LayoutComponent < Primer::Component
|
5
6
|
with_content_areas :main, :sidebar
|
6
7
|
|
@@ -11,15 +12,31 @@ module Primer
|
|
11
12
|
DEFAULT_SIDEBAR_COL = 3
|
12
13
|
ALLOWED_SIDEBAR_COLS = (1..(MAX_COL - 1)).to_a.freeze
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
# @example 40|Default
|
16
|
+
# <%= render(Primer::LayoutComponent.new) do |component| %>
|
17
|
+
# <% component.with(:sidebar) { "Sidebar" } %>
|
18
|
+
# <% component.with(:main) { "Main" } %>
|
19
|
+
# <% end %>
|
20
|
+
#
|
21
|
+
# @example 40|Left sidebar
|
22
|
+
# <%= render(Primer::LayoutComponent.new(side: :left)) do |component| %>
|
23
|
+
# <% component.with(:sidebar) { "Sidebar" } %>
|
24
|
+
# <% component.with(:main) { "Main" } %>
|
25
|
+
# <% end %>
|
26
|
+
#
|
27
|
+
# @param responsive [Boolean] Whether to collapse layout to a single column at smaller widths.
|
28
|
+
# @param side [Symbol] Which side to display the sidebar on. <%= one_of(Primer::LayoutComponent::ALLOWED_SIDES) %>
|
29
|
+
# @param sidebar_col [Integer] Sidebar column width.
|
30
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
31
|
+
def initialize(responsive: false, side: DEFAULT_SIDE, sidebar_col: DEFAULT_SIDEBAR_COL, **system_arguments)
|
32
|
+
@system_arguments = system_arguments
|
33
|
+
@side = fetch_or_fallback(ALLOWED_SIDES, side, DEFAULT_SIDE)
|
17
34
|
@responsive = responsive
|
18
|
-
@
|
35
|
+
@system_arguments[:classes] = class_names(
|
19
36
|
"gutter-condensed gutter-lg",
|
20
|
-
@
|
37
|
+
@system_arguments[:classes]
|
21
38
|
)
|
22
|
-
@
|
39
|
+
@system_arguments[:direction] = responsive ? [:column, nil, :row] : nil
|
23
40
|
|
24
41
|
@sidebar_col = fetch_or_fallback(ALLOWED_SIDEBAR_COLS, sidebar_col, DEFAULT_SIDEBAR_COL)
|
25
42
|
@main_col = MAX_COL - @sidebar_col
|
@@ -1,19 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
+
# Use links for moving from one page to another. The Link component styles anchor tags with default blue styling and hover text-decoration.
|
4
5
|
class LinkComponent < Primer::Component
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
# @example 40|Default
|
7
|
+
# <%= render(Primer::LinkComponent.new(href: "http://www.google.com")) { "Link" } %>
|
8
|
+
#
|
9
|
+
# @example 40|Muted
|
10
|
+
# <%= render(Primer::LinkComponent.new(href: "http://www.google.com", muted: true)) { "Link" } %>
|
11
|
+
#
|
12
|
+
# @param href [String] URL to be used for the Link
|
13
|
+
# @param muted [Boolean] Uses light gray for Link color, and blue on hover
|
14
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
15
|
+
def initialize(href:, muted: false, **system_arguments)
|
16
|
+
@system_arguments = system_arguments
|
17
|
+
@system_arguments[:tag] = :a
|
18
|
+
@system_arguments[:href] = href
|
19
|
+
@system_arguments[:classes] = class_names(
|
20
|
+
@system_arguments[:classes],
|
11
21
|
"muted-link" => fetch_or_fallback([true, false], muted, false)
|
12
22
|
)
|
13
23
|
end
|
14
24
|
|
15
25
|
def call
|
16
|
-
render(Primer::BaseComponent.new(**@
|
26
|
+
render(Primer::BaseComponent.new(**@system_arguments)) { content }
|
17
27
|
end
|
18
28
|
end
|
19
29
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
+
# Renders an [Octicon](https://primer.style/octicons/) with <%= link_to_system_arguments_docs %>.
|
4
5
|
class OcticonComponent < Primer::Component
|
5
6
|
include Primer::ClassNameHelper
|
6
7
|
include OcticonsHelper
|
@@ -13,15 +14,32 @@ module Primer
|
|
13
14
|
}.freeze
|
14
15
|
SIZE_OPTIONS = SIZE_MAPPINGS.keys
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
# @example 25|Default
|
18
|
+
# <%= render(Primer::OcticonComponent.new(icon: "check")) %>
|
19
|
+
#
|
20
|
+
# @example 40|Medium
|
21
|
+
# <%= render(Primer::OcticonComponent.new(icon: "people", size: :medium)) %>
|
22
|
+
#
|
23
|
+
# @example 80|Large
|
24
|
+
# <%= render(Primer::OcticonComponent.new(icon: "x", size: :large)) %>
|
25
|
+
#
|
26
|
+
# @param icon [String] Name of [Octicon](https://primer.style/octicons/) to use.
|
27
|
+
# @param size [Symbol] <%= one_of(Primer::OcticonComponent::SIZE_MAPPINGS) %>
|
28
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
29
|
+
def initialize(icon:, size: SIZE_DEFAULT, **system_arguments)
|
30
|
+
@icon, @system_arguments = icon, system_arguments
|
18
31
|
|
19
|
-
@
|
20
|
-
@
|
32
|
+
@system_arguments[:class] = Primer::Classify.call(**@system_arguments)[:class]
|
33
|
+
@system_arguments[:height] ||= SIZE_MAPPINGS[size]
|
34
|
+
|
35
|
+
# Filter out classify options to prevent them from becoming invalid html attributes.
|
36
|
+
# Note height and width are both classify options and valid html attributes.
|
37
|
+
octicon_helper_options = @system_arguments.slice(:height, :width)
|
38
|
+
@system_arguments = @system_arguments.except(*Primer::Classify::VALID_KEYS, :classes).merge(octicon_helper_options)
|
21
39
|
end
|
22
40
|
|
23
41
|
def call
|
24
|
-
octicon(@icon, **@
|
42
|
+
octicon(@icon, **@system_arguments)
|
25
43
|
end
|
26
44
|
end
|
27
45
|
end
|
@@ -1,22 +1,56 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
+
# Use popovers to bring attention to specific user interface elements, typically to suggest an action or to guide users through a new experience.
|
5
|
+
#
|
6
|
+
# By default, the popover renders with absolute positioning, meaning it should usually be wrapped in an element with a relative position in order to be positioned properly. To render the popover with relative positioning, use the relative property.
|
4
7
|
class PopoverComponent < Primer::Component
|
5
8
|
include ViewComponent::Slotable
|
6
9
|
|
7
10
|
with_slot :heading, class_name: "Heading"
|
8
11
|
with_slot :body, class_name: "Body"
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
# @example 150|Default
|
14
|
+
# <%= render Primer::PopoverComponent.new do |component| %>
|
15
|
+
# <% component.slot(:heading) do %>
|
16
|
+
# Activity feed
|
17
|
+
# <% end %>
|
18
|
+
# <% component.slot(:body) do %>
|
19
|
+
# This is the Popover body.
|
20
|
+
# <% end %>
|
21
|
+
# <% end %>
|
22
|
+
#
|
23
|
+
# @example 150|Large
|
24
|
+
# <%= render Primer::PopoverComponent.new do |component| %>
|
25
|
+
# <% component.slot(:heading) do %>
|
26
|
+
# Activity feed
|
27
|
+
# <% end %>
|
28
|
+
# <% component.slot(:body, large: true) do %>
|
29
|
+
# This is the large Popover body.
|
30
|
+
# <% end %>
|
31
|
+
# <% end %>
|
32
|
+
#
|
33
|
+
# @example 150|Caret position
|
34
|
+
# <%= render Primer::PopoverComponent.new do |component| %>
|
35
|
+
# <% component.slot(:heading) do %>
|
36
|
+
# Activity feed
|
37
|
+
# <% end %>
|
38
|
+
# <% component.slot(:body, caret: :left) do %>
|
39
|
+
# This is the large Popover body.
|
40
|
+
# <% end %>
|
41
|
+
# <% end %>
|
42
|
+
#
|
43
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
44
|
+
def initialize(**system_arguments)
|
45
|
+
@system_arguments = system_arguments
|
46
|
+
@system_arguments[:tag] ||= :div
|
47
|
+
@system_arguments[:classes] = class_names(
|
48
|
+
system_arguments[:classes],
|
15
49
|
"Popover"
|
16
50
|
)
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
51
|
+
@system_arguments[:position] ||= :relative
|
52
|
+
@system_arguments[:right] = false unless system_arguments.key?(:right)
|
53
|
+
@system_arguments[:left] = false unless system_arguments.key?(:left)
|
20
54
|
end
|
21
55
|
|
22
56
|
def render?
|
@@ -24,14 +58,15 @@ module Primer
|
|
24
58
|
end
|
25
59
|
|
26
60
|
class Heading < ViewComponent::Slot
|
27
|
-
|
28
|
-
|
29
|
-
@
|
30
|
-
@
|
61
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
62
|
+
def initialize(**system_arguments)
|
63
|
+
@system_arguments = system_arguments
|
64
|
+
@system_arguments[:mb] ||= 2
|
65
|
+
@system_arguments[:tag] ||= :h4
|
31
66
|
end
|
32
67
|
|
33
68
|
def component
|
34
|
-
Primer::HeadingComponent.new(**@
|
69
|
+
Primer::HeadingComponent.new(**@system_arguments)
|
35
70
|
end
|
36
71
|
end
|
37
72
|
|
@@ -52,23 +87,26 @@ module Primer
|
|
52
87
|
:top_right => "Popover-message--top-right"
|
53
88
|
}.freeze
|
54
89
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
90
|
+
# @param caret [Symbol] <%= one_of(Primer::PopoverComponent::Body::CARET_MAPPINGS.keys) %>
|
91
|
+
# @param large [Boolean] Whether to use the large version of the component.
|
92
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
93
|
+
def initialize(caret: CARET_DEFAULT, large: false, **system_arguments)
|
94
|
+
@system_arguments = system_arguments
|
95
|
+
@system_arguments[:classes] = class_names(
|
96
|
+
system_arguments[:classes],
|
59
97
|
"Popover-message Box",
|
60
98
|
CARET_MAPPINGS[fetch_or_fallback(CARET_MAPPINGS.keys, caret, CARET_DEFAULT)],
|
61
99
|
"Popover-message--large" => large
|
62
100
|
)
|
63
|
-
@
|
64
|
-
@
|
65
|
-
@
|
66
|
-
@
|
67
|
-
@
|
101
|
+
@system_arguments[:p] ||= 4
|
102
|
+
@system_arguments[:mt] ||= 2
|
103
|
+
@system_arguments[:mx] ||= :auto
|
104
|
+
@system_arguments[:text_align] ||= :left
|
105
|
+
@system_arguments[:box_shadow] ||= :large
|
68
106
|
end
|
69
107
|
|
70
108
|
def component
|
71
|
-
Primer::BoxComponent.new(**@
|
109
|
+
Primer::BoxComponent.new(**@system_arguments)
|
72
110
|
end
|
73
111
|
end
|
74
112
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<%= render Primer::BaseComponent.new(**@
|
1
|
+
<%= render Primer::BaseComponent.new(**@system_arguments) do %>
|
2
2
|
<% items.each do |item| %>
|
3
|
-
<%= render Primer::BaseComponent.new(**item.
|
3
|
+
<%= render Primer::BaseComponent.new(**item.system_arguments) %>
|
4
4
|
<% end %>
|
5
5
|
<% end %>
|
@@ -1,23 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
##
|
4
|
-
# Use progress components to visualize task completion.
|
5
|
-
|
6
|
-
## Basic example
|
7
|
-
#
|
8
|
-
# The `Primer::ProgressBarComponent` can take the following arguments:
|
9
|
-
#
|
10
|
-
# 1. `size` (string). Can be "small" or "large". Increases the height of the progress bar.
|
11
|
-
#
|
12
|
-
# The `Primer::ProgressBarComponent` uses the [Slots API](https://github.com/github/view_component#slots-experimental) and at least one slot is required for the component to render. Each slot accepts a `percentage` parameter, which is used to set the width of the completed bar.
|
13
|
-
#
|
14
|
-
# ```ruby
|
15
|
-
# <%= render(Primer::ProgressBarComponent.new(size: :small)) do |component| %>
|
16
|
-
# <% component.slot(:item, bg: :blue-4, percentage: 50) %>
|
17
|
-
# <% end %>
|
18
|
-
# ```
|
19
|
-
##
|
20
3
|
module Primer
|
4
|
+
# Use ProgressBar to visualize task completion.
|
21
5
|
class ProgressBarComponent < Primer::Component
|
22
6
|
include ViewComponent::Slotable
|
23
7
|
|
@@ -32,15 +16,38 @@ module Primer
|
|
32
16
|
}.freeze
|
33
17
|
|
34
18
|
SIZE_OPTIONS = SIZE_MAPPINGS.keys
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
19
|
+
# @example 20|Default
|
20
|
+
# <%= render(Primer::ProgressBarComponent.new) do |component| %>
|
21
|
+
# <% component.slot(:item, percentage: 25) %>
|
22
|
+
# <% end %>
|
23
|
+
#
|
24
|
+
# @example 20|Small
|
25
|
+
# <%= render(Primer::ProgressBarComponent.new(size: :small)) do |component| %>
|
26
|
+
# <% component.slot(:item, bg: :blue_4, percentage: 50) %>
|
27
|
+
# <% end %>
|
28
|
+
#
|
29
|
+
# @example 30|Large
|
30
|
+
# <%= render(Primer::ProgressBarComponent.new(size: :large)) do |component| %>
|
31
|
+
# <% component.slot(:item, bg: :red_4, percentage: 75) %>
|
32
|
+
# <% end %>
|
33
|
+
#
|
34
|
+
# @example 20|Multiple items
|
35
|
+
# <%= render(Primer::ProgressBarComponent.new) do |component| %>
|
36
|
+
# <% component.slot(:item, percentage: 10) %>
|
37
|
+
# <% component.slot(:item, bg: :blue_4, percentage: 20) %>
|
38
|
+
# <% component.slot(:item, bg: :red_4, percentage: 30) %>
|
39
|
+
# <% end %>
|
40
|
+
#
|
41
|
+
# @param size [Symbol] <%= one_of(Primer::ProgressBarComponent::SIZE_OPTIONS) %> Increases height.
|
42
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
43
|
+
def initialize(size: SIZE_DEFAULT, **system_arguments)
|
44
|
+
@system_arguments = system_arguments
|
45
|
+
@system_arguments[:classes] = class_names(
|
46
|
+
@system_arguments[:classes],
|
40
47
|
"Progress",
|
41
48
|
SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)]
|
42
49
|
)
|
43
|
-
@
|
50
|
+
@system_arguments[:tag] = :span
|
44
51
|
|
45
52
|
end
|
46
53
|
|
@@ -50,16 +57,19 @@ module Primer
|
|
50
57
|
|
51
58
|
class Item < ViewComponent::Slot
|
52
59
|
include ClassNameHelper
|
53
|
-
attr_reader :
|
60
|
+
attr_reader :system_arguments
|
54
61
|
|
55
|
-
|
62
|
+
# @param percentage [Integer] Percentage completion of item.
|
63
|
+
# @param bg [Symbol] Color of item.
|
64
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
65
|
+
def initialize(percentage: 0, bg: :green, **system_arguments)
|
56
66
|
@percentage = percentage
|
57
|
-
@
|
67
|
+
@system_arguments = system_arguments
|
58
68
|
|
59
|
-
@
|
60
|
-
@
|
61
|
-
@
|
62
|
-
@
|
69
|
+
@system_arguments[:tag] = :span
|
70
|
+
@system_arguments[:bg] = bg
|
71
|
+
@system_arguments[:style] = "width: #{@percentage}%;"
|
72
|
+
@system_arguments[:classes] = class_names("Progress-item", @system_arguments[:classes])
|
63
73
|
end
|
64
74
|
end
|
65
75
|
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<%= render Primer::BaseComponent.new(**@system_arguments) do %>
|
2
|
+
<circle cx="8" cy="8" r="7" stroke="currentColor" stroke-opacity="0.25" stroke-width="2" vector-effect="non-scaling-stroke" />
|
3
|
+
<path d="M15 8a7.002 7.002 0 00-7-7" stroke="currentColor" stroke-width="2" stroke-linecap="round" vector-effect="non-scaling-stroke">
|
4
|
+
<animateTransform attributeName="transform" type="rotate" from="0 8 8" to="360 8 8" dur="1s" repeatCount="indefinite" />
|
5
|
+
</path>
|
6
|
+
<% end %>
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Primer
|
4
|
+
# Use Primer::SpinnerComponent to let users know that content is being loaded.
|
5
|
+
class SpinnerComponent < Primer::Component
|
6
|
+
|
7
|
+
DEFAULT_SIZE = :medium
|
8
|
+
SIZE_MAPPINGS = {
|
9
|
+
:small => 16,
|
10
|
+
DEFAULT_SIZE => 32,
|
11
|
+
:large => 64,
|
12
|
+
}.freeze
|
13
|
+
SIZE_OPTIONS = SIZE_MAPPINGS.keys
|
14
|
+
# Setting `box-sizing: content-box` allows consumers to add padding
|
15
|
+
# to the spinner without shrinking the icon
|
16
|
+
DEFAULT_STYLE = "box-sizing: content-box; color: var(--color-icon-primary);"
|
17
|
+
|
18
|
+
#
|
19
|
+
# @example 48|Default
|
20
|
+
# <%= render(Primer::SpinnerComponent.new) %>
|
21
|
+
#
|
22
|
+
# @example 32|Small
|
23
|
+
# <%= render(Primer::SpinnerComponent.new(size: :small)) %>
|
24
|
+
#
|
25
|
+
# @example 80|Large
|
26
|
+
# <%= render(Primer::SpinnerComponent.new(size: :large)) %>
|
27
|
+
#
|
28
|
+
# @param size [Symbol] <%= one_of(Primer::SpinnerComponent::SIZE_MAPPINGS) %>
|
29
|
+
def initialize(size: DEFAULT_SIZE, style: DEFAULT_STYLE, **system_arguments)
|
30
|
+
@system_arguments = system_arguments
|
31
|
+
@system_arguments[:tag] = :svg
|
32
|
+
@system_arguments[:width] = SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)]
|
33
|
+
@system_arguments[:height] = SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)]
|
34
|
+
@system_arguments[:viewBox] = "0 0 16 16"
|
35
|
+
@system_arguments[:fill] = :none
|
36
|
+
@system_arguments[:style] = DEFAULT_STYLE unless style.nil?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,14 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
+
# Component for rendering the status of an item.
|
4
5
|
class StateComponent < Primer::Component
|
5
|
-
# Component for rendering the status of an item
|
6
|
-
#
|
7
|
-
# title(string): (required) title attribute
|
8
|
-
# color(symbol): label background color
|
9
|
-
# size(symbol): label size
|
10
|
-
# counter(integer): counter value
|
11
|
-
# **args(hash): utility parameters for Primer::Classify
|
12
6
|
COLOR_DEFAULT = :default
|
13
7
|
COLOR_MAPPINGS = {
|
14
8
|
COLOR_DEFAULT => "",
|
@@ -28,18 +22,36 @@ module Primer
|
|
28
22
|
TAG_DEFAULT = :span
|
29
23
|
TAG_OPTIONS = [TAG_DEFAULT, :div, :a]
|
30
24
|
|
25
|
+
# @example 40|Default
|
26
|
+
# <%= render(Primer::StateComponent.new(title: "title")) { "State" } %>
|
27
|
+
#
|
28
|
+
# @example 40|Colors
|
29
|
+
# <%= render(Primer::StateComponent.new(title: "title")) { "Default" } %>
|
30
|
+
# <%= render(Primer::StateComponent.new(title: "title", color: :green)) { "Green" } %>
|
31
|
+
# <%= render(Primer::StateComponent.new(title: "title", color: :red)) { "Red" } %>
|
32
|
+
# <%= render(Primer::StateComponent.new(title: "title", color: :purple)) { "Purple" } %>
|
33
|
+
#
|
34
|
+
# @example 40|Sizes
|
35
|
+
# <%= render(Primer::StateComponent.new(title: "title")) { "Default" } %>
|
36
|
+
# <%= render(Primer::StateComponent.new(title: "title", size: :small)) { "Small" } %>
|
37
|
+
#
|
38
|
+
# @param title [String] `title` HTML attribute.
|
39
|
+
# @param color [Symbol] Background color. <%= one_of(Primer::StateComponent::COLOR_OPTIONS) %>
|
40
|
+
# @param tag [Symbol] HTML tag for element. <%= one_of(Primer::StateComponent::TAG_OPTIONS) %>
|
41
|
+
# @param size [Symbol] <%= one_of(Primer::StateComponent::SIZE_OPTIONS) %>
|
42
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
31
43
|
def initialize(
|
32
44
|
title:,
|
33
45
|
color: COLOR_DEFAULT,
|
34
46
|
tag: TAG_DEFAULT,
|
35
47
|
size: SIZE_DEFAULT,
|
36
|
-
**
|
48
|
+
**system_arguments
|
37
49
|
)
|
38
|
-
@
|
39
|
-
@
|
40
|
-
@
|
41
|
-
@
|
42
|
-
@
|
50
|
+
@system_arguments = system_arguments
|
51
|
+
@system_arguments[:title] = title
|
52
|
+
@system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_DEFAULT)
|
53
|
+
@system_arguments[:classes] = class_names(
|
54
|
+
@system_arguments[:classes],
|
43
55
|
"State",
|
44
56
|
COLOR_MAPPINGS[fetch_or_fallback(COLOR_OPTIONS, color, COLOR_DEFAULT)],
|
45
57
|
SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)]
|
@@ -47,7 +59,7 @@ module Primer
|
|
47
59
|
end
|
48
60
|
|
49
61
|
def call
|
50
|
-
render(Primer::BaseComponent.new(**@
|
62
|
+
render(Primer::BaseComponent.new(**@system_arguments)) { content }
|
51
63
|
end
|
52
64
|
end
|
53
65
|
end
|