Previews

No matching results.

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
<nav aria-labelledby="heading-31b0cc76-a958-460c-bb64-883841bb05a2" data-view-component="true">
<h2 id="heading-31b0cc76-a958-460c-bb64-883841bb05a2" data-view-component="true" class="ActionListHeader">Account 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-7d30bca5-9733-4611-88db-d606dbafc0ec" 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 data-item-id="" data-targets="nav-list.items" data-view-component="true" class="ActionListItem">
<a id="item-a5c5c392-98cb-4b18-a11e-09d28e3a8c66" href="/billing" 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-credit-card">
<path d="M10.75 9a.75.75 0 0 0 0 1.5h1.5a.75.75 0 0 0 0-1.5h-1.5Z"></path><path d="M0 3.75C0 2.784.784 2 1.75 2h12.5c.966 0 1.75.784 1.75 1.75v8.5A1.75 1.75 0 0 1 14.25 14H1.75A1.75 1.75 0 0 1 0 12.25ZM14.5 6.5h-13v5.75c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25Zm0-2.75a.25.25 0 0 0-.25-.25H1.75a.25.25 0 0 0-.25.25V5h13Z"></path>
</svg>
</span>
<span data-view-component="true" class="ActionListItem-label">
Billing
</span>
</a>
</li>
<li data-item-id="" data-targets="nav-list.items" data-view-component="true" class="ActionListItem">
<a id="item-06744823-4089-4557-a7dd-3476764fa2d5" href="/change_password" 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-key">
<path d="M10.5 0a5.499 5.499 0 1 1-1.288 10.848l-.932.932a.749.749 0 0 1-.53.22H7v.75a.749.749 0 0 1-.22.53l-.5.5a.749.749 0 0 1-.53.22H5v.75a.749.749 0 0 1-.22.53l-.5.5a.749.749 0 0 1-.53.22h-2A1.75 1.75 0 0 1 0 14.25v-2c0-.199.079-.389.22-.53l4.932-4.932A5.5 5.5 0 0 1 10.5 0Zm-4 5.5c-.001.431.069.86.205 1.269a.75.75 0 0 1-.181.768L1.5 12.56v1.69c0 .138.112.25.25.25h1.69l.06-.06v-1.19a.75.75 0 0 1 .75-.75h1.19l.06-.06v-1.19a.75.75 0 0 1 .75-.75h1.19l1.023-1.025a.75.75 0 0 1 .768-.18A4 4 0 1 0 6.5 5.5ZM11 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path>
</svg>
</span>
<span data-view-component="true" class="ActionListItem-label">
Change password
</span>
</a>
</li>
<li data-item-id="" data-targets="nav-list.items" data-view-component="true" class="ActionListItem">
<a id="item-8126f338-9cfa-4ce5-8c53-5717bd887c6a" 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 circle" />
</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>
</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
render(Primer::Beta::NavList.new) do |list|
list.with_heading(title: "Account settings")
list.with_item(label: "General", href: "/general") do |item|
item.with_leading_visual_icon(icon: :gear)
end
list.with_item(label: "Billing", href: "/billing") do |item|
item.with_leading_visual_icon(icon: :"credit-card")
end
list.with_item(label: "Change password", href: "/change_password") do |item|
item.with_leading_visual_icon(icon: :key)
end
list.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"
)
end

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'
@controller
export 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
}
}