primer_view_components 0.0.8 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25626f31190d4622e822db5eb8f435f103c0a77668cb78c1db16eec60ac4dfb9
4
- data.tar.gz: e551785879e69a0bd7c2ae62a97a39f311dc3dbc415bc5dade637d97fa297910
3
+ metadata.gz: 055f773c8e99df5c9bce23d6a5199e71148d0331d6abe6c02fd1f16321a54130
4
+ data.tar.gz: e5310f927e76533daa46918acb24b48ea7bdd684a8f8e4c9090e3545a2e7f3fd
5
5
  SHA512:
6
- metadata.gz: 6a77219748e0c7018f789df844cd6f6e83159b2fef82a5b81985c277d0427d85442e4e14c6f9934e387afc3f1d2291f31a3d88c9630c8f4910bae992d39a0188
7
- data.tar.gz: 15b0b2a9faa1603f57d263a2a6b18f2eb4e1aa325d8c261bfce9f803571ae9a5075b1d51f8a5f3bf31bc7f12662dbe914f7380f71518fe6896b947f2d000757b
6
+ metadata.gz: e6b7159b56e4a0674a7ec68e4aa0666bb2a3e3cb5ef7b90e8c418149200af1255789adc87e4b3955a9a2d6e97afb9ebe2746928ccb32ece3395c28de315206dc
7
+ data.tar.gz: cc962a06f62249016eccfd224ab3655117ac193fa7f6ebb40aff91212690464047f95e2822bf4b5c8ae83d8c82df02e955f0c8ffc350e9aed85c313623388a61
@@ -1,6 +1,38 @@
1
- # main
1
+ # CHANGELOG
2
2
 
3
- # 0.0.8
3
+ ## main
4
+
5
+ ## 0.0.13
6
+
7
+ * Add support for `xl` breakpoint.
8
+
9
+ *Joel Hawksley*
10
+
11
+ ## 0.0.12
12
+
13
+ * Adds support for disabling inline box-sizing style for `SpinnerComponent` via style parameter `Primer::SpinnerComponent.new(style: nil)`.
14
+
15
+ *Chris Wilson*
16
+
17
+ ## 0.0.11
18
+
19
+ * Renames DetailsComponent::OVERLAY_DEFAULT to DetailsComponent::NO_OVERLAY to more correctly describe its value.
20
+
21
+ *Justin Kenyon*
22
+
23
+ ## 0.0.10
24
+
25
+ * Add SpinnerComponent
26
+
27
+ *Cole Bemis*
28
+
29
+ ## 0.0.9
30
+
31
+ * BREAKING CHANGE: OcticonComponent no longer accepts `class` parameter; use `classes` instead.
32
+
33
+ *heynan0*
34
+
35
+ ## 0.0.8
4
36
 
5
37
  * Add support for border margins, such as: `border_top: 0`.
6
38
 
@@ -10,19 +42,17 @@
10
42
 
11
43
  *Joel Hawksley*
12
44
 
13
- ## Breaking changes
14
-
15
- * BlankslateComponent accepts `icon_size` instead of `icon_height`.
45
+ * BREAKING CHANGE: BlankslateComponent accepts `icon_size` instead of `icon_height`.
16
46
 
17
47
  *Joel Hawksley*
18
48
 
19
- # 0.0.7
49
+ ## 0.0.7
20
50
 
21
51
  * Use `octicons_helper` v11.0.0.
22
52
 
23
53
  *Joel Hawksley*
24
54
 
25
- # 0.0.6
55
+ ## 0.0.6
26
56
 
27
57
  * Updated the invalid class name error message
28
58
 
@@ -40,21 +70,19 @@
40
70
 
41
71
  *Manuel Puyol*
42
72
 
43
- ## Breaking changes
44
-
45
- * Changed `DetailsComponent` summary and body to be slots
73
+ * BREAKING CHANGE: Changed `DetailsComponent` summary and body to be slots
46
74
 
