x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<nav aria-labelledby="heading-5ca293c3-e732-4579-8b4c-dd111f7e566f" data-view-component="true"> <h2 id="heading-5ca293c3-e732-4579-8b4c-dd111f7e566f" data-view-component="true" class="ActionListHeader">Repository settings</h2> <nav-list> <ul data-target="nav-list.topLevelList" data-view-component="true" class="ActionListWrap"> <li data-item-id="" data-targets="nav-list.items" data-view-component="true" class="ActionListItem"> <a id="item-941cc417-6db3-4f67-92f2-b9a091d56609" href="/general" data-view-component="true" class="ActionListContent ActionListContent--visual16"> <span class="ActionListItem-visual ActionListItem-visual--leading"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-gear"> <path d="M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.103-.303c.644-.176 1.392.021 1.82.63.27.385.506.792.704 1.218.315.675.111 1.422-.364 1.891l-.814.806c-.049.048-.098.147-.088.294.016.257.016.515 0 .772-.01.147.038.246.088.294l.814.806c.475.469.679 1.216.364 1.891a7.977 7.977 0 0 1-.704 1.217c-.428.61-1.176.807-1.82.63l-1.102-.302c-.067-.019-.177-.011-.3.071a5.909 5.909 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.106c-.168.646-.715 1.196-1.458 1.26a8.006 8.006 0 0 1-1.402 0c-.743-.064-1.289-.614-1.458-1.26l-.289-1.106c-.018-.066-.079-.158-.212-.224a5.738 5.738 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.103.303c-.644.176-1.392-.021-1.82-.63a8.12 8.12 0 0 1-.704-1.218c-.315-.675-.111-1.422.363-1.891l.815-.806c.05-.048.098-.147.088-.294a6.214 6.214 0 0 1 0-.772c.01-.147-.038-.246-.088-.294l-.815-.806C.635 6.045.431 5.298.746 4.623a7.92 7.92 0 0 1 .704-1.217c.428-.61 1.176-.807 1.82-.63l1.102.302c.067.019.177.011.3-.071.214-.143.437-.272.668-.386.133-.066.194-.158.211-.224l.29-1.106C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm-.571 1.525c-.036.003-.108.036-.137.146l-.289 1.105c-.147.561-.549.967-.998 1.189-.173.086-.34.183-.5.29-.417.278-.97.423-1.529.27l-1.103-.303c-.109-.03-.175.016-.195.045-.22.312-.412.644-.573.99-.014.031-.021.11.059.19l.815.806c.411.406.562.957.53 1.456a4.709 4.709 0 0 0 0 .582c.032.499-.119 1.05-.53 1.456l-.815.806c-.081.08-.073.159-.059.19.162.346.353.677.573.989.02.03.085.076.195.046l1.102-.303c.56-.153 1.113-.008 1.53.27.161.107.328.204.501.29.447.222.85.629.997 1.189l.289 1.105c.029.109.101.143.137.146a6.6 6.6 0 0 0 1.142 0c.036-.003.108-.036.137-.146l.289-1.105c.147-.561.549-.967.998-1.189.173-.086.34-.183.5-.29.417-.278.97-.423 1.529-.27l1.103.303c.109.029.175-.016.195-.045.22-.313.411-.644.573-.99.014-.031.021-.11-.059-.19l-.815-.806c-.411-.406-.562-.957-.53-1.456a4.709 4.709 0 0 0 0-.582c-.032-.499.119-1.05.53-1.456l.815-.806c.081-.08.073-.159.059-.19a6.464 6.464 0 0 0-.573-.989c-.02-.03-.085-.076-.195-.046l-1.102.303c-.56.153-1.113.008-1.53-.27a4.44 4.44 0 0 0-.501-.29c-.447-.222-.85-.629-.997-1.189l-.289-1.105c-.029-.11-.101-.143-.137-.146a6.6 6.6 0 0 0-1.142 0ZM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0ZM9.5 8a1.5 1.5 0 1 0-3.001.001A1.5 1.5 0 0 0 9.5 8Z"></path> </svg> </span> <span data-view-component="true" class="ActionListItem-label"> General </span> </a> </li> <li role="presentation" aria-hidden="true" data-view-component="true" class="ActionList-sectionDivider"></li> <li data-item-id="" data-targets="nav-list.items" data-view-component="true" class="ActionListItem"> <a id="item-7cd87833-b2da-4114-ab37-cea61b0b14a2" href="/settings" data-view-component="true" class="ActionListContent ActionListContent--visual16"> <span class="ActionListItem-visual ActionListItem-visual--leading"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-beaker"> <path d="M5 5.782V2.5h-.25a.75.75 0 0 1 0-1.5h6.5a.75.75 0 0 1 0 1.5H11v3.282l3.666 5.76C15.619 13.04 14.543 15 12.767 15H3.233c-1.776 0-2.852-1.96-1.899-3.458Zm-2.4 6.565a.75.75 0 0 0 .633 1.153h9.534a.75.75 0 0 0 .633-1.153L12.225 10.5h-8.45ZM9.5 2.5h-3V6c0 .143-.04.283-.117.403L4.73 9h6.54L9.617 6.403A.746.746 0 0 1 9.5 6Z"></path> </svg> </span> <span data-view-component="true" class="ActionListItem-label"> Settings </span> </a> </li> <li role="presentation" aria-hidden="true" data-view-component="true" class="ActionList-sectionDivider"></li> <li data-view-component="true"> <nav-list-group> <action-list> <div data-view-component="true"> <div data-view-component="true" class="ActionList-sectionDivider"> <h3 id="heading-title-5477931f-8e85-461d-a1d2-aeb6c6ef4cf2" data-view-component="true" class="ActionList-sectionDivider-title"> Access </h3> </div> <ul id="group-e205d2ca-ab70-4659-9cea-fd6154359e53" role="list" aria-labelledby="heading-title-5477931f-8e85-461d-a1d2-aeb6c6ef4cf2" data-view-component="true" class="ActionListWrap"> <li data-item-id="" data-targets="nav-list.items" data-view-component="true" class="ActionListItem"> <a id="item-1f7f2695-ecbd-41f3-b790-5aec73d5d2f7" href="/profile" data-view-component="true" class="ActionListContent ActionListContent--visual16"> <span class="ActionListItem-visual ActionListItem-visual--leading"> <img role="presentation" src="https://avatars.githubusercontent.com/u/103004183?v=4" size="16" height="16" width="16" data-view-component="true" class="avatar avatar-small" /> </span> <span data-view-component="true" class="ActionListItem-descriptionWrap ActionListItem-descriptionWrap--inline"> <span data-view-component="true" class="ActionListItem-label"> hulk_smash </span> <span data-view-component="true" class="ActionListItem-description">Bruce Banner</span> </span></a> </li> <li data-item-id="collaborators" data-targets="nav-list.items" data-view-component="true" class="ActionListItem"> <a id="item-1021616c-3be7-4902-9b2a-ca29acd59be1" href="/collaborators" data-view-component="true" class="ActionListContent ActionListContent--visual16"> <span class="ActionListItem-visual ActionListItem-visual--leading"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-people"> <path d="M2 5.5a3.5 3.5 0 1 1 5.898 2.549 5.508 5.508 0 0 1 3.034 4.084.75.75 0 1 1-1.482.235 4 4 0 0 0-7.9 0 .75.75 0 0 1-1.482-.236A5.507 5.507 0 0 1 3.102 8.05 3.493 3.493 0 0 1 2 5.5ZM11 4a3.001 3.001 0 0 1 2.22 5.018 5.01 5.01 0 0 1 2.56 3.012.749.749 0 0 1-.885.954.752.752 0 0 1-.549-.514 3.507 3.507 0 0 0-2.522-2.372.75.75 0 0 1-.574-.73v-.352a.75.75 0 0 1 .416-.672A1.5 1.5 0 0 0 11 5.5.75.75 0 0 1 11 4Zm-5.5-.5a2 2 0 1 0-.001 3.999A2 2 0 0 0 5.5 3.5Z"></path> </svg> </span> <span data-view-component="true" class="ActionListItem-label"> Collaborators and teams </span> </a> </li> <li data-item-id="" data-targets="nav-list.items" data-view-component="true" class="ActionListItem ActionListItem--hasSubItem"> <button id="item-b72c1500-d3ca-4feb-9ae2-fab0f123c6a4" type="button" aria-expanded="true" data-action=" click:nav-list#handleItemWithSubItemClick keydown:nav-list#handleItemWithSubItemKeydown " data-view-component="true" class="ActionListContent ActionListContent--hasActiveSubItem ActionListContent--visual16"> <span class="ActionListItem-visual ActionListItem-visual--leading"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-comment-discussion"> <path d="M1.75 1h8.5c.966 0 1.75.784 1.75 1.75v5.5A1.75 1.75 0 0 1 10.25 10H7.061l-2.574 2.573A1.458 1.458 0 0 1 2 11.543V10h-.25A1.75 1.75 0 0 1 0 8.25v-5.5C0 1.784.784 1 1.75 1ZM1.5 2.75v5.5c0 .138.112.25.25.25h1a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h3.5a.25.25 0 0 0 .25-.25v-5.5a.25.25 0 0 0-.25-.25h-8.5a.25.25 0 0 0-.25.25Zm13 2a.25.25 0 0 0-.25-.25h-.5a.75.75 0 0 1 0-1.5h.5c.966 0 1.75.784 1.75 1.75v5.5A1.75 1.75 0 0 1 14.25 12H14v1.543a1.458 1.458 0 0 1-2.487 1.03L9.22 12.28a.749.749 0 0 1 .326-1.275.749.749 0 0 1 .734.215l2.22 2.22v-2.19a.75.75 0 0 1 .75-.75h1a.25.25 0 0 0 .25-.25Z"></path> </svg> </span> <span data-view-component="true" class="ActionListItem-label"> Moderation options </span> <span class="ActionListItem-visual ActionListItem-action--trailing"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-chevron-down ActionListItem-collapseIcon"> <path d="M12.78 5.22a.749.749 0 0 1 0 1.06l-4.25 4.25a.749.749 0 0 1-1.06 0L3.22 6.28a.749.749 0 1 1 1.06-1.06L8 8.939l3.72-3.719a.749.749 0 0 1 1.06 0Z"></path> </svg> </span> </button> <ul role="list" data-action="keydown:nav-list#handleItemWithSubItemKeydown" aria-labelledby="item-b72c1500-d3ca-4feb-9ae2-fab0f123c6a4" data-view-component="true" class="ActionList ActionList--subGroup"> <li data-item-id="interaction_limits" data-targets="nav-list.items" data-view-component="true" class="ActionListItem--subItem ActionListItem"> <a id="item-36814fbc-efa6-4440-aa05-1a3673a90335" href="/interaction-limits" data-view-component="true" class="ActionListContent"> <span data-view-component="true" class="ActionListItem-label"> Interaction limits </span> </a> </li> <li data-item-id="code_review_limits" data-targets="nav-list.items" data-view-component="true" class="ActionListItem--subItem ActionListItem ActionListItem--navActive"> <a id="item-5aa34dfc-226e-46d2-815b-e4f1df9a82d6" href="/review-limits" aria-current="page" data-view-component="true" class="ActionListContent"> <span data-view-component="true" class="ActionListItem-label"> Code review limits </span> </a> </li> <li data-item-id="reported_content" data-targets="nav-list.items" data-view-component="true" class="ActionListItem--subItem ActionListItem"> <a id="item-1e7eb71e-aa15-4e9f-87bd-595e8d4addc1" href="/reported-content" data-view-component="true" class="ActionListContent"> <span data-view-component="true" class="ActionListItem-label"> Reported content </span> </a> </li> </ul> </li> </ul> </div> </action-list> </nav-list-group> </li> </ul> </nav-list></nav>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
render(Primer::Beta::NavList.new(selected_item_id: :code_review_limits)) do |list| list.with_heading(title: "Repository settings") list.with_item(label: "General", href: "/general") do |item| item.with_leading_visual_icon(icon: :gear) end list.with_divider list.with_item(label: "Settings", href: "/settings") do |item| item.with_leading_visual_icon(icon: :beaker) end list.with_group do |group| group.with_heading(title: "Access") group.with_avatar_item( src: "https://avatars.githubusercontent.com/u/103004183?v=4", username: "hulk_smash", full_name: "Bruce Banner", full_name_scheme: :inline, href: "/profile", avatar_arguments: { shape: :square } ) group.with_item(label: "Collaborators and teams", href: "/collaborators", selected_by_ids: :collaborators) do |item| item.with_leading_visual_icon(icon: :people) end group.with_item(label: "Moderation options") do |item| item.with_leading_visual_icon(icon: :"comment-discussion") item.with_item(label: "Interaction limits", href: "/interaction-limits", selected_by_ids: :interaction_limits) item.with_item(label: "Code review limits", href: "/review-limits", selected_by_ids: :code_review_limits) item.with_item(label: "Reported content", href: "/reported-content", selected_by_ids: :reported_content) end endend
No notes provided.
No params configured.
app/components/primer/beta/nav_list.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/* eslint-disable custom-elements/expose-class-on-global */import {controller, target, targets} from '@github/catalyst'import {ActionListTruncationObserver} from '../alpha/action_list'@controllerexport class NavListElement extends HTMLElement { @targets items: HTMLElement[] @target topLevelList: HTMLElement #truncationObserver: ActionListTruncationObserver connectedCallback() { // groups are wrapped in <action-list>, which handles resizing on its own if (this.topLevelList) { this.#truncationObserver = new ActionListTruncationObserver(this.topLevelList) } } disconnectedCallback() { if (this.topLevelList) { this.#truncationObserver.unobserve(this.topLevelList) } } selectItemById(itemId: string | null): boolean { if (!itemId) return false const selectedItem = this.#findSelectedNavItemById(itemId) if (selectedItem) { this.#select(selectedItem) return true } return false } selectItemByHref(href: string | null): boolean { if (!href) return false const selectedItem = this.#findSelectedNavItemByHref(href) if (selectedItem) { this.#select(selectedItem) return true } return false } selectItemByCurrentLocation(): boolean { const selectedItem = this.#findSelectedNavItemByCurrentLocation() if (selectedItem) { this.#select(selectedItem) return true } return false } // expand collapsible item onClick expandItem(item: HTMLElement) { item.nextElementSibling?.removeAttribute('data-hidden') item.setAttribute('aria-expanded', 'true') } collapseItem(item: HTMLElement) { item.nextElementSibling?.setAttribute('data-hidden', '') item.setAttribute('aria-expanded', 'false') item.focus() } itemIsExpanded(item: HTMLElement | null) { if (item?.tagName === 'A') { return true } return item?.getAttribute('aria-expanded') === 'true' } // expand/collapse item handleItemWithSubItemClick(e: Event) { const el = e.target if (!(el instanceof HTMLElement)) return const button = el.closest<HTMLButtonElement>('button') if (!button) return if (this.itemIsExpanded(button)) { this.collapseItem(button) } else { this.expandItem(button) } /* eslint-disable-next-line no-restricted-syntax */ e.stopPropagation() } // collapse item handleItemWithSubItemKeydown(e: KeyboardEvent) { const el = e.currentTarget if (!(el instanceof HTMLElement)) return let button = el.closest<HTMLButtonElement>('button') if (!button) { const button_id = el.getAttribute('aria-labelledby') if (button_id) { button = document.getElementById(button_id) as HTMLButtonElement } else { return } } if (this.itemIsExpanded(button) && e.key === 'Escape') { this.collapseItem(button) } /* eslint-disable-next-line no-restricted-syntax */ e.stopPropagation() } #findSelectedNavItemById(itemId: string): HTMLElement | null { // First we compare the selected link to data-item-id for each nav item for (const navItem of this.items) { if (navItem.classList.contains('ActionListItem--hasSubItem')) { continue } const keys = navItem.getAttribute('data-item-id')?.split(' ') || [] if (keys.includes(itemId)) { return navItem } } return null } #findSelectedNavItemByHref(href: string): HTMLElement | null { // If we didn't find a match, we compare the selected link to the href of each nav item const selectedNavItem = this.querySelector<HTMLAnchorElement>(`.ActionListContent[href="${href}"]`) if (selectedNavItem) { return selectedNavItem.closest('.ActionListItem') } return null } #findSelectedNavItemByCurrentLocation(): HTMLElement | null { return this.#findSelectedNavItemByHref(window.location.pathname) } #select(navItem: HTMLElement) { const currentlySelectedItem = this.querySelector('.ActionListItem--navActive') as HTMLElement if (currentlySelectedItem) this.#deselect(currentlySelectedItem) navItem.classList.add('ActionListItem--navActive') if (navItem.children.length > 0) { navItem.children[0].setAttribute('aria-current', 'page') } const parentMenu = this.#findParentMenu(navItem) if (parentMenu) { this.expandItem(parentMenu) parentMenu.classList.add('ActionListContent--hasActiveSubItem') } } #deselect(navItem: HTMLElement) { navItem.classList.remove('ActionListItem--navActive') if (navItem.children.length > 0) { navItem.children[0].removeAttribute('aria-current') } const parentMenu = this.#findParentMenu(navItem) if (parentMenu) { this.collapseItem(parentMenu) parentMenu.classList.remove('ActionListContent--hasActiveSubItem') } } #findParentMenu(navItem: HTMLElement): HTMLElement | null { if (!navItem.classList.contains('ActionListItem--subItem')) return null const parent = navItem.closest('li.ActionListItem--hasSubItem')?.querySelector('button.ActionListContent') if (parent) { return parent as HTMLElement } else { return null } }}declare global { interface Window { NavListElement: typeof NavListElement }}