Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(playground): migrate console to web component #12251

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions client/src/playground/console.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { createComponent } from "@lit/react";
import { html, LitElement } from "lit";
import React from "react";

import styles from "./console.scss?css" with { type: "css" };

/** @import { VConsole } from "./types" */

export class PlayConsole extends LitElement {
static properties = {
vConsole: { attribute: false },
};

static styles = styles;

constructor() {
super();
/** @type {VConsole[]} */
this.vConsole = [];
}

render() {
return html`
<span>Console</span>
<ul>
${this.vConsole.map(({ message }) => {
return html`
<li>
<code>${message}</code>
</li>
`;
})}
</ul>
`;
}

updated() {
const output = this.renderRoot.querySelector("ul");
output?.scrollTo({ top: output.scrollHeight });
}
}

customElements.define("play-console", PlayConsole);

export const ReactPlayConsole = createComponent({
tagName: "play-console",
elementClass: PlayConsole,
react: React,
});
33 changes: 33 additions & 0 deletions client/src/playground/console.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
:host {
display: flex;
flex-direction: column;
font-size: smaller;
LeoMcA marked this conversation as resolved.
Show resolved Hide resolved
margin: 0;
width: 100%;

> span {
background-color: var(--code-background-inline);
font-weight: 600;
text-align: center;
width: 100%;
}

ul {
background-color: var(--code-background-inline);
height: 6rem;
list-style: none;
margin: 0;
max-height: 6rem;
overflow: auto;
padding: 0;
width: 100%;

li {
padding: 0 1rem;

&::before {
content: ">";
}
}
}
}
30 changes: 0 additions & 30 deletions client/src/playground/console.tsx

This file was deleted.

31 changes: 0 additions & 31 deletions client/src/playground/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -235,37 +235,6 @@ main.play {
height: 100%;
width: 100%;
}

#play-console {
display: flex;
flex-direction: column;
font-size: smaller;
margin: 0;
width: 100%;

> span {
background-color: var(--code-background-inline);
font-weight: 600;
text-align: center;
width: 100%;
}

ul {
background-color: var(--code-background-inline);
height: 6rem;
max-height: 6rem;
overflow: auto;
width: 100%;

li {
padding: 0 1rem;

&::before {
content: ">";
}
}
}
}
}
}
}
5 changes: 3 additions & 2 deletions client/src/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import {
import "./index.scss";
import { PLAYGROUND_BASE_HOST } from "../env";
import { FlagForm, ShareForm } from "./forms";
import { Console, VConsole } from "./console";
import { ReactPlayConsole } from "./console";
import { useGleanClick } from "../telemetry/glean-context";
import { PLAYGROUND } from "../telemetry/constants";
import type { VConsole } from "./types";

const HTML_DEFAULT = "";
const CSS_DEFAULT = "";
Expand Down Expand Up @@ -418,7 +419,7 @@ export default function Playground() {
src={iframeSrc}
sandbox="allow-scripts allow-same-origin allow-forms"
></iframe>
<Console vConsole={vConsole} />
<ReactPlayConsole vConsole={vConsole} />
<SidePlacement extraClasses={["horizontal"]} />
</section>
</main>
Expand Down
4 changes: 4 additions & 0 deletions client/src/playground/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface VConsole {
prop: string;
message: string;
}
Loading