47
75
  *Manuel Puyol*
48
76
 
49
- # 0.0.5
77
+ ## 0.0.5
50
78
 
51
79
  * Add support for box_shadow
52
80
  * Add components:
53
- * Popover
81
+ * Popover
54
82
 
55
83
  *Sarah Vessels*
56
84
 
57
- # 0.0.4
85
+ ## 0.0.4
58
86
 
59
87
  * Added support for mx: and my: :auto.
60
88
 
@@ -63,19 +91,20 @@
63
91
  * Added support for custom layout sizes.
64
92
 
65
93
  *Manuel Puyol*
66
- # 0.0.3
67
94
 
68
- * Add support for responsive `float` style argument.
95
+ ## 0.0.3
96
+
97
+ * Add support for responsive `float` system argument.
69
98
 
70
99
  *Joel Hawksley*
71
100
 
72
101
  * Add components:
73
- * Avatar
74
- * Blankslate
102
+ * Avatar
103
+ * Blankslate
75
104
 
76
105
  *Manuel Puyol, Ben Emdon*
77
106
 
78
- # 0.0.1
107
+ ## 0.0.1
79
108
 
80
109
  * Add initial gem configuration.
81
110
 
@@ -90,24 +119,24 @@
90
119
  *Manuel Puyol*
91
120
 
92
121
  * Add components:
93
- * BorderBox
94
- * Box
95
- * Breadcrumb
96
- * Button
97
- * Counter
98
- * Details
99
- * Dropdown
100
- * Flex
101
- * FlexItem
102
- * Heading
103
- * Label
104
- * Layout
105
- * Link
106
- * ProgressBar
107
- * State
108
- * Subhead
109
- * Text
110
- * TimelineItem
111
- * UnderlineNav
122
+ * BorderBox
123
+ * Box
124
+ * Breadcrumb
125
+ * Button
126
+ * Counter
127
+ * Details
128
+ * Dropdown
129
+ * Flex
130
+ * FlexItem
131
+ * Heading
132
+ * Label
133
+ * Layout
134
+ * Link
135
+ * ProgressBar
136
+ * State
137
+ * Subhead
138
+ * Text
139
+ * TimelineItem
140
+ * UnderlineNav
112
141
 
113
142
  *Manuel Puyol*
data/README.md CHANGED
@@ -8,168 +8,9 @@
8
8
 
9
9
  _Note: This library is in pre-release development and should not be considered stable._
10
10
 
11
- ## Design philosophy
11
+ ## Documentation
12
12
 
