Skip to content

Commit

Permalink
chore(playground): migrate console to web component
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA committed Dec 5, 2024
1 parent 6ee580e commit ea01236
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 63 deletions.
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,
});
34 changes: 34 additions & 0 deletions client/src/playground/console.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
:host {
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 {
margin: 0;
padding: 0;
list-style: none;

background-color: var(--code-background-inline);
height: 6rem;
max-height: 6rem;
overflow: auto;
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;
}

0 comments on commit ea01236

Please sign in to comment.