primer_view_components 0.0.5 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ea13d4d8ce56ffb157e20f463e512f3f0b0d8f437202e9cee264edea500344c
4
- data.tar.gz: 615a05c503420d654c6d5db7c772e9caca674af934aecc7c89100507d7dc405f
3
+ metadata.gz: f4ccf1dd55332ea7b350841d78e04a0f56a0f036749638c30041582500cc561c
4
+ data.tar.gz: f948087b2dba1cd217296a08260db95a8973cf8e58d4e1240a2c45295ef17e24
5
5
  SHA512:
6
- metadata.gz: 998e0a5a94c8e5a639d636b8a67b41a62fb596d4380d7b0f234709ae03599139df3c8a86d5854db8fc00b102a0b21ad3f0d1a854b1cf93141f9f1feafbfdf7dd
7
- data.tar.gz: 9095e97ae9f8d0bcea88bc0ae239f30fb1484dae7ab8f4830f79500e7a122b2e6ecfc899ce28e0b38a0936799efc32af9dcf8ec611c25f8bdad1b429de9c68f4
6
+ metadata.gz: 2359e308fa78d78b5cb0f4e76791bfcd6a9714b7295320d04f293f0b7e0351c4fbad90a13743c61e9401de9c69c1269ee791167638715e7fafc594a47b8a242b
7
+ data.tar.gz: 2089d76d7cdef40b4bce9871d2b0ade0f492751ba057dc99e6fabc4654390656e0cdef57004931d66b1ea75f6189581dbf840bedbb7b89ee6d0fbfdb31d13136
@@ -1,14 +1,70 @@
1
- # main
1
+ # CHANGELOG
2
2
 
3
- # 0.0.5
3
+ ## main
4
+
5
+ ## 0.0.10
6
+
7
+ * Add SpinnerComponent
8
+
9
+ *Cole Bemis*
10
+
11
+ ## 0.0.9
12
+
13
+ * BREAKING CHANGE: OcticonComponent no longer accepts `class` parameter; use `classes` instead.
14
+
15
+ *heynan0*
16
+
17
+ ## 0.0.8
18
+
19
+ * Add support for border margins, such as: `border_top: 0`.
20
+
21
+ *Natasha Umer*
22
+
23
+ * Add FlashComponent and OcticonComponent.
24
+
25
+ *Joel Hawksley*
26
+
27
+ * BREAKING CHANGE: BlankslateComponent accepts `icon_size` instead of `icon_height`.
28
+
29
+ *Joel Hawksley*
30
+
31
+ ## 0.0.7
32
+
33
+ * Use `octicons_helper` v11.0.0.
34
+
35
+ *Joel Hawksley*
36
+
37
+ ## 0.0.6
38
+
39
+ * Updated the invalid class name error message
40
+
41
+ *emplums*
42
+
43
+ * Updated README with testing instructions
44
+
45
+ *emplums*
46
+
47
+ * Add large and spacious option to BlankslateComponent
48
+
49
+ *simurai*
50
+
51
+ * Add option for `ButtonComponent` to render a `summary` tag
52
+
53
+ *Manuel Puyol*
54
+
55
+ * BREAKING CHANGE: Changed `DetailsComponent` summary and body to be slots
56
+
57
+ *Manuel Puyol*
58
+
59
+ ## 0.0.5
4
60
 
5
61
  * Add support for box_shadow
6
62
  * Add components:
7
- * Popover
63
+ * Popover
8
64
 
9
65
  *Sarah Vessels*
10
66
 
11
- # 0.0.4
67
+ ## 0.0.4
12
68
 
13
69
  * Added support for mx: and my: :auto.
14
70
 
@@ -17,19 +73,20 @@
17
73
  * Added support for custom layout sizes.
18
74
 
19
75
  *Manuel Puyol*
20
- # 0.0.3
76
+
77
+ ## 0.0.3
21
78
 
22
79
  * Add support for responsive `float` style argument.
23
80
 
24
81
  *Joel Hawksley*
25
82
 
26
83
  * Add components:
27
- * Avatar
28
- * Blankslate
84
+ * Avatar
85
+ * Blankslate
29
86
 
