primer_view_components 0.0.43 → 0.0.47
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 +4 -4
- data/CHANGELOG.md +220 -3
- data/app/assets/javascripts/primer_view_components.js +1 -1
- data/app/assets/javascripts/primer_view_components.js.map +1 -1
- data/app/components/primer/alpha/button_marketing.rb +70 -0
- data/app/components/primer/avatar_stack_component.rb +9 -3
- data/app/components/primer/base_component.rb +52 -23
- data/app/components/primer/beta/auto_complete.rb +159 -0
- data/app/components/primer/beta/auto_complete/auto_complete.d.ts +1 -0
- data/app/components/primer/{auto_complete → beta/auto_complete}/auto_complete.html.erb +1 -0
- data/app/components/primer/beta/auto_complete/auto_complete.js +1 -0
- data/app/components/primer/{auto_complete → beta/auto_complete}/auto_complete.ts +0 -0
- data/app/components/primer/beta/auto_complete/item.rb +44 -0
- data/app/components/primer/beta/avatar.rb +77 -0
- data/app/components/primer/beta/text.rb +27 -0
- data/app/components/primer/blankslate_component.rb +2 -1
- data/app/components/primer/border_box_component.rb +3 -0
- data/app/components/primer/button_component.rb +3 -2
- data/app/components/primer/clipboard_copy.rb +25 -7
- data/app/components/primer/component.rb +4 -0
- data/app/components/primer/details_component.rb +18 -3
- data/app/components/primer/dropdown.d.ts +1 -0
- data/app/components/primer/{dropdown_component.html.erb → dropdown.html.erb} +2 -1
- data/app/components/primer/dropdown.js +1 -0
- data/app/components/primer/dropdown.rb +149 -0
- data/app/components/primer/dropdown.ts +1 -0
- data/app/components/primer/dropdown/menu.d.ts +1 -0
- data/app/components/primer/dropdown/menu.html.erb +25 -0
- data/app/components/primer/dropdown/menu.js +1 -0
- data/app/components/primer/dropdown/menu.rb +99 -0
- data/app/components/primer/dropdown/menu.ts +1 -0
- data/app/components/primer/heading_component.rb +1 -1
- data/app/components/primer/icon_button.rb +1 -1
- data/app/components/primer/image_crop.rb +1 -1
- data/app/components/primer/markdown.rb +9 -9
- data/app/components/primer/menu_component.rb +7 -3
- data/app/components/primer/navigation/tab_component.rb +6 -6
- data/app/components/primer/octicon_component.rb +3 -2
- data/app/components/primer/popover_component.rb +6 -3
- data/app/components/primer/primer.d.ts +2 -1
- data/app/components/primer/primer.js +2 -1
- data/app/components/primer/primer.ts +2 -1
- data/app/components/primer/spinner_component.rb +2 -0
- data/app/components/primer/tab_nav_component.rb +5 -3
- data/app/components/primer/timeline_item_component.rb +2 -2
- data/app/components/primer/tooltip.rb +1 -1
- data/app/components/primer/truncate.rb +5 -0
- data/app/components/primer/underline_nav_component.rb +10 -4
- data/{app/lib → lib}/primer/classify.rb +16 -33
- data/{app/lib → lib}/primer/classify/cache.rb +6 -40
- data/{app/lib → lib}/primer/classify/flex.rb +0 -0
- data/{app/lib → lib}/primer/classify/functional_background_colors.rb +2 -0
- data/{app/lib → lib}/primer/classify/functional_border_colors.rb +2 -0
- data/{app/lib → lib}/primer/classify/functional_colors.rb +0 -0
- data/{app/lib → lib}/primer/classify/functional_text_colors.rb +2 -0
- data/{app/lib → lib}/primer/classify/grid.rb +0 -0
- data/lib/primer/classify/utilities.rb +148 -0
- data/lib/primer/classify/utilities.yml +1271 -0
- data/lib/primer/view_components.rb +1 -0
- data/lib/primer/view_components/linters/argument_mappers/button.rb +82 -0
- data/lib/primer/view_components/linters/argument_mappers/conversion_error.rb +10 -0
- data/lib/primer/view_components/linters/argument_mappers/system_arguments.rb +47 -0
- data/lib/primer/view_components/linters/button_component_migration_counter.rb +24 -1
- data/lib/primer/view_components/linters/flash_component_migration_counter.rb +1 -1
- data/lib/primer/view_components/linters/helpers.rb +137 -18
- data/lib/primer/view_components/statuses.rb +14 -0
- data/lib/primer/view_components/version.rb +1 -1
- data/lib/tasks/docs.rake +179 -110
- data/lib/tasks/utilities.rake +105 -0
- data/lib/yard/docs_helper.rb +13 -3
- data/static/statuses.json +9 -7
- metadata +41 -27
- data/app/components/primer/auto_complete.rb +0 -100
- data/app/components/primer/auto_complete/item.rb +0 -42
- data/app/components/primer/avatar_component.rb +0 -75
- data/app/components/primer/button_marketing_component.rb +0 -68
- data/app/components/primer/dropdown/menu_component.html.erb +0 -12
- data/app/components/primer/dropdown/menu_component.rb +0 -46
- data/app/components/primer/dropdown_component.rb +0 -73
- data/app/components/primer/text_component.rb +0 -25
- data/app/lib/primer/classify/spacing.rb +0 -63
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :utilities do
|
4
|
+
task :build do
|
5
|
+
require "yaml"
|
6
|
+
require "json"
|
7
|
+
require File.expand_path("./../../demo/config/environment.rb", __dir__)
|
8
|
+
|
9
|
+
# Keys that are looked for to be included in the utilities.yml file
|
10
|
+
SUPPORTED_KEYS = %i[
|
11
|
+
anim
|
12
|
+
d
|
13
|
+
float
|
14
|
+
hide
|
15
|
+
m mt mr mb ml mx my
|
16
|
+
p pt pr pb pl px py
|
17
|
+
position
|
18
|
+
wb
|
19
|
+
v
|
20
|
+
].freeze
|
21
|
+
|
22
|
+
# Replacements for some classnames that end up being a different argument key
|
23
|
+
REPLACEMENT_KEYS = {
|
24
|
+
"^anim" => "animation",
|
25
|
+
"^v-align" => "vertical_align",
|
26
|
+
"^d" => "display",
|
27
|
+
"^wb" => "word_break",
|
28
|
+
"^v" => "visibility"
|
29
|
+
}.freeze
|
30
|
+
|
31
|
+
BREAKPOINTS = [nil, "sm", "md", "lg", "xl"].freeze
|
32
|
+
|
33
|
+
css_data =
|
34
|
+
JSON.parse(
|
35
|
+
File.read(
|
36
|
+
File.join(
|
37
|
+
__FILE__.split("lib/tasks/utilities.rake")[0], "/node_modules/@primer/css/dist/stats/utilities.json"
|
38
|
+
)
|
39
|
+
)
|
40
|
+
)["selectors"]["values"]
|
41
|
+
|
42
|
+
output = {}
|
43
|
+
|
44
|
+
css_data.each do |selector|
|
45
|
+
selector.sub!(/^./, "")
|
46
|
+
# Next if selector has ancestors or sibling selectors
|
47
|
+
next if selector.match?(/[:><~\[\.]/)
|
48
|
+
next unless SUPPORTED_KEYS.any? { |key| selector.start_with?("#{key}-") }
|
49
|
+
|
50
|
+
# Dupe so we still have the selector at the end of slicing it up
|
51
|
+
classname = selector.dup
|
52
|
+
key = ""
|
53
|
+
|
54
|
+
# Look for a replacement key
|
55
|
+
REPLACEMENT_KEYS.each do |k, v|
|
56
|
+
next unless classname.match?(Regexp.new(k))
|
57
|
+
|
58
|
+
key = v
|
59
|
+
classname.sub!(Regexp.new(k + "-"), "")
|
60
|
+
end
|
61
|
+
|
62
|
+
# If we didn't find a replacement, grab the first text before hyphen
|
63
|
+
if classname == selector
|
64
|
+
key = classname.split("-").first
|
65
|
+
classname.sub!(/^[^-]+-/, "")
|
66
|
+
end
|
67
|
+
|
68
|
+
# Check if the next bit of the classname is a breakpoint
|
69
|
+
if classname.match?(/^(sm-|md-|lg-|xl-)/)
|
70
|
+
breakpoint = classname.split("-").first
|
71
|
+
classname.sub!(/^[^-]+-/, "")
|
72
|
+
end
|
73
|
+
|
74
|
+
# Change the rest from hypens to underscores
|
75
|
+
classname.sub!(/\-/, "_")
|
76
|
+
|
77
|
+
# convert padding/margin negative values ie n7 to -7
|
78
|
+
classname.sub!(/^n/, "-") if classname.match?(/^n[0-9]/)
|
79
|
+
|
80
|
+
key = key.to_sym
|
81
|
+
|
82
|
+
classname = if classname.match?(/\A[-+]?[0-9]+\z/)
|
83
|
+
classname.to_i
|
84
|
+
else
|
85
|
+
classname.to_sym
|
86
|
+
end
|
87
|
+
|
88
|
+
if output[key].nil?
|
89
|
+
output[key] = { classname => Array.new(5, nil) }
|
90
|
+
elsif output[key][classname].nil?
|
91
|
+
output[key][classname] = Array.new(5, nil)
|
92
|
+
end
|
93
|
+
|
94
|
+
output[key][classname][BREAKPOINTS.index(breakpoint)] = selector
|
95
|
+
end
|
96
|
+
|
97
|
+
output.transform_values! do |x|
|
98
|
+
x.transform_values { |y| y.reverse.drop_while(&:nil?).reverse }
|
99
|
+
end
|
100
|
+
|
101
|
+
File.open("lib/primer/classify/utilities.yml", "w") do |f|
|
102
|
+
f.puts YAML.dump(output)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/lib/yard/docs_helper.rb
CHANGED
@@ -3,7 +3,13 @@
|
|
3
3
|
module YARD
|
4
4
|
# Helper methods to use for yard documentation
|
5
5
|
module DocsHelper
|
6
|
-
def one_of(enumerable, lower: false)
|
6
|
+
def one_of(enumerable, lower: false, sort: true)
|
7
|
+
# Sort the array if requested
|
8
|
+
if sort
|
9
|
+
compare = ->(a, b) { a.class == b.class ? a <=> b : a.class.to_s <=> b.class.to_s }
|
10
|
+
enumerable = enumerable.sort { |a, b| compare.call(a, b) }
|
11
|
+
end
|
12
|
+
|
7
13
|
values =
|
8
14
|
case enumerable
|
9
15
|
when Hash
|
@@ -14,7 +20,7 @@ module YARD
|
|
14
20
|
enumerable.map do |key|
|
15
21
|
pretty_value(key)
|
16
22
|
end
|
17
|
-
|
23
|
+
end
|
18
24
|
|
19
25
|
prefix = "One of"
|
20
26
|
prefix = prefix.downcase if lower
|
@@ -22,6 +28,10 @@ module YARD
|
|
22
28
|
"#{prefix} #{values.to_sentence(last_word_connector: ', or ')}."
|
23
29
|
end
|
24
30
|
|
31
|
+
def link_to_accessibility
|
32
|
+
"[Accessibility](#system-arguments)"
|
33
|
+
end
|
34
|
+
|
25
35
|
def link_to_system_arguments_docs
|
26
36
|
"[System arguments](/system-arguments)"
|
27
37
|
end
|
@@ -31,7 +41,7 @@ module YARD
|
|
31
41
|
end
|
32
42
|
|
33
43
|
def link_to_component(component)
|
34
|
-
short_name = component.name.gsub(/Primer|::|Component/, "")
|
44
|
+
short_name = component.name.gsub(/Primer|::|Alpha|Beta|Component/, "")
|
35
45
|
"[#{short_name}](/components/#{short_name.downcase})"
|
36
46
|
end
|
37
47
|
|
data/static/statuses.json
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
{
|
2
|
-
"Primer::
|
3
|
-
"Primer::AutoComplete::Item": "beta",
|
4
|
-
"Primer::AvatarComponent": "beta",
|
2
|
+
"Primer::Alpha::ButtonMarketing": "alpha",
|
5
3
|
"Primer::AvatarStackComponent": "beta",
|
6
4
|
"Primer::BaseButton": "beta",
|
7
5
|
"Primer::BaseComponent": "beta",
|
6
|
+
"Primer::Beta::AutoComplete": "beta",
|
7
|
+
"Primer::Beta::AutoComplete::Input": "alpha",
|
8
|
+
"Primer::Beta::AutoComplete::Item": "beta",
|
9
|
+
"Primer::Beta::Avatar": "beta",
|
10
|
+
"Primer::Beta::Text": "beta",
|
8
11
|
"Primer::BlankslateComponent": "beta",
|
9
12
|
"Primer::BorderBoxComponent": "beta",
|
10
13
|
"Primer::BoxComponent": "stable",
|
@@ -12,13 +15,13 @@
|
|
12
15
|
"Primer::BreadcrumbComponent::ItemComponent": "alpha",
|
13
16
|
"Primer::ButtonComponent": "beta",
|
14
17
|
"Primer::ButtonGroup": "beta",
|
15
|
-
"Primer::ButtonMarketingComponent": "alpha",
|
16
18
|
"Primer::ClipboardCopy": "alpha",
|
17
19
|
"Primer::CloseButton": "beta",
|
18
20
|
"Primer::CounterComponent": "beta",
|
19
21
|
"Primer::DetailsComponent": "beta",
|
20
|
-
"Primer::Dropdown
|
21
|
-
"Primer::
|
22
|
+
"Primer::Dropdown": "alpha",
|
23
|
+
"Primer::Dropdown::Menu": "alpha",
|
24
|
+
"Primer::Dropdown::Menu::Item": "alpha",
|
22
25
|
"Primer::DropdownMenuComponent": "deprecated",
|
23
26
|
"Primer::FlashComponent": "beta",
|
24
27
|
"Primer::FlexComponent": "deprecated",
|
@@ -44,7 +47,6 @@
|
|
44
47
|
"Primer::SubheadComponent": "beta",
|
45
48
|
"Primer::TabContainerComponent": "alpha",
|
46
49
|
"Primer::TabNavComponent": "beta",
|
47
|
-
"Primer::TextComponent": "beta",
|
48
50
|
"Primer::TimeAgoComponent": "beta",
|
49
51
|
"Primer::TimelineItemComponent": "beta",
|
50
52
|
"Primer::TimelineItemComponent::BadgeComponent": "alpha",
|
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.
|
4
|
+
version: 0.0.47
|
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: 2021-
|
11
|
+
date: 2021-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -338,7 +338,7 @@ dependencies:
|
|
338
338
|
- - "~>"
|
339
339
|
- !ruby/object:Gem::Version
|
340
340
|
version: 0.9.25
|
341
|
-
description:
|
341
|
+
description:
|
342
342
|
email:
|
343
343
|
- opensource+primer_view_components@github.com
|
344
344
|
executables: []
|
@@ -350,19 +350,23 @@ files:
|
|
350
350
|
- README.md
|
351
351
|
- app/assets/javascripts/primer_view_components.js
|
352
352
|
- app/assets/javascripts/primer_view_components.js.map
|
353
|
-
- app/components/primer/
|
353
|
+
- app/components/primer/alpha/button_marketing.rb
|
354
354
|
- app/components/primer/auto_complete/auto_complete.d.ts
|
355
|
-
- app/components/primer/auto_complete/auto_complete.html.erb
|
356
355
|
- app/components/primer/auto_complete/auto_complete.js
|
357
|
-
- app/components/primer/auto_complete/auto_complete.ts
|
358
356
|
- app/components/primer/auto_complete/auto_component.d.ts
|
359
357
|
- app/components/primer/auto_complete/auto_component.js
|
360
|
-
- app/components/primer/auto_complete/item.rb
|
361
|
-
- app/components/primer/avatar_component.rb
|
362
358
|
- app/components/primer/avatar_stack_component.html.erb
|
363
359
|
- app/components/primer/avatar_stack_component.rb
|
364
360
|
- app/components/primer/base_button.rb
|
365
361
|
- app/components/primer/base_component.rb
|
362
|
+
- app/components/primer/beta/auto_complete.rb
|
363
|
+
- app/components/primer/beta/auto_complete/auto_complete.d.ts
|
364
|
+
- app/components/primer/beta/auto_complete/auto_complete.html.erb
|
365
|
+
- app/components/primer/beta/auto_complete/auto_complete.js
|
366
|
+
- app/components/primer/beta/auto_complete/auto_complete.ts
|
367
|
+
- app/components/primer/beta/auto_complete/item.rb
|
368
|
+
- app/components/primer/beta/avatar.rb
|
369
|
+
- app/components/primer/beta/text.rb
|
366
370
|
- app/components/primer/blankslate_component.html.erb
|
367
371
|
- app/components/primer/blankslate_component.rb
|
368
372
|
- app/components/primer/border_box_component.html.erb
|
@@ -374,7 +378,6 @@ files:
|
|
374
378
|
- app/components/primer/button_component.rb
|
375
379
|
- app/components/primer/button_group.html.erb
|
376
380
|
- app/components/primer/button_group.rb
|
377
|
-
- app/components/primer/button_marketing_component.rb
|
378
381
|
- app/components/primer/clipboard_copy.html.erb
|
379
382
|
- app/components/primer/clipboard_copy.rb
|
380
383
|
- app/components/primer/clipboard_copy_component.d.ts
|
@@ -385,10 +388,16 @@ files:
|
|
385
388
|
- app/components/primer/counter_component.rb
|
386
389
|
- app/components/primer/details_component.html.erb
|
387
390
|
- app/components/primer/details_component.rb
|
388
|
-
- app/components/primer/dropdown
|
389
|
-
- app/components/primer/dropdown
|
390
|
-
- app/components/primer/
|
391
|
-
- app/components/primer/
|
391
|
+
- app/components/primer/dropdown.d.ts
|
392
|
+
- app/components/primer/dropdown.html.erb
|
393
|
+
- app/components/primer/dropdown.js
|
394
|
+
- app/components/primer/dropdown.rb
|
395
|
+
- app/components/primer/dropdown.ts
|
396
|
+
- app/components/primer/dropdown/menu.d.ts
|
397
|
+
- app/components/primer/dropdown/menu.html.erb
|
398
|
+
- app/components/primer/dropdown/menu.js
|
399
|
+
- app/components/primer/dropdown/menu.rb
|
400
|
+
- app/components/primer/dropdown/menu.ts
|
392
401
|
- app/components/primer/dropdown_menu_component.html.erb
|
393
402
|
- app/components/primer/dropdown_menu_component.rb
|
394
403
|
- app/components/primer/flash_component.html.erb
|
@@ -439,7 +448,6 @@ files:
|
|
439
448
|
- app/components/primer/tab_container_component.ts
|
440
449
|
- app/components/primer/tab_nav_component.html.erb
|
441
450
|
- app/components/primer/tab_nav_component.rb
|
442
|
-
- app/components/primer/text_component.rb
|
443
451
|
- app/components/primer/time_ago_component.d.ts
|
444
452
|
- app/components/primer/time_ago_component.js
|
445
453
|
- app/components/primer/time_ago_component.rb
|
@@ -451,15 +459,6 @@ files:
|
|
451
459
|
- app/components/primer/underline_nav_component.html.erb
|
452
460
|
- app/components/primer/underline_nav_component.rb
|
453
461
|
- app/lib/primer/class_name_helper.rb
|
454
|
-
- app/lib/primer/classify.rb
|
455
|
-
- app/lib/primer/classify/cache.rb
|
456
|
-
- app/lib/primer/classify/flex.rb
|
457
|
-
- app/lib/primer/classify/functional_background_colors.rb
|
458
|
-
- app/lib/primer/classify/functional_border_colors.rb
|
459
|
-
- app/lib/primer/classify/functional_colors.rb
|
460
|
-
- app/lib/primer/classify/functional_text_colors.rb
|
461
|
-
- app/lib/primer/classify/grid.rb
|
462
|
-
- app/lib/primer/classify/spacing.rb
|
463
462
|
- app/lib/primer/fetch_or_fallback_helper.rb
|
464
463
|
- app/lib/primer/join_style_arguments_helper.rb
|
465
464
|
- app/lib/primer/octicon/cache.rb
|
@@ -467,16 +466,31 @@ files:
|
|
467
466
|
- app/lib/primer/tabbed_component_helper.rb
|
468
467
|
- app/lib/primer/test_selector_helper.rb
|
469
468
|
- app/lib/primer/view_helper.rb
|
469
|
+
- lib/primer/classify.rb
|
470
|
+
- lib/primer/classify/cache.rb
|
471
|
+
- lib/primer/classify/flex.rb
|
472
|
+
- lib/primer/classify/functional_background_colors.rb
|
473
|
+
- lib/primer/classify/functional_border_colors.rb
|
474
|
+
- lib/primer/classify/functional_colors.rb
|
475
|
+
- lib/primer/classify/functional_text_colors.rb
|
476
|
+
- lib/primer/classify/grid.rb
|
477
|
+
- lib/primer/classify/utilities.rb
|
478
|
+
- lib/primer/classify/utilities.yml
|
470
479
|
- lib/primer/view_components.rb
|
471
480
|
- lib/primer/view_components/engine.rb
|
472
481
|
- lib/primer/view_components/linters.rb
|
482
|
+
- lib/primer/view_components/linters/argument_mappers/button.rb
|
483
|
+
- lib/primer/view_components/linters/argument_mappers/conversion_error.rb
|
484
|
+
- lib/primer/view_components/linters/argument_mappers/system_arguments.rb
|
473
485
|
- lib/primer/view_components/linters/button_component_migration_counter.rb
|
474
486
|
- lib/primer/view_components/linters/flash_component_migration_counter.rb
|
475
487
|
- lib/primer/view_components/linters/helpers.rb
|
488
|
+
- lib/primer/view_components/statuses.rb
|
476
489
|
- lib/primer/view_components/version.rb
|
477
490
|
- lib/tasks/coverage.rake
|
478
491
|
- lib/tasks/docs.rake
|
479
492
|
- lib/tasks/statuses.rake
|
493
|
+
- lib/tasks/utilities.rake
|
480
494
|
- lib/yard/docs_helper.rb
|
481
495
|
- lib/yard/renders_many_handler.rb
|
482
496
|
- lib/yard/renders_one_handler.rb
|
@@ -486,7 +500,7 @@ licenses:
|
|
486
500
|
- MIT
|
487
501
|
metadata:
|
488
502
|
allowed_push_host: https://rubygems.org
|
489
|
-
post_install_message:
|
503
|
+
post_install_message:
|
490
504
|
rdoc_options: []
|
491
505
|
require_paths:
|
492
506
|
- lib
|
@@ -501,8 +515,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
501
515
|
- !ruby/object:Gem::Version
|
502
516
|
version: '0'
|
503
517
|
requirements: []
|
504
|
-
rubygems_version: 3.
|
505
|
-
signing_key:
|
518
|
+
rubygems_version: 3.1.2
|
519
|
+
signing_key:
|
506
520
|
specification_version: 4
|
507
521
|
summary: ViewComponents for the Primer Design System
|
508
522
|
test_files: []
|
@@ -1,100 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Primer
|
4
|
-
# Use `AutoComplete` to populate input values from server search results.
|
5
|
-
# @accessibility
|
6
|
-
# Always provide a label for the `Autocomplete` component.
|
7
|
-
class AutoComplete < Primer::Component
|
8
|
-
status :beta
|
9
|
-
|
10
|
-
DEFAULT_INPUT_TYPE = :text
|
11
|
-
INPUT_TYPE_OPTIONS = [DEFAULT_INPUT_TYPE, :search].freeze
|
12
|
-
|
13
|
-
# Required input used to search for results
|
14
|
-
#
|
15
|
-
# @param type [Symbol] <%= one_of(Primer::AutoComplete::INPUT_TYPE_OPTIONS) %>
|
16
|
-
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
17
|
-
renders_one :input, lambda { |type: DEFAULT_INPUT_TYPE, classes: "form-control", **system_arguments|
|
18
|
-
system_arguments[:tag] = :input
|
19
|
-
system_arguments[:type] = fetch_or_fallback(INPUT_TYPE_OPTIONS, type, DEFAULT_INPUT_TYPE)
|
20
|
-
system_arguments[:classes] = classes
|
21
|
-
Primer::BaseComponent.new(**system_arguments)
|
22
|
-
}
|
23
|
-
|
24
|
-
# Optional icon to be rendered before the input. Has the same arguments as <%= link_to_component(Primer::OcticonComponent) %>.
|
25
|
-
renders_one :icon, Primer::OcticonComponent
|
26
|
-
|
27
|
-
# Customizable results list.
|
28
|
-
#
|
29
|
-
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
30
|
-
renders_one :results, lambda { |**system_arguments|
|
31
|
-
system_arguments[:tag] = :ul
|
32
|
-
system_arguments[:id] = @id
|
33
|
-
system_arguments[:classes] = class_names(
|
34
|
-
"autocomplete-results",
|
35
|
-
system_arguments[:classes]
|
36
|
-
)
|
37
|
-
|
38
|
-
Primer::BaseComponent.new(**system_arguments)
|
39
|
-
}
|
40
|
-
|
41
|
-
# @example Default
|
42
|
-
# <%= render(Primer::AutoComplete.new(src: "/users/search", id: "user-popup", position: :relative)) do |c| %>
|
43
|
-
# <% c.input(type: :text, name: "input") %>
|
44
|
-
# <% c.results do %>
|
45
|
-
# <%= render(Primer::AutoComplete::Item.new(selected: true, value: "value")) do |c| %>
|
46
|
-
# Selected
|
47
|
-
# <% end %>
|
48
|
-
# <%= render(Primer::AutoComplete::Item.new(value: "value")) do |c| %>
|
49
|
-
# Not selected
|
50
|
-
# <% end %>
|
51
|
-
# <% end %>
|
52
|
-
# <% end %>
|
53
|
-
#
|
54
|
-
# @example With custom classes for the results
|
55
|
-
# <%= render(Primer::AutoComplete.new(src: "/users/search", id: "user-popup", position: :relative)) do |c| %>
|
56
|
-
# <% c.input(type: :text, name: "input") %>
|
57
|
-
# <% c.results(classes: "custom-class") do %>
|
58
|
-
# <%= render(Primer::AutoComplete::Item.new(selected: true, value: "value")) do |c| %>
|
59
|
-
# Selected
|
60
|
-
# <% end %>
|
61
|
-
# <%= render(Primer::AutoComplete::Item.new(value: "value")) do |c| %>
|
62
|
-
# Not selected
|
63
|
-
# <% end %>
|
64
|
-
# <% end %>
|
65
|
-
# <% end %>
|
66
|
-
#
|
67
|
-
# @example With Icon
|
68
|
-
# <%= render(Primer::AutoComplete.new(src: "/users/search", id: "user-popup", position: :relative)) do |c| %>
|
69
|
-
# <% c.input(type: :text, name: "input") %>
|
70
|
-
# <% c.icon(icon: :search) %>
|
71
|
-
# <% c.results do %>
|
72
|
-
# <%= render(Primer::AutoComplete::Item.new(selected: true, value: "value")) do |c| %>
|
73
|
-
# Selected
|
74
|
-
# <% end %>
|
75
|
-
# <%= render(Primer::AutoComplete::Item.new(value: "value")) do |c| %>
|
76
|
-
# Not selected
|
77
|
-
# <% end %>
|
78
|
-
# <% end %>
|
79
|
-
# <% end %>
|
80
|
-
#
|
81
|
-
# @param src [String] The route to query.
|
82
|
-
# @param id [String] Id of the list element.
|
83
|
-
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
84
|
-
def initialize(src:, id:, **system_arguments)
|
85
|
-
@id = id
|
86
|
-
|
87
|
-
@system_arguments = system_arguments
|
88
|
-
@system_arguments[:tag] = "auto-complete"
|
89
|
-
@system_arguments[:src] = src
|
90
|
-
@system_arguments[:for] = id
|
91
|
-
end
|
92
|
-
|
93
|
-
# add `results` without needing to explicitly call it in the view
|
94
|
-
def before_render
|
95
|
-
raise ArgumentError, "Missing `input` slot" if input.blank?
|
96
|
-
|
97
|
-
results(classes: "") unless results
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|