Skip to content

Commit edbd4ce

Browse files
committed
Moves Graph search buttons into the input
Uses `gl-button` and adds `input` appearance Adds click & focus support to the popover
1 parent 6b8bbd6 commit edbd4ce

File tree

5 files changed

+219
-230
lines changed

5 files changed

+219
-230
lines changed

src/webviews/apps/plus/graph/GraphWrapper.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ export function GraphWrapper({
13141314
<GlPopover
13151315
className="popover"
13161316
placement="bottom-start"
1317-
trigger="focus"
1317+
trigger="click focus"
13181318
arrow={false}
13191319
distance={0}
13201320
>
@@ -1393,7 +1393,6 @@ export function GraphWrapper({
13931393
</span>
13941394
<GlSearchBox
13951395
ref={searchEl}
1396-
label="Search Commits"
13971396
step={searchPosition}
13981397
total={searchResults?.count ?? 0}
13991398
valid={Boolean(searchQuery?.query && searchQuery.query.length > 2)}
@@ -1429,7 +1428,7 @@ export function GraphWrapper({
14291428
<GlPopover
14301429
className="popover"
14311430
placement="bottom-end"
1432-
trigger="focus"
1431+
trigger="click focus"
14331432
arrow={false}
14341433
distance={0}
14351434
>

src/webviews/apps/shared/components/button.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { PropertyValueMap } from 'lit';
22
import { css, html, LitElement } from 'lit';
33
import { customElement, property, query } from 'lit/decorators.js';
4+
import { ifDefined } from 'lit/directives/if-defined.js';
5+
import type { GlTooltip } from './overlays/tooltip';
46
import { focusOutlineButton } from './styles/lit/a11y.css';
57
import { elementBase } from './styles/lit/base.css';
68
import './overlays/tooltip';
@@ -28,6 +30,7 @@ export class GlButton extends LitElement {
2830
--button-padding: 0.4rem;
2931
--button-gap: 0.6rem;
3032
--button-compact-padding: 0.4rem;
33+
--button-input-padding: 0.1rem;
3134
--button-tight-padding: 0.4rem 0.8rem;
3235
--button-line-height: 1.35;
3336
--button-border: var(--vscode-button-border, transparent);
@@ -87,6 +90,12 @@ export class GlButton extends LitElement {
8790
${focusOutlineButton}
8891
}
8992
93+
:host([appearance='input']),
94+
:host([role='checkbox']:focus-within),
95+
:host([aria-checked]:focus-within) {
96+
outline-offset: -1px;
97+
}
98+
9099
:host([full]),
91100
:host([full]) .control {
92101
width: 100%;
@@ -98,6 +107,7 @@ export class GlButton extends LitElement {
98107
--button-hover-background: var(--vscode-button-secondaryHoverBackground);
99108
}
100109
110+
:host([appearance='input']),
101111
:host([appearance='toolbar']) {
102112
--button-background: transparent;
103113
--button-foreground: var(--vscode-foreground);
@@ -119,6 +129,14 @@ export class GlButton extends LitElement {
119129
--button-foreground: var(--color-foreground);
120130
}
121131
132+
:host([appearance='input']) .control {
133+
padding: var(--button-input-padding);
134+
--button-line-height: 1.1;
135+
height: 1.8rem;
136+
gap: 0.2rem;
137+
}
138+
139+
:host([appearance='input'][href]) > a,
122140
:host([appearance='toolbar'][href]) > a {
123141
display: flex;
124142
align-items: center;
@@ -142,12 +160,26 @@ export class GlButton extends LitElement {
142160
--code-icon-v-align: unset;
143161
}
144162
163+
:host(:hover:not([disabled]):not([aria-checked='true'])) {
164+
background-color: var(--vscode-inputOption-hoverBackground);
165+
}
166+
145167
:host([disabled]) {
146168
opacity: 0.4;
147169
cursor: not-allowed;
148170
pointer-events: none;
149171
}
150172
173+
:host([disabled][aria-checked='true']) {
174+
opacity: 0.8;
175+
}
176+
177+
:host([aria-checked='true']) {
178+
background-color: var(--vscode-inputOption-activeBackground);
179+
color: var(--vscode-inputOption-activeForeground);
180+
border-color: var(--vscode-inputOption-activeBorder);
181+
}
182+
151183
gl-tooltip {
152184
height: 100%;
153185
width: 100%;
@@ -162,7 +194,7 @@ export class GlButton extends LitElement {
162194
protected control!: HTMLElement;
163195

164196
@property({ reflect: true })
165-
appearance?: 'alert' | 'secondary' | 'toolbar';
197+
appearance?: 'alert' | 'secondary' | 'toolbar' | 'input';
166198

167199
@property({ type: Boolean, reflect: true })
168200
disabled = false;
@@ -184,6 +216,9 @@ export class GlButton extends LitElement {
184216
@property()
185217
tooltip?: string;
186218

219+
@property()
220+
tooltipPlacement?: GlTooltip['placement'] = 'bottom';
221+
187222
protected override updated(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
188223
super.updated(changedProperties);
189224

@@ -194,11 +229,13 @@ export class GlButton extends LitElement {
194229

195230
protected override render() {
196231
if (this.tooltip) {
197-
return html`<gl-tooltip .content=${this.tooltip}>${this.renderControl()}</gl-tooltip>`;
232+
return html`<gl-tooltip .content=${this.tooltip} placement=${ifDefined(this.tooltipPlacement)}
233+
>${this.renderControl()}</gl-tooltip
234+
>`;
198235
}
199236

200237
if (this.querySelectorAll('[slot="tooltip"]').length > 0) {
201-
return html`<gl-tooltip>
238+
return html`<gl-tooltip placement=${ifDefined(this.tooltipPlacement)}>
202239
${this.renderControl()}
203240
<slot name="tooltip" slot="content"></slot>
204241
</gl-tooltip>`;

src/webviews/apps/shared/components/overlays/popover.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type SlPopup from '@shoelace-style/shoelace/dist/components/popup/popup.js';
22
import { css, html, LitElement } from 'lit';
33
import { customElement, property, query } from 'lit/decorators.js';
4-
import '@shoelace-style/shoelace/dist/components/popup/popup.js';
54
import { parseDuration, waitForEvent } from '../../dom';
65
import { GlElement, observe } from '../element';
6+
import '@shoelace-style/shoelace/dist/components/popup/popup.js';
77

88
// Adapted from shoelace tooltip
99

@@ -222,6 +222,7 @@ export class GlPopover extends GlElement {
222222
this.addEventListener('blur', this.handleTriggerBlur, true);
223223
this.addEventListener('focus', this.handleTriggerFocus, true);
224224
this.addEventListener('click', this.handleTriggerClick);
225+
this.addEventListener('mousedown', this.handleTriggerMouseDown);
225226
this.addEventListener('mouseover', this.handleMouseOver);
226227
this.addEventListener('mouseout', this.handleMouseOut);
227228
}
@@ -256,13 +257,27 @@ export class GlPopover extends GlElement {
256257
private handleTriggerClick = () => {
257258
if (this.hasTrigger('click')) {
258259
if (this.open) {
260+
if (this._skipHideOnClick) {
261+
this._skipHideOnClick = false;
262+
return;
263+
}
264+
259265
void this.hide();
260266
} else {
261267
void this.show();
262268
}
263269
}
264270
};
265271

272+
private _skipHideOnClick = false;
273+
private handleTriggerMouseDown = () => {
274+
if (this.hasTrigger('click') && this.hasTrigger('focus') && !this.matches(':focus-within')) {
275+
this._skipHideOnClick = true;
276+
} else {
277+
this._skipHideOnClick = false;
278+
}
279+
};
280+
266281
private handleTriggerFocus = () => {
267282
if (this.hasTrigger('focus')) {
268283
void this.show();

src/webviews/apps/shared/components/search/search-box.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,6 @@ export class GlSearchBox extends GlElement {
113113
@property({ type: String })
114114
errorMessage = '';
115115

116-
@property({ type: String })
117-
label = 'Search';
118-
119-
@property({ type: String })
120-
placeholder = 'Search commits (↑↓ for history), e.g. "Updates dependencies" author:eamodio';
121-
122116
@property({ type: String })
123117
value = '';
124118

@@ -270,8 +264,6 @@ export class GlSearchBox extends GlElement {
270264
exportparts="search: search"
271265
.errorMessage="${this.errorMessage}"
272266
.filter=${this.filter}
273-
.label="${this.label}"
274-
.placeholder="${this.placeholder}"
275267
.matchAll="${this.matchAll}"
276268
.matchCase="${this.matchCase}"
277269
.matchRegex="${this.matchRegex}"

0 commit comments

Comments
 (0)