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
<nav aria-label="Workflow results" data-view-component="true">
<nav-list>
<nav-list-group>
<div data-view-component="true">
<div data-view-component="true" class="ActionList-sectionDivider">
<h3 id="heading-title-c81cc41a-b49d-4e26-92e7-a5612f49f241" data-view-component="true" class="ActionList-sectionDivider-title">
Workflows
</h3>
</div>
<ul id="group-20ded6fd-78c6-4055-839d-7fba3179ca9d" role="list" aria-labelledby="heading-title-c81cc41a-b49d-4e26-92e7-a5612f49f241" data-view-component="true" class="ActionListWrap">
<li data-targets="nav-list.items nav-list.items" data-item-id="" data-view-component="true" class="ActionListItem ActionListItem--withActions">
<a id="item-880793a6-b06b-447c-ae1d-f14b5226e354" href="/workflows/1" data-view-component="true" class="ActionListContent">
<span data-view-component="true" class="ActionListItem-label">
Build and Test
</span></a>
<button name="build_and_test_button" id="icon-button-2d8bc98f-f842-47f8-b682-67a4d0a21fb3" aria-labelledby="tooltip-c5b92c0d-16a6-46a1-93e2-99f335c56b39" type="button" data-view-component="true" class="Button Button--iconOnly Button--invisible Button--medium ActionListItem-trailingAction"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-sync Button-visual">
<path d="M1.705 8.005a.75.75 0 0 1 .834.656 5.5 5.5 0 0 0 9.592 2.97l-1.204-1.204a.25.25 0 0 1 .177-.427h3.646a.25.25 0 0 1 .25.25v3.646a.25.25 0 0 1-.427.177l-1.38-1.38A7.002 7.002 0 0 1 1.05 8.84a.75.75 0 0 1 .656-.834ZM8 2.5a5.487 5.487 0 0 0-4.131 1.869l1.204 1.204A.25.25 0 0 1 4.896 6H1.25A.25.25 0 0 1 1 5.75V2.104a.25.25 0 0 1 .427-.177l1.38 1.38A7.002 7.002 0 0 1 14.95 7.16a.75.75 0 0 1-1.49.178A5.5 5.5 0 0 0 8 2.5Z"></path>
</svg>
</button><tool-tip id="tooltip-c5b92c0d-16a6-46a1-93e2-99f335c56b39" for="icon-button-2d8bc98f-f842-47f8-b682-67a4d0a21fb3" popover="manual" data-direction="s" data-type="label" data-view-component="true" class="sr-only position-absolute">Build and test: re-run workflow</tool-tip>
</li>
<li data-targets="nav-list.items nav-list.items" data-item-id="" data-view-component="true" class="ActionListItem ActionListItem--withActions">
<a id="item-99d3681b-1daa-425d-8def-2853aee2ca2d" href="/workflows/2" data-view-component="true" class="ActionListContent">
<span data-view-component="true" class="ActionListItem-label">
Publish
</span></a>
<button name="publish_button" id="icon-button-89d9f0b4-4d5d-459a-b7a0-ca07885d1a38" aria-labelledby="tooltip-d7c589f2-b973-47a7-92ab-cd88f94dcd10" type="button" data-view-component="true" class="Button Button--iconOnly Button--invisible Button--medium ActionListItem-trailingAction"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-sync Button-visual">
<path d="M1.705 8.005a.75.75 0 0 1 .834.656 5.5 5.5 0 0 0 9.592 2.97l-1.204-1.204a.25.25 0 0 1 .177-.427h3.646a.25.25 0 0 1 .25.25v3.646a.25.25 0 0 1-.427.177l-1.38-1.38A7.002 7.002 0 0 1 1.05 8.84a.75.75 0 0 1 .656-.834ZM8 2.5a5.487 5.487 0 0 0-4.131 1.869l1.204 1.204A.25.25 0 0 1 4.896 6H1.25A.25.25 0 0 1 1 5.75V2.104a.25.25 0 0 1 .427-.177l1.38 1.38A7.002 7.002 0 0 1 14.95 7.16a.75.75 0 0 1-1.49.178A5.5 5.5 0 0 0 8 2.5Z"></path>
</svg>
</button><tool-tip id="tooltip-d7c589f2-b973-47a7-92ab-cd88f94dcd10" for="icon-button-89d9f0b4-4d5d-459a-b7a0-ca07885d1a38" popover="manual" data-direction="s" data-type="label" data-view-component="true" class="sr-only position-absolute">Publish: re-run workflow</tool-tip>
</li>
</ul>
</div>
</nav-list-group>
</nav-list>
</nav>
<script type="text/javascript" data-eval="true">
const breadButton = document.querySelector("[name=build_and_test_button]")
breadButton.addEventListener("click", () => alert("The 'Build and Test' workflow will be re-run."))
const cheeseButton = document.querySelector("[name=publish_button]")
cheeseButton.addEventListener("click", () => alert("The 'Publish' workflow will be re-run."))
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<%= render(Primer::Beta::NavList.new(aria: { label: "Workflow results" })) do |list| %>
<% list.with_group do |group| %>
<% group.with_heading(title: "Workflows") %>
<% group.with_item(label: "Build and Test", href: "/workflows/1") do |item| %>
<%= item.with_trailing_action(icon: :sync, aria: { label: "Build and test: re-run workflow" }, name: "build_and_test_button") %>
<% end %>
<% group.with_item(label: "Publish", href: "/workflows/2") do |item| %>
<%= item.with_trailing_action(icon: :sync, aria: { label: "Publish: re-run workflow" }, name: "publish_button") %>
<% end %>
<% end %>
<% end %>
<script type="text/javascript" data-eval="true">
const breadButton = document.querySelector("[name=build_and_test_button]")
breadButton.addEventListener("click", () => alert("The 'Build and Test' workflow will be re-run."))
const cheeseButton = document.querySelector("[name=publish_button]")
cheeseButton.addEventListener("click", () => alert("The 'Publish' workflow will be re-run."))
</script>

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
/* eslint-disable custom-elements/expose-class-on-global */
import {controller, targets} from '@github/catalyst'
@controller
export class NavListElement extends HTMLElement {
@targets items: HTMLElement[]
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
}
}