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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -37
  3. data/README.md +2 -161
  4. data/app/components/primer/avatar_component.rb +22 -11
  5. data/app/components/primer/base_component.rb +56 -11
  6. data/app/components/primer/blankslate_component.html.erb +2 -2
  7. data/app/components/primer/blankslate_component.rb +71 -116
  8. data/app/components/primer/border_box_component.html.erb +5 -5
  9. data/app/components/primer/border_box_component.rb +45 -33
  10. data/app/components/primer/box_component.rb +6 -4
  11. data/app/components/primer/breadcrumb_component.html.erb +2 -2
  12. data/app/components/primer/breadcrumb_component.rb +23 -30
  13. data/app/components/primer/button_component.rb +28 -11
  14. data/app/components/primer/component.rb +1 -0
  15. data/app/components/primer/counter_component.rb +14 -9
  16. data/app/components/primer/details_component.html.erb +1 -1
  17. data/app/components/primer/details_component.rb +18 -18
  18. data/app/components/primer/dropdown_menu_component.html.erb +1 -1
  19. data/app/components/primer/dropdown_menu_component.rb +6 -6
  20. data/app/components/primer/flash_component.html.erb +2 -2
  21. data/app/components/primer/flash_component.rb +43 -13
  22. data/app/components/primer/flex_component.rb +5 -5
  23. data/app/components/primer/flex_item_component.rb +5 -5
  24. data/app/components/primer/heading_component.rb +4 -4
  25. data/app/components/primer/label_component.rb +25 -8
  26. data/app/components/primer/layout_component.html.erb +1 -1
  27. data/app/components/primer/layout_component.rb +23 -6
  28. data/app/components/primer/link_component.rb +17 -7
  29. data/app/components/primer/octicon_component.rb +23 -5
  30. data/app/components/primer/popover_component.html.erb +1 -1
  31. data/app/components/primer/popover_component.rb +61 -23
  32. data/app/components/primer/progress_bar_component.html.erb +2 -2
  33. data/app/components/primer/progress_bar_component.rb +40 -30
  34. data/app/components/primer/slot.rb +1 -0
  35. data/app/components/primer/spinner_component.html.erb +6 -0
  36. data/app/components/primer/spinner_component.rb +39 -0
  37. data/app/components/primer/state_component.rb +26 -14
  38. data/app/components/primer/subhead_component.html.erb +4 -4
  39. data/app/components/primer/subhead_component.rb +68 -43
  40. data/app/components/primer/text_component.rb +10 -4
  41. data/app/components/primer/timeline_item_component.html.erb +4 -4
  42. data/app/components/primer/timeline_item_component.rb +48 -24
  43. data/app/components/primer/underline_nav_component.html.erb +1 -1
  44. data/app/components/primer/underline_nav_component.rb +5 -5
  45. data/app/components/primer/view_components.rb +1 -0
  46. data/lib/primer/classify.rb +2 -4
  47. data/lib/primer/view_components/version.rb +1 -1
  48. metadata +22 -6
@@ -1,9 +1,9 @@
1
- <%= render Primer::BaseComponent.new(**@kwargs) do %>
1
+ <%= render Primer::BaseComponent.new(**@system_arguments) do %>
2
2
  <% if @icon.present? %>
3
3
  <%= render(Primer::OcticonComponent.new(
4
4
  icon: @icon,
5
5
  size: @icon_size,
6
- class: "blankslate-icon"
6
+ classes: "blankslate-icon"
7
7
  )) %>
8
8
  <% end %>
9
9
 
