forked from lit/lit.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds JS/TS toggle to interactive docs samples (lit#478)
Adds a JS/TS toggle to all interactive samples in the docs, behind the `?mods=jsSamples` feature flag. Note: The playground page, tutorial page, and static samples will come in a followup PR. Also note: There are a some issues with the JS samples that I've seen already, mostly around `/*playground-fold*/` and `/*playground-hide*/` comments not getting preserved quite right. I'll address those in a followup too. Also moves the "open in playground" link from the top-right of the preview to the top-right of the whole playground. I think this makes more sense since its an action on the whole thing, not just the preview, but especially now that there will be a second control there. Also fixes upgrade layout shift issues with inline playgrounds. Part of lit#332
- Loading branch information
Showing
8 changed files
with
343 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/lit-dev-content/src/components/litdev-example-controls.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* @license | ||
* Copyright 2021 Google LLC | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
import {LitElement, html, css, customElement, property} from 'lit-element'; | ||
import './litdev-typescript-switch.js'; | ||
|
||
/** | ||
* Controls for lit.dev code examples. | ||
*/ | ||
@customElement('litdev-example-controls') | ||
export class LitDevExampleControls extends LitElement { | ||
static override styles = css` | ||
:host { | ||
display: flex; | ||
align-items: center; | ||
margin-left: auto; | ||
} | ||
#openInPlayground { | ||
display: flex; | ||
color: inherit; | ||
opacity: 70%; | ||
margin-left: 10px; | ||
} | ||
#openInPlayground:hover { | ||
opacity: 100%; | ||
} | ||
`; | ||
|
||
/** | ||
* Path to the project dir from `samples/PROJECT/project.json`. | ||
*/ | ||
@property() | ||
project?: string; | ||
|
||
override render() { | ||
return html` | ||
<litdev-typescript-switch></litdev-typescript-switch> | ||
<a | ||
id="openInPlayground" | ||
title="Open this example in the playground" | ||
target="_blank" | ||
href="/playground/#sample=${this.project}" | ||
> | ||
<!-- Source: https://material.io/resources/icons/?icon=launch&style=baseline --> | ||
<svg width="22px" height="22px" viewBox="0 0 24 24" fill="#5f5f5f"> | ||
<path | ||
d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z" | ||
/> | ||
</svg> | ||
</a> | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'litdev-typescript-controls': LitDevExampleControls; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.