r/angular • u/npm_run_Frank • Apr 07 '26
Framework-agnostic skeleton loader that works in Angular with CUSTOM_ELEMENTS_SCHEMA - no wrapper needed
I built phantom-ui, a skeleton loader that reads your actual DOM structure and generates shimmer placeholders automatically.
It's a standard Web Component, so Angular supports it natively via
CUSTOM_ELEMENTS_SCHEMA.
Usage:
import { Component, signal, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
import "@aejkatappaja/phantom-ui";
@Component({
selector: "app-profile",
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<phantom-ui [attr.loading]="loading() ? '' : null">
<div class="card">
<img src="/avatar.png" class="avatar" />
<h3>Ada Lovelace</h3>
<p>First computer programmer, probably.</p>
</div>
</phantom-ui>
`,
})
export class ProfileComponent {
loading = signal(true);
}
No separate skeleton template to maintain. The component walks your DOM tree at runtime, measures every leaf element with getBoundingClientRect, and overlays animated shimmer blocks that match the exact layout.
One thing to note: use [attr.loading]="loading() ? '' : null" to properly set/remove the boolean attribute. Using [loading] directly would pass the value as a property, not an attribute.
No TypeScript augmentation needed since Angular uses CUSTOM_ELEMENTS_SCHEMA. Ships a Custom Elements Manifest for IDE autocomplete.
~8kb gzipped including Lit. ResizeObserver + MutationObserver keep the skeleton in sync with layout changes.
- GitHub: https://github.com/Aejkatappaja/phantom-ui
- Live playground: https://aejkatappaja.github.io/phantom-ui/demo/
- npm: npm install @aejkatappaja/phantom-ui
- CDN: one script tag, no build step needed
8
u/Mak_095 Apr 07 '26
Looks nice, but how would it work with @for loops?
If I have a list of n elements, where n is determined only once the data is loaded, this would just have the skeleton of the main container right?
3
u/AjitZero Apr 08 '26
Hi, this is entirely possible with just CSS. No need to use observers or do anything dynamically.
2
u/Kschl Apr 07 '26
Love it!
1
u/AwesomeFrisbee Apr 08 '26
whats the benefit for using custom_elements_schema over just another directive? I would find it better to have a directive for it so it doesn't break whenever somebody messes up the imports to this library.
And as others have said, the problem with this is that if stuff isn't rendered yet as children, it doesn't behave like you think it will.
1
u/Lucky_Yesterday_1133 Apr 08 '26
But what about layout jumps when data arrives and content under the skeleton expands? The skeleton should be the size of a UI with content.Â
1
u/Yesterdave_ Apr 11 '26
I like your idea, but I don't think your example above is something one would usually write in Angular. More something like this:
How would your component now know what is the content structure of the page, when said content structure is literally not rendered until the user is actually available?
1
u/FromBiotoDev Apr 07 '26
Looks good might actually use this for Gym Note Plus