@@ -1,118 +1,73 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
- # Blankslates are for when there is a lack of content within a page or section. Use them as placeholders to tell users why something isn't there.
5
- #
6
- # ## Basic example
7
- #
8
- # The `Primer::BlankslateComponent` supports the following arguments to add a basic blankslate:
9
- #
10
- # 1. `title` (`String` optional). Text that appears in a larger bold font.
11
- # 2. `description` (`String` optional). Text that appears below the title. Typically a whole sentence.
12
- #
13
- # ```ruby
14
- # <%= render Primer::BlankslateComponent.new(
15
- # title: "Title",
16
- # description: "Description",
17
- # ) %>
18
- # ```
19
- #
20
- # ## Icon or graphic (optional)
21
- #
22
- # Add an `icon` to give additional context. Please refer to the [Octicons](https://primer.style/octicons/) documentation to choose an icon.
23
- #
24
- # ```ruby
25
- # <%= render Primer::BlankslateComponent.new(
26
- # icon: "octoface",
27
- # title: "Title",
28
- # description: "Description",
29
- # ) %>
30
- # ```
31
- #
32
- # Alternatively you can also add a graphic by providing a path (`image_src`) to an image instead.Also, make sure to add an alternative description (`image_alt`). It will be used for the `alt` tag.
33
- #
34
- # ```ruby
35
- # <%= render Primer::BlankslateComponent.new(
36
- # image_src: "file.svg",
37
- # image_alt: "Description of the image",
38
- # title: "Title",
39
- # description: "Description",
40
- # ) %>
41
- # ```
42
- #
43
- # Both icon and graphic will appear above the title.
44
- #
45
- #
46
- # ## Custom content (optional)
47
- #
48
- # You can add any custom content that typically is used instead of the description:
49
- #
50
- # ```ruby
51
- # <%= render Primer::BlankslateComponent.new(
52
- # icon: "octoface",
53
- # title: "Title",
54
- # ) do %>
55
- # <p>Your custom content here</p>
56
- # <% end %>
57
- # ```
58
- #
59
- # ## Action button (optional)
60
- #
61
- # You can provide an action button to help users replace the blankslate. The button will appear below the description and custom content. It takes the following arguments:
62
- #
63
- # - `button_text` (`String` optional). The text of the button.
64
- # - `button_url` (`String` optional). The URL where the user will be taken after clicking the button.
65
- #
66
- # ```ruby
67
- # <%= render Primer::BlankslateComponent.new(
68
- # icon: "book",
69
- # title: "Welcome to the mona wiki!",
70
- # description: "Wikis provide a place in your repository to lay out the roadmap of your project, show the current status, and document software better, together.",
71
- #
72
- # button_text: "Create the first page",
73
- # button_url: "https://github.com/monalisa/mona/wiki/_new",
74
- # ) %>
75
- # ```
76
- #
77
- # ## Link (optional)
78
- #
79
- # Add an additional link to help users learn more about a feature. The link will be shown at the very bottom:
80
- #
81
- # - `link_text` (`String` optional). The text of the link.
82
- # - `link_url` (`String` optional). The URL where the user will be taken after clicking the link.
83
- #
84
- # ```ruby
85
- # <%= render Primer::BlankslateComponent.new(
86
- # icon: "book",
87
- # title: "Welcome to the mona wiki!",
88
- # description: "Wikis provide a place in your repository to lay out the roadmap of your project, show the current status, and document software better, together.",
89
- # button_text: "Create the first page",
90
- # button_url: "https://github.com/monalisa/mona/wiki/_new",
91
- # link_text: "Learn more about wikis",
92
- # link_url: "https://docs.github.com/en/github/building-a-strong-community/about-wikis",
93
- # ) %>
94
- # ```
95
- #
96
- # ## Variations (optional)
97
- #
98
- # There are a few variations of how the Blankslate appears:
99
- #
100
- # - `narrow` (`Boolean` optional). Adds a maximum width.
101
- # - `large` (`Boolean` optional). Increaeses the font size.
102
- # - `spacious` (`Boolean` optional). Adds extra padding.
103
- #
104
- # ```ruby
105
- # <%= render Primer::BlankslateComponent.new(
106
- # icon: "book",
107
- # title: "Welcome to the mona wiki!",
108
- # description: "Wikis provide a place in your repository to lay out the roadmap of your project, show the current status, and document software better, together.",
109
- #
110
- # narrow: true,
111
- # large: true,
112
- # spacious: true,
113
- # ) %>
114
- # ```
4
+ # Use Primer::BlankslateComponent when there is a lack of content within a page or section. Use as placeholder to tell users why something isn't there.
115
5
  class BlankslateComponent < Primer::Component
6
+ #
7
+ # @example 150|Basic
8
+ # <%= render Primer::BlankslateComponent.new(
9
+ # title: "Title",
10
+ # description: "Description",
11
+ # ) %>
12
+ #
13
+ # @example 190|Icon|Add an `icon` to give additional context. Refer to the [Octicons](https://primer.style/octicons/) documentation to choose an icon.
14
+ # <%= render Primer::BlankslateComponent.new(
15
+ # icon: "octoface",
16
+ # title: "Title",
17
+ # description: "Description",
18
+ # ) %>
19
+ #
20
+ # @example 150|Custom content|Pass custom content as a block in place of `description`.
21
+ # <%= render Primer::BlankslateComponent.new(
22
+ # title: "Title",
23
+ # ) do %>
24
+ # <em>Your custom content here</em>
25
+ # <% end %>
26
+ #
27
+ # @example 270|Action button|Provide a button to guide users to take action from the blankslate. The button appears below the description and custom content.
28
+ # <%= render Primer::BlankslateComponent.new(
29
+ # icon: "book",
30
+ # title: "Welcome to the mona wiki!",
31
+ # description: "Wikis provide a place in your repository to lay out the roadmap of your project, show the current status, and document software better, together.",
32
+ #
33
+ # button_text: "Create the first page",
34
+ # button_url: "https://github.com/monalisa/mona/wiki/_new",
35
+ # ) %>
36
+ #
37
+ # @example 225|Link|Add an additional link to help users learn more about a feature. The link will be shown at the very bottom:
38
+ # <%= render Primer::BlankslateComponent.new(
39
+ # icon: "book",
40
+ # title: "Welcome to the mona wiki!",
41
+ # description: "Wikis provide a place in your repository to lay out the roadmap of your project, show the current status, and document software better, together.",
42
+ # link_text: "Learn more about wikis",
43
+ # link_url: "https://docs.github.com/en/github/building-a-strong-community/about-wikis",
44
+ # ) %>
45
+ #
46
+ # @example 340|Variations|There are a few variations of how the Blankslate appears: `narrow` adds a maximum width, `large` increases the font size, and `spacious` adds extra padding.
47
+ # <%= render Primer::BlankslateComponent.new(
48
+ # icon: "book",
49
+ # title: "Welcome to the mona wiki!",
50
+ # description: "Wikis provide a place in your repository to lay out the roadmap of your project, show the current status, and document software better, together.",
51
+ # narrow: true,
52
+ # large: true,
53
+ # spacious: true,
54
+ # ) %>
55
+ #
56
+ # @param title [String] Text that appears in a larger bold font.
57
+ # @param title_tag [Symbol] HTML tag to use for title.
58
+ # @param icon [String] Octicon icon to use at top of component.
59
+ # @param icon_size [Symbol] <%= one_of(Primer::OcticonComponent::SIZE_MAPPINGS) %>
60
+ # @param image_src [String] Image to display.
61
+ # @param image_alt [String] Alt text for image.
62
+ # @param description [String] Text that appears below the title. Typically a whole sentence.
63
+ # @param button_text [String] The text of the button.
64
+ # @param button_url [String] The URL where the user will be taken after clicking the button.
65
+ # @param button_classes [String] Classes to apply to action button
66
+ # @param link_text [String] The text of the link.
67
+ # @param link_url [String] The URL where the user will be taken after clicking the link.
68
+ # @param narrow [Boolean] Adds a maximum width.
69
+ # @param large [Boolean] Increases the font size.
70
+ # @param spacious [Boolean] Adds extra padding.
116
71
  def initialize(
117
72
  title: "",
118
73
  title_tag: :h3,
@@ -132,12 +87,12 @@ module Primer
132
87
  large: false,
133
88
  spacious: false,
134
89
 
135
- **kwargs
90
+ **system_arguments
136
91
  )
137
- @kwargs = kwargs
138
- @kwargs[:tag] ||= :div
139
- @kwargs[:classes] = class_names(
140
- @kwargs[:classes],
92
+ @system_arguments = system_arguments
93
+ @system_arguments[:tag] ||= :div
94
+ @system_arguments[:classes] = class_names(
95
+ @system_arguments[:classes],
141
96
  "blankslate",
142
97
  "blankslate-narrow": narrow,
143
98
  "blankslate-large": large,
@@ -1,25 +1,25 @@
1
- <%= render Primer::BaseComponent.new(**@kwargs) do %>
1
+ <%= render Primer::BaseComponent.new(**@system_arguments) do %>
2
2
  <% if header %>
3
- <%= render Primer::BaseComponent.new(**header.kwargs) do %>
3
+ <%= render Primer::BaseComponent.new(**header.system_arguments) do %>
4
4
  <%= header.content %>
5
5
  <% end %>
6
6
  <% end %>
7
7
  <% if body %>
8
- <%= render Primer::BaseComponent.new(**body.kwargs) do %>
8
+ <%= render Primer::BaseComponent.new(**body.system_arguments) do %>
9
9
  <%= body.content %>
10
10
  <% end %>
11
11
  <% end %>
12
12
  <% if rows.any? %>
13
13
  <ul>
14
14
  <% rows.each do |row| %>
15
- <%= render Primer::BaseComponent.new(**row.kwargs) do %>
15
+ <%= render Primer::BaseComponent.new(**row.system_arguments) do %>
16
16
  <%= row.content %>
17
17
  <% end %>
18
18
  <% end %>
19
19
  </ul>
20
20
  <% end %>
21
21
  <% if footer %>
22
- <%= render Primer::BaseComponent.new(**footer.kwargs) do %>
22
+ <%= render Primer::BaseComponent.new(**footer.system_arguments) do %>
23
23
  <%= footer.content %>
24
24
  <% end %>
25
25
  <% end %>
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
+ # BorderBox is a Box component with a border.
4
5
  class BorderBoxComponent < Primer::Component
5
6
  include ViewComponent::Slotable
6
7
 
@@ -9,12 +10,23 @@ module Primer
9
10
  with_slot :footer, class_name: "Footer"
10
11
  with_slot :row, collection: true, class_name: "Row"
11
12
 
12
- def initialize(**kwargs)
13
- @kwargs = kwargs
14
- @kwargs[:tag] = :div
15
- @kwargs[:classes] = class_names(
13
+ # @example 350|Header, body, rows, and footer
14
+ # <%= render(Primer::BorderBoxComponent.new) do |component|
15
+ # component.slot(:header) { "Header" }
16
+ # component.slot(:body) { "Body" }
17
+ # component.slot(:row) { "Row one" }
18
+ # component.slot(:row) { "Row two" }
19
+ # component.slot(:row) { "Row three" }
20
+ # component.slot(:footer) { "Footer" }
21
+ # end %>
22
+ #
23
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
24
+ def initialize(**system_arguments)
25
+ @system_arguments = system_arguments
26
+ @system_arguments[:tag] = :div
27
+ @system_arguments[:classes] = class_names(
16
28
  "Box",
17
- kwargs[:classes]
29
+ system_arguments[:classes]
18
30
  )
19
31
  end
20
32
 
@@ -23,53 +35,53 @@ module Primer
23
35
  end
24
36
 
25
37
  class Header < Primer::Slot
26
-
27
- attr_reader :kwargs
28
- def initialize(**kwargs)
29
- @kwargs = kwargs
30
- @kwargs[:tag] = :div
31
- @kwargs[:classes] = class_names(
38
+ attr_reader :system_arguments
39
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
40
+ def initialize(**system_arguments)
41
+ @system_arguments = system_arguments
42
+ @system_arguments[:tag] = :div
43
+ @system_arguments[:classes] = class_names(
32
44
  "Box-header",
33
- kwargs[:classes]
45
+ system_arguments[:classes]
34
46
  )
35
47
  end
36
48
  end
37
49
 
38
50
  class Body < Primer::Slot
39
-
40
- attr_reader :kwargs
41
- def initialize(**kwargs)
42
- @kwargs = kwargs
43
- @kwargs[:tag] = :div
44
- @kwargs[:classes] = class_names(
51
+ attr_reader :system_arguments
52
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
53
+ def initialize(**system_arguments)
54
+ @system_arguments = system_arguments
55
+ @system_arguments[:tag] = :div
56
+ @system_arguments[:classes] = class_names(
45
57
  "Box-body",
46
- kwargs[:classes]
58
+ system_arguments[:classes]
47
59
  )
48
60
  end
49
61
  end
50
62
 
51
63
  class Footer < Primer::Slot
52
-
53
- attr_reader :kwargs
54
- def initialize(**kwargs)
55
- @kwargs = kwargs
56
- @kwargs[:tag] = :div
57
- @kwargs[:classes] = class_names(
64
+ attr_reader :system_arguments
65
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
66
+ def initialize(**system_arguments)
67
+ @system_arguments = system_arguments
68
+ @system_arguments[:tag] = :div
69
+ @system_arguments[:classes] = class_names(
58
70
  "Box-footer",
59
- kwargs[:classes]
71
+ system_arguments[:classes]
60
72
  )
61
73
  end
62
74
  end
63
75
 
64
76
  class Row < Primer::Slot
65
-
66
- attr_reader :kwargs
67
- def initialize(**kwargs)
68
- @kwargs = kwargs
69
- @kwargs[:tag] = :li
70
- @kwargs[:classes] = class_names(
77
+ attr_reader :system_arguments
78
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
79
+ def initialize(**system_arguments)
80
+ @system_arguments = system_arguments
81
+ @system_arguments[:tag] = :li
82
+ @system_arguments[:classes] = class_names(
71
83
  "Box-row",
72
- kwargs[:classes]
84
+ system_arguments[:classes]
73
85
  )
74
86
  end
75
87
  end
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
+ # A basic wrapper component for most layout related needs.
4
5
  class BoxComponent < Primer::Component
5
- def initialize(**kwargs)
6
- @kwargs = kwargs
7
- @kwargs[:tag] = :div
6
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
7
+ def initialize(**system_arguments)
8
+ @system_arguments = system_arguments
9
+ @system_arguments[:tag] = :div
8
10
  end
9
11
 
10
12
  def call
11
- render(Primer::BaseComponent.new(**@kwargs)) { content }
13
+ render(Primer::BaseComponent.new(**@system_arguments)) { content }
12
14
  end
13
15
  end
14
16
  end
@@ -1,8 +1,8 @@
1
- <%= render Primer::BaseComponent.new(**@kwargs) do %>
1
+ <%= render Primer::BaseComponent.new(**@system_arguments) do %>
2
2
  <ol>
3
3
  <% items.each do |item| %>
4
4
  <%# The <li> and <a> need to be on the same line to prevent unwanted whitespace %>
5
- <%= render Primer::BaseComponent.new(**item.kwargs) do %><%- if item.href.present? %><a href="<%= item.href %>"><%= item.content %></a><%- else %><%= item.content %><%- end %><%- end %>
5
+ <%= render Primer::BaseComponent.new(**item.system_arguments) do %><%- if item.href.present? %><a href="<%= item.href %>"><%= item.content %></a><%- else %><%= item.content %><%- end %><%- end %>
6
6
  <% end %>
7
7
  </ol>
8
8
  <% end %>
@@ -1,51 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ##
4
- # Breadcrumbs are used to display page hierarchy within a section of the site. All of the items in the breadcrumb "trail" are links except for the final item which is a plain string indicating the current page.
5
- #
6
- # ## Example
7
- #
8
- # The `Primer::BreadcrumbComponent` 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 can accept the following parameters:
9
- #
10
- # 1. `href` (string). The URL to link to.
11
- # 2. `selected` (boolean, default=false). Flag indicating whether or not the item is selected and not rendered as a link.
12
- #
13
- # Note that if if both `href` and `selected: true` are passed in, `href` will be ignored and the item will not be rendered as a link.
14
- #
15
- # ```ruby
16
- # <%= render(Primer::BreadcrumbComponent.new) do |component| %>
17
- # <% component.slot(:item, href: "/") do %>Home<% end %>
18
- # <% component.slot(:item, href: "/about") do %>About<% end %>
19
- # <% component.slot(:item, selected: true) do %>Team<% end %>
20
- # <% end %>
21
- # ```
22
- ##
23
3
  module Primer
4
+ # Use breadcrumbs to display page hierarchy within a section of the site. All of the items in the breadcrumb "trail" are links except for the final item, which is a plain string indicating the current page.
24
5
  class BreadcrumbComponent < Primer::Component
25
6
  include ViewComponent::Slotable
26
7
 
27
8
  with_slot :item, collection: true, class_name: "BreadcrumbItem"
28
9
 
29
- def initialize(**kwargs)
30
- @kwargs = kwargs
31
- @kwargs[:tag] = :nav
32
- @kwargs[:aria] = { label: "Breadcrumb" }
10
+ # @example 40|Basic
11
+ # <%= render(Primer::BreadcrumbComponent.new) do |component| %>
12
+ # <% component.slot(:item, href: "/") do %>Home<% end %>
13
+ # <% component.slot(:item, href: "/about") do %>About<% end %>
14
+ # <% component.slot(:item, selected: true) do %>Team<% end %>
15
+ # <% end %>
16
+ #
17
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
18
+ def initialize(**system_arguments)
19
+ @system_arguments = system_arguments
20
+ @system_arguments[:tag] = :nav
21
+ @system_arguments[:aria] = { label: "Breadcrumb" }
33
22
  end
34
23
 
35
24
  def render?
36
25
  items.any?
37
26
  end
38
27
 
28
+ # _Note: if both `href` and `selected: true` are passed in, `href` will be ignored and the item will not be rendered as a link._
39
29
  class BreadcrumbItem < Primer::Slot
40
- attr_reader :href, :kwargs
30
+ attr_reader :href, :system_arguments
41
31
 
42
- def initialize(href: nil, selected: false, **kwargs)
43
- @href, @kwargs = href, kwargs
32
+ # @param href [String] The URL to link to.
33
+ # @param selected [Boolean] Whether or not the item is selected and not rendered as a link.
34
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
35
+ def initialize(href: nil, selected: false, **system_arguments)
36
+ @href, @system_arguments = href, system_arguments
44
37
 
45
38
  @href = nil if selected
46
- @kwargs[:tag] = :li
47
- @kwargs[:"aria-current"] = "page" if selected
48
- @kwargs[:classes] = "breadcrumb-item #{@kwargs[:classes]}"
39
+ @system_arguments[:tag] = :li
40
+ @system_arguments[:"aria-current"] = "page" if selected
41
+ @system_arguments[:classes] = "breadcrumb-item #{@system_arguments[:classes]}"
49
42
  end
50
43
  end
51
44
  end