primer_view_components 0.0.122 → 0.1.0

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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/app/assets/javascripts/primer_view_components.js +1 -1
  4. data/app/assets/javascripts/primer_view_components.js.map +1 -1
  5. data/app/assets/styles/primer_view_components.css +2 -2
  6. data/app/assets/styles/primer_view_components.css.map +1 -1
  7. data/app/components/primer/alpha/action_list/item.rb +11 -0
  8. data/app/components/primer/alpha/action_list.css.json +41 -0
  9. data/app/components/primer/alpha/auto_complete.css.json +11 -0
  10. data/app/components/primer/alpha/banner.css.json +14 -0
  11. data/app/components/primer/alpha/button_marketing.css.json +10 -0
  12. data/app/components/primer/alpha/dialog.css.json +63 -0
  13. data/app/components/primer/alpha/dropdown.css.json +21 -0
  14. data/app/components/primer/alpha/layout.css.json +27 -0
  15. data/app/components/primer/alpha/menu.css.json +11 -0
  16. data/app/components/primer/alpha/nav_list/item.rb +7 -1
  17. data/app/components/primer/alpha/nav_list/section.rb +5 -5
  18. data/app/components/primer/alpha/nav_list.d.ts +6 -3
  19. data/app/components/primer/alpha/nav_list.js +98 -6
  20. data/app/components/primer/alpha/nav_list.rb +7 -2
  21. data/app/components/primer/alpha/nav_list.ts +109 -3
  22. data/app/components/primer/alpha/overlay/body.rb +26 -0
  23. data/app/components/primer/alpha/overlay/footer.rb +41 -0
  24. data/app/components/primer/alpha/overlay/header.html.erb +15 -0
  25. data/app/components/primer/alpha/overlay/header.rb +47 -0
  26. data/app/components/primer/alpha/overlay.css +1 -0
  27. data/app/components/primer/alpha/overlay.css.json +11 -0
  28. data/app/components/primer/alpha/overlay.css.map +1 -0
  29. data/app/components/primer/alpha/overlay.html.erb +11 -0
  30. data/app/components/primer/alpha/overlay.pcss +14 -0
  31. data/app/components/primer/alpha/overlay.rb +194 -0
  32. data/app/components/primer/alpha/segmented_control.css.json +15 -0
  33. data/app/components/primer/alpha/tab_nav.css.json +10 -0
  34. data/app/components/primer/alpha/text_field.css.json +38 -0
  35. data/app/components/primer/alpha/toggle_switch.css.json +16 -0
  36. data/app/components/primer/alpha/underline_nav.css.json +13 -0
  37. data/app/components/primer/anchored_position.d.ts +27 -0
  38. data/app/components/primer/anchored_position.js +149 -0
  39. data/app/components/primer/anchored_position.ts +167 -0
  40. data/app/components/primer/beta/avatar.css.json +14 -0
  41. data/app/components/primer/beta/avatar_stack.css.json +9 -0
  42. data/app/components/primer/beta/blankslate.css.json +12 -0
  43. data/app/components/primer/beta/border_box.css.json +32 -0
  44. data/app/components/primer/beta/breadcrumbs.css.json +4 -0
  45. data/app/components/primer/beta/button.css.json +22 -0
  46. data/app/components/primer/beta/counter.css.json +6 -0
  47. data/app/components/primer/beta/flash.css.json +15 -0
  48. data/app/components/primer/beta/flash.html.erb +1 -2
  49. data/app/components/primer/beta/label.css.json +20 -0
  50. data/app/components/primer/beta/link.css.json +8 -0
  51. data/app/components/primer/beta/popover.css.json +18 -0
  52. data/app/components/primer/beta/progress_bar.css.json +6 -0
  53. data/app/components/primer/beta/state.css.json +10 -0
  54. data/app/components/primer/beta/subhead.css.json +8 -0
  55. data/app/components/primer/beta/timeline_item.css.json +9 -0
  56. data/app/components/primer/beta/truncate.css.json +6 -0
  57. data/app/components/primer/component.rb +1 -1
  58. data/app/components/primer/primer.d.ts +2 -0
  59. data/app/components/primer/primer.js +2 -0
  60. data/app/components/primer/primer.pcss +3 -0
  61. data/app/components/primer/primer.ts +2 -0
  62. data/app/components/primer/truncate.css.json +7 -0
  63. data/app/lib/primer/css/layout.css.json +263 -0
  64. data/app/lib/primer/css/utilities.css.json +1636 -0
  65. data/lib/primer/view_components/linters/base_linter.rb +1 -1
  66. data/lib/primer/view_components/linters/disallow_component_css_counter.rb +30 -0
  67. data/lib/primer/view_components/version.rb +2 -2
  68. data/lib/primer/yard/component_manifest.rb +1 -0
  69. data/previews/primer/alpha/overlay_preview/middle_of_page.html.erb +17 -0
  70. data/previews/primer/alpha/overlay_preview.rb +107 -0
  71. data/static/arguments.json +104 -0
  72. data/static/audited_at.json +4 -0
  73. data/static/classes.json +311 -0
  74. data/static/constants.json +102 -0
  75. data/static/previews.json +21 -0
  76. data/static/statuses.json +4 -0
  77. metadata +19 -2