30
87
  *Manuel Puyol, Ben Emdon*
31
88
 
32
- # 0.0.1
89
+ ## 0.0.1
33
90
 
34
91
  * Add initial gem configuration.
35
92
 
@@ -44,24 +101,24 @@
44
101
  *Manuel Puyol*
45
102
 
46
103
  * Add components:
47
- * BorderBox
48
- * Box
49
- * Breadcrumb
50
- * Button
51
- * Counter
52
- * Details
53
- * Dropdown
54
- * Flex
55
- * FlexItem
56
- * Heading
57
- * Label
58
- * Layout
59
- * Link
60
- * ProgressBar
61
- * State
62
- * Subhead
63
- * Text
64
- * TimelineItem
65
- * UnderlineNav
104
+ * BorderBox
105
+ * Box
106
+ * Breadcrumb
107
+ * Button
108
+ * Counter
109
+ * Details
110
+ * Dropdown
111
+ * Flex
112
+ * FlexItem
113
+ * Heading
114
+ * Label
115
+ * Layout
116
+ * Link
117
+ * ProgressBar
118
+ * State
119
+ * Subhead
120
+ * Text
121
+ * TimelineItem
122
+ * UnderlineNav
66
123
 
67
124
  *Manuel Puyol*
data/README.md CHANGED
@@ -77,6 +77,10 @@ Some components have their own specific arguments, but they can all be styled wi
77
77
  | `font_weight` | `text-<value>` | `font_weight: :bold` → `.text-bold` |
78
78
  | `border` | `border-<value>` | `border: :bottom` → `.border-bottom` |
79
79
  | `border_color` | `border-<value>` | `border: :green` → `.border-green` |
80
+ | `border_top` | `border-top-<value>` | `border_top: 0` → `.border-top-0` |
81
+ | `border_bottom` | `border-bottom-<value>` | `border_bottom: 0` → `.border-bottom-0` |
82
+ | `border_left` | `border-left-<value>` | `border_left: 0` → `.border-left-0` |
83
+ | `border_right` | `border-right-<value>` | `border_right: 0` → `.border-right-0` |
80
84
  | `word_break` | `wb-<value>` | `word_break: :break_all` → `.wb-break-all` |
81
85
  | `direction` | `flex-<value>` | `direction: :row` → `.flex-row` |
82
86
  | `justify_content` | `flex-justify-<value>` | `justify_content: :center` → `.flex-justify-center` |
@@ -84,6 +88,7 @@ Some components have their own specific arguments, but they can all be styled wi
84
88
  | `box_shadow` | `box-shadow-<value>` | `box_shadow: :medium` → `.box-shadow-medium` |
85
89
 
86
90
  #### Boolean arguments
91
+
87
92
  | Component arguments | True | False |
88
93
  | -------------- | ------- | ------ |
89
94
  | `underline` | `underline: true` → `.text-underline` | `underline: false` → `.no-underline` |
@@ -112,7 +117,7 @@ The same label using `Primer::HeadingComponent`:
112
117
 
113
118
  ## Contributing
114
119
 
