primer_view_components 0.0.10 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -1
- data/README.md +2 -175
- data/app/components/primer/avatar_component.rb +11 -11
- data/app/components/primer/base_component.rb +101 -9
- data/app/components/primer/blankslate_component.html.erb +1 -1
- data/app/components/primer/blankslate_component.rb +6 -6
- 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 +26 -9
- data/app/components/primer/component.rb +1 -0
- data/app/components/primer/counter_component.rb +16 -15
- 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 +42 -12
- 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 +37 -14
- data/app/components/primer/layout_component.html.erb +1 -1
- data/app/components/primer/layout_component.rb +22 -5
- data/app/components/primer/link_component.rb +17 -7
- data/app/components/primer/octicon_component.rb +20 -7
- 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 +1 -1
- data/app/components/primer/spinner_component.rb +12 -11
- 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/lib/primer/classify.rb +7 -6
- data/lib/primer/view_components/version.rb +1 -1
- metadata +3 -3
@@ -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
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= render Primer::BaseComponent.new(**@
|
1
|
+
<%= render Primer::BaseComponent.new(**@system_arguments) do %>
|
2
2
|
<circle cx="8" cy="8" r="7" stroke="currentColor" stroke-opacity="0.25" stroke-width="2" vector-effect="non-scaling-stroke" />
|
3
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
4
|
<animateTransform attributeName="transform" type="rotate" from="0 8 8" to="360 8 8" dur="1s" repeatCount="indefinite" />
|
@@ -11,6 +11,9 @@ module Primer
|
|
11
11
|
:large => 64,
|
12
12
|
}.freeze
|
13
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);"
|
14
17
|
|
15
18
|
#
|
16
19
|
# @example 48|Default
|
@@ -22,17 +25,15 @@ module Primer
|
|
22
25
|
# @example 80|Large
|
23
26
|
# <%= render(Primer::SpinnerComponent.new(size: :large)) %>
|
24
27
|
#
|
25
|
-
# @param size [Symbol]
|
26
|
-
def initialize(size: DEFAULT_SIZE, **
|
27
|
-
@
|
28
|
-
@
|
29
|
-
@
|
30
|
-
@
|
31
|
-
@
|
32
|
-
@
|
33
|
-
|
34
|
-
# to the spinner without shrinking the icon
|
35
|
-
@kwargs[:style] = "box-sizing: content-box; color: var(--color-icon-primary);"
|
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?
|
36
37
|
end
|
37
38
|
end
|
38
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
|
@@ -1,16 +1,16 @@
|
|
1
|
-
<%= render Primer::BaseComponent.new(**@
|
1
|
+
<%= render Primer::BaseComponent.new(**@system_arguments) do %>
|
2
2
|
<% if heading.present? %>
|
3
|
-
<%= render Primer::BaseComponent.new(**heading.
|
3
|
+
<%= render Primer::BaseComponent.new(**heading.system_arguments) do %>
|
4
4
|
<%= heading.content %>
|
5
5
|
<% end %>
|
6
6
|
<% end %>
|
7
7
|
<% if actions.present? %>
|
8
|
-
<%= render Primer::BaseComponent.new(**actions.
|
8
|
+
<%= render Primer::BaseComponent.new(**actions.system_arguments) do %>
|
9
9
|
<%= actions.content %>
|
10
10
|
<% end %>
|
11
11
|
<% end %>
|
12
12
|
<% if description.present? %>
|
13
|
-
<%= render Primer::BaseComponent.new(**description.
|
13
|
+
<%= render Primer::BaseComponent.new(**description.system_arguments) do %>
|
14
14
|
<%= description.content %>
|
15
15
|
<% end %>
|
16
16
|
<% end %>
|
@@ -1,26 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# This component consists of a .Subhead container, which has a light gray bottom border.
|
4
|
-
|
5
|
-
# Use a heading element whenever possible as they can be
|
6
|
-
# used as navigation for assistive technologies, and avoid skipping levels.
|
7
|
-
|
8
|
-
# ## Basic example
|
9
|
-
|
10
|
-
# The `Primer::SubheadComponent` can take the following arguments:
|
11
|
-
|
12
|
-
# 1. `heading` (string). The heading to be rendered.
|
13
|
-
# 2. `actions` (content). Slot to render any actions to the right of heading.
|
14
|
-
# 3. `description` (string). Slot to render description under the heading.
|
15
|
-
|
16
|
-
# ```erb
|
17
|
-
# <%= Primer::SubheadComponent.new(heading: "Hello world")) do |component| %>
|
18
|
-
# <% component.slot(:actions) do %>
|
19
|
-
# My Actions
|
20
|
-
# <% end %>
|
21
|
-
# <% end %>
|
22
|
-
# ```
|
23
3
|
module Primer
|
4
|
+
# Use the Subhead component for page headings.
|
24
5
|
class SubheadComponent < Primer::Component
|
25
6
|
include ViewComponent::Slotable
|
26
7
|
|
@@ -28,18 +9,58 @@ module Primer
|
|
28
9
|
with_slot :actions, class_name: "Actions"
|
29
10
|
with_slot :description, class_name: "Description"
|
30
11
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
12
|
+
# @example 95|Default
|
13
|
+
# <%= render(Primer::SubheadComponent.new) do |component| %>
|
14
|
+
# <% component.slot(:heading) do %>
|
15
|
+
# My Heading
|
16
|
+
# <% end %>
|
17
|
+
# <% component.slot(:description) do %>
|
18
|
+
# My Description
|
19
|
+
# <% end %>
|
20
|
+
# <% end %>
|
21
|
+
#
|
22
|
+
# @example 95|Without border
|
23
|
+
# <%= render(Primer::SubheadComponent.new(hide_border: true)) do |component| %>
|
24
|
+
# <% component.slot(:heading) do %>
|
25
|
+
# My Heading
|
26
|
+
# <% end %>
|
27
|
+
# <% component.slot(:description) do %>
|
28
|
+
# My Description
|
29
|
+
# <% end %>
|
30
|
+
# <% end %>
|
31
|
+
#
|
32
|
+
# @example 95|With actions
|
33
|
+
# <%= render(Primer::SubheadComponent.new) do |component| %>
|
34
|
+
# <% component.slot(:heading) do %>
|
35
|
+
# My Heading
|
36
|
+
# <% end %>
|
37
|
+
# <% component.slot(:description) do %>
|
38
|
+
# My Description
|
39
|
+
# <% end %>
|
40
|
+
# <% component.slot(:actions) do %>
|
41
|
+
# <%= render(
|
42
|
+
# Primer::ButtonComponent.new(
|
43
|
+
# tag: :a, href: "http://www.google.com", button_type: :danger
|
44
|
+
# )
|
45
|
+
# ) { "Action" } %>
|
46
|
+
# <% end %>
|
47
|
+
# <% end %>
|
48
|
+
#
|
49
|
+
# @param spacious [Boolean] Whether to add spacing to the Subhead.
|
50
|
+
# @param hide_border [Boolean] Whether to hide the border under the heading.
|
51
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
52
|
+
def initialize(spacious: false, hide_border: false, **system_arguments)
|
53
|
+
@system_arguments = system_arguments
|
54
|
+
|
55
|
+
@system_arguments[:tag] = :div
|
56
|
+
@system_arguments[:classes] =
|
36
57
|
class_names(
|
37
|
-
@
|
58
|
+
@system_arguments[:classes],
|
38
59
|
"Subhead hx_Subhead--responsive",
|
39
60
|
"Subhead--spacious": spacious,
|
40
61
|
"border-bottom-0": hide_border
|
41
62
|
)
|
42
|
-
@
|
63
|
+
@system_arguments[:mb] ||= hide_border ? 0 : nil
|
43
64
|
end
|
44
65
|
|
45
66
|
def render?
|
@@ -49,13 +70,15 @@ module Primer
|
|
49
70
|
class Heading < ViewComponent::Slot
|
50
71
|
include ClassNameHelper
|
51
72
|
|
52
|
-
attr_reader :
|
73
|
+
attr_reader :system_arguments
|
53
74
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
@
|
58
|
-
|
75
|
+
# @param danger [Boolean] Whether to style the heading as dangerous.
|
76
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
77
|
+
def initialize(danger: false, **system_arguments)
|
78
|
+
@system_arguments = system_arguments
|
79
|
+
@system_arguments[:tag] ||= :div
|
80
|
+
@system_arguments[:classes] = class_names(
|
81
|
+
@system_arguments[:classes],
|
59
82
|
"Subhead-heading",
|
60
83
|
"Subhead-heading--danger": danger
|
61
84
|
)
|
@@ -65,24 +88,26 @@ module Primer
|
|
65
88
|
class Actions < ViewComponent::Slot
|
66
89
|
include ClassNameHelper
|
67
90
|
|
68
|
-
attr_reader :
|
91
|
+
attr_reader :system_arguments
|
69
92
|
|
70
|
-
|
71
|
-
|
72
|
-
@
|
73
|
-
@
|
93
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
94
|
+
def initialize(**system_arguments)
|
95
|
+
@system_arguments = system_arguments
|
96
|
+
@system_arguments[:tag] = :div
|
97
|
+
@system_arguments[:classes] = class_names(@system_arguments[:classes], "Subhead-actions")
|
74
98
|
end
|
75
99
|
end
|
76
100
|
|
77
101
|
class Description < ViewComponent::Slot
|
78
102
|
include ClassNameHelper
|
79
103
|
|
80
|
-
attr_reader :
|
104
|
+
attr_reader :system_arguments
|
81
105
|
|
82
|
-
|
83
|
-
|
84
|
-
@
|
85
|
-
@
|
106
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
107
|
+
def initialize(**system_arguments)
|
108
|
+
@system_arguments = system_arguments
|
109
|
+
@system_arguments[:tag] = :div
|
110
|
+
@system_arguments[:classes] = class_names(@system_arguments[:classes], "Subhead-description")
|
86
111
|
end
|
87
112
|
end
|
88
113
|
end
|
@@ -1,14 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
+
# The Text component is a wrapper component that will apply typography styles to the text inside.
|
4
5
|
class TextComponent < Primer::Component
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
# @example 70|Default
|
7
|
+
# <%= render(Primer::TextComponent.new(tag: :p, font_weight: :bold)) { "Bold Text" } %>
|
8
|
+
# <%= render(Primer::TextComponent.new(tag: :p, color: :red_5)) { "Red Text" } %>
|
9
|
+
#
|
10
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
11
|
+
def initialize(**system_arguments)
|
12
|
+
@system_arguments = system_arguments
|
13
|
+
@system_arguments[:tag] ||= :span
|
8
14
|
end
|
9
15
|
|
10
16
|
def call
|
11
|
-
render(Primer::BaseComponent.new(**@
|
17
|
+
render(Primer::BaseComponent.new(**@system_arguments)) { content }
|
12
18
|
end
|
13
19
|
end
|
14
20
|
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
<%= render Primer::BaseComponent.new(**
|
1
|
+
<%= render Primer::BaseComponent.new(**system_arguments) do %>
|
2
2
|
<% if avatar %>
|
3
|
-
<%= render Primer::AvatarComponent.new(alt: avatar.alt, src: avatar.src, size: avatar.size, square: avatar.square, **avatar.
|
3
|
+
<%= render Primer::AvatarComponent.new(alt: avatar.alt, src: avatar.src, size: avatar.size, square: avatar.square, **avatar.system_arguments) %>
|
4
4
|
<% end %>
|
5
5
|
|
6
6
|
<% if badge %>
|
7
|
-
<%= render Primer::BaseComponent.new(**badge.
|
7
|
+
<%= render Primer::BaseComponent.new(**badge.system_arguments) do %>
|
8
8
|
<%= octicon badge.icon %>
|
9
9
|
<% end %>
|
10
10
|
<% end %>
|
11
11
|
|
12
12
|
<% if body %>
|
13
|
-
<%= render Primer::BaseComponent.new(**body.
|
13
|
+
<%= render Primer::BaseComponent.new(**body.system_arguments) do %>
|
14
14
|
<%= body.content %>
|
15
15
|
<% end %>
|
16
16
|
<% end %>
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
+
# Use `TimelineItem` to display items on a vertical timeline, connected by badge elements.
|
4
5
|
class TimelineItemComponent < Primer::Component
|
5
6
|
include ViewComponent::Slotable
|
6
7
|
|
@@ -8,14 +9,26 @@ module Primer
|
|
8
9
|
with_slot :badge, class_name: "Badge"
|
9
10
|
with_slot :body, class_name: "Body"
|
10
11
|
|
11
|
-
attr_reader :
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
attr_reader :system_arguments
|
13
|
+
|
14
|
+
# @example 75|Default
|
15
|
+
# <div style="padding-left: 60px">
|
16
|
+
# <%= render(Primer::TimelineItemComponent.new) do |component| %>
|
17
|
+
# <% component.slot(:avatar, src: "https://github.com/github.png", alt: "github") %>
|
18
|
+
# <% component.slot(:badge, bg: :green, color: :white, icon: :check) %>
|
19
|
+
# <% component.slot(:body) { "Success!" } %>
|
20
|
+
# <% end %>
|
21
|
+
# </div>
|
22
|
+
#
|
23
|
+
# @param condensed [Boolean] Reduce the vertical padding and remove the background from the badge item. Most commonly used in commits.
|
24
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
25
|
+
def initialize(condensed: false, **system_arguments)
|
26
|
+
@system_arguments = system_arguments
|
27
|
+
@system_arguments[:tag] = :div
|
28
|
+
@system_arguments[:classes] = class_names(
|
16
29
|
"TimelineItem",
|
17
30
|
condensed ? "TimelineItem--condensed" : "",
|
18
|
-
|
31
|
+
system_arguments[:classes]
|
19
32
|
)
|
20
33
|
end
|
21
34
|
|
@@ -24,44 +37,55 @@ module Primer
|
|
24
37
|
end
|
25
38
|
|
26
39
|
class Avatar < Primer::Slot
|
27
|
-
attr_reader :
|
28
|
-
|
40
|
+
attr_reader :system_arguments, :alt, :src, :size, :square
|
41
|
+
|
42
|
+
# @param alt [String] Alt text for avatar image.
|
43
|
+
# @param src [String] Src attribute for avatar image.
|
44
|
+
# @param size [Integer] Image size.
|
45
|
+
# @param square [Boolean] Whether to round the edges of the image.
|
46
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
47
|
+
def initialize(alt: nil, src: nil, size: 40, square: true, **system_arguments)
|
29
48
|
@alt = alt
|
30
49
|
@src = src
|
31
50
|
@size = size
|
32
51
|
@square = square
|
33
52
|
|
34
|
-
@
|
35
|
-
@
|
36
|
-
@
|
53
|
+
@system_arguments = system_arguments
|
54
|
+
@system_arguments[:tag] = :div
|
55
|
+
@system_arguments[:classes] = class_names(
|
37
56
|
"TimelineItem-avatar",
|
38
|
-
|
57
|
+
system_arguments[:classes]
|
39
58
|
)
|
40
59
|
end
|
41
60
|
end
|
42
61
|
|
43
62
|
class Badge < Primer::Slot
|
44
|
-
attr_reader :
|
45
|
-
|
63
|
+
attr_reader :system_arguments, :icon
|
64
|
+
|
65
|
+
# @param icon [String] Name of [Octicon](https://primer.style/octicons/) to use.
|
66
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
67
|
+
def initialize(icon: nil, **system_arguments)
|
46
68
|
@icon = icon
|
47
69
|
|
48
|
-
@
|
49
|
-
@
|
50
|
-
@
|
70
|
+
@system_arguments = system_arguments
|
71
|
+
@system_arguments[:tag] = :div
|
72
|
+
@system_arguments[:classes] = class_names(
|
51
73
|
"TimelineItem-badge",
|
52
|
-
|
74
|
+
system_arguments[:classes]
|
53
75
|
)
|
54
76
|
end
|
55
77
|
end
|
56
78
|
|
57
79
|
class Body < Primer::Slot
|
58
|
-
attr_reader :
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
@
|
80
|
+
attr_reader :system_arguments
|
81
|
+
|
82
|
+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
83
|
+
def initialize(**system_arguments)
|
84
|
+
@system_arguments = system_arguments
|
85
|
+
@system_arguments[:tag] = :div
|
86
|
+
@system_arguments[:classes] = class_names(
|
63
87
|
"TimelineItem-body",
|
64
|
-
|
88
|
+
system_arguments[:classes]
|
65
89
|
)
|
66
90
|
end
|
67
91
|
end
|