@@ -128,6 +128,7 @@ module Primer
128
128
  # @param parent [Primer::Alpha::ActionList::Item] This item's parent item. `nil` if this item is at the root. Used internally.
129
129
  # @param label [String] Item label.
130
130
  # @param label_classes [String] CSS classes that will be added to the label.
131
+ # @param label_arguments [Hash] <%= link_to_system_arguments_docs %> used to construct the label.
131
132
  # @param content_arguments [Hash] <%= link_to_system_arguments_docs %> used to construct the item's anchor or button tag.
132
133
  # @param truncate_label [Boolean] Truncate label with ellipsis.
133
134
  # @param href [String] Link URL.
@@ -144,6 +145,7 @@ module Primer
144
145
  list:,
145
146
  label:,
146
147
  label_classes: nil,
148
+ label_arguments: {},
147
149
  content_arguments: {},
148
150
  parent: nil,
149
151
  truncate_label: false,
@@ -187,9 +189,14 @@ module Primer
187
189
  @system_arguments[:aria] ||= {}
188
190
  @system_arguments[:aria][:disabled] = "true" if @disabled
189
191
 
192
+ @system_arguments[:data] ||= {}
193
+ @system_arguments[:data][:targets] = "#{list_class.custom_element_name}.items"
194
+
190
195
  @label_arguments = {
196
+ **label_arguments,
191
197
  classes: class_names(
192
198
  label_classes,
199
+ label_arguments[:classes],
193
200
  "ActionListItem-label",
194
201
  "ActionListItem-label--truncate" => @truncate_label
195
202
  )
@@ -236,6 +243,10 @@ module Primer
236
243
  "ActionListContent--blockDescription" => description && @description_scheme == :block
237
244
  )
238
245
  end
246
+
247
+ def list_class
248
+ Primer::Alpha::ActionList
249
+ end
239
250
  end
240
251
  end
241
252
  end
@@ -119,5 +119,46 @@
119
119
  ".ActionList-sectionDivider--filled",
120
120
  ".ActionList-sectionDivider--filled:empty",
121
121
  ".ActionList-sectionDivider--filled:first-child"
122
+ ],
123
+ "classes": [
124
+ "ActionListWrap",
125
+ "ActionListWrap--inset",
126
+ "ActionListWrap--divided",
127
+ "ActionListItem-label",
128
+ "ActionListItem-descriptionWrap--inline",
129
+ "ActionList-sectionDivider",
130
+ "ActionListItem",
131
+ "ActionListItem--navActive",
132
+ "ActionListItem--hasSubItem",
133
+ "ActionListContent",
134
+ "ActionListItem-multiSelectCheckmark",
135
+ "ActionListItem-singleSelectCheckmark",
136
+ "ActionListItem-multiSelectIcon",
137
+ "ActionListItem-multiSelectIconRect",
138
+ "ActionListItem-description",
139
+ "ActionListItem-visual",
140
+ "ActionListItem--danger",
141
+ "ActionList--subGroup",
142
+ "ActionListContent--visual16",
143
+ "ActionListContent--visual20",
144
+ "ActionListContent--visual24",
145
+ "ActionListItem-collapseIcon",
146
+ "ActionListContent--hasActiveSubItem",
147
+ "ActionListContent--sizeLarge",
148
+ "ActionListContent--sizeXLarge",
149
+ "ActionListContent--blockDescription",
150
+ "ActionListItem-action--leading",
151
+ "ActionListItem-visual--leading",
152
+ "ActionListItem-visual--trailing",
153
+ "ActionListItem-action--trailing",
154
+ "ActionListItem-descriptionWrap",
155
+ "ActionListItem-action",
156
+ "ActionListItem-label--truncate",
157
+ "ActionListItem--subItem",
158
+ "ActionListItem--withActions",
159
+ "ActionListItem-trailingAction",
160
+ "ActionListItem--trailingActionHover",
161
+ "ActionList-sectionDivider-title",
162
+ "ActionList-sectionDivider--filled"
122
163
  ]