13
- Primer ViewComponents aims to mimic the API of [Primer Components](https://github.com/primer/components), while using [Primer CSS](https://github.com/primer/css) under the hood.
14
-
15
- ## Installation
16
-
17
- In `Gemfile`, add:
18
-
19
- ```ruby
20
- gem "primer_view_components"
21
- ```
22
-
23
- In `config/application.rb`, add **after the application definition**
24
-
25
- ```ruby
26
- require "primer/view_components/engine"
27
- ```
28
-
29
- ## Usage
30
-
31
- ### Built-in styling arguments
32
-
33
- Primer components should be styled using the built-in arguments when possible. Most Primer utility classes for spacing, alignment, display, and colors have equivalent component arguments.
34
-
35
- Example label built with Primer CSS:
36
-
37
- ```html
38
- <span title="Label: Suggested" class="Label Label--outline Label--outline-green ml-2 v-align-middle">Suggested</span>
39
- ```
40
-
41
- The same label using `Primer::LabelComponent`:
42
-
43
- ```erb
44
- <%= render Primer::LabelComponent.new(ml: 2, vertical_align: :middle, scheme: :green, title: "Label: Suggested") do %>
45
- Suggested
46
- <% end %>
47
- ```
48
-
49
- Some components have their own specific arguments, but they can all be styled with the following arguments.
50
-
51
- | Component argument | Primer class | Example |
52
- | --------------- | --------------- | -------- |
53
- | `m` | `m-<value>` | `m: 4` → `.m-4` |
54
- | `my` | `my-<value>` | `my: 4` → `.my-4` |
55
- | `mx` | `my-<value>` | `mx: 4` → `.mx-4` |
56
- | `mt` | `mt-<value>` | `mt: 4` → `.mt-4` |
57
- | `mb` | `mb-<value>` | `mb: 4` → `.mb-4` |
58
- | `ml` | `ml-<value>` | `ml: 4` → `.ml-4` |
59
- | `mr` | `mr-<value>` | `mr: 4` → `.mr-4` |
60
- | `p` | `p-<value>` | `p: 4` → `.p-4` |
61
- | `py` | `py-<value>` | `py: 4` → `.py-4` |
62
- | `px` | `py-<value>` | `px: 4` → `.px-4` |
63
- | `pt` | `pt-<value>` | `pt: 4` → `.pt-4` |
64
- | `pb` | `pb-<value>` | `pb: 4` → `.pb-4` |
65
- | `pl` | `pl-<value>` | `pl: 4` → `.pl-4` |
66
- | `pr` | `pr-<value>` | `pr: 4` → `.pr-4` |
67
- | `pr` | `pr-<value>` | `pr: 4` → `.pr-4` |
68
- | `f` | `f-<value>` | `f: 4` → `.f-4` |
69
- | `color` | `color-<value>` | `color: :red_500` → `.color-red-500` |
70
- | `text` | `text-<value>` | `text: :green` → `.text-green` |
71
- | `bg` | `bg-<value>` | `bg: :blue_light` → `.bg-blue-light` |
72
- | `display` | `d-<value>` | `display: :none` → `.d-none` |
73
- | `float` | `float-<value>` | `float: :right` → `.float-right` |
74
- | `vertical_align` | `v-align-<value>` | `vertical_align: :baseline` → `.v-align-baseline` |
75
- | `text_align` | `text-<value>` | `text_align: :right` → `.text-right` |
76
- | `font_size` | `f<value>` | `font_size: 4` → `.f4` |
77
- | `font_weight` | `text-<value>` | `font_weight: :bold` → `.text-bold` |
78
- | `border` | `border-<value>` | `border: :bottom` → `.border-bottom` |
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` |
84
- | `word_break` | `wb-<value>` | `word_break: :break_all` → `.wb-break-all` |
85
- | `direction` | `flex-<value>` | `direction: :row` → `.flex-row` |
86
- | `justify_content` | `flex-justify-<value>` | `justify_content: :center` → `.flex-justify-center` |
87
- | `align_items` | `flex-items-<value>` | `align_items: :baseline` → `.flex-items-baseline` |
88
- | `box_shadow` | `box-shadow-<value>` | `box_shadow: :medium` → `.box-shadow-medium` |
89
-
90
- #### Boolean arguments
91
- | Component arguments | True | False |
92
- | -------------- | ------- | ------ |
93
- | `underline` | `underline: true` → `.text-underline` | `underline: false` → `.no-underline` |
94
- | `top` | n/a | `top: false` → `.top-0` |
95
- | `bottom` | n/a | `bottom: false` → `.bottom-0` |
96
- | `left` | n/a | `left: false` → `.left-0` |
97
- | `right` | n/a | `right: false` → `.right-0` |
98
-
99
- #### Responsive arguments
100
-
101
- Different classes can be used for different breakpoints just like in Primer CSS. Simply use an array with the four values required for `[none, small, medium, large]`. If no breakpoint is needed for a breakpoint, pass `nil`.
102
-
103
- Example heading built with Primer CSS:
104
-
105
- ```html
106
- <h1 class="mt-0 mt-lg-4">Hello world</h1>
107
- ```
108
-
109
- The same label using `Primer::HeadingComponent`:
110
-
111
- ```erb
112
- <%= render Primer::HeadingComponent.new(mt: [0, nil, nil, 4]) do %>
113
- Hello world
114
- <% end %>
115
- ```
116
-
117
- ## Contributing
118
-
119
- 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
-
121
- ### Setting up
122
-
123
- Run
124
-
125
- ```bash
126
- script/setup
127
- ```
128
-
129
- to install all necessary dependencies
130
-
131
-
132
- ### Running tests
133
-
134
- To run the full test suite:
135
-
136
- ```bash
137
- bundle exec rake
138
- ```
139
-
140
- ### Storybook
141
-
142
- *We recommend having [overmind](https://github.com/DarthSim/overmind) installed to run both rails and storybook, but it is not required.*
143
-
144
- To run storybook:
145
-
146
- ```bash
147
- script/storybook
148
- ```
149
-
150
- ### Developing with another app
151
-
152
- In your `Gemfile`, change:
153
-
154
- ```ruby
155
- gem "primer_view_components"
156
- ```
157
-
158
- to
159
-
160
- ```ruby
161
- gem "primer_view_components", path: "path_to_the_gem" # e.g. path: "~/primer/view_components"
162
- ```
163
-
164
- Then, `bundle install` to update references. You'll now be able to see changes from the gem without having to build it.
165
- Remember that restarting the Rails server is necessary to see changes, as the gem is loaded at boot time.
166
-
167
- To minimize the number of restarts, we recommend checking the component in Storybook first, and then when it's in a good state,
168
- you can check it in your app.
169
-
170
- ### Documentation
171
-
172
- Document components with [YARD](https://yardoc.org/). Docs are published to [RubyDoc.info](https://rubydoc.info/github/primer/view_components).
13
+ Visit [https://primer.style/view-components/](https://primer.style/view-components//) to view documentation.
173
14
 
174
15
  ## License
175
16
 
@@ -1,28 +1,39 @@
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
 
7
- def initialize(src:, alt:, size: 20, square: false, **kwargs)
8
- @kwargs = kwargs
9
- @kwargs[:tag] = :img
10
- @kwargs[:src] = src
11
- @kwargs[:alt] = alt
12
- @kwargs[:size] = size
13
- @kwargs[:height] = size
14
- @kwargs[:width] = size
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.
18
+ def initialize(src:, alt:, size: 20, square: false, **system_arguments)
19
+ @system_arguments = system_arguments
20
+ @system_arguments[:tag] = :img
21
+ @system_arguments[:src] = src
22
+ @system_arguments[:alt] = alt
23
+ @system_arguments[:size] = size
24
+ @system_arguments[:height] = size
25
+ @system_arguments[:width] = size
15
26
 
16
- @kwargs[:classes] = class_names(
27
+ @system_arguments[:classes] = class_names(
17
28
  "avatar",
18
- kwargs[:classes],
29
+ system_arguments[:classes],
19
30
  "avatar--small" => size < SMALL_THRESHOLD,
20
31
  "CircleBadge" => !square
21
32
  )
22
33
  end
23
34
 
24
35
  def call
25
- render(Primer::BaseComponent.new(**@kwargs)) { content }
36
+ render(Primer::BaseComponent.new(**@system_arguments)) { content }
26
37
  end
27
38
  end
28
39
  end
@@ -1,25 +1,70 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Primer
4
- # Base component used by other Primer components.
4
+ # All Primer ViewComponents accept a standard set of options called System Arguments, mimicking the [styled-system API](https://styled-system.com/table) [used by Primer React](https://primer.style/components/system-props).
5
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
6
+ # Under the hood, System Arguments are [mapped](https://github.com/primer/view_components/blob/main/lib/primer/classify.rb) to Primer CSS classes, with any remaining options passed to Rails' [`content_tag`](https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag).
7
+ #
8
+ # ## Responsive values
9
+ #
10
+ # To apply different values across responsive breakpoints, pass an array with up to five values in the order `[default, small, medium, large, xlarge]`. To skip a breakpoint, pass `nil`.
11
+ #
12
+ # For example:
13
+ #
14
+ # ```erb
15
+ # <%= render Primer::HeadingComponent.new(mt: [0, nil, nil, 4, 2]) do %>
16
+ # Hello world
17
+ # <% end %>
18
+ # ```
19
+ #
20
+ # Renders:
21
+ #
22
+ # ```html
23
+ # <h1 class="mt-0 mt-lg-4 mt-xl-2">Hello world</h1>
24
+ # ```
9
25
  #
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
26
  class BaseComponent < Primer::Component
15
27
  TEST_SELECTOR_TAG = :test_selector
16
28
 
17
- def initialize(tag:, classes: nil, **args)
29
+ # @param m [Integer] Margin. <%= one_of((-6..6).to_a) %>
30
+ # @param mt [Integer] Margin left. <%= one_of((-6..6).to_a) %>
31
+ # @param mr [Integer] Margin right. <%= one_of((-6..6).to_a) %>
32
+ # @param mb [Integer] Margin bottom. <%= one_of((-6..6).to_a) %>
33
+ # @param ml [Integer] Margin left. <%= one_of((-6..6).to_a) %>
34
+ # @param mx [Integer] Horizontal margins. <%= one_of((-6..6).to_a + [:auto]) %>
35
+ # @param my [Integer] Vertical margins. <%= one_of((-6..6).to_a) %>
36
+ # @param m [Integer] Padding. <%= one_of((0..6).to_a) %>
37
+ # @param mt [Integer] Padding left. <%= one_of((0..6).to_a) %>
38
+ # @param mr [Integer] Padding right. <%= one_of((0..6).to_a) %>
39
+ # @param mb [Integer] Padding bottom. <%= one_of((0..6).to_a) %>
40
+ # @param ml [Integer] Padding left. <%= one_of((0..6).to_a) %>
41
+ # @param mx [Integer] Horizontal padding. <%= one_of((0..6).to_a) %>
42
+ # @param my [Integer] Vertical padding. <%= one_of((0..6).to_a) %>
43
+ #
44
+ # @param position [Symbol] <%= one_of([:relative, :absolute, :fixed]) %>
45
+ #
46
+ # @param top [Boolean] If `false`, sets `top: 0`.
47
+ # @param right [Boolean] If `false`, sets `right: 0`.
48
+ # @param bottom [Boolean] If `false`, sets `bottom: 0`.
49
+ # @param left [Boolean] If `false`, sets `left: 0`.
50
+ #
51
+ # @param display [Symbol] <%= one_of([:block, :none, :inline, :inline_block, :table, :table_cell]) %>
52
+ #
53
+ # @param hide [Symbol] Hide the element at a specific breakpoint. <%= one_of([:sm, :md, :lg, :xl]) %>
54
+ #
55
+ # @param vertical_align [Symbol] <%= one_of([:baseline, :top, :middle, :bottom, :text_top, :text_bottom]) %>
56
+ #
57
+ # @param float [Symbol] <%= one_of([:left, :right]) %>
58
+ #
59
+ # @param font_size [String] <%= one_of(["00", "0", "1", "2", "3", "4", "5", "6"]) %>
60
+ # @param tag [Symbol] HTML tag name to be passed to `tag.send`
61
+ # @param classes [String] CSS class name value to be concatenated with generated Primer CSS classes
62
+ def initialize(tag:, classes: nil, **system_arguments)
18
63
  @tag = tag
19
- @result = Primer::Classify.call(**args.merge(classes: classes))
64
+ @result = Primer::Classify.call(**system_arguments.merge(classes: classes))
20
65
 
21
66
  # Filter out Primer keys so they don't get assigned as HTML attributes
22
- @content_tag_args = add_test_selector(args).except(*Primer::Classify::VALID_KEYS)
67
+ @content_tag_args = add_test_selector(system_arguments).except(*Primer::Classify::VALID_KEYS)
23
68
  end
24
69
 
25
70
  def call