primer_view_components 0.0.77 → 0.0.78

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f84596b796b25618ed97b1f6fd73cca3e3d1a379589d06748d167e18a36118b0
4
- data.tar.gz: 6d9aa8f0332223a345227263eeae4f71e21724208ceed6fcb7f929e322beb177
3
+ metadata.gz: 14696807be6f622296821fc11d6d18603697762804b6dcd3d1d9904fb738ab3a
4
+ data.tar.gz: 6d4fb8b39611673742ee07c3b3ea8efc5b12c32e501aa57300c2269016bfd212
5
5
  SHA512:
6
- metadata.gz: c1f71999579298bd8e7649ee0be439be3261b6fd76729bdf69dd771381160c0caad8ce7a2fae10c5df49163ba9aabba6741697c81fa7e868f684a19df86290f2
7
- data.tar.gz: 4783a639eb3848cbf1f3cf068c4905751bcdfb9ebc4c58ce10d45c16c5c0a85a6eed3cc689e06771176894590eeecba23aeb0cc37bfd35a57494461e7efdd8a6
6
+ metadata.gz: 13db29020f596d335cc64dfdf018a04896471d73de9d60a175cf68d4414bc671209f66c5de2c9abe03a88f3680ccef9c7ef96e81a3f0b83910be53aaaa64bf53
7
+ data.tar.gz: fca103d7eaea214d08184b5f959797806d1c5d1f809b9de1a4250cada31b023f92f9a496c2208fc7feb0559b174925c2389c796b6b3af18665aeb4818f788563
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.78
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1186](https://github.com/primer/view_components/pull/1186) [`ff2c3fe1`](https://github.com/primer/view_components/commit/ff2c3fe1913d7a1d65dbd4f608b68155ed247bef) Thanks [@joelhawksley](https://github.com/joelhawksley)! - Revert #1163, as additional work will be needed to ship those changes to production successfully.
8
+
3
9
  ## 0.0.77
4
10
 
5
11
  ### Patch Changes
@@ -1,26 +1,24 @@
1
1
  <%= render Primer::BaseComponent.new(**@system_arguments) do %>
2
- <div class="<%= @form_group_classes %>">
3
- <label for="<%= @input_id %>" class="FormControl-label <% if @visually_hide_label %>sr-only<% end %>">
2
+ <label for="<%= @input_id %>" class="<%= @label_classes %>">
3
+ <% if @is_label_visible %>
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>
14
5
  <% else %>
15
- <%= input %>
6
+ <span class="sr-only"><%= @label_text %></span>
16
7
  <% end %>
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 %>
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 %>
22
19
  </div>
23
- </div>
24
- </div>
20
+ <% end %>
21
+ <%= results %>
22
+ </span>
25
23
  <div id="<%= @list_id %>-feedback" class="sr-only"></div>
26
24
  <% end %>
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # TODO: use generic ActionList item for Autocomplete
4
3
  module Primer
5
4
  module Beta
6
5
  class AutoComplete
@@ -30,17 +29,14 @@ module Primer
30
29
  @system_arguments[:"aria-disabled"] = true if disabled
31
30
 
32
31
  @system_arguments[:classes] = class_names(
33
- "ActionList-item",
34
- system_arguments[:classes]
32
+ "autocomplete-item",
33
+ system_arguments[:classes],
34
+ "disabled" => disabled
35
35
  )
36
36
  end
37
37
 
38
38
  def call
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
39
+ render(Primer::BaseComponent.new(**@system_arguments)) { content }
44
40
  end
45
41
  end
46
42
  end
@@ -8,20 +8,11 @@ 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 hide the label, set `visually_hide_label` to `true`.
11
+ # * If you must use a non-visible label, set `is_label_visible` to `false`.
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
-
25
16
  #
26
17
  # Customizable results list.
27
18
  #
@@ -31,26 +22,13 @@ module Primer
31
22
  system_arguments[:tag] = :ul
32
23
  system_arguments[:id] = @list_id
33
24
  system_arguments[:classes] = class_names(
34
- "ActionList",
25
+ "autocomplete-results",
35
26
  system_arguments[:classes]
36
27
  )
37
28
 
38
29
  Primer::BaseComponent.new(**system_arguments)
39
30
  }