123
164
  }
@@ -19,5 +19,16 @@
19
19
  ".autocomplete-item.navigation-focus *",
20
20
  ".autocomplete-item.selected *",
21
21
  ".autocomplete-item[aria-selected=true] *"
22
+ ],
23
+ "classes": [
24
+ "autocomplete-label-stacked",
25
+ "autocomplete-label-inline",
26
+ "autocomplete-body",
27
+ "autocomplete-embedded-icon-wrap",
28
+ "form-control",
29
+ "autocomplete-results",
30
+ "autocomplete-item",
31
+ "navigation-focus",
32
+ "selected"
22
33
  ]
23
34
  }
@@ -20,5 +20,19 @@
20
20
  ".Banner.Banner--success .Banner-visual .octicon",
21
21
  ".Banner.Banner--full",
22
22
  ".Banner.Banner--full-whenNarrow"
23
+ ],
24
+ "classes": [
25
+ "Banner",
26
+ "Banner-actions",
27
+ "Banner-visual",
28
+ "octicon",
29
+ "Banner-message",
30
+ "Banner-title",
31
+ "Banner-close",
32
+ "Banner--warning",
33
+ "Banner--error",
34
+ "Banner--success",
35
+ "Banner--full",
36
+ "Banner--full-whenNarrow"
23
37
  ]
24
38
  }
@@ -29,5 +29,15 @@
29
29
  ".btn-signup-mktg:focus-visible",
30
30
  ".btn-small-mktg",
31
31
  ".btn-large-mktg"
32
+ ],
33
+ "classes": [
34
+ "btn-mktg",
35
+ "focus",
36
+ "disabled",
37
+ "btn-muted-mktg",
38
+ "btn-subtle-mktg",
39
+ "btn-signup-mktg",
40
+ "btn-small-mktg",
41
+ "btn-large-mktg"
32
42
  ]
33
43
  }
@@ -78,5 +78,68 @@
78
78
  ".Overlay-backdrop--side-whenNarrow.Overlay-backdrop--placement-top-whenNarrow>.Overlay-whenNarrow",
79
79
  ".Overlay-backdrop--full-whenNarrow",
80
80
  ".Overlay-backdrop--full-whenNarrow .Overlay"
81
+ ],
82
+ "classes": [
83
+ "Overlay--hidden",
84
+ "Overlay--visibilityHidden",
85
+ "Overlay",
86
+ "Overlay--size-auto",
87
+ "Overlay--size-full",
88
+ "Overlay--size-xsmall",
89
+ "Overlay--size-small",
90
+ "Overlay--size-small-portrait",
91
+ "Overlay--size-medium",
92
+ "Overlay--size-medium-portrait",
93
+ "Overlay--size-large",
94
+ "Overlay--size-xlarge",
95
+ "Overlay--height-auto",
96
+ "Overlay--height-xsmall",
97
+ "Overlay--height-small",
98
+ "Overlay--height-medium",
99
+ "Overlay--height-large",
100
+ "Overlay--height-xlarge",
101
+ "Overlay--width-auto",
102
+ "Overlay--width-small",
103
+ "Overlay--width-medium",
104
+ "Overlay--width-large",
105
+ "Overlay--width-xlarge",
106
+ "Overlay--width-xxlarge",
107
+ "Overlay--motion-scaleFade",
108
+ "Overlay-form",
109
+ "Overlay-header",
110
+ "Overlay-header--divided",
111
+ "Overlay-body",
112
+ "Overlay-header--large",
113
+ "Overlay-headerContentWrap",
114
+ "Overlay-titleWrap",
115
+ "Overlay-title",
116
+ "Overlay-description",
117
+ "Overlay-actionWrap",
118
+ "Overlay-body--paddingCondensed",
119
+ "Overlay-body--paddingNone",
120
+ "Overlay-footer",
121
+ "Overlay-footer--divided",
122
+ "Overlay-footer--alignStart",
123
+ "Overlay-footer--alignCenter",
124
+ "Overlay-footer--alignEnd",
125
+ "Overlay-closeButton",
126
+ "close-button",
127
+ "Overlay-backdrop--center",
128
+ "Overlay-backdrop--anchor",
129
+ "Overlay-backdrop--side",
130
+ "Overlay-backdrop--placement-left",
131
+ "Overlay-backdrop--placement-right",
132
+ "Overlay-backdrop--placement-bottom",
133
+ "Overlay-backdrop--placement-top",
134
+ "Overlay-backdrop--full",
135
+ "Overlay-backdrop--center-whenNarrow",
136
+ "Overlay-backdrop--anchor-whenNarrow",
137
+ "Overlay-backdrop--side-whenNarrow",
138
+ "Overlay-backdrop--placement-left-whenNarrow",
139
+ "Overlay-whenNarrow",
140
+ "Overlay-backdrop--placement-right-whenNarrow",
141
+ "Overlay-backdrop--placement-bottom-whenNarrow",
142
+ "Overlay-backdrop--placement-top-whenNarrow",
143
+ "Overlay-backdrop--full-whenNarrow"
81
144
  ]
82
145
  }
@@ -36,5 +36,26 @@
36
36
  ".dropdown-menu-sw:after",
37
37
  ".dropdown-menu-se:before",
38
38
  ".dropdown-menu-se:after"
39
+ ],
40
+ "classes": [
41
+ "dropdown",
42
+ "dropdown-caret",
43
+ "dropdown-menu",
44
+ "dropdown-menu-no-overflow",
45
+ "dropdown-item",
46
+ "octicon",
47
+ "color-fg-",
48
+ "Label",
49
+ "btn-link",
50
+ "dropdown-signout",
51
+ "dropdown-divider",
52
+ "dropdown-header",
53
+ "octicon-check",
54
+ "dropdown-menu-w",
55
+ "dropdown-menu-e",
56
+ "dropdown-menu-ne",
57
+ "dropdown-menu-s",
58
+ "dropdown-menu-sw",
59
+ "dropdown-menu-se"
39
60
  ]
40
61
  }
@@ -76,5 +76,32 @@
76
76
  ".Layout-main .Layout-main-centered-xl>.container-lg",
77
77
  ".Layout-main .Layout-main-centered-xl>.container-md",
78
78
  ".Layout-main .Layout-main-centered-xl>.container-xl"
79
+ ],
80
+ "classes": [
81
+ "Layout",
82
+ "Layout-divider",
83
+ "Layout-main",
84
+ "Layout-sidebar",
85
+ "Layout--sidebarPosition-flowRow-start",
86
+ "Layout--sidebarPosition-flowRow-end",
87
+ "Layout--sidebarPosition-flowRow-none",
88
+ "Layout--divided",
89
+ "Layout-divider--flowRow-hidden",
90
+ "Layout-divider--flowRow-shallow",
91
+ "Layout--flowRow-until-md",
92
+ "Layout--flowRow-until-lg",
93
+ "Layout--gutter-none",
94
+ "Layout--gutter-condensed",
95
+ "Layout--gutter-spacious",
96
+ "Layout--sidebar-narrow",
97
+ "Layout--sidebar-wide",
98
+ "Layout--sidebarPosition-start",
99
+ "Layout--sidebarPosition-end",
100
+ "Layout-main-centered-lg",
101
+ "Layout-main-centered-md",
102
+ "Layout-main-centered-xl",
103
+ "container-lg",
104
+ "container-md",
105
+ "container-xl"
79
106
  ]
80
107
  }
@@ -24,5 +24,16 @@
24
24
  ".menu-heading:hover",
25
25
  ".menu-heading:first-child",
26
26
  ".menu-heading:last-child"
27
+ ],
28
+ "classes": [
29
+ "menu",
30
+ "menu-item",
31
+ "selected",
32
+ "octicon",
33
+ "Counter",
34
+ "menu-warning",
35
+ "avatar",
36
+ "alert",
37
+ "menu-heading"
27
38
  ]
28
39
  }
@@ -53,7 +53,7 @@ module Primer
53
53
  end
54
54
 
55
55
  def active?
56
- item_active?(self)
56
+ item_active?(self) && items.empty?
57
57
  end
58
58
 
59
59
  # Cause this item to show its list of sub items when rendered.
@@ -75,6 +75,8 @@ module Primer
75
75
 
76
76
  raise "Cannot render a trailing action for an item with subitems" if items.present? && trailing_action.present?
77
77
 
78
+ raise "Cannot pass `selected_by_ids:` for an item with subitems, since parent items cannot be selected" if items.present? && @selected_by_ids.present?
79
+
78
80
  return if items.blank?
79
81
 
80
82
  @content_arguments[:tag] = :button
@@ -119,6 +121,10 @@ module Primer
119
121
  def current_page?(url)
120
122
  helpers.current_page?(url)
121
123
  end
124
+
125
+ def list_class
126
+ Primer::Alpha::NavList
127
+ end
122
128
  end
123
129
  end
124
130
  end
@@ -28,17 +28,17 @@ module Primer
28
28
  system_arguments[:data][:action] = "click:nav-list#showMore"
29
29
  system_arguments[:data][:"current-page"] = "1"
30
30
  system_arguments[:data][:"total-pages"] = pages.to_s
31
- system_arguments[:label_classes] = class_names(
32
- system_arguments[:label_classes],
33
- "color-fg-accent"
34
- )
31
+ system_arguments[:label_arguments] = {
32
+ **system_arguments[:label_arguments] || {},
33
+ color: :accent
34
+ }
35
35
 
36
36
  component_klass.new(list: self, src: src, **system_arguments)
37
37
  }
38
38
 
39
39
  # @private
40
40
  def self.custom_element_name
41
- "nav-list"
41
+ Primer::Alpha::NavList.custom_element_name
42
42
  end
43
43
 
44
44
  # @param selected_item_id [Symbol] The ID of the currently selected item. Used internally.
@@ -1,5 +1,7 @@
1
- declare class NavListElement extends HTMLElement {
1
+ export declare class NavListElement extends HTMLElement {
2
+ #private;
2
3
  list: HTMLElement;
4
+ items: HTMLElement[];
3
5
  showMoreItem: HTMLElement;
4
6
  focusMarkers: HTMLElement[];
5
7
  connectedCallback(): void;
@@ -9,17 +11,18 @@ declare class NavListElement extends HTMLElement {
9
11
  get currentPage(): number;
10
12
  get totalPages(): number;
11
13
  get paginationSrc(): string;
14
+ selectItemById(itemId: string | null): boolean;
15
+ selectItemByHref(href: string | null): boolean;
16
+ selectItemByCurrentLocation(): boolean;
12
17
  expandItem(item: HTMLElement): void;
13
18
  collapseItem(item: HTMLElement): void;
14
19
  itemIsExpanded(item: HTMLElement | null): boolean;
15
20
  handleItemWithSubItemClick(e: Event): void;
16
21
  private showMore;
17
22
  private setShowMoreItemState;
18
- private parseHTML;
19
23
  }
20
24
  declare global {
21
25
  interface Window {
22
26
  NavListElement: typeof NavListElement;
23
27
  }
24
28
  }
25
- export {};
@@ -4,9 +4,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _NavListElement_instances, _NavListElement_parseHTML, _NavListElement_findSelectedNavItemById, _NavListElement_findSelectedNavItemByHref, _NavListElement_findSelectedNavItemByCurrentLocation, _NavListElement_select, _NavListElement_deselect, _NavListElement_findParentMenu;
7
13
  /* eslint-disable custom-elements/expose-class-on-global */
8
14
  import { controller, target, targets } from '@github/catalyst';
9
15
  let NavListElement = class NavListElement extends HTMLElement {
16
+ constructor() {
17
+ super(...arguments);
18
+ _NavListElement_instances.add(this);
19
+ }
10
20
  connectedCallback() {
11
21
  this.setShowMoreItemState();
12
22
  }
@@ -34,6 +44,34 @@ let NavListElement = class NavListElement extends HTMLElement {
34
44
  get paginationSrc() {
35
45
  return this.showMoreItem.getAttribute('src') || '';
36
46
  }
47
+ selectItemById(itemId) {
48
+ if (!itemId)
49
+ return false;
50
+ const selectedItem = __classPrivateFieldGet(this, _NavListElement_instances, "m", _NavListElement_findSelectedNavItemById).call(this, itemId);
51
+ if (selectedItem) {
52
+ __classPrivateFieldGet(this, _NavListElement_instances, "m", _NavListElement_select).call(this, selectedItem);
53
+ return true;
54
+ }
55
+ return false;
56
+ }
57
+ selectItemByHref(href) {
58
+ if (!href)
59
+ return false;
60
+ const selectedItem = __classPrivateFieldGet(this, _NavListElement_instances, "m", _NavListElement_findSelectedNavItemByHref).call(this, href);
61
+ if (selectedItem) {
62
+ __classPrivateFieldGet(this, _NavListElement_instances, "m", _NavListElement_select).call(this, selectedItem);
63
+ return true;
64
+ }
65
+ return false;
66
+ }
67
+ selectItemByCurrentLocation() {
68
+ const selectedItem = __classPrivateFieldGet(this, _NavListElement_instances, "m", _NavListElement_findSelectedNavItemByCurrentLocation).call(this);
69
+ if (selectedItem) {
70
+ __classPrivateFieldGet(this, _NavListElement_instances, "m", _NavListElement_select).call(this, selectedItem);
71
+ return true;
72
+ }
73
+ return false;
74
+ }
37
75
  // expand collapsible item onClick
38
76
  expandItem(item) {
39
77
  var _a;
@@ -92,7 +130,7 @@ let NavListElement = class NavListElement extends HTMLElement {
92
130
  this.currentPage--;
93
131
  return;
94
132
  }
95
- const fragment = this.parseHTML(document, html);
133
+ const fragment = __classPrivateFieldGet(this, _NavListElement_instances, "m", _NavListElement_parseHTML).call(this, document, html);
96
134
  (_a = fragment === null || fragment === void 0 ? void 0 : fragment.querySelector('li > a')) === null || _a === void 0 ? void 0 : _a.setAttribute('data-targets', 'nav-list.focusMarkers');
97
135
  this.list.insertBefore(fragment, this.showMoreItem);
98
136
  (_b = this.focusMarkers.pop()) === null || _b === void 0 ? void 0 : _b.focus();
@@ -109,16 +147,69 @@ let NavListElement = class NavListElement extends HTMLElement {
109
147
  this.showMoreItem.hidden = true;
110
148
  }
111
149
  }
112
- parseHTML(document, html) {
113
- const template = document.createElement('template');
114
- // eslint-disable-next-line github/no-inner-html
115
- template.innerHTML = html;
116
- return document.importNode(template.content, true);
150
+ };
151
+ _NavListElement_instances = new WeakSet(), _NavListElement_parseHTML = function _NavListElement_parseHTML(document, html) {
152
+ const template = document.createElement('template');
153
+ // eslint-disable-next-line github/no-inner-html
154
+ template.innerHTML = html;
155
+ return document.importNode(template.content, true);
156
+ }, _NavListElement_findSelectedNavItemById = function _NavListElement_findSelectedNavItemById(itemId) {
157
+ var _a;
158
+ // First we compare the selected link to data-item-id for each nav item
159
+ for (const navItem of this.items) {
160
+ if (navItem.classList.contains('ActionListItem--hasSubItem')) {
161
+ continue;
162
+ }
163
+ const keys = ((_a = navItem.getAttribute('data-item-id')) === null || _a === void 0 ? void 0 : _a.split(' ')) || [];
164
+ if (keys.includes(itemId)) {
165
+ return navItem;
166
+ }
167
+ }
168
+ return null;
169
+ }, _NavListElement_findSelectedNavItemByHref = function _NavListElement_findSelectedNavItemByHref(href) {
170
+ // If we didn't find a match, we compare the selected link to the href of each nav item
171
+ const selectedNavItem = this.querySelector(`.ActionListContent[href="${href}"]`);
172
+ if (selectedNavItem) {
173
+ return selectedNavItem.closest('.ActionListItem');
174
+ }
175
+ return null;
176
+ }, _NavListElement_findSelectedNavItemByCurrentLocation = function _NavListElement_findSelectedNavItemByCurrentLocation() {
177
+ return __classPrivateFieldGet(this, _NavListElement_instances, "m", _NavListElement_findSelectedNavItemByHref).call(this, window.location.pathname);
178
+ }, _NavListElement_select = function _NavListElement_select(navItem) {
179
+ const currentlySelectedItem = this.querySelector('.ActionListItem--navActive');
180
+ if (currentlySelectedItem)
181
+ __classPrivateFieldGet(this, _NavListElement_instances, "m", _NavListElement_deselect).call(this, currentlySelectedItem);
182
+ navItem.classList.add('ActionListItem--navActive');
183
+ const parentMenu = __classPrivateFieldGet(this, _NavListElement_instances, "m", _NavListElement_findParentMenu).call(this, navItem);
184
+ if (parentMenu) {
185
+ this.expandItem(parentMenu);
186
+ parentMenu.classList.add('ActionListContent--hasActiveSubItem');
187
+ }
188
+ }, _NavListElement_deselect = function _NavListElement_deselect(navItem) {
189
+ navItem.classList.remove('ActionListItem--navActive');
190
+ const parentMenu = __classPrivateFieldGet(this, _NavListElement_instances, "m", _NavListElement_findParentMenu).call(this, navItem);
191
+ if (parentMenu) {
192
+ this.collapseItem(parentMenu);
193
+ parentMenu.classList.remove('ActionListContent--hasActiveSubItem');
194
+ }
195
+ }, _NavListElement_findParentMenu = function _NavListElement_findParentMenu(navItem) {
196
+ var _a;
197
+ if (!navItem.classList.contains('ActionListItem--subItem'))
198
+ return null;
199
+ const parent = (_a = navItem.closest('li.ActionListItem--hasSubItem')) === null || _a === void 0 ? void 0 : _a.querySelector('button.ActionListContent');
200
+ if (parent) {
201
+ return parent;
202
+ }
203
+ else {
204
+ return null;
117
205
  }
118
206
  };
119
207
  __decorate([
120
208
  target
121
209
  ], NavListElement.prototype, "list", void 0);
210
+ __decorate([
211
+ targets
212
+ ], NavListElement.prototype, "items", void 0);
122
213
  __decorate([
123
214
  target
124
215
  ], NavListElement.prototype, "showMoreItem", void 0);
@@ -128,3 +219,4 @@ __decorate([
128
219
  NavListElement = __decorate([
129
220
  controller
130
221
  ], NavListElement);
222
+ export { NavListElement };
@@ -17,6 +17,11 @@ module Primer
17
17
  class NavList < Primer::Component
18
18
  status :alpha
19
19
 
20
+ # @private
21
+ def self.custom_element_name
22
+ "nav-list"
23
+ end
24
+
20
25
  # Sections. Each section is a list of links and an optional heading.
21
26
  #
22
27
  # @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::NavList::Section) %>.
@@ -62,7 +67,7 @@ module Primer
62
67
  # <%= render(Primer::Alpha::NavList.new(selected_item_id: :email_notifications)) do |component| %>
63
68
  # <% component.with_section(aria: { label: "Account settings" }) do |section| %>
64
69
  # <% section.with_heading(title: "Account Settings") %>
65
- # <% section.with_item(label: "Notification settings", selected_by_ids: :notifications) do |item| %>
70
+ # <% section.with_item(label: "Notification settings") do |item| %>
66
71
  # <% item.with_leading_visual_icon(icon: :bell) %>
67
72
  # <% item.with_item(label: "Email", selected_by_ids: :email_notifications, href: "/account/notifications/email") do |subitem| %>
68
73
  # <% subitem.with_trailing_visual_icon(icon: :mail) %>
@@ -71,7 +76,7 @@ module Primer
71
76
  # <% subitem.with_trailing_visual_icon(icon: :"device-mobile") %>
72
77
  # <% end %>
73
78
  # <% end %>
74
- # <% section.with_item(label: "Messages", selected_by_ids: :messages) do |item| %>
79
+ # <% section.with_item(label: "Messages") do |item| %>
75
80
  # <% item.with_leading_visual_icon(icon: :bookmark) %>
76
81
  # <% item.with_item(label: "Inbox", href: "/account/messages/inbox") do |subitem| %>
77
82
  # <% subitem.with_trailing_visual_counter(count: 10) %>