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

feat(interactive-examples): support CSS examples #12664

Merged
merged 60 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
44e5c7f
refactor(play/editor): extract _defaultExtensions()
caugner Feb 20, 2025
69fca21
feat(play): add `<play-editor-line>` component
caugner Feb 20, 2025
3d58ec8
feat(play): replace line editor by minimal attribute
caugner Feb 20, 2025
9844a66
wip(ix): prototype css choice logic
LeoMcA Feb 20, 2025
fbb14be
enhance(ix): highlight selected choice
caugner Feb 21, 2025
11f3223
chore(ix): style CSS Choice header
caugner Feb 21, 2025
a311ae9
chore(ix): sync CSS Choice element design
caugner Feb 21, 2025
4796b89
chore(ix): add line between choices
caugner Feb 21, 2025
1798aef
chore(ix): apply CSS Choice base style
caugner Feb 21, 2025
3e866e9
chore(ix): add CSS Choice arrow
caugner Feb 21, 2025
4130c28
fix(ix): apply CSS Choice height/overflow on first-child
caugner Feb 21, 2025
6ce7382
chore(ix): distribute CSS Choice choices vs output
caugner Feb 21, 2025
485faa6
feat(ix): mark unsupported CSS choice
caugner Feb 21, 2025
55722d3
chore(ix): add basic responsive CSS Choice layout
caugner Feb 21, 2025
d8aa431
chore(ix): remove resolved TODO notes
caugner Feb 21, 2025
8dea694
enhance(ix): select first tab + reset values properly
caugner Feb 21, 2025
2336db1
enhance(ix): reduce delay for CSS Choice editor
caugner Feb 21, 2025
ec12321
fix(ix): use correct default height
caugner Feb 24, 2025
70fa2b5
fix(ix): select first choice properly
caugner Feb 24, 2025
1ed7bb6
fix(ix/choices): move padding out of iframe
caugner Feb 24, 2025
7424239
fix(ix/choices): unset iframe body font-size
caugner Feb 24, 2025
404688a
chore(ix/choice): reduce iframe height
caugner Feb 24, 2025
a0f2b52
chore(ix/choice): reduce space between columns
caugner Feb 24, 2025
1bc44f4
fix(ix/choice): scroll on overflow
caugner Feb 24, 2025
80cfb88
chore(play): do not wrap in minimal editor
caugner Feb 24, 2025
d4f0845
fix(ix/choice): avoid border overflow
caugner Feb 24, 2025
303cc01
fix(ix/choice): use border-bottom on small screens
caugner Feb 24, 2025
9115f17
chore(ix/choice): hide ::after in vertical layout
caugner Feb 24, 2025
5a52823
chore(ix/choice): add unsupported border-color to editor
caugner Feb 24, 2025
3d43fb5
wip(ix): migration script now includes section in html, so port style…
LeoMcA Feb 25, 2025
7c73a95
fix(ix): deal with overflowing editors
LeoMcA Feb 25, 2025
675f93d
fix(ix): lower specificity of default styles so examples can override
LeoMcA Feb 25, 2025
3454bf6
wip(ix): add transition styling
LeoMcA Feb 25, 2025
a6549fd
Merge remote-tracking branch 'origin/main' into new-interactive-examp…
LeoMcA Feb 26, 2025
c4b362c
Merge remote-tracking branch 'origin/main' into new-interactive-examp…
LeoMcA Feb 26, 2025
7ee1ba8
chore(ix): remove unnecessary console.log
caugner Feb 26, 2025
253cd21
fix(ix): signal runner ready state via message
caugner Feb 26, 2025
0090e29
chore(ix): remove unused "js" height
caugner Feb 26, 2025
a167503
wip(ix): simplify some css variables
LeoMcA Feb 26, 2025
12359e6
wip(ix): don't set live-sample default styles, will move choice.js/cs…
LeoMcA Feb 26, 2025
b3a41cd
chore(play): condense postMessage error handling
caugner Feb 26, 2025
be54554
fix(ix): avoid controller reset in chocies
caugner Feb 27, 2025
abc52ad
fix(ix/choices): prefill unsupported mask
caugner Feb 28, 2025
49fb639
fix(ix/choice): set first choice on initial load
caugner Feb 28, 2025
b235911
Merge remote-tracking branch 'origin/main' into new-interactive-examp…
LeoMcA Mar 4, 2025
371ea0f
fix(ix-choice): scrollbar at bottom and correct background color
LeoMcA Mar 4, 2025
d541891
fix(ix-choice): support dark mode
LeoMcA Mar 4, 2025
79673cf
wip(ix): extract runner defaults into type
LeoMcA Mar 4, 2025
aced780
fix(ix): fix csp error for blank.localhost
LeoMcA Mar 4, 2025
46cc584
fix(ix-choice): keep same height for js demos
LeoMcA Mar 4, 2025
97fd3a3
wip(ix): refactor choices/console/tabs into seperate classes
LeoMcA Mar 4, 2025
474763a
wip(ix): replace unsupported mask with array
LeoMcA Mar 5, 2025
0010c8e
wip(ix): post ready message after DOM loaded
LeoMcA Mar 5, 2025
7a30ebb
wip(ix): move choice js/css into cloud function
LeoMcA Mar 5, 2025
46c4e2e
fix(ix): split choice/update event handlers
LeoMcA Mar 5, 2025
a2ed08c
wip(ix): small refactor to play-runner using iframe ref
LeoMcA Mar 5, 2025
8bcafda
wip(ix): small fixes to css
LeoMcA Mar 5, 2025
7b50b7b
wip(ix): fix check:tsc
LeoMcA Mar 5, 2025
14873b3
Merge remote-tracking branch 'origin/main' into new-interactive-examp…
LeoMcA Mar 5, 2025
3d8b895
Merge remote-tracking branch 'origin/main' into new-interactive-examp…
LeoMcA Mar 6, 2025
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
12 changes: 10 additions & 2 deletions client/src/lit/interactive-example/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

