primer_view_components 0.0.74 → 0.0.75

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.
@@ -1,24 +1,26 @@
1
1
  <%= render Primer::BaseComponent.new(**@system_arguments) do %>
2
- <label for="<%= @input_id %>" class="<%= @label_classes %>">
3
- <% if @is_label_visible %>
2
+ <div class="<%= @form_group_classes %>">
3
+ <label for="<%= @input_id %>" class="FormControl-label <% if @visually_hide_label %>sr-only<% end %>">
4
4
  <%= @label_text %>
5
+ </label>
6
+ <% if leading_visual || @show_clear_button %>
7
+ <div class="<%= @field_wrap_classes %> <% if leading_visual %>FormControl-fieldWrap--input-leadingVisual<% end %>">
8
+ <%= leading_visual %>
9
+ <%= input %>
10
+ <% if @show_clear_button %>
11
+ <button id="<%= @input_id %>-clear" class="FormControl--input-trailingAction" aria-label="Clear"><%= primer_octicon "x-circle-fill" %></button>
12
+ <% end %>
13
+ </div>
5
14
  <% else %>
6
- <span class="sr-only"><%= @label_text %></span>
15
+ <%= input %>
7
16
  <% end %>
8
- </label>
9
- <span class="autocomplete-body">
10
- <% if @with_icon %>
11
- <div class="form-control autocomplete-embedded-icon-wrap">
12
- <%= render Primer::OcticonComponent.new(:search) %>
13
- <% end %>
14
- <%= input %>
15
- <% if @is_clearable %>
16
- <button id="<%= @input_id %>-clear" class="btn-octicon" aria-label="Clear"><%= primer_octicon "x" %></button>
17
- <% end %>
18
- <% if @with_icon %>
17
+ </div>
18
+ <div class="Overlay-backdrop--anchor">
19
+ <div class="Overlay Overlay--height-auto Overlay--width-auto">
20
+ <div class="Overlay-body Overlay-body--paddingNone">
21
+ <%= results %>
19
22
  </div>
20
- <% end %>
21
- <%= results %>
22
- </span>
23
+ </div>
24
+ </div>
23
25
  <div id="<%= @list_id %>-feedback" class="sr-only"></div>
24
26
  <% end %>
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # TODO: use generic ActionList item for Autocomplete
3
4
  module Primer
4
5
  module Beta
5
6
  class AutoComplete
@@ -29,14 +30,17 @@ module Primer
29
30
  @system_arguments[:"aria-disabled"] = true if disabled
30
31
 
31
32
  @system_arguments[:classes] = class_names(
32
- "autocomplete-item",
33
- system_arguments[:classes],
34
- "disabled" => disabled
33
+ "ActionList-item",
34
+ system_arguments[:classes]
35
35
  )
36
36
  end
37
37
 
38
38
  def call
39
- render(Primer::BaseComponent.new(**@system_arguments)) { content }
39
+ render(Primer::BaseComponent.new(**@system_arguments)) do
40
+ render(Primer::BaseComponent.new(tag: :span, classes: "ActionList-content")) do
41
+ render(Primer::BaseComponent.new(tag: :span, classes: "ActionList-item-label")) { content }
42
+ end
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -8,11 +8,20 @@ module Primer
8
8
  # Always set an accessible label to help the user interact with the component.
9
9
  #
10
10
  # * `label_text` is required and visible by default.
11
- # * If you must use a non-visible label, set `is_label_visible` to `false`.
11
+ # * If you must hide the label, set `visually_hide_label` to `true`.
12
12
  # However, please note that a visible label should almost always
13
13
  # be used unless there is compelling reason not to. A placeholder is not a label.
14
14
  class AutoComplete < Primer::Component
15
15
  status :beta
16
+
17
+ DEFAULT_SIZE = :medium
18
+ SIZE_MAPPINGS = {
19
+ :small => "FormControl--small",
20
+ DEFAULT_SIZE => "FormControl--medium",
21
+ :large => "FormControl--large"
22
+ }.freeze
23
+ SIZE_OPTIONS = SIZE_MAPPINGS.keys
24
+
16
25
  #
