|
| 1 | +import { consume } from '@lit/context'; |
| 2 | +import { css, html, LitElement, nothing } from 'lit'; |
| 3 | +import { customElement, query, state } from 'lit/decorators.js'; |
| 4 | +import type { State } from '../../../home/protocol'; |
| 5 | +import { CollapseSectionCommand, TogglePreviewEnabledCommand } from '../../../home/protocol'; |
| 6 | +import { focusOutline } from '../../shared/components/styles/lit/a11y.css'; |
| 7 | +import { linkBase } from '../../shared/components/styles/lit/base.css'; |
| 8 | +import { ipcContext } from '../../shared/context'; |
| 9 | +import type { HostIpc } from '../../shared/ipc'; |
| 10 | +import { stateContext } from '../context'; |
| 11 | +import '../../shared/components/button-container'; |
| 12 | +import '../../shared/components/overlays/tooltip'; |
| 13 | + |
| 14 | +export const previewBannerTagName = 'gl-preview-banner'; |
| 15 | + |
| 16 | +@customElement(previewBannerTagName) |
| 17 | +export class GlPreviewBanner extends LitElement { |
| 18 | + static override shadowRootOptions: ShadowRootInit = { |
| 19 | + ...LitElement.shadowRootOptions, |
| 20 | + delegatesFocus: true, |
| 21 | + }; |
| 22 | + |
| 23 | + static override styles = [ |
| 24 | + linkBase, |
| 25 | + css` |
| 26 | + .text-button, |
| 27 | + .feedback { |
| 28 | + padding: 0.4rem 0.8rem; |
| 29 | + } |
| 30 | +
|
| 31 | + .text-button { |
| 32 | + appearance: none; |
| 33 | + background: none; |
| 34 | + border: none; |
| 35 | + color: inherit; |
| 36 | + text-align: end; |
| 37 | + cursor: pointer; |
| 38 | + width: 100%; |
| 39 | + } |
| 40 | + .text-button:hover, |
| 41 | + .text-button:focus-within { |
| 42 | + background-color: var(--gl-card-background); |
| 43 | + } |
| 44 | + .text-button:focus-visible { |
| 45 | + ${focusOutline} |
| 46 | + } |
| 47 | +
|
| 48 | + gl-card::part(base) { |
| 49 | + margin-block-end: 1.2rem; |
| 50 | + } |
| 51 | + `, |
| 52 | + ]; |
| 53 | + |
| 54 | + @consume<State>({ context: stateContext, subscribe: true }) |
| 55 | + @state() |
| 56 | + private _state!: State; |
| 57 | + |
| 58 | + @consume<HostIpc>({ context: ipcContext, subscribe: true }) |
| 59 | + @state() |
| 60 | + private _ipc!: HostIpc; |
| 61 | + |
| 62 | + @state() |
| 63 | + private closed = false; |
| 64 | + |
| 65 | + @query('button') |
| 66 | + private _button!: HTMLButtonElement; |
| 67 | + |
| 68 | + override render() { |
| 69 | + if (this._state.previewEnabled === true) { |
| 70 | + return html` |
| 71 | + <gl-card> |
| 72 | + <p><strong>Welcome to the new Home View!</strong></p> |
| 73 | + <p> |
| 74 | + We're reinventing GitLens' Home to be a more helpful daily workflow tool. We'll continue to |
| 75 | + refine this view and welcome your |
| 76 | + <a href="https://github.com/gitkraken/vscode-gitlens/discussions/3721">feedback</a>. |
| 77 | + </p> |
| 78 | + <button-container> |
| 79 | + <gl-button appearance="secondary" @click=${() => this.togglePreview()} full |
| 80 | + ><code-icon icon="arrow-left"></code-icon> Revert to Old Home View</gl-button |
| 81 | + > |
| 82 | + </button-container> |
| 83 | + <gl-button |
| 84 | + slot="actions" |
| 85 | + appearance="toolbar" |
| 86 | + tooltip="Dismiss Welcome" |
| 87 | + @click=${() => this.onClose()} |
| 88 | + ><code-icon icon="close"></code-icon |
| 89 | + ></gl-button> |
| 90 | + </gl-card> |
| 91 | + `; |
| 92 | + } |
| 93 | + |
| 94 | + if (this.closed || this._state.previewCollapsed === true) { |
| 95 | + return nothing; |
| 96 | + } |
| 97 | + |
| 98 | + return html` |
| 99 | + <gl-tooltip placement="bottom"> |
| 100 | + <button class="text-button text-button--end" @click=${() => this.togglePreview()}> |
| 101 | + New Home View <code-icon icon="arrow-right"></code-icon> |
| 102 | + </button> |
| 103 | + <p slot="content"> |
| 104 | + <strong>Switch to the new Home View!</strong><br /> |
| 105 | + We're reinventing GitLens' Home to be a more helpful daily workflow tool. We'll continue to refine |
| 106 | + this view and welcome your feedback. |
| 107 | + </p> |
| 108 | + </gl-tooltip> |
| 109 | + `; |
| 110 | + } |
| 111 | + |
| 112 | + private togglePreview() { |
| 113 | + this._ipc.sendCommand(TogglePreviewEnabledCommand); |
| 114 | + } |
| 115 | + |
| 116 | + private onClose() { |
| 117 | + this.closed = true; |
| 118 | + |
| 119 | + this._ipc.sendCommand(CollapseSectionCommand, { |
| 120 | + section: 'newHomePreview', |
| 121 | + collapsed: true, |
| 122 | + }); |
| 123 | + } |
| 124 | + |
| 125 | + override focus() { |
| 126 | + this._button?.focus(); |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +declare global { |
| 131 | + interface HTMLElementTagNameMap { |
| 132 | + [previewBannerTagName]: GlPreviewBanner; |
| 133 | + } |
| 134 | +} |
0 commit comments