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

docs: update demo #901

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5900ff6
chore: add editorconfig
Lodin Oct 15, 2024
a50f219
docs: add stories stub
Lodin Oct 18, 2024
a294bab
Revert "docs: add stories stub"
Lodin Oct 22, 2024
841b499
docs: update demo [initial]
Lodin Oct 28, 2024
e253d96
refactor: continue improving new demo app
Lodin Oct 28, 2024
74c21f8
refactor: implement multipage
Lodin Oct 30, 2024
af70080
docs: add more pages
Lodin Oct 31, 2024
d2eac8d
docs: improve snippets
Lodin Nov 1, 2024
7f71326
Update README.md
platosha Nov 1, 2024
28e010b
chore(deps-dev): bump stylelint from 16.9.0 to 16.10.0 (#894)
dependabot[bot] Nov 1, 2024
41849b1
fix: add route v1 compatibility type definitions (#895)
platosha Nov 4, 2024
ba77154
chore: rename `d.ts` files to `t.ts` to resolve `skipLibCheck` issue …
Lodin Nov 4, 2024
9a2f3f6
chore: use concurrently instead of abandoned npm-run-all (#899)
Lodin Nov 4, 2024
feaf164
docs: add lifecycle-callback page
Lodin Nov 4, 2024
5e76716
chore: update package-lock.json
platosha Nov 5, 2024
829ac9c
docs: apply global Lumo styles
platosha Nov 5, 2024
0b8d393
docs: add navigation trigger demo
Lodin Nov 5, 2024
f559a26
docs: remove theme decorator
Lodin Nov 5, 2024
44e66c1
docs: add theme toggle
Lodin Nov 5, 2024
0cec9a3
docs: improve readability
Lodin Nov 5, 2024
15aefd8
docs: improve styling & theme handling
Lodin Nov 5, 2024
614644e
docs: improve code highlighting
Lodin Nov 6, 2024
d19b697
docs: add snippet extending & improve code content
Lodin Nov 6, 2024
4cc484f
docs: fix eslint issue
Lodin Nov 6, 2024
7f37767
docs: finalize redirect demo
Lodin Nov 6, 2024
ca8b582
docs: convert more pages
Lodin Nov 8, 2024
abbbec0
docs: finalize demo pages
Lodin Nov 8, 2024
32bb323
docs: rearrange files
Lodin Nov 11, 2024
9e24724
docs: fix several issues
Lodin Nov 11, 2024
328b172
docs: improve several parts
Lodin Nov 11, 2024
909be20
docs: fix two lifecycle-callback demos
Lodin Nov 11, 2024
2c08bfb
docs: fix issues
Lodin Nov 12, 2024
83d877c
docs: improve code & text
Lodin Nov 13, 2024
67e6fc7
docs: remove all Polymer mentions
Lodin Nov 13, 2024
70a4435
docs: make build system work correctly
Lodin Nov 13, 2024
dc3d6a4
docs: remove old demo sources & replace with the new ones
Lodin Nov 13, 2024
390a61a
docs: update urls
Lodin Nov 13, 2024
be28e4a
fix: add route v1 compatibility type definitions (#895)
platosha Nov 4, 2024
b5920d6
chore: rename `d.ts` files to `t.ts` to resolve `skipLibCheck` issue …
Lodin Nov 4, 2024
04a7c88
fix: use es2021 as a target for TypeScript (#900)
Lodin Nov 7, 2024
ec4d16e
Merge branch 'main' into docs/update-demo
Lodin Nov 13, 2024
385c81b
chore: fix package.json
Lodin Nov 13, 2024
5f5f808
refactor: revert debugging change
Lodin Nov 13, 2024
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
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{java,xml}]
indent_size = 4

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"extends": [
"vaadin/typescript-requiring-type-checking",
"vaadin/imports-typescript",
"vaadin/lit",
"vaadin/prettier",
"vaadin/testing",
"plugin:oxlint/recommended"
"vaadin/testing"
],
"parserOptions": {
"project": "./tsconfig.json"
Expand Down
19 changes: 7 additions & 12 deletions demo/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
{
"rules": {
},
"globals": {
"ElementDemo": false,
"DemoReadyEventEmitter": false,
"Router": false
"extends": ["../.eslintrc.json"],
"root": true,
"parserOptions": {
"project": "./tsconfig.json"
},
"overrides": [{
"files": ["vaadin-router-code-splitting-demos.html"],
"parserOptions": {
"ecmaVersion": 2017
}
}]
"rules": {
"@typescript-eslint/unbound-method": "off"
}
}
12 changes: 12 additions & 0 deletions demo/@debug/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<title>Debug</title>
<script async type="module" src="./index.ts"></script>
</head>
<body>
<vaadin-demo-layout app-title="Debug">
<vaadin-demo-debug></vaadin-demo-debug>
</vaadin-demo-layout>
</body>
</html>
22 changes: 22 additions & 0 deletions demo/@debug/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable import/no-duplicates, import/default */
import '@helpers/common.js';
import '@helpers/vaadin-presentation.js';
import { html, LitElement, type TemplateResult } from 'lit';
import { customElement } from 'lit/decorators.js';

// An URL of the iframe to debug
// eslint-disable-next-line import/order
import url1 from '../url-generation/d4/iframe.html?url';

declare global {
interface HTMLElementTagNameMap {
'vaadin-demo-debug': DemoDebug;
}
}

@customElement('vaadin-demo-debug')
export default class DemoDebug extends LitElement {
override render(): TemplateResult {
return html`<vaadin-presentation src=${url1}></vaadin-presentation>`;
}
}
3 changes: 3 additions & 0 deletions demo/@helpers/common.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host {
display: block;
}
3 changes: 3 additions & 0 deletions demo/@helpers/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import '@vaadin/vaadin-lumo-styles/badge-global.js';
import '@vaadin/vaadin-lumo-styles/color-global.js';
import '@vaadin/vaadin-lumo-styles/typography-global.js';
33 changes: 33 additions & 0 deletions demo/@helpers/iframe.script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import './common.css';
import './common.js';

import { Router } from '@vaadin/router';

history.replaceState(null, '', '/');

type MessageData = Readonly<{ url: string }>;

type ParentData = {
source: MessageEventSource | null;
origin: string;
};

let parentData: ParentData | undefined;

function updateParentUrl() {
if (parentData?.source) {
parentData.source.postMessage({ url: location.href }, { targetOrigin: location.origin });
}
}

addEventListener('message', ({ data, origin, source }: MessageEvent<MessageData | null>) => {
if (data != null) {
Router.go(new URL(data.url, location.origin).href);
} else {
parentData = { source, origin };
}

updateParentUrl();
});

addEventListener('vaadin-router-location-changed', updateParentUrl);
15 changes: 15 additions & 0 deletions demo/@helpers/nested-styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
:host {
display: flex;
flex-direction: column;
background: #ddd;
padding: 5px;
min-height: 100vh;
}

main {
margin-top: 10px;
padding: 5px;
background: #fff;
flex: 1 0 auto;
min-height: 80px;
}
4 changes: 4 additions & 0 deletions demo/@helpers/page.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
code {
background: var(--code-background);
padding: 0.2em 0.4em;
}
6 changes: 6 additions & 0 deletions demo/@helpers/shared-styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.note {
background-color: #24c0ea;
padding: 1em;
color: white;
border-radius: 4px;
}
23 changes: 23 additions & 0 deletions demo/@helpers/theme-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { ReactiveController, ReactiveControllerHost } from 'lit';

export default class ThemeController implements ReactiveController {
readonly #host: ReactiveControllerHost;
#controller?: AbortController;

constructor(host: ReactiveControllerHost) {
(this.#host = host).addController(this);
}

get value(): string {
return document.documentElement.getAttribute('theme') ?? 'light';
}

hostConnected(): void {
this.#controller = new AbortController();
addEventListener('theme-changed', () => this.#host.requestUpdate(), { signal: this.#controller.signal });
}

hostDisconnected(): void {
this.#controller?.abort();
}
}
39 changes: 39 additions & 0 deletions demo/@helpers/vaadin-demo-code-snippet-file.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
header {
padding: 0.3rem 0.3rem;
font-size: 0.8rem;
display: flex;
justify-content: space-between;
align-items: center;
background: var(--code-file-background);
}

section {
display: flex;
flex-direction: column;
gap: 0.5rem;
}

.title {
font-family: monospace;
}

.buttons {
display: flex;
gap: 1rem;
}

/* ======= Highlight.js styles ======= */

:host([theme~='dark']) {
@nested-import 'highlight.js/styles/atom-one-dark.css';
}

:host([theme~='light']) {
@nested-import 'highlight.js/styles/vs.css';
}

pre {
margin: 0;
padding: 0.5rem 1rem;
background: var(--code-background);
}
69 changes: 69 additions & 0 deletions demo/@helpers/vaadin-demo-code-snippet-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* eslint-disable @typescript-eslint/unbound-method */
import '@vaadin/button/src/vaadin-button';
import '@vaadin/icon/src/vaadin-icon';
import { type TemplateResult, LitElement, html, nothing } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { map } from 'lit/directives/map.js';
import ThemeController from './theme-controller.js';
import css from './vaadin-demo-code-snippet-file.css?ctr';

export type CodeSnippet = Readonly<{
id?: string;
code: [original: string, full: TemplateResult, ...rest: TemplateResult[]];
title?: string;
}>;

@customElement('vaadin-demo-code-snippet-file')
export default class DemoCodeSnippetFile extends LitElement {
static override styles = [css];

@property({ attribute: false }) accessor file: CodeSnippet | undefined;

@state() accessor #expanded = false;

readonly #theme = new ThemeController(this);

override updated(): void {
this.setAttribute('theme', this.#theme.value);
}

override render(): TemplateResult | typeof nothing {
if (!this.file) {
return nothing;
}

const [_, full, ...snippets] = this.file.code;

return html`
<header>
<div class="title">${this.file.title}</div>
<div class="buttons">
<vaadin-icon icon="vaadin:expand" @click=${this.#toggleExpanded}></vaadin-icon>
<vaadin-icon icon="vaadin:copy" @click=${this.#copyToClipboard}></vaadin-icon>
</div>
</header>
<section>
${this.#expanded
? html`<pre><code>${full}</code></pre>`
: map(snippets, (snippet) => html`<pre><code>${snippet}</code></pre>`)}
</section>
`;
}

#toggleExpanded(): void {
this.#expanded = !this.#expanded;
}

async #copyToClipboard(): Promise<void> {
const [original] = this.file?.code ?? [];
if (original) {
await navigator.clipboard.writeText(original);
}
}
}

declare global {
interface HTMLElementTagNameMap {
'vaadin-demo-code-snippet-file': DemoCodeSnippetFile;
}
}
5 changes: 5 additions & 0 deletions demo/@helpers/vaadin-demo-code-snippet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:host {
display: block;
max-height: 20rem;
overflow-y: auto;
}
41 changes: 41 additions & 0 deletions demo/@helpers/vaadin-demo-code-snippet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-disable import/no-duplicates */
import { html, LitElement, type TemplateResult } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js';
import type { CodeSnippet } from './vaadin-demo-code-snippet-file.js';
import './vaadin-demo-code-snippet-file.js';
import css from './vaadin-demo-code-snippet.css?ctr';

declare global {
interface HTMLElementTagNameMap {
'vaadin-demo-code-snippet': DemoCodeSnippet;
}

interface WindowEventMap {
'theme-changed': Event;
}
}

export type { CodeSnippet };

function renderFile(file: CodeSnippet): TemplateResult {
return html`<vaadin-demo-code-snippet-file .file=${file}></vaadin-demo-code-snippet-file>`;
}

@customElement('vaadin-demo-code-snippet')
export default class DemoCodeSnippet extends LitElement {
static override styles = [css];

@property({ attribute: false }) accessor files: readonly CodeSnippet[] = [];

override render(): TemplateResult {
switch (this.files.length) {
case 0:
return html``;
case 1:
return renderFile(this.files[0]);
default:
return html` ${repeat(this.files, ({ id }) => id, renderFile)} `;
}
}
}
34 changes: 34 additions & 0 deletions demo/@helpers/vaadin-demo-layout.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
:host {
--code-background-light: hsl(35, 83%, 91%);
--code-file-background-light: hsl(35, 83%, 85%);
--code-background-dark: hsl(0, 0%, 17%);
--code-file-background-dark: hsl(0, 0%, 23%);
}

:host([theme~='dark']) {
--code-background: var(--code-background-dark);
--code-file-background: var(--code-file-background-dark);
}

:host([theme~='light']) {
--code-background: var(--code-background-light);
--code-file-background: var(--code-file-background-light);
}

@media (max-width: 767px) {
main {
padding: 0;
}
}

main {
padding: 0 20%;
}

.navbar {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
padding: 0 1rem;
}
Loading
Loading