Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates the list-tree toggle in commit details
- Loading branch information
Showing
6 changed files
with
147 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/webviews/apps/shared/components/actions/action-item.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { attr, css, customElement, FASTElement, html } from '@microsoft/fast-element'; | ||
|
||
const template = html<ActionItem>`<a | ||
role="${x => (!x.href ? 'button' : null)}" | ||
type="${x => (!x.href ? 'button' : null)}" | ||
aria-label="${x => x.label}" | ||
title="${x => x.label}" | ||
><code-icon icon="${x => x.icon}"></code-icon | ||
></a>`; | ||
|
||
const styles = css` | ||
:host { | ||
box-sizing: border-box; | ||
display: inline-flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: 2rem; | ||
height: 2rem; | ||
border-radius: 0.5rem; | ||
color: inherit; | ||
padding: 0.2rem; | ||
vertical-align: text-bottom; | ||
text-decoration: none; | ||
cursor: pointer; | ||
} | ||
:host(:focus) { | ||
outline: 1px solid var(--vscode-focusBorder); | ||
outline-offset: -1px; | ||
} | ||
:host(:hover) { | ||
background-color: var(--vscode-toolbar-hoverBackground); | ||
} | ||
:host(:active) { | ||
background-color: var(--vscode-toolbar-activeBackground); | ||
} | ||
`; | ||
|
||
@customElement({ name: 'action-item', template: template, styles: styles }) | ||
export class ActionItem extends FASTElement { | ||
@attr | ||
href?: string; | ||
|
||
@attr | ||
label: string = ''; | ||
|
||
@attr | ||
icon: string = ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { css, customElement, FASTElement, html, observable, slotted } from '@microsoft/fast-element'; | ||
import '../codicon'; | ||
|
||
const template = html<ActionNav>`<template role="navigation"><slot ${slotted('actionNodes')}></slot></template>`; | ||
|
||
const styles = css` | ||
:host { | ||
display: flex; | ||
align-items: center; | ||
user-select: none; | ||
} | ||
`; | ||
|
||
@customElement({ name: 'action-nav', template: template, styles: styles }) | ||
export class ActionNav extends FASTElement { | ||
@observable | ||
actionNodes?: HTMLElement[]; | ||
|
||
actionNodesDisposer?: () => void; | ||
actionNodesChanged(_oldValue?: HTMLElement[], newValue?: HTMLElement[]) { | ||
this.actionNodesDisposer?.(); | ||
|
||
if (!newValue?.length) { | ||
return; | ||
} | ||
|
||
const handleKeydown = this.handleKeydown.bind(this); | ||
const nodeEvents = newValue | ||
?.filter(node => node.nodeType === 1) | ||
.map((node, i) => { | ||
node.setAttribute('tabindex', i === 0 ? '0' : '-1'); | ||
node.addEventListener('keydown', handleKeydown, false); | ||
return { | ||
dispose: () => { | ||
node?.removeEventListener('keydown', handleKeydown, false); | ||
}, | ||
}; | ||
}); | ||
|
||
this.actionNodesDisposer = () => { | ||
nodeEvents?.forEach(({ dispose }) => dispose()); | ||
}; | ||
} | ||
|
||
override disconnectedCallback() { | ||
this.actionNodesDisposer?.(); | ||
} | ||
|
||
handleKeydown(e: KeyboardEvent) { | ||
if (!e.target || this.actionNodes == null || this.actionNodes.length < 2) return; | ||
const target = e.target as HTMLElement; | ||
|
||
let $next: HTMLElement | null = null; | ||
if (e.key === 'ArrowLeft') { | ||
$next = target.previousElementSibling as HTMLElement; | ||
if ($next == null) { | ||
const filteredNodes = this.actionNodes.filter(node => node.nodeType === 1); | ||
$next = filteredNodes[filteredNodes.length - 1] ?? null; | ||
} | ||
} else if (e.key === 'ArrowRight') { | ||
$next = target.nextElementSibling as HTMLElement; | ||
if ($next == null) { | ||
$next = this.actionNodes.find(node => node.nodeType === 1) ?? null; | ||
} | ||
} | ||
if ($next == null || $next === target) { | ||
return; | ||
} | ||
target.setAttribute('tabindex', '-1'); | ||
$next.setAttribute('tabindex', '0'); | ||
$next.focus(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters