Skip to content

Commit d3070e9

Browse files
committed
Adds text label to explain commit in Inspect view
1 parent 912ce26 commit d3070e9

File tree

2 files changed

+103
-2
lines changed

2 files changed

+103
-2
lines changed

src/webviews/apps/commitDetails/components/gl-commit-details.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { GlDetailsBase } from './gl-details-base';
2121
import '../../shared/components/actions/action-item';
2222
import '../../shared/components/actions/action-nav';
2323
import '../../shared/components/button';
24+
import '../../shared/components/chips/action-chip';
2425
import '../../shared/components/code-icon';
2526
import '../../shared/components/commit/commit-identity';
2627
import '../../shared/components/commit/commit-stats';
@@ -171,15 +172,16 @@ export class GlCommitDetails extends GlDetailsBase {
171172
this.state?.orgSettings.ai !== false,
172173
() => html`
173174
<div class="message-block-actions">
174-
<action-item
175+
<gl-action-chip
175176
label="Explain this ${this.isStash ? 'Stash' : 'Commit'}"
176177
icon="sparkle"
177178
data-action="explain-commit"
178179
aria-busy="${this.explainBusy ? 'true' : nothing}"
179180
?disabled="${this.explainBusy ? true : nothing}"
180181
@click=${this.onExplainChanges}
181182
@keydown=${this.onExplainChanges}
182-
></action-item>
183+
><span>explain</span></gl-action-chip
184+
>
183185
</div>
184186
`,
185187
)}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { css, html, LitElement, nothing } from 'lit';
2+
import { customElement, property, query } from 'lit/decorators.js';
3+
import { focusOutline } from '../styles/lit/a11y.css';
4+
import '../overlays/tooltip';
5+
import '../code-icon';
6+
7+
@customElement('gl-action-chip')
8+
export class ActionChip extends LitElement {
9+
static override shadowRootOptions: ShadowRootInit = {
10+
...LitElement.shadowRootOptions,
11+
delegatesFocus: true,
12+
};
13+
14+
static override styles = css`
15+
:host {
16+
box-sizing: border-box;
17+
display: inline-flex;
18+
justify-content: center;
19+
align-items: center;
20+
min-width: 2rem;
21+
height: 2rem;
22+
border-radius: 0.5rem;
23+
color: inherit;
24+
padding: 0.2rem;
25+
vertical-align: text-bottom;
26+
text-decoration: none;
27+
cursor: pointer;
28+
}
29+
30+
:host(:focus-within) {
31+
${focusOutline}
32+
}
33+
34+
:host(:hover) {
35+
background-color: var(--vscode-toolbar-hoverBackground);
36+
}
37+
38+
:host(:active) {
39+
background-color: var(--vscode-toolbar-activeBackground);
40+
}
41+
42+
:host([disabled]) {
43+
pointer-events: none;
44+
opacity: 0.5;
45+
}
46+
47+
a {
48+
display: inline-flex;
49+
justify-content: center;
50+
align-items: center;
51+
gap: 0.2rem;
52+
vertical-align: middle;
53+
color: inherit;
54+
}
55+
a:focus {
56+
outline: none;
57+
}
58+
59+
::slotted(*) {
60+
padding-inline-end: 0.2rem;
61+
vertical-align: middle;
62+
text-transform: capitalize;
63+
}
64+
`;
65+
66+
@property()
67+
href?: string;
68+
69+
@property()
70+
label?: string;
71+
72+
@property()
73+
icon = '';
74+
75+
@property({ type: Boolean })
76+
disabled = false;
77+
78+
@query('a')
79+
private defaultFocusEl!: HTMLAnchorElement;
80+
81+
override render(): unknown {
82+
return html`
83+
<gl-tooltip hoist content="${this.label ?? nothing}">
84+
<a
85+
role="${!this.href ? 'button' : nothing}"
86+
type="${!this.href ? 'button' : nothing}"
87+
?disabled=${this.disabled}
88+
href=${this.href ?? nothing}
89+
>
90+
<code-icon icon="${this.icon}"></code-icon><slot></slot>
91+
</a>
92+
</gl-tooltip>
93+
`;
94+
}
95+
96+
override focus(options?: FocusOptions): void {
97+
this.defaultFocusEl.focus(options);
98+
}
99+
}

0 commit comments

Comments
 (0)