interactive-example {
display: block;
height: 444px;
height: 375px;
margin: 1rem 0;

&[name^="JavaScript Demo:" i] {
height: 444px;
}

&[height="shorter"] {
height: 364px;
}
Expand All @@ -27,7 +31,11 @@ interactive-example {
}

@media (max-width: $screen-lg) {
height: 513px;
height: 675px;

&[name^="JavaScript Demo:" i] {
height: 513px;
}

&[height="shorter"] {
height: 433px;
Expand Down
122 changes: 25 additions & 97 deletions client/src/lit/interactive-example/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { html, LitElement } from "lit";
import { ref, createRef } from "lit/directives/ref.js";
import { ifDefined } from "lit/directives/if-defined.js";
import { decode } from "he";

import "../play/editor.js";
import "../play/controller.js";
import "../play/console.js";
import "../play/runner.js";
import { LitElement } from "lit";
import { createRef } from "lit/directives/ref.js";

import { GleanMixin } from "../glean-mixin.js";
import "./tabs.js";
import { InteractiveExampleWithChoices } from "./with-choices.js";
import { InteractiveExampleWithConsole } from "./with-console.js";
import { InteractiveExampleWithTabs } from "./with-tabs.js";

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

Expand All @@ -21,10 +17,8 @@ import styles from "./index.scss?css" with { type: "css" };
const LANGUAGE_CLASSES = ["html", "js", "css", "wat"];
const GLEAN_EVENT_TYPES = ["focus", "copy", "cut", "paste", "click"];

export class InteractiveExample extends GleanMixin(LitElement) {
static properties = {
name: { type: String },
};
export class InteractiveExampleBase extends GleanMixin(LitElement) {
static properties = { name: { type: String } };

static styles = styles;

Expand Down Expand Up @@ -52,7 +46,7 @@ export class InteractiveExample extends GleanMixin(LitElement) {

_initialCode() {
const exampleNodes = this.closest("section")?.querySelectorAll(
".code-example pre[class*=interactive-example]"
".code-example pre.interactive-example"
);
const code = Array.from(exampleNodes || []).reduce((acc, pre) => {
const language = Array.from(pre.classList).find((c) =>
Expand All @@ -67,10 +61,17 @@ export class InteractiveExample extends GleanMixin(LitElement) {
}
: acc;
}, /** @type {Object<string, string>} */ ({}));
const choiceNodes = this.closest("section")?.querySelectorAll(
".code-example pre.interactive-example-choice"
);
this._choices = Array.from(choiceNodes || []).map((pre) =>
pre.textContent?.trim()
);
this._languages = Object.keys(code);
this._template =
(this._languages.length === 1 && this._languages[0] === "js") ||
(this._languages.includes("js") && this._languages.includes("wat"))
this._template = this._choices.length
? "choices"
: (this._languages.length === 1 && this._languages[0] === "js") ||
(this._languages.includes("js") && this._languages.includes("wat"))
? "console"
: "tabbed";
return code;
Expand Down Expand Up @@ -108,85 +109,6 @@ export class InteractiveExample extends GleanMixin(LitElement) {
this._code = this._initialCode();
}

_renderConsole() {
return html`
<play-controller ${ref(this._controller)}>
<div class="template-console">
<header>
<h4>${decode(this.name)}</h4>
</header>
${this._languages.length === 1
? html`<play-editor
id="editor"
language=${ifDefined(this._languages[0])}
></play-editor>`
: html`<ix-tab-wrapper>
${this._languages.map(
(lang) => html`
<ix-tab id=${lang}>${this._langName(lang)}</ix-tab>
<ix-tab-panel id=${`${lang}-panel`}>
<play-editor language=${lang}></play-editor>
</ix-tab-panel>
`
)}
</ix-tab-wrapper>`}
<div class="buttons">
<button id="execute" @click=${this._run}>Run</button>
<button id="reset" @click=${this._reset}>Reset</button>
</div>
<play-console id="console"></play-console>
<play-runner
defaults=${ifDefined(
this._languages.includes("wat") ? "ix-wat" : undefined
)}
></play-runner>
</div>
</play-controller>
`;
}

_renderTabbed() {
return html`
<play-controller ${ref(this._controller)} run-on-start run-on-change>
<div class="template-tabbed">
<header>
<h4>${decode(this.name)}</h4>
<button id="reset" @click=${this._reset}>Reset</button>
</header>
<ix-tab-wrapper>
${this._languages.map(
(lang) => html`
<ix-tab id=${lang}>${this._langName(lang)}</ix-tab>
<ix-tab-panel id=${`${lang}-panel`}>
<play-editor language=${lang}></play-editor>
</ix-tab-panel>
`
)}
</ix-tab-wrapper>
<div class="output-wrapper">
<h4>Output</h4>
<play-runner
${ref(this._runner)}
sandbox="allow-top-navigation-by-user-activation"
defaults="ix-tabbed"
></play-runner>
</div>
</div>
</play-controller>
`;
}

render() {
switch (this._template) {
case "console":
return this._renderConsole();
case "tabbed":
return this._renderTabbed();
default:
return "";
}
}

firstUpdated() {
if (this._controller.value) {
this._controller.value.code = this._code;
Expand All @@ -201,4 +123,10 @@ export class InteractiveExample extends GleanMixin(LitElement) {
}
}

export class InteractiveExample extends InteractiveExampleWithChoices(
InteractiveExampleWithTabs(
InteractiveExampleWithConsole(InteractiveExampleBase)
)
) {}

customElements.define("interactive-example", InteractiveExample);
Loading
Loading