primer_view_components 0.0.1 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +92 -2
  3. data/README.md +149 -0
  4. data/app/components/primer/avatar_component.rb +28 -0
  5. data/app/components/primer/base_component.rb +42 -0
  6. data/app/components/primer/blankslate_component.html.erb +27 -0
  7. data/app/components/primer/blankslate_component.rb +164 -0
  8. data/app/components/primer/border_box_component.html.erb +26 -0
  9. data/app/components/primer/border_box_component.rb +77 -0
  10. data/app/components/primer/box_component.rb +14 -0
  11. data/app/components/primer/breadcrumb_component.html.erb +8 -0
  12. data/app/components/primer/breadcrumb_component.rb +52 -0
  13. data/app/components/primer/button_component.rb +58 -0
  14. data/app/components/primer/component.rb +9 -0
  15. data/app/components/primer/counter_component.rb +85 -0
  16. data/app/components/primer/details_component.html.erb +8 -0
  17. data/app/components/primer/details_component.rb +63 -0
  18. data/app/components/primer/dropdown_menu_component.html.erb +8 -0
  19. data/app/components/primer/dropdown_menu_component.rb +28 -0
  20. data/app/components/primer/flex_component.rb +81 -0
  21. data/app/components/primer/flex_item_component.rb +21 -0
  22. data/app/components/primer/heading_component.rb +14 -0
  23. data/app/components/primer/label_component.rb +48 -0
  24. data/app/components/primer/layout_component.html.erb +17 -0
  25. data/app/components/primer/layout_component.rb +28 -0
  26. data/app/components/primer/link_component.rb +19 -0
  27. data/app/components/primer/popover_component.html.erb +10 -0
  28. data/app/components/primer/popover_component.rb +75 -0
  29. data/app/components/primer/progress_bar_component.html.erb +5 -0
  30. data/app/components/primer/progress_bar_component.rb +66 -0
  31. data/app/components/primer/slot.rb +8 -0
  32. data/app/components/primer/state_component.rb +53 -0
  33. data/app/components/primer/subhead_component.html.erb +17 -0
  34. data/app/components/primer/subhead_component.rb +89 -0
  35. data/app/components/primer/text_component.rb +14 -0
  36. data/app/components/primer/timeline_item_component.html.erb +17 -0
  37. data/app/components/primer/timeline_item_component.rb +69 -0
  38. data/app/components/primer/underline_nav_component.html.erb +11 -0
  39. data/app/components/primer/underline_nav_component.rb +22 -0
  40. data/app/components/primer/view_components.rb +48 -0
  41. data/lib/primer/class_name_helper.rb +27 -0
  42. data/lib/primer/classify.rb +245 -0
  43. data/lib/primer/fetch_or_fallback_helper.rb +41 -0
  44. data/lib/primer/view_components.rb +3 -0
  45. data/lib/primer/view_components/engine.rb +11 -0
  46. data/lib/primer/view_components/version.rb +1 -1
  47. metadata +203 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8df1dc4f482b73265126a1235b1797912bc6262f1dd3895bb02e95365187cd3a
4
- data.tar.gz: 88890fae6a2e9db3fd17d6cb28ba12cfab09ff05d90c04a74012ab013a2b7c21
3
+ metadata.gz: 8e2de200019cce82f6ab8da4f177fffa54cf62f703bca353b05376c9c7cb62ab
4
+ data.tar.gz: 9166cc8d3208cbaee4e9c0ae12cca3c5b53faa56d081fd4baa28f79b0d48f1fa
5
5
  SHA512:
6
- metadata.gz: 7cdc96278f5790ecd4c6dfcb8dd0ac3cfd9da6255fe1f442070941621af1cb5fd7e321ea7f8782a9be6d8338c01406432747bc7e5b3fc4b605c463d7153000a5
7
- data.tar.gz: 269e81f0aa474620d3b6f8398d96bd40bcce8bc11d3c117caea79b46ef1e8158da21f911337386f467145f6263394c01e45cfe58307db52051d04a9e2e22bce4
6
+ metadata.gz: deb5e962d169066fe55d7c28f9c81f7d5e59f5e13ee57dd33dfc80b0f37422c60feabb850ec4c6c02253ad3cace554a0146f74ed1287e075560ee39453e2f1f3
7
+ data.tar.gz: e15db34d645de8e42bb29136d95c2caf87c61e4c2c84f09bbbe9a4f11ed48a99478c1f06b0fc7bf165806a74b30e6ff15fcaf1439b3bebee290765759cd3f0b5
@@ -1,5 +1,95 @@
1
- # main
1
+ # 0.0.7
2
+
3
+ * Use `octicons_helper` v11.0.0.
4
+
5
+ *Joel Hawksley*
6
+
7
+ # 0.0.6
8
+
9
+ * Updated the invalid class name error message
10
+
11
+ *emplums*
12
+
13
+ * Updated README with testing instructions
14
+
15
+ *emplums*
16
+
17
+ * Add large and spacious option to BlankslateComponent
18
+
19
+ *simurai*
20
+
21
+ * Add option for `ButtonComponent` to render a `summary` tag
22
+
23
+ *Manuel Puyol*
24
+
25
+ ## Breaking changes
26
+
27
+ * Changed `DetailsComponent` summary and body to be slots
28
+
29
+ *Manuel Puyol*
30
+
31
+ # 0.0.5
32
+
33
+ * Add support for box_shadow
34
+ * Add components:
35
+ * Popover
36
+
37
+ *Sarah Vessels*
38
+
39
+ # 0.0.4
40
+
41
+ * Added support for mx: and my: :auto.
42
+
43
+ *Christian Giordano*
44
+
45
+ * Added support for custom layout sizes.
46
+
47
+ *Manuel Puyol*
48
+ # 0.0.3
49
+
50
+ * Add support for responsive `float` style argument.
51
+
52
+ *Joel Hawksley*
53
+
54
+ * Add components:
55
+ * Avatar
56
+ * Blankslate
57
+
58
+ *Manuel Puyol, Ben Emdon*
59
+
60
+ # 0.0.1
2
61
 
3
62
  * Add initial gem configuration.
4
63
 
5
- *Manuel Puyol, Joel Hawksley*
64
+ *Manuel Puyol, Joel Hawksley*
65
+
66
+ * Add demo app and storybook to test
67
+
68
+ *Manuel Puyol*
69
+
70
+ * Add Classify, FetchOrFallback and ClassName helpers
71
+
72
+ *Manuel Puyol*
73
+
74
+ * Add components:
75
+ * BorderBox
76
+ * Box
77
+ * Breadcrumb
78
+ * Button
79
+ * Counter
80
+ * Details
81
+ * Dropdown
82
+ * Flex
83
+ * FlexItem
84
+ * Heading
85
+ * Label
86
+ * Layout
87
+ * Link
88
+ * ProgressBar
89
+ * State
90
+ * Subhead
91
+ * Text
92
+ * TimelineItem
93
+ * UnderlineNav
94
+
95
+ *Manuel Puyol*
data/README.md CHANGED
@@ -6,6 +6,12 @@
6
6
 
7
7
  <p align="center">ViewComponents for the Primer Design System</p>
8
8
 
9
+ _Note: This library is in pre-release development and should not be considered stable._
10
+
11
+ ## Design philosophy
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
+
9
15
  ## Installation
10
16
 
11
17
  In `Gemfile`, add:
@@ -14,10 +20,153 @@ In `Gemfile`, add:
14
20
  gem "primer_view_components"
15
21
  ```
16
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
+ | `word_break` | `wb-<value>` | `word_break: :break_all` → `.wb-break-all` |
81
+ | `direction` | `flex-<value>` | `direction: :row` → `.flex-row` |
82
+ | `justify_content` | `flex-justify-<value>` | `justify_content: :center` → `.flex-justify-center` |
83
+ | `align_items` | `flex-items-<value>` | `align_items: :baseline` → `.flex-items-baseline` |
84
+ | `box_shadow` | `box-shadow-<value>` | `box_shadow: :medium` → `.box-shadow-medium` |
85
+
86
+ #### Boolean arguments
87
+ | Component arguments | True | False |
88
+ | -------------- | ------- | ------ |
89
+ | `underline` | `underline: true` → `.text-underline` | `underline: false` → `.no-underline` |
90
+ | `top` | n/a | `top: false` → `.top-0` |
91
+ | `bottom` | n/a | `bottom: false` → `.bottom-0` |
92
+ | `left` | n/a | `left: false` → `.left-0` |
93
+ | `right` | n/a | `right: false` → `.right-0` |
94
+
95
+ #### Responsive arguments
96
+
97
+ 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`.
98
+
99
+ Example heading built with Primer CSS:
100
+
101
+ ```html
102
+ <h1 class="mt-0 mt-lg-4">Hello world</h1>
103
+ ```
104
+
105
+ The same label using `Primer::HeadingComponent`:
106
+
107
+ ```erb
108
+ <%= render Primer::HeadingComponent.new(mt: [0, nil, nil, 4]) do %>
109
+ Hello world
110
+ <% end %>
111
+ ```
112
+
17
113
  ## Contributing
18
114
 
19
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.
20
116
 
117
+ ### Setting up
118
+
119
+ Run
120
+
121
+ ```bash
122
+ script/setup
123
+ ```
124
+
125
+ to install all necessary dependencies
126
+
127
+
128
+ ### Running tests
129
+
130
+ To run the full test suite:
131
+
132
+ ```bash
133
+ bundle exec rake
134
+ ```
135
+
136
+ ### Storybook
137
+
138
+ *We recommend having [overmind](https://github.com/DarthSim/overmind) installed to run both rails and storybook, but it is not required.*
139
+
140
+ To run storybook:
141
+
142
+ ```bash
143
+ script/storybook
144
+ ```
145
+
146
+ ### Developing with another app
147
+
148
+ In your `Gemfile`, change:
149
+
150
+ ```ruby
151
+ gem "primer_view_components"
152
+ ```
153
+
154
+ to
155
+
156
+ ```ruby
157
+ gem "primer_view_components", path: "path_to_the_gem" # e.g. path: "~/primer/view_components"
158
+ ```
159
+
160
+ Then, `bundle install` to update references. You'll now be able to see changes from the gem without having to build it.
161
+ Remember that restarting the Rails server is necessary to see changes, as the gem is loaded at boot time.
162
+
163
+ To minimize the number of restarts, we recommend checking the component in Storybook first, and then when it's in a good state,
164
+ you can check it in your app.
165
+
166
+ ### Documentation
167
+
168
+ Document components with [YARD](https://yardoc.org/). Docs are published to [RubyDoc.info](https://rubydoc.info/github/primer/view_components).
169
+
21
170
  ## License
22
171
 
23
172
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ class AvatarComponent < Primer::Component
5
+ SMALL_THRESHOLD = 24
6
+
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
15
+
16
+ @kwargs[:classes] = class_names(
17
+ "avatar",
18
+ kwargs[:classes],
19
+ "avatar--small" => size < SMALL_THRESHOLD,
20
+ "CircleBadge" => !square
21
+ )
22
+ end
23
+
24
+ def call
25
+ render(Primer::BaseComponent.new(**@kwargs)) { content }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
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
+ class BaseComponent < Primer::Component
15
+ TEST_SELECTOR_TAG = :test_selector
16
+
17
+ def initialize(tag:, classes: nil, **args)
18
+ @tag = tag
19
+ @result = Primer::Classify.call(**args.merge(classes: classes))
20
+
21
+ # 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)
23
+ end
24
+
25
+ def call
26
+ tag.public_send(
27
+ @tag, content, **@content_tag_args.merge(@result)
28
+ )
29
+ end
30
+
31
+ private
32
+
33
+ def add_test_selector(args)
34
+ if args.key?(TEST_SELECTOR_TAG) && !Rails.env.production?
35
+ args[:data] ||= {}
36
+ args[:data][TEST_SELECTOR_TAG] = args[TEST_SELECTOR_TAG]
37
+ end
38
+
39
+ args.except(TEST_SELECTOR_TAG)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ <%= render Primer::BaseComponent.new(**@kwargs) do %>
2
+ <% if @icon.present? %>
3
+ <%= octicon @icon, height: @icon_height, class: "blankslate-icon" %>
4
+ <% end %>
5
+
6
+ <% if @image_src.present? && @image_alt.present? %>
7
+ <%= image_tag "#{@image_src}", class: "mb-3", size: "56x56", alt: "#{@image_alt}" %>
8
+ <% end %>
9
+
10
+ <<%= @title_tag %> class="mb-1"><%= @title %></<%= @title_tag %>>
11
+
12
+ <% if @description.present? %>
13
+ <p><%= @description %></p>
14
+ <% end %>
15
+
16
+ <%= content %>
17
+
18
+ <% if @button_text.present? && @button_url.present? %>
19
+ <a class="btn <%= @button_classes %>" href="<%= @button_url %>"><%= @button_text %></a>
20
+ <% end %>
21
+
22
+ <% if @link_text.present? && @link_url.present? %>
23
+ <p>
24
+ <%= link_to "#{@link_url}" do %><%= @link_text %><% end %>
25
+ </p>
26
+ <% end %>
27
+ <% end %>
@@ -0,0 +1,164 @@
1
+ # frozen_string_literal: true
2
+
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
+ # - `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
+ # ```
115
+ class BlankslateComponent < Primer::Component
116
+ def initialize(
117
+ # required
118
+ title:,
119
+
120
+ # optional
121
+ title_tag: :h3,
122
+ icon: "",
123
+ icon_height: 32,
124
+ image_src: "",
125
+ image_alt: " ",
126
+ description: "",
127
+ button_text: "",
128
+ button_url: "",
129
+ button_classes: "btn-primary my-3",
130
+ link_text: "",
131
+ link_url: "",
132
+
133
+ #variations
134
+ narrow: false,
135
+ large: false,
136
+ spacious: false,
137
+
138
+ **kwargs
139
+ )
140
+ @kwargs = kwargs
141
+ @kwargs[:tag] = :div
142
+ @kwargs[:classes] = class_names(
143
+ @kwargs[:classes],
144
+ "blankslate",
145
+ "blankslate-narrow": narrow,
146
+ "blankslate-large": large,
147
+ "blankslate-spacious": spacious,
148
+ )
149
+
150
+ @title_tag = title_tag
151
+ @icon = icon
152
+ @icon_height = icon_height
153
+ @image_src = image_src
154
+ @image_alt = image_alt
155
+ @title = title
156
+ @description = description
157
+ @button_text = button_text
158
+ @button_url = button_url
159
+ @button_classes = button_classes
160
+ @link_text = link_text
161
+ @link_url = link_url
162
+ end
163
+ end
164
+ end