11import type { PropertyValueMap } from 'lit' ;
22import { css , html , LitElement } from 'lit' ;
33import { customElement , property , query } from 'lit/decorators.js' ;
4+ import { ifDefined } from 'lit/directives/if-defined.js' ;
5+ import type { GlTooltip } from './overlays/tooltip' ;
46import { focusOutlineButton } from './styles/lit/a11y.css' ;
57import { elementBase } from './styles/lit/base.css' ;
68import './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 > ` ;
0 commit comments