Skip to content

Commit

Permalink
Demonstrate adding a new component
Browse files Browse the repository at this point in the history
  • Loading branch information
niedzielski committed Feb 9, 2024
1 parent 6b08a5b commit 056ed3e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
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

0 comments on commit 056ed3e

Please sign in to comment.