-
Notifications
You must be signed in to change notification settings - Fork 0
Demo enhancements #37
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5d16569
Initial restyling
831ad64
Discover, register elements automatically
6b35759
ES2021 fix
f7320c4
Removed hard-coded element names from CSS
3476834
Placeholder suppression cleanup
e974ffa
sidebar styling adjustments
4336646
Added transition for collapsing details
118b015
Shrink h1 h2
b1dddc3
Add copy button to styling section
e493e09
Cap syntax-highlighter height + scrolling
64648eb
Copy to clipboard fixes
89b54d0
Switch to IntersectionObserver
24ab7d4
Cleanup for setTimeout
3ba002f
tests
f51818a
CR suggestion fixes
b6355b2
Updated tests with 'expanded' class
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,26 +1,104 @@ | ||
| import { html, LitElement } from 'lit'; | ||
| import { customElement } from 'lit/decorators.js'; | ||
| // unsafeHTML is needed to render dynamic custom-element tag names; | ||
| // Lit's html`` tag cannot render variable tag names directly. | ||
| import { unsafeHTML } from 'lit/directives/unsafe-html.js'; | ||
|
|
||
| import '@src/elements/ia-button/ia-button-story'; | ||
| import '@src/labs/ia-snow/ia-snow-story'; | ||
| import '@src/elements/ia-combo-box/ia-combo-box-story'; | ||
| import '@src/elements/ia-status-indicator/ia-status-indicator-story'; | ||
| const storyModules = import.meta.glob( | ||
| ['../src/elements/**/*-story.ts', '../src/labs/**/*-story.ts'], | ||
| { eager: true } | ||
| ); | ||
|
|
||
| const storyEntries = Object.keys(storyModules) | ||
| .map(path => { | ||
| const labs = path.includes('/src/labs/'); | ||
| const parts = path.split('/'); | ||
| const filename = parts[parts.length - 1]; // e.g. "ia-button-story.ts" | ||
| const tag = filename.replace(/-story\.ts$/, ''); | ||
| return { tag, storyTag: `${tag}-story`, id: `elem-${tag}`, labs }; | ||
| }) | ||
| .sort((a, b) => a.tag.localeCompare(b.tag)); | ||
|
|
||
| const productionEntries = storyEntries.filter(e => !e.labs); | ||
| const labsEntries = storyEntries.filter(e => e.labs); | ||
| const ALL_ENTRIES = [...productionEntries, ...labsEntries]; | ||
|
|
||
| @customElement('app-root') | ||
| export class AppRoot extends LitElement { | ||
| createRenderRoot() { return this; } | ||
|
|
||
| private _observer?: IntersectionObserver; | ||
| private _abortController = new AbortController(); | ||
|
|
||
| render() { | ||
| return html` | ||
| <h1>🏛️ Internet Archive Elements ⚛️</h1> | ||
| <nav id="ia-sidebar"> | ||
| <h2>Production-Ready</h2> | ||
| ${productionEntries.map(e => html`<a href="#${e.id}"><${e.tag}></a>`)} | ||
| <h2>Labs 🧪</h2> | ||
| ${labsEntries.map(e => html`<a href="#${e.id}"><${e.tag}></a>`)} | ||
| </nav> | ||
| <div id="ia-content"> | ||
| <h1>Internet Archive Elements</h1> | ||
| <h2>Production-Ready Elements</h2> | ||
| ${productionEntries.map(e => html` | ||
| <div id="${e.id}" class="ia-anchor"> | ||
| ${unsafeHTML(`<${e.storyTag}></${e.storyTag}>`)} | ||
| </div> | ||
| `)} | ||
| <h2>Labs Elements</h2> | ||
| ${labsEntries.map(e => html` | ||
| <div id="${e.id}" class="ia-anchor"> | ||
| ${unsafeHTML(`<${e.storyTag}></${e.storyTag}>`)} | ||
| </div> | ||
| `)} | ||
| </div> | ||
| `; | ||
| } | ||
|
|
||
| <h2>🚀 Production-Ready Elements</h2> | ||
| firstUpdated() { | ||
| const allIds = ALL_ENTRIES.map(e => e.id); | ||
|
|
||
| <ia-status-indicator-story></ia-status-indicator-story> | ||
| <ia-combo-box-story></ia-combo-box-story> | ||
| const links = Object.fromEntries( | ||
| allIds.map(id => [id, this.querySelector(`#ia-sidebar a[href="#${id}"]`)]) | ||
| ); | ||
|
|
||
| <h2>🧪 Labs Elements</h2> | ||
| const visible = new Set<string>(); | ||
|
|
||
| <ia-snow-story></ia-snow-story> | ||
| <ia-button-story></ia-button-story> | ||
| `; | ||
| // Only anchors in the top 30% of the viewport count as "active". | ||
| // The first (topmost) visible anchor wins. | ||
| this._observer = new IntersectionObserver( | ||
| entries => { | ||
| for (const entry of entries) { | ||
| if (entry.isIntersecting) visible.add(entry.target.id); | ||
| else visible.delete(entry.target.id); | ||
| } | ||
| const activeId = allIds.find(id => visible.has(id)) ?? allIds[0]; | ||
| allIds.forEach(id => links[id]?.classList.toggle('active', id === activeId)); | ||
pezvi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| { rootMargin: '0px 0px -70% 0px' }, | ||
| ); | ||
|
|
||
| allIds.forEach(id => { | ||
| const el = document.getElementById(id); | ||
| if (el) this._observer!.observe(el); | ||
| }); | ||
|
|
||
| allIds.forEach(id => { | ||
| links[id]?.addEventListener('click', (e: Event) => { | ||
| e.preventDefault(); | ||
| const el = document.getElementById(id); | ||
| if (el) { | ||
| const top = el.getBoundingClientRect().top + window.scrollY; | ||
| window.scrollTo({ top: Math.max(0, top - 16), behavior: 'smooth' }); | ||
| } | ||
| }, { signal: this._abortController.signal }); | ||
| }); | ||
| } | ||
|
|
||
| disconnectedCallback() { | ||
| super.disconnectedCallback(); | ||
| this._observer?.disconnect(); | ||
| this._abortController.abort(); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.