|
| 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