115
- Bug reports and pull requests are welcome on GitHub at https://github.com/primer/view_components. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
120
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/primer/view_components](https://github.com/primer/view_components). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
116
121
 
117
122
  ### Setting up
118
123
 
@@ -122,18 +127,30 @@ Run
122
127
  script/setup
123
128
  ```
124
129
 
125
- to install all necessary dependencies
130
+ To install all necessary dependencies.
131
+
132
+ ### Running tests
133
+
134
+ To run the full test suite:
135
+
136
+ ```bash
137
+ bundle exec rake
138
+ ```
139
+
140
+ ### Writing documentation
126
141
 
127
- ### Storybook
142
+ Documentation is written as [YARD](https://yardoc.org/) comments directly in the source code, compiled into Markdown via `rake docs:build` and served by [Doctocat](https://github.com/primer/doctocat).
128
143
 
129
- *We recommend having [overmind](https://github.com/DarthSim/overmind) installed to run both rails and storybook, but it is not required.*
144
+ ### Storybook / Documentation
130
145
 
131
- To run storybook:
146
+ To run Storybook and the documentation site, run:
132
147
 
133
148
  ```bash
134
- script/storybook
149
+ script/dev
135
150
  ```
136
151
 
152
+ _Note: Overmind is required to run script/dev._
153
+
137
154
  ### Developing with another app
138
155
 
139
156
  In your `Gemfile`, change:
@@ -154,6 +171,20 @@ Remember that restarting the Rails server is necessary to see changes, as the ge
154
171
  To minimize the number of restarts, we recommend checking the component in Storybook first, and then when it's in a good state,
155
172
  you can check it in your app.
156
173
 
174
+ ### Documentation
175
+
176
+ Document components with [YARD](https://yardoc.org/). Docs are published to [RubyDoc.info](https://rubydoc.info/github/primer/view_components).
177
+
178
+ ## Deploying to Heroku
179
+
180
+ We have both `staging` and `production` environments. To deploy Storybook to Heroku, run the following in `#primer-view-components-ops`:
181
+
182
+ ```bash
183
+ .deploy primer-view-components</branch> to <environment>
184
+ ```
185
+
186
+ If no `branch` is passed, `main` will be deployed.
187
+
157
188
  ## License
158
189
 
159
190
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,9 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
+ # Avatars are images used to represent users and organizations on GitHub.
5
+ # Use the default round avatar for users, and the `square` argument
6
+ # for organizations or any other non-human avatars.
4
7
  class AvatarComponent < Primer::Component
5
8
  SMALL_THRESHOLD = 24
6
9
 
10
+ #
11
+ # @example 34|Default
12
+ # <%= render(Primer::AvatarComponent.new(src: "http://placekitten.com/200/200", alt: "@kittenuser")) %>
13
+ #
14
+ # @param src [String] The source url of the avatar image
15
+ # @param alt [String] Passed through to alt on img tag
16
+ # @param size [Integer] Adds the avatar-small class if less than 24
17
+ # @param square [Boolean] Used to create a square avatar.
7
18
  def initialize(src:, alt:, size: 20, square: false, **kwargs)
8
19
  @kwargs = kwargs
9
20
  @kwargs[:tag] = :img
@@ -2,18 +2,15 @@
2
2
 
3
3
  module Primer
4
4
  # Base component used by other Primer components.
5
- #
6
- # tag(symbol): HTML tag name to be passed to tag.send(tag)
7
- # class_names(string): CSS class name value to be concatenated with generated Primer CSS classes
8
- # args(hash): Combination of arguments for classes_from_hash and content_tag
9
- #
10
- # Example usage:
11
- # <%= render Primer::BaseComponent, tag: :a, href: "http://www.google.com", mt: 4 do %>Link<% end %>
12
- # generates:
13
- # <a href="http://www.google.com" class="mt-4">Link</a>
14
5
  class BaseComponent < Primer::Component
15
6
  TEST_SELECTOR_TAG = :test_selector
16
7
 
8
+ #
9
+ # @example 34|Default
10
+ # <%= render(Primer::BaseComponent.new(tag: :a, href: "http://www.google.com", mt: 4)) { "Link" } %>
11
+ #
12
+ # @param tag [Symbol] HTML tag name to be passed to tag.send(tag)
13
+ # @param classes [String] CSS class name value to be concatenated with generated Primer CSS classes
17
14
  def initialize(tag:, classes: nil, **args)
18
15
  @tag = tag
19
16
  @result = Primer::Classify.call(**args.merge(classes: classes))
@@ -23,9 +20,7 @@ module Primer
23
20
  end
24
21
 
25
22
  def call
26
- tag.public_send(
27
- @tag, content, **@content_tag_args.merge(@result)
28
- )
23
+ content_tag(@tag, content, **@content_tag_args.merge(@result))
29
24
  end
30
25
 
31
26
  private
@@ -1,13 +1,19 @@
1
1
  <%= render Primer::BaseComponent.new(**@kwargs) do %>
2
2
  <% if @icon.present? %>
3
- <%= octicon @icon, height: @icon_height, class: "blankslate-icon" %>
3
+ <%= render(Primer::OcticonComponent.new(
4
+ icon: @icon,
5
+ size: @icon_size,
6
+ classes: "blankslate-icon"
7
+ )) %>
4
8
  <% end %>
5
9
 
6
10
  <% if @image_src.present? && @image_alt.present? %>
7
11
  <%= image_tag "#{@image_src}", class: "mb-3", size: "56x56", alt: "#{@image_alt}" %>
8
12
  <% end %>
9
13
 
10
- <<%= @title_tag %> class="mb-1"><%= @title %></<%= @title_tag %>>
14
+ <% if @title.present? %>
15
+ <%= render Primer::BaseComponent.new(tag: @title_tag, mb: 1) do %><%= @title %><% end %>
16
+ <% end %>
11
17
 
12
18
  <% if @description.present? %>
13
19
  <p><%= @description %></p>
@@ -1,122 +1,78 @@
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` required). 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
- #
102
- # ```ruby
103
- # <%= render Primer::BlankslateComponent.new(
104
- # icon: "book",
105
- # title: "Welcome to the mona wiki!",
106
- # 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.",
107
- #
108
- # narrow: true,
109
- # ) %>
110
- # ```
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.
111
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.keys.map { |k| "`:#{k}`" }.to_sentence %>
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.
112
71
  def initialize(
113
- # required
114
- title:,
115
-
116
- # optional
72
+ title: "",
117
73
  title_tag: :h3,
118
74
  icon: "",
119
- icon_height: 32,
75
+ icon_size: :medium,
120
76
  image_src: "",
121
77
  image_alt: " ",
122
78
  description: "",
@@ -128,20 +84,24 @@ module Primer
128
84
 
129
85
  #variations
130
86
  narrow: false,
87
+ large: false,
88
+ spacious: false,
131
89
 
132
90
  **kwargs
133
91
  )
134
92
  @kwargs = kwargs
135
- @kwargs[:tag] = :div
93
+ @kwargs[:tag] ||= :div
136
94
  @kwargs[:classes] = class_names(
137
95
  @kwargs[:classes],
138
96
  "blankslate",
139
97
  "blankslate-narrow": narrow,
98
+ "blankslate-large": large,
99
+ "blankslate-spacious": spacious,
140
100
  )
141
101
 
142
102
  @title_tag = title_tag
143
103
  @icon = icon
144
- @icon_height = icon_height
104
+ @icon_size = icon_size
145
105
  @image_src = image_src
146
106
  @image_alt = image_alt
147
107
  @title = title
@@ -20,7 +20,7 @@ module Primer
20
20
  VARIANT_OPTIONS = VARIANT_MAPPINGS.keys
21
21
 
22
22
  DEFAULT_TAG = :button
23
- TAG_OPTIONS = [DEFAULT_TAG, :a].freeze
23
+ TAG_OPTIONS = [DEFAULT_TAG, :a, :summary].freeze
24
24
 
25
25
  DEFAULT_TYPE = :button
26
26
  TYPE_OPTIONS = [DEFAULT_TYPE, :reset, :submit].freeze
@@ -45,9 +45,9 @@ module Primer
45
45
  @kwargs[:classes] = class_names(
46
46
  "btn",
47
47
  kwargs[:classes],
48
- BUTTON_TYPE_MAPPINGS[fetch_or_fallback(BUTTON_TYPE_OPTIONS, button_type.to_sym, DEFAULT_BUTTON_TYPE)],
48
+ BUTTON_TYPE_MAPPINGS[fetch_or_fallback(BUTTON_TYPE_OPTIONS, button_type, DEFAULT_BUTTON_TYPE)],
49
49
  VARIANT_MAPPINGS[fetch_or_fallback(VARIANT_OPTIONS, variant, DEFAULT_VARIANT)],
50
- group_item ? "BtnGroup-item" : ""
50
+ "BtnGroup-item" => group_item
51
51
  )
52
52
  end
53
53
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
+ # Use Primer::CounterComponent to add a count to navigational elements and buttons.
4
5
  class CounterComponent < Primer::Component
5
6
  DEFAULT_SCHEME = :default
6
7
  SCHEME_MAPPINGS = {
@@ -9,6 +10,17 @@ module Primer
9
10
  :light_gray => "Counter Counter--gray-light",
10
11
  }.freeze
11
12
 
13
+ #
14
+ # @example 34|Default
15
+ # <%= render(Primer::CounterComponent.new(count: 25)) %>
16
+ #
17
+ # @param count [Integer, Float::INFINITY, nil] The number to be displayed (e.x. # of issues, pull requests)
18
+ # @param scheme [Symbol] Color scheme. One of `SCHEME_MAPPINGS.keys`.
19
+ # @param limit [Integer] Maximum value to display. (e.x. if count == 6,000 and limit == 5000, counter will display "5,000+")
20
+ # @param hide_if_zero [Boolean] If true, a `hidden` attribute is added to the counter if `count` is zero.
21
+ # @param text [String] Text to display instead of count.
22
+ # @param round [Boolean] Whether to apply our standard rounding logic to value.
23
+ # @param kwargs [Hash] Style arguments to be passed to Primer::Classify
12
24
  def initialize(
13
25
  count: 0,
14
26
  scheme: DEFAULT_SCHEME,
@@ -1,6 +1,8 @@
1
1
  <%= render Primer::BaseComponent.new(**@kwargs) do %>
2
- <%= render Primer::BaseComponent.new(**@summary_kwargs) do %>
3
- <%= summary %>
2
+ <%= render summary.component do %>
3
+ <%= summary.content %>
4
+ <% end %>
5
+ <%= render body.component do %>
6
+ <%= body.content %>
4
7
  <% end %>
5
- <%= body %>
6
8
  <% end %>
@@ -7,6 +7,8 @@ module Primer
7
7
  # reset will remove all styles from the <summary> element.
8
8
  #
9
9
  class DetailsComponent < Primer::Component
10
+ include ViewComponent::Slotable
11
+
10
12
  OVERLAY_DEFAULT = :none
11
13
  OVERLAY_MAPPINGS = {
12
14
  OVERLAY_DEFAULT => "",
@@ -14,25 +16,48 @@ module Primer
14
16
  :dark => "details-overlay details-overlay-dark",
15
17
  }.freeze
16
18
 
17
- BUTTON_DEFAULT = :default
18
- BUTTON_RESET = :reset
19
- BUTTON_OPTIONS = [BUTTON_DEFAULT, BUTTON_RESET]
20
-
21
- with_content_areas :summary, :body
22
-
23
- def initialize(overlay: OVERLAY_DEFAULT, button: BUTTON_DEFAULT, **kwargs)
24
- @button = fetch_or_fallback(BUTTON_OPTIONS, button, BUTTON_DEFAULT)
19
+ with_slot :body, class_name: "Body"
20
+ with_slot :summary, class_name: "Summary"
25
21
 
22
+ def initialize(overlay: OVERLAY_DEFAULT, reset: false, **kwargs)
26
23
  @kwargs = kwargs
27
24
  @kwargs[:tag] = :details
28
25
  @kwargs[:classes] = class_names(
29
26
  kwargs[:classes],
30
27
  OVERLAY_MAPPINGS[fetch_or_fallback(OVERLAY_MAPPINGS.keys, overlay, OVERLAY_DEFAULT)],
31
- "details-reset" => @button == BUTTON_RESET
28
+ "details-reset" => reset
32
29
  )
30
+ end
31
+
32
+ def render?
33
+ summary.present? && body.present?
34
+ end
35
+
36
+ class Summary < Primer::Slot
37
+ def initialize(button: true, **kwargs)
38
+ @button = button
39
+
40
+ @kwargs = kwargs
41
+ @kwargs[:tag] = :summary
42
+ @kwargs[:role] = "button"
43
+ end
44
+
45
+ def component
46
+ return Primer::BaseComponent.new(**@kwargs) unless @button
47
+
48
+ Primer::ButtonComponent.new(**@kwargs)
49
+ end
50
+ end
51
+
52
+ class Body < Primer::Slot
53
+ def initialize(**kwargs)
54
+ @kwargs = kwargs
55
+ @kwargs[:tag] ||= :div
56
+ end
33
57
 
34
- @summary_kwargs = { tag: :summary, role: "button" }
35
- @summary_kwargs[:classes] = "btn" if @button == BUTTON_DEFAULT
58
+ def component
59
+ Primer::BaseComponent.new(**@kwargs)
60
+ end
36
61
  end
37
62
  end
38
63
  end
@@ -0,0 +1,14 @@
1
+ <%= render Primer::BaseComponent.new(**@kwargs) do %>
2
+ <%= render(Primer::OcticonComponent.new(icon: @icon)) if @icon %>
3
+ <%= content %>
4
+ <% if @dismissible %>
5
+ <button class="flash-close js-flash-close" type="button" aria-label="Close">
6
+ <%= render(Primer::OcticonComponent.new(icon: "x")) %>
7
+ </button>
8
+ <% end %>
9
+ <% if actions.present? %>
10
+ <%= render Primer::BaseComponent.new(**actions.kwargs) do %>
11
+ <%= actions.content %>
12
+ <% end %>
13
+ <% end %>
14
+ <% end %>
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ class FlashComponent < Primer::Component
5
+ include ViewComponent::Slotable
6
+
7
+ with_slot :actions, class_name: "Actions"
8
+
9
+ DEFAULT_VARIANT = :default
10
+ VARIANT_MAPPINGS = {
11
+ DEFAULT_VARIANT => "",
12
+ :warning => "flash-warn",
13
+ :danger => "flash-error",
14
+ :success => "flash-success"
15
+ }.freeze
16
+
17
+ def initialize(full: false, spacious: false, dismissible: false, icon: nil, variant: DEFAULT_VARIANT, **kwargs)
18
+ @icon = icon
19
+ @dismissible = dismissible
20
+ @kwargs = kwargs
21
+ @kwargs[:tag] = :div
22
+ @kwargs[:classes] = class_names(
23
+ @kwargs[:classes],
24
+ "flash",
25
+ VARIANT_MAPPINGS[fetch_or_fallback(VARIANT_MAPPINGS.keys, variant, DEFAULT_VARIANT)],
26
+ "flash-full": full
27
+ )
28
+ @kwargs[:mb] ||= spacious ? 4 : nil
29
+ end
30
+
31
+ class Actions < ViewComponent::Slot
32
+ include ClassNameHelper
33
+
34
+ attr_reader :kwargs
35
+
36
+ def initialize(**kwargs)
37
+ @kwargs = kwargs
38
+ @kwargs[:tag] = :div
39
+ @kwargs[:classes] = class_names(@kwargs[:classes], "flash-action")
40
+ end
41
+ end
42
+ end
43
+ end
@@ -13,7 +13,7 @@ module Primer
13
13
 
14
14
  def initialize(responsive: false, side: DEFAULT_SIDE, sidebar_col: DEFAULT_SIDEBAR_COL, **kwargs)
15
15
  @kwargs = kwargs
16
- @side = fetch_or_fallback(ALLOWED_SIDES, side.to_sym, DEFAULT_SIDE)
16
+ @side = fetch_or_fallback(ALLOWED_SIDES, side, DEFAULT_SIDE)
17
17
  @responsive = responsive
18
18
  @kwargs[:classes] = class_names(
19
19
  "gutter-condensed gutter-lg",
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ class OcticonComponent < Primer::Component
5
+ include Primer::ClassNameHelper
6
+ include OcticonsHelper
7
+
8
+ SIZE_DEFAULT = :small
9
+ SIZE_MAPPINGS = {
10
+ SIZE_DEFAULT => 16,
11
+ :medium => 32,
12
+ :large => 64,
13
+ }.freeze
14
+ SIZE_OPTIONS = SIZE_MAPPINGS.keys
15
+
16
+ def initialize(icon:, size: SIZE_DEFAULT, **kwargs)
17
+ @icon, @kwargs = icon, kwargs
18
+
19
+ @kwargs[:class] = Primer::Classify.call(**@kwargs)[:class]
20
+ @kwargs[:height] ||= SIZE_MAPPINGS[size]
21
+
22
+ # Filter out classify options to prevent them from becoming invalid html attributes.
23
+ # Note height and width are both classify options and valid html attributes.
24
+ octicon_helper_options = @kwargs.slice(:height, :width)
25
+ @kwargs = @kwargs.except(*Primer::Classify::VALID_KEYS, :classes).merge(octicon_helper_options)
26
+ end
27
+
28
+ def call
29
+ octicon(@icon, **@kwargs)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,6 @@
1
+ <%= render Primer::BaseComponent.new(**@kwargs) 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,38 @@
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
+
15
+ #
16
+ # @example 48|Default
17
+ # <%= render(Primer::SpinnerComponent.new) %>
18
+ #
19
+ # @example 32|Small
20
+ # <%= render(Primer::SpinnerComponent.new(size: :small)) %>
21
+ #
22
+ # @example 80|Large
23
+ # <%= render(Primer::SpinnerComponent.new(size: :large)) %>
24
+ #
25
+ # @param size [Symbol] One of <%= Primer::SpinnerComponent::SIZE_OPTIONS.map { |k| "`:#{k}`" }.to_sentence(last_word_connector: ', or ') %>
26
+ def initialize(size: DEFAULT_SIZE, **kwargs)
27
+ @kwargs = kwargs
28
+ @kwargs[:tag] = :svg
29
+ @kwargs[:width] = SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)]
30
+ @kwargs[:height] = SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)]
31
+ @kwargs[:viewBox] = "0 0 16 16"
32
+ @kwargs[:fill] = :none
33
+ # Setting `box-sizing: content-box` allows consumers to add padding
34
+ # to the spinner without shrinking the icon
35
+ @kwargs[:style] = "box-sizing: content-box; color: var(--color-icon-primary);"
36
+ end
37
+ end
38
+ end
@@ -33,14 +33,17 @@ require_relative "button_component"
33
33
  require_relative "counter_component"
34
34
  require_relative "details_component"
35
35
  require_relative "dropdown_menu_component"
36
+ require_relative "flash_component"
36
37
  require_relative "flex_component"
37
38
  require_relative "flex_item_component"
38
39
  require_relative "heading_component"
39
40
  require_relative "label_component"
40
41
  require_relative "layout_component"
41
42
  require_relative "link_component"
43
+ require_relative "octicon_component"
42
44
  require_relative "popover_component"
43
45
  require_relative "progress_bar_component"
46
+ require_relative "spinner_component"
44
47
  require_relative "state_component"
45
48
  require_relative "subhead_component"
46
49
  require_relative "text_component"
@@ -78,11 +78,13 @@ module Primer
78
78
  }
79
79
  }.freeze
80
80
  BORDER_KEYS = [:border, :border_color].freeze
81
+ BORDER_MARGIN_KEYS = [:border_top, :border_bottom, :border_left, :border_right].freeze
81
82
  TYPOGRAPHY_KEYS = [:font_size].freeze
82
83
  VALID_KEYS = (
83
84
  CONCAT_KEYS +
84
85
  BOOLEAN_MAPPINGS.keys +
85
86
  BORDER_KEYS +
87
+ BORDER_MARGIN_KEYS +
86
88
  TYPOGRAPHY_KEYS +
87
89
  TEXT_KEYS +
88
90
  [
@@ -131,7 +133,7 @@ module Primer
131
133
  raise ArgumentError.new(
132
134
  "Primer CSS class #{'name'.pluralize(invalid_class_names.length)} \
133
135
  #{invalid_class_names.to_sentence} #{'is'.pluralize(invalid_class_names.length)} \
134
- not allowed, use hash syntax instead. This warning will not be raised in production.",
136
+ not allowed, use style arguments instead (https://github.com/primer/view_components#built-in-styling-arguments). This warning will not be raised in production.",
135
137
  )
136
138
  end
137
139
  end
@@ -196,6 +198,8 @@ module Primer
196
198
  memo[:classes] << "wb-#{dasherized_val}"
197
199
  elsif BORDER_KEYS.include?(key)
198
200
  memo[:classes] << "border-#{dasherized_val}"
201
+ elsif BORDER_MARGIN_KEYS.include?(key)
202
+ memo[:classes] << "#{key.to_s.dasherize}-#{val}"
199
203
  elsif key == DIRECTION_KEY
200
204
  memo[:classes] << "flex#{breakpoint}-#{dasherized_val}"
201
205
  elsif key == JUSTIFY_CONTENT_KEY
@@ -5,7 +5,7 @@ module Primer
5
5
  module VERSION
6
6
  MAJOR = 0
7
7
  MINOR = 0
8
- PATCH = 5
8
+ PATCH = 10
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primer_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-19 00:00:00.000000000 Z
11
+ date: 2020-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -59,7 +59,7 @@ dependencies:
59
59
  version: 9.0.0
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
- version: 11.0.0
62
+ version: 12.0.0
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
@@ -69,7 +69,21 @@ dependencies:
69
69
  version: 9.0.0
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
- version: 11.0.0
72
+ version: 12.0.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: listen
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '3.0'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '3.0'
73
87
  - !ruby/object:Gem::Dependency
74
88
  name: minitest
75
89
  requirement: !ruby/object:Gem::Requirement
@@ -126,7 +140,49 @@ dependencies:
126
140
  - - "~>"
127
141
  - !ruby/object:Gem::Version
128
142
  version: 0.13.0
129
- description:
143
+ - !ruby/object:Gem::Dependency
144
+ name: simplecov
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: 0.18.0
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - "~>"
155
+ - !ruby/object:Gem::Version
156
+ version: 0.18.0
157
+ - !ruby/object:Gem::Dependency
158
+ name: simplecov-console
159
+ requirement: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - "~>"
162
+ - !ruby/object:Gem::Version
163
+ version: 0.7.2
164
+ type: :development
165
+ prerelease: false
166
+ version_requirements: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - "~>"
169
+ - !ruby/object:Gem::Version
170
+ version: 0.7.2
171
+ - !ruby/object:Gem::Dependency
172
+ name: yard
173
+ requirement: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - "~>"
176
+ - !ruby/object:Gem::Version
177
+ version: 0.9.25
178
+ type: :development
179
+ prerelease: false
180
+ version_requirements: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - "~>"
183
+ - !ruby/object:Gem::Version
184
+ version: 0.9.25
185
+ description:
130
186
  email:
131
187
  - opensource+primer_view_components@github.com
132
188
  executables: []
@@ -152,6 +208,8 @@ files:
152
208
  - app/components/primer/details_component.rb
153
209
  - app/components/primer/dropdown_menu_component.html.erb
154
210
  - app/components/primer/dropdown_menu_component.rb
211
+ - app/components/primer/flash_component.html.erb
212
+ - app/components/primer/flash_component.rb
155
213
  - app/components/primer/flex_component.rb
156
214
  - app/components/primer/flex_item_component.rb
157
215
  - app/components/primer/heading_component.rb
@@ -159,11 +217,14 @@ files:
159
217
  - app/components/primer/layout_component.html.erb
160
218
  - app/components/primer/layout_component.rb
161
219
  - app/components/primer/link_component.rb
220
+ - app/components/primer/octicon_component.rb
162
221
  - app/components/primer/popover_component.html.erb
163
222
  - app/components/primer/popover_component.rb
164
223
  - app/components/primer/progress_bar_component.html.erb
165
224
  - app/components/primer/progress_bar_component.rb
166
225
  - app/components/primer/slot.rb
226
+ - app/components/primer/spinner_component.html.erb
227
+ - app/components/primer/spinner_component.rb
167
228
  - app/components/primer/state_component.rb
168
229
  - app/components/primer/subhead_component.html.erb
169
230
  - app/components/primer/subhead_component.rb
@@ -184,7 +245,7 @@ licenses:
184
245
  - MIT
185
246
  metadata:
186
247
  allowed_push_host: https://rubygems.org
187
- post_install_message:
248
+ post_install_message:
188
249
  rdoc_options: []
189
250
  require_paths:
190
251
  - lib
@@ -199,8 +260,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
260
  - !ruby/object:Gem::Version
200
261
  version: '0'
201
262
  requirements: []
202
- rubygems_version: 3.1.2
203
- signing_key:
263
+ rubygems_version: 3.0.3
264
+ signing_key:
204
265
  specification_version: 4
205
266
  summary: ViewComponents for the Primer Design System
206
267
  test_files: []