17
26
  # Customizable results list.
18
27
  #
@@ -22,13 +31,26 @@ module Primer
22
31
  system_arguments[:tag] = :ul
23
32
  system_arguments[:id] = @list_id
24
33
  system_arguments[:classes] = class_names(
25
- "autocomplete-results",
34
+ "ActionList",
26
35
  system_arguments[:classes]
27
36
  )
28
37
 
29
38
  Primer::BaseComponent.new(**system_arguments)
30
39
  }
31
40
 
41
+ #
42
+ # Leading visual.
43
+ #
44
+ # - `leading_visual_icon` for a <%= link_to_component(Primer::OcticonComponent) %>.
45
+ #
46
+ # @param system_arguments [Hash] Same arguments as <%= link_to_component(Primer::OcticonComponent) %>.
47
+ renders_one :leading_visual, types: {
48
+ icon: lambda { |**system_arguments|
49
+ system_arguments[:classes] = class_names("FormControl--input-leadingVisual")
50
+ Primer::OcticonComponent.new(**system_arguments)
51
+ }
52
+ }
53
+
32
54
  # Customizable input used to search for results.
33
55
  # It is preferred to use this slot sparingly - it will be created by default if not explicity added.
34
56
  #
@@ -38,7 +60,7 @@ module Primer
38
60
  sanitized_args = deny_single_argument(:autofocus, "autofocus is not allowed for accessibility reasons. See https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus#accessibility_considerations for more information.", **sanitized_args)
39
61
  deny_aria_key(
40
62
  :label,
41
- "instead of `aria-label`, include `label_text` and set `is_label_visible` to `false` on the component initializer.",
63
+ "instead of `aria-label`, include `label_text` and set `visually_hide_label` to `true` on the component initializer.",
42
64
  **sanitized_args
43
65
  )
44
66
  deny_single_argument(
@@ -55,45 +77,82 @@ module Primer
55
77
  sanitized_args[:name] = @input_name
56
78
  sanitized_args[:tag] = :input
57
79
  sanitized_args[:autocomplete] = "off"
58
-
80
+ sanitized_args[:disabled] = true if @disabled
81
+ sanitized_args[:invalid] = true if @invalid
59
82
  sanitized_args[:type] = :text
60
83
  sanitized_args[:classes] = class_names(
61
- "form-control",
84
+ "FormControl",
85
+ "FormControl--input",
86
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, @size, DEFAULT_SIZE)],
62
87
  sanitized_args[:classes]
63
88
  )
89
+ sanitized_args[:placeholder] = @placeholder
64
90
 
65
91
  Primer::BaseComponent.new(**sanitized_args)
66
92
  }
67
93
 
68
- # @example Default
94
+ # @example Leading visual
69
95
  # @description
70
- # Labels are stacked by default.
96
+ # Display any Octicon as a leading visual within the field
71
97
  # @code
72
- # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", input_id: "fruits-input--default", list_id: "fruits-popup--default")) %>
98
+ # <%= render(Primer::Beta::AutoComplete.new(label_text: "Select a fruit", src: "/auto_complete", input_id:"input-id-1", list_id: "list-id-1")) do |c| %>
99
+ # <% c.leading_visual_icon(icon: :search) %>
100
+ # <% c.results do %>
101
+ # <%= render(Primer::Beta::AutoComplete::Item.new(selected: true, value: "apple")) do |_c| %>
102
+ # Apple
103
+ # <% end %>
104
+ # <%= render(Primer::Beta::AutoComplete::Item.new(value: "orange")) do |_c| %>
105
+ # Orange
106
+ # <% end %>
107
+ # <% end %>
108
+ # <% end %>
73
109
  #
74
- # @example With inline label
110
+ # @example Trailing action
75
111
  # @description
76
- # Labels can be inline by setting `is_label_inline: true`. However, labels will always become stacked on smaller screen sizes.
112
+ # Show a clear button
77
113
  # @code
78
- # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", is_label_inline: true, input_id: "fruits-input--inline-label", list_id: "fruits-popup--inline-label")) %>
114
+ # <%= render(Primer::Beta::AutoComplete.new(label_text: "Select a fruit", input_id: "input-id-2", list_id: "list-id-2", src: "/auto_complete", show_clear_button: true )) do |c| %>
115
+ # <% c.results do %>
116
+ # <%= render(Primer::Beta::AutoComplete::Item.new(selected: true, value: "apple")) do |_c| %>
117
+ # Apple
118
+ # <% end %>
119
+ # <%= render(Primer::Beta::AutoComplete::Item.new(value: "orange")) do |_c| %>
120
+ # Orange
121
+ # <% end %>
122
+ # <% end %>
123
+ # <% end %>
79
124
  #
80
- # @example With non-visible label
125
+ # @example Visually hidden label
81
126
  # @description
82
- # A non-visible label may be rendered with `is_label_visible: false`, but it is highly discouraged. See <%= link_to_accessibility %>.
127
+ # A non-visible label may be rendered with `visually_hide_label: true`, but it is highly discouraged. See <%= link_to_accessibility %>.
83
128
  # @code
84
- # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", input_id: "fruits-input--non-visible-label", list_id: "fruits-popup--non-visible-label", is_label_visible: false)) %>
129
+ # <%= render(Primer::Beta::AutoComplete.new(label_text: "Select a fruit", input_id: "fruits-input--custom-results-1", list_id: "fruits-popup--custom-result-1", src: "/auto_complete", visually_hide_label: true)) do |c| %>
130
+ # <% c.leading_visual_icon(icon: :search) %>
131
+ # <% c.results do %>
132
+ # <%= render(Primer::Beta::AutoComplete::Item.new(selected: true, value: "apple")) do |_c| %>
133
+ # Apple
134
+ # <% end %>
135
+ # <%= render(Primer::Beta::AutoComplete::Item.new(value: "orange")) do |_c| %>
136
+ # Orange
137
+ # <% end %>
138
+ # <% end %>
139
+ # <% end %>
85
140
  #
86
- # @example With icon
141
+ # @example Full width field
87
142
  # @description
88
- # To display a search icon, set `with_icon` to `true`.
143
+ # To allow field to span width of its container, set `full_width` to `true`.
89
144
  # @code
90
- # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", list_id: "fruits-popup--icon", input_id: "fruits-input--icon", with_icon: true)) %>
91
- #
92
- # @example With icon and non-visible label
93
- # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", list_id: "fruits-popup--icon-no-label", input_id: "fruits-input--icon-no-label", with_icon: true, is_label_visible: false)) %>
94
- #
95
- # @example With clear button
96
- # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", input_id: "fruits-input--clear", list_id: "fruits-popup--clear", is_clearable: true)) %>
145
+ # <%= render(Primer::Beta::AutoComplete.new(label_text: "Select a fruit", input_id: "fruits-input--custom-results-2", list_id: "fruits-popup--custom-results-2", src: "/auto_complete", full_width: true)) do |c| %>
146
+ # <% c.leading_visual_icon(icon: :search) %>
147
+ # <% c.results do %>
148
+ # <%= render(Primer::Beta::AutoComplete::Item.new(selected: true, value: "apple")) do |_c| %>
149
+ # Apple
150
+ # <% end %>
151
+ # <%= render(Primer::Beta::AutoComplete::Item.new(value: "orange")) do |_c| %>
152
+ # Orange
153
+ # <% end %>
154
+ # <% end %>
155
+ # <% end %>
97
156
  #
98
157
  # @example With custom classes for the input
99
158
  # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", input_id: "fruits-input--custom-input", list_id: "fruits-popup--custom-input")) do |c| %>
@@ -117,25 +176,42 @@ module Primer
117
176
  # @param input_id [String] Id of the input element.
118
177
  # @param input_name [String] Optional name of the input element, defaults to `input_id` when not set.
119
178
  # @param list_id [String] Id of the list element.
120
- # @param with_icon [Boolean] Controls if a search icon is visible, defaults to `false`.
121
- # @param is_label_visible [Boolean] Controls if the label is visible. If `false`, screen reader only text will be added.
122
- # @param is_clearable [Boolean] Adds optional clear button.
123
- # @param is_label_inline [Boolean] Controls if the label is inline. On smaller screens, label will always become stacked.
179
+ # @param visually_hide_label [Boolean] Controls if the label is visible. If `true`, screen reader only text will be added.
180
+ # @param show_clear_button [Boolean] Adds optional clear button.
124
181
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
125
- def initialize(label_text:, src:, list_id:, input_id:, input_name: nil, is_label_visible: true, is_label_inline: false, with_icon: false, is_clearable: false, **system_arguments)
182
+ # @param size [Hash] Input size can be small, medium (default), or large
183
+ # @param full_width [Boolean] Input can be full-width or fit to content
184
+ # @param disabled [Boolean] Disabled input
185
+ # @param invalid [Boolean] Invalid input
186
+ # @param placeholder [String] The placeholder text displayed within the input
187
+ def initialize(label_text:, src:, list_id:, input_id:, input_name: nil, placeholder: nil, show_clear_button: false, visually_hide_label: false, size: DEFAULT_SIZE, full_width: false, disabled: false, invalid: false, **system_arguments)
126
188
  @label_text = label_text
127
189
  @list_id = list_id
128
190
  @input_id = input_id
129
191
  @input_name = input_name || input_id
130
- @is_label_visible = is_label_visible
131
- @with_icon = with_icon
132
- @is_clearable = is_clearable
133
-
134
- @label_classes = label_classes(is_label_visible: is_label_visible, is_label_inline: is_label_inline)
192
+ @placeholder = placeholder
193
+ @visually_hide_label = visually_hide_label
194
+ @show_clear_button = show_clear_button
135
195
  @system_arguments = deny_tag_argument(**system_arguments)
136
196
  @system_arguments[:tag] = "auto-complete"
137
197
  @system_arguments[:src] = src
138
198
  @system_arguments[:for] = list_id
199
+ @disabled = disabled
200
+ @invalid = invalid
201
+ @size = size
202
+ @full_width = full_width
203
+ @field_wrap_classes = class_names(
204
+ "FormControl-fieldWrap",
205
+ "FormControl-fieldWrap--input",
206
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, @size, DEFAULT_SIZE)],
207
+ "FormControl-fieldWrap--disabled": disabled,
208
+ "FormControl-fieldWrap--invalid": invalid,
209
+ "FormControl-fieldWrap--input-trailingAction": show_clear_button
210
+ )
211
+ @form_group_classes = class_names(
212
+ "FormGroup",
213
+ "FormGroup--fullWidth": full_width
214
+ )
139
215
  end
140
216
 
141
217
  # add `input` and `results` without needing to explicitly call them in the view
@@ -143,20 +219,6 @@ module Primer
143
219
  results(classes: "") unless results
144
220
  input(classes: "") unless input
145
221
  end
146
-
147
- private
148
-
149
- # Private: determines the label classes based on component configration.
150
- #
151
- # If the label is not visible, return an empty string.
152
- #
153
- # @param args [Hash] The component configuration.
154
- # @return [String] The label classes.
155
- def label_classes(**args)
156
- return "" if args[:is_label_visible] == false
157
-
158
- args[:is_label_inline] ? "autocomplete-label-inline" : "autocomplete-label-stacked"
159
- end
160
222
  end
161
223
  end
162
224
  end
@@ -5,7 +5,7 @@ module Primer
5
5
  module VERSION
6
6
  MAJOR = 0
7
7
  MINOR = 0
8
- PATCH = 74
8
+ PATCH = 75
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
11
11
  end
@@ -33,6 +33,16 @@ module RuboCop
33
33
  # }
34
34
  #
35
35
  DEPRECATED = {
36
+ is_label_inline: nil,
37
+ with_icon: nil,
38
+ is_label_visible: {
39
+ false => "visually_hide_label: true",
40
+ true => "visually_hide_label: false"
41
+ },
42
+ is_clearable: {
43
+ false => "show_clear_button: false",
44
+ true => "show_clear_button: true"
45
+ },
36
46
  bg: {
37
47
  white: "bg: :primary",
38
48
  gray_light: "bg: :secondary",
data/lib/tasks/docs.rake CHANGED
@@ -343,11 +343,10 @@ namespace :docs do
343
343
  nav_yaml = YAML.load_file(nav_yaml_file)
344
344
  adr_entry = {
345
345
  "title" => "Architecture decisions",
346
- "url" => "/adr",
347
346
  "children" => nav_entries.compact
348
347
  }
349
348
 
350
- existing_index = nav_yaml.index { |entry| entry["url"] == "/adr" }
349
+ existing_index = nav_yaml.index { |entry| entry["title"] == "Architecture decisions" }
351
350
  if existing_index
352
351
  nav_yaml[existing_index] = adr_entry
353
352
  else
data/static/arguments.yml CHANGED
@@ -210,28 +210,39 @@
210
210
  type: String
211
211
  default: N/A
212
212
  description: Id of the list element.
213
- - name: with_icon
213
+ - name: visually_hide_label
214
214
  type: Boolean
215
215
  default: "`false`"
216
- description: Controls if a search icon is visible, defaults to `false`.
217
- - name: is_label_visible
218
- type: Boolean
219
- default: "`true`"
220
- description: Controls if the label is visible. If `false`, screen reader only
221
- text will be added.
222
- - name: is_clearable
216
+ description: Controls if the label is visible. If `true`, screen reader only text
217
+ will be added.
218
+ - name: show_clear_button
223
219
  type: Boolean
224
220
  default: "`false`"
225
221
  description: Adds optional clear button.
226
- - name: is_label_inline
227
- type: Boolean
228
- default: "`false`"
229
- description: Controls if the label is inline. On smaller screens, label will always
230
- become stacked.
231
222
  - name: system_arguments
232
223
  type: Hash
233
224
  default: N/A
234
225
  description: "[System arguments](/system-arguments)"
226
+ - name: size
227
+ type: Hash
228
+ default: "`:medium`"
229
+ description: Input size can be small, medium (default), or large
230
+ - name: full_width
231
+ type: Boolean
232
+ default: "`false`"
233
+ description: Input can be full-width or fit to content
234
+ - name: disabled
235
+ type: Boolean
236
+ default: "`false`"
237
+ description: Disabled input
238
+ - name: invalid
239
+ type: Boolean
240
+ default: "`false`"
241
+ description: Invalid input
242
+ - name: placeholder
243
+ type: String
244
+ default: "`nil`"
245
+ description: The placeholder text displayed within the input
235
246
  - component: AutoCompleteItem
236
247
  source: https://github.com/primer/view_components/tree/main/app/components/primer/beta/auto_complete/item.rb
237
248
  parameters:
data/static/classes.yml CHANGED
@@ -1,4 +1,8 @@
1
1
  ---
2
+ - ".ActionList"
3
+ - ".ActionList-content"
4
+ - ".ActionList-item"
5
+ - ".ActionList-item-label"
2
6
  - ".AvatarStack"
3
7
  - ".AvatarStack--right"
4
8
  - ".AvatarStack--three-plus"
@@ -19,6 +23,18 @@
19
23
  - ".Counter"
20
24
  - ".Counter--primary"
21
25
  - ".Counter--secondary"
26
+ - ".FormControl"
27
+ - ".FormControl--input"
28
+ - ".FormControl--input-leadingVisual"
29
+ - ".FormControl--input-trailingAction"
30
+ - ".FormControl--medium"
31
+ - ".FormControl-fieldWrap"
32
+ - ".FormControl-fieldWrap--input"
33
+ - ".FormControl-fieldWrap--input-leadingVisual"
34
+ - ".FormControl-fieldWrap--input-trailingAction"
35
+ - ".FormControl-label"
36
+ - ".FormGroup"
37
+ - ".FormGroup--fullWidth"
22
38
  - ".Label"
23
39
  - ".Label--accent"
24
40
  - ".Label--attention"
@@ -49,6 +65,12 @@
49
65
  - ".Link--muted"
50
66
  - ".Link--primary"
51
67
  - ".Link--secondary"
68
+ - ".Overlay"
69
+ - ".Overlay--height-auto"
70
+ - ".Overlay--width-auto"
71
+ - ".Overlay-backdrop--anchor"
72
+ - ".Overlay-body"
73
+ - ".Overlay-body--paddingNone"
52
74
  - ".Popover"
53
75
  - ".Popover-message"
54
76
  - ".Popover-message--large"
@@ -82,12 +104,6 @@
82
104
  - ".UnderlineNav-item"
83
105
  - ".UnderlineNav-octicon"
84
106
  - ".anim-rotate"
85
- - ".autocomplete-body"
86
- - ".autocomplete-embedded-icon-wrap"
87
- - ".autocomplete-item"
88
- - ".autocomplete-label-inline"
89
- - ".autocomplete-label-stacked"
90
- - ".autocomplete-results"
91
107
  - ".avatar"
92
108
  - ".avatar-more"
93
109
  - ".avatar-small"
@@ -167,7 +183,6 @@
167
183
  - ".flex-justify-center"
168
184
  - ".flex-shrink-0"
169
185
  - ".float-right"
170
- - ".form-control"
171
186
  - ".gutter-condensed"
172
187
  - ".gutter-lg"
173
188
  - ".hidden-text-expander"
@@ -199,7 +199,18 @@
199
199
  ]
200
200
  },
201
201
  "Primer::Beta::AutoComplete": {
202
- "Item": "Primer::Beta::AutoComplete::Item"
202
+ "DEFAULT_SIZE": "medium",
203
+ "Item": "Primer::Beta::AutoComplete::Item",
204
+ "SIZE_MAPPINGS": {
205
+ "small": "FormControl--small",
206
+ "medium": "FormControl--medium",
207
+ "large": "FormControl--large"
208
+ },
209
+ "SIZE_OPTIONS": [
210
+ "small",
211
+ "medium",
212
+ "large"
213
+ ]
203
214
  },
204
215
  "Primer::Beta::AutoComplete::Item": {
205
216
  },
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.74
4
+ version: 0.0.75
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: 2022-05-13 00:00:00.000000000 Z
11
+ date: 2022-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -366,7 +366,7 @@ dependencies:
366
366
  - - "~>"
367
367
  - !ruby/object:Gem::Version
368
368
  version: 0.9.25
369
- description:
369
+ description:
370
370
  email:
371
371
  - opensource+primer_view_components@github.com
372
372
  executables: []
@@ -580,7 +580,7 @@ licenses:
580
580
  - MIT
581
581
  metadata:
582
582
  allowed_push_host: https://rubygems.org
583
- post_install_message:
583
+ post_install_message:
584
584
  rdoc_options: []
585
585
  require_paths:
586
586
  - lib
@@ -595,8 +595,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
595
595
  - !ruby/object:Gem::Version
596
596
  version: '0'
597
597
  requirements: []
598
- rubygems_version: 3.2.22
599
- signing_key:
598
+ rubygems_version: 3.1.6
599
+ signing_key:
600
600
  specification_version: 4
601
601
  summary: ViewComponents for the Primer Design System
602
602
  test_files: []