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

Demonstrate adding a new component #6

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
40 changes: 40 additions & 0 deletions src/ui/components/play-demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
LitElement,
css,
html,
type CSSResultGroup,
type TemplateResult
} from 'lit'
import {customElement, property} from 'lit/decorators.js'
import {Bubble} from '../bubble.js'

declare global {
interface HTMLElementEventMap {
'fancy-click': CustomEvent<FancyClick>
}
interface HTMLElementTagNameMap {
'play-demo': PlayDemo
}
}

export type FancyClick = {num: number}

@customElement('play-demo')
export class PlayDemo extends LitElement {
@property({attribute: false}) example?: string

static override styles: CSSResultGroup = css``

protected override render(): TemplateResult {
return html`<button
@click=${() => {
console.log('hello! button clicked!')
this.dispatchEvent(
Bubble<FancyClick>('fancy-click', {num: Math.random()})
)
}}
>
hello!
</button>`
}
}
8 changes: 7 additions & 1 deletion src/ui/components/play-pen/play-pen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import type {PlayPreview} from '../play-preview.js'
import type {PlayToast} from '../play-toast.js'
import penVars from './pen-vars.css'

import '../play-demo.js'
import type {FancyClick} from '../play-demo.js'
import '../play-editor/play-editor.js'
import '../play-pen-footer.js'
import '../play-pen-header.js'
Expand Down Expand Up @@ -162,7 +164,7 @@ export class PlayPen extends LitElement {

protected override render(): TemplateResult {
return html`
<play-toast>Copied the URL!</play-toast
<play-toast>Copied the URL2!</play-toast
><play-pen-header
name=${this._name}
.srcByLabel=${this.srcByLabel}
Expand Down Expand Up @@ -191,6 +193,10 @@ export class PlayPen extends LitElement {
><slot></slot
></play-editor>
<div class="preview">
<play-demo
@fancy-click=${(ev: CustomEvent<FancyClick>) =>
this._editor.setSrc(ev.detail.num.toString())}
></play-demo>
<play-preview
.bundle=${this._bundle}
previewWidth=${this._previewWidth}
Expand Down
2 changes: 2 additions & 0 deletions src/ui/components/play-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export class PlayPreview extends LitElement {
this.dispatchEvent(
Bubble<PreviewError>('error', {type: 'Error', err: ev.detail})
)}
@devvit-ui-logs=${(ev: CustomEvent<unknown>) =>
console.log('got some logs', ev.detail)}
.meta="${this.#meta}"
.client=${this._client}
.scheme=${this.scheme}
Expand Down
Loading