Skip to content

Commit 2d3cf8e

Browse files
committed
fix (playground): allow report hint banner to be dismissed
1 parent c215501 commit 2d3cf8e

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

components/playground/element.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,34 @@
104104
flex-grow: 1;
105105
}
106106

107+
.playground__runner-report-hint-banner-button {
108+
display: flex;
109+
110+
padding: 0.5em;
111+
112+
font-size: 0.875em;
113+
font-weight: 450;
114+
115+
background-color: transparent;
116+
border: none;
117+
118+
&:hover {
119+
background-color: var(--color-background-secondary);
120+
}
121+
122+
.report-hint {
123+
flex-grow: 1;
124+
}
125+
126+
.report-hint-banner-close-button {
127+
margin-left: auto;
128+
}
129+
130+
.report-hint-banner-close-button:hover {
131+
color: var(--error-color, #dd3333);
132+
}
133+
}
134+
107135
.playground__console {
108136
background-color: var(--color-background-secondary);
109137
border-top: var(--border);

components/playground/element.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class MDNPlayground extends L10nMixin(LitElement) {
3030

3131
static properties = {
3232
_gistID: { state: true },
33+
_showReportHintBanner: { state: true },
3334
};
3435

3536
constructor() {
@@ -38,6 +39,8 @@ export class MDNPlayground extends L10nMixin(LitElement) {
3839
this._autoRun = true;
3940
/** @type {string | undefined} */
4041
this._gistId = undefined;
42+
/** @type {boolean} */
43+
this._showReportHintBanner = false;
4144
}
4245

4346
/** @type {Ref<MDNPlayController>} */
@@ -188,6 +191,7 @@ ${"```"}`,
188191

189192
if (idParam) {
190193
this._gistId = idParam;
194+
this._showReportHintBanner = true;
191195
}
192196

193197
const { srcPrefix: srcPrefixState, code } =
@@ -255,7 +259,16 @@ ${"```"}`,
255259
this.requestUpdate();
256260
}
257261

262+
/** @param {Event} [event] */
263+
_dismissReportHintBanner(event) {
264+
if (event && event instanceof Event) {
265+
event.stopPropagation();
266+
}
267+
this._showReportHintBanner = false;
268+
}
269+
258270
_reportOpen() {
271+
this._dismissReportHintBanner();
259272
this._reportModal.value?.showModal();
260273
}
261274

@@ -282,6 +295,22 @@ ${"```"}`,
282295
this._user.run();
283296
}
284297

298+
_renderReportHintBanner() {
299+
return html`<button
300+
class="playground__runner-report-hint-banner-button"
301+
@click=${this._reportOpen}
302+
>
303+
<span class="report-hint">Seeing something inappropriate?</span>
304+
<span
305+
role="button"
306+
class="report-hint-banner-close-button"
307+
@click=${this._dismissReportHintBanner}
308+
aria-label=${this.l10n`Close report hint banner`}
309+
>X</span
310+
>
311+
</button>`;
312+
}
313+
285314
render() {
286315
const { code, initialCode } = this._controller.value ?? {};
287316
const hasCode = Object.values(code ?? {}).some(Boolean);
@@ -356,10 +385,8 @@ ${"```"}`,
356385
</details>
357386
</section>
358387
<section class="playground__runner-console">
359-
${this._gistId
360-
? html`<mdn-button @click=${this._reportOpen} variant="plain">
361-
Seeing something inappropriate?
362-
</mdn-button>`
388+
${this._gistId && this._showReportHintBanner
389+
? html`${this._renderReportHintBanner()}`
363390
: nothing}
364391
<mdn-play-runner></mdn-play-runner>
365392
<div class="playground__console">

0 commit comments

Comments
 (0)