1
1
import type { PropertyValueMap } from 'lit' ;
2
2
import { css , html , LitElement } from 'lit' ;
3
3
import { customElement , property , query } from 'lit/decorators.js' ;
4
+ import { ifDefined } from 'lit/directives/if-defined.js' ;
5
+ import type { GlTooltip } from './overlays/tooltip' ;
4
6
import { focusOutlineButton } from './styles/lit/a11y.css' ;
5
7
import { elementBase } from './styles/lit/base.css' ;
6
8
import './overlays/tooltip' ;
@@ -28,6 +30,7 @@ export class GlButton extends LitElement {
28
30
--button-padding: 0.4rem;
29
31
--button-gap: 0.6rem;
30
32
--button-compact-padding: 0.4rem;
33
+ --button-input-padding: 0.1rem;
31
34
--button-tight-padding: 0.4rem 0.8rem;
32
35
--button-line-height: 1.35;
33
36
--button-border: var(--vscode-button-border, transparent);
@@ -87,6 +90,12 @@ export class GlButton extends LitElement {
87
90
${ focusOutlineButton }
88
91
}
89
92
93
+ :host([appearance='input']),
94
+ :host([role='checkbox']:focus-within),
95
+ :host([aria-checked]:focus-within) {
96
+ outline-offset: -1px;
97
+ }
98
+
90
99
:host([full]),
91
100
:host([full]) .control {
92
101
width: 100%;
@@ -98,6 +107,7 @@ export class GlButton extends LitElement {
98
107
--button-hover-background: var(--vscode-button-secondaryHoverBackground);
99
108
}
100
109
110
+ :host([appearance='input']),
101
111
:host([appearance='toolbar']) {
102
112
--button-background: transparent;
103
113
--button-foreground: var(--vscode-foreground);
@@ -119,6 +129,14 @@ export class GlButton extends LitElement {
119
129
--button-foreground: var(--color-foreground);
120
130
}
121
131
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,
122
140
:host([appearance='toolbar'][href]) > a {
123
141
display: flex;
124
142
align-items: center;
@@ -142,12 +160,26 @@ export class GlButton extends LitElement {
142
160
--code-icon-v-align: unset;
143
161
}
144
162
163
+ :host(:hover:not([disabled]):not([aria-checked='true'])) {
164
+ background-color: var(--vscode-inputOption-hoverBackground);
165
+ }
166
+
145
167
:host([disabled]) {
146
168
opacity: 0.4;
147
169
cursor: not-allowed;
148
170
pointer-events: none;
149
171
}
150
172
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
+
151
183
gl-tooltip {
152
184
height: 100%;
153
185
width: 100%;
@@ -162,7 +194,7 @@ export class GlButton extends LitElement {
162
194
protected control ! : HTMLElement ;
163
195
164
196
@property ( { reflect : true } )
165
- appearance ?: 'alert' | 'secondary' | 'toolbar' ;
197
+ appearance ?: 'alert' | 'secondary' | 'toolbar' | 'input' ;
166
198
167
199
@property ( { type : Boolean , reflect : true } )
168
200
disabled = false ;
@@ -184,6 +216,9 @@ export class GlButton extends LitElement {
184
216
@property ( )
185
217
tooltip ?: string ;
186
218
219
+ @property ( )
220
+ tooltipPlacement ?: GlTooltip [ 'placement' ] = 'bottom' ;
221
+
187
222
protected override updated ( changedProperties : PropertyValueMap < any > | Map < PropertyKey , unknown > ) : void {
188
223
super . updated ( changedProperties ) ;
189
224
@@ -194,11 +229,13 @@ export class GlButton extends LitElement {
194
229
195
230
protected override render ( ) {
196
231
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
+ > ` ;
198
235
}
199
236
200
237
if ( this . querySelectorAll ( '[slot="tooltip"]' ) . length > 0 ) {
201
- return html `< gl-tooltip >
238
+ return html `< gl-tooltip placement = ${ ifDefined ( this . tooltipPlacement ) } >
202
239
${ this . renderControl ( ) }
203
240
< slot name ="tooltip " slot ="content "> </ slot >
204
241
</ gl-tooltip > ` ;
0 commit comments