40
31
 
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
-
54
32
  # Customizable input used to search for results.
55
33
  # It is preferred to use this slot sparingly - it will be created by default if not explicity added.
56
34
  #
@@ -60,7 +38,7 @@ module Primer
60
38
  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)
61
39
  deny_aria_key(
62
40
  :label,
63
- "instead of `aria-label`, include `label_text` and set `visually_hide_label` to `true` on the component initializer.",
41
+ "instead of `aria-label`, include `label_text` and set `is_label_visible` to `false` on the component initializer.",
64
42
  **sanitized_args
65
43
  )
66
44
  deny_single_argument(
@@ -77,82 +55,45 @@ module Primer
77
55
  sanitized_args[:name] = @input_name
78
56
  sanitized_args[:tag] = :input
79
57
  sanitized_args[:autocomplete] = "off"
80
- sanitized_args[:disabled] = true if @disabled
81
- sanitized_args[:invalid] = true if @invalid
58
+
82
59
  sanitized_args[:type] = :text
83
60
  sanitized_args[:classes] = class_names(
84
- "FormControl",
85
- "FormControl--input",
86
- SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, @size, DEFAULT_SIZE)],
61
+ "form-control",
87
62
  sanitized_args[:classes]
88
63
  )
89
- sanitized_args[:placeholder] = @placeholder
90
64
 
91
65
  Primer::BaseComponent.new(**sanitized_args)
92
66
  }
93
67
 
94
- # @example Leading visual
68
+ # @example Default
95
69
  # @description
96
- # Display any Octicon as a leading visual within the field
70
+ # Labels are stacked by default.
97
71
  # @code
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 %>
72
+ # <%= render(Primer::Beta::AutoComplete.new(label_text: "Fruits", src: "/auto_complete", input_id: "fruits-input--default", list_id: "fruits-popup--default")) %>
109
73
  #
110
- # @example Trailing action
74
+ # @example With inline label
111
75
  # @description
112
- # Show a clear button
76
+ # Labels can be inline by setting `is_label_inline: true`. However, labels will always become stacked on smaller screen sizes.
113
77
  # @code
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 %>
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")) %>
124
79
  #
125
- # @example Visually hidden label
80
+ # @example With non-visible label
126
81
  # @description
127
- # A non-visible label may be rendered with `visually_hide_label: true`, but it is highly discouraged. See <%= link_to_accessibility %>.
82
+ # A non-visible label may be rendered with `is_label_visible: false`, but it is highly discouraged. See <%= link_to_accessibility %>.
128
83
  # @code
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 %>
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)) %>
140
85
  #
141
- # @example Full width field
86
+ # @example With icon
142
87
  # @description
143
- # To allow field to span width of its container, set `full_width` to `true`.
88
+ # To display a search icon, set `with_icon` to `true`.
144
89
  # @code
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 %>
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)) %>
156
97
  #
157
98
  # @example With custom classes for the input
158
99
  # <%= 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| %>
@@ -176,42 +117,25 @@ module Primer
176
117
  # @param input_id [String] Id of the input element.
177
118
  # @param input_name [String] Optional name of the input element, defaults to `input_id` when not set.
178
119
  # @param list_id [String] Id of the list element.
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.
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.
181
124
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
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)
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)
188
126
  @label_text = label_text
189
127
  @list_id = list_id
190
128
  @input_id = input_id
191
129
  @input_name = input_name || input_id
192
- @placeholder = placeholder
193
- @visually_hide_label = visually_hide_label
194
- @show_clear_button = show_clear_button
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)
195
135
  @system_arguments = deny_tag_argument(**system_arguments)
196
136
  @system_arguments[:tag] = "auto-complete"
197
137
  @system_arguments[:src] = src
198
138
  @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
- )
215
139
  end
216
140
 
217
141
  # add `input` and `results` without needing to explicitly call them in the view
@@ -219,6 +143,20 @@ module Primer
219
143
  results(classes: "") unless results
220
144
  input(classes: "") unless input
221
145
  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
222
160
  end
223
161
  end
224
162
  end
@@ -5,7 +5,7 @@ module Primer
5
5
  module VERSION
6
6
  MAJOR = 0
7
7
  MINOR = 0
8
- PATCH = 77
8
+ PATCH = 78
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
11
11
  end
data/static/arguments.yml CHANGED
@@ -210,39 +210,28 @@
210
210
  type: String
211
211
  default: N/A
212
212
  description: Id of the list element.
213
- - name: visually_hide_label
213
+ - name: with_icon
214
214
  type: Boolean
215
215
  default: "`false`"
216
- description: Controls if the label is visible. If `true`, screen reader only text
217
- will be added.
218
- - name: show_clear_button
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
219
223
  type: Boolean
220
224
  default: "`false`"
221
225
  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.
222
231
  - name: system_arguments
223
232
  type: Hash
224
233
  default: N/A
225
234
  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
246
235
  - component: AutoCompleteItem
247
236
  source: https://github.com/primer/view_components/tree/main/app/components/primer/beta/auto_complete/item.rb
248
237
  parameters:
data/static/classes.yml CHANGED
@@ -1,8 +1,4 @@
1
1
  ---
2
- - ".ActionList"
3
- - ".ActionList-content"
4
- - ".ActionList-item"
5
- - ".ActionList-item-label"
6
2
  - ".AvatarStack"
7
3
  - ".AvatarStack--right"
8
4
  - ".AvatarStack--three-plus"
@@ -23,18 +19,6 @@
23
19
  - ".Counter"
24
20
  - ".Counter--primary"
25
21
  - ".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"
38
22
  - ".Label"
39
23
  - ".Label--accent"
40
24
  - ".Label--attention"
@@ -65,12 +49,6 @@
65
49
  - ".Link--muted"
66
50
  - ".Link--primary"
67
51
  - ".Link--secondary"
68
- - ".Overlay"
69
- - ".Overlay--height-auto"
70
- - ".Overlay--width-auto"
71
- - ".Overlay-backdrop--anchor"
72
- - ".Overlay-body"
73
- - ".Overlay-body--paddingNone"
74
52
  - ".Popover"
75
53
  - ".Popover-message"
76
54
  - ".Popover-message--large"
@@ -104,6 +82,12 @@
104
82
  - ".UnderlineNav-item"
105
83
  - ".UnderlineNav-octicon"
106
84
  - ".anim-rotate"
85
+ - ".autocomplete-body"
86
+ - ".autocomplete-embedded-icon-wrap"
87
+ - ".autocomplete-item"
88
+ - ".autocomplete-label-inline"
89
+ - ".autocomplete-label-stacked"
90
+ - ".autocomplete-results"
107
91
  - ".avatar"
108
92
  - ".avatar-more"
109
93
  - ".avatar-small"
@@ -183,6 +167,7 @@
183
167
  - ".flex-justify-center"
184
168
  - ".flex-shrink-0"
185
169
  - ".float-right"
170
+ - ".form-control"
186
171
  - ".gutter-condensed"
187
172
  - ".gutter-lg"
188
173
  - ".hidden-text-expander"
@@ -199,18 +199,7 @@
199
199
  ]
200
200
  },
201
201
  "Primer::Beta::AutoComplete": {
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
- ]
202
+ "Item": "Primer::Beta::AutoComplete::Item"
214
203
  },
215
204
  "Primer::Beta::AutoComplete::Item": {
216
205
  },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primer_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.77
4
+ version: 0.0.78
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source