Skeleton

Display a placeholder preview of your content before the data gets loaded to reduce load-time frustration.

<nb-skeleton variant="circle"></nb-skeleton>
<nb-skeleton variant="rect"></nb-skeleton>                                
<nb-skeleton count="2"></nb-skeleton>
                                
david@ubuntu:~
Buil with stencil.js
Docs created, using:
Spectre.css Codepen.io
To make a contribution to the world by making tools for the mind that advance humankind.

Install

You can get it on NPM installing skeleton-webcomponent-loader as a project dependency or via UNPKG

npm i skeleton-webcomponent-loader

You can choose one of the following options to add skeleton loader's script to the page:

  • ESM import (Webpack/Browsers which support ES modules/Angular/React) (seems like the simpliest way)
    import {defineCustomElements as initSkeleton} from  './node_modules/skeleton-webcomponent-loader/loader/index.js';
    initSkeleton();
  • Script tag via UNPKG (global npm delivery network) (could be used anywhere - any framework, without framework)
    <script  type="module"  src="https://unpkg.com/skeleton-webcomponent-loader@2.0.0/dist/skeleton-webcomponent/skeleton-webcomponent.esm.js"></script>
    <script  type="nomodule"  src="https://unpkg.com/skeleton-webcomponent-loader@/dist/skeleton-webcomponent/skeleton-webcomponent.js"></script>
  • Script tag via npm (could be used anywhere - any framework, without framework)
    <script type="module"  src="./node_modules/skeleton-webcomponent-loader/dist/skeleton-webcomponent/skeleton-webcomponent.esm.js"></script>
    <script  type="nomodule"  src="./node_modules/skeleton-webcomponent-loader/dist/skeleton-webcomponent/skeleton-webcomponent.js"></script>
  • Angular In app.module.ts or any module which uses skeleton in order to provide ability to use webcomponents:
    
    @NgModule({
        //whatever you have on app module goes here... 
        schemas: [CUSTOM_ELEMENTS_SCHEMA]
    })
    export class AppModule {}
    

    And in main.ts: or you can add it via stript tags in index.html as described before

    
            import {defineCustomElements as initSkeleton} from  './node_modules/skeleton-webcomponent-loader/loader/index.js';
    initSkeleton();
        

Variants

Property appearance supports 2 kinds of shapes: default and circle.

See the Pen skeleton loader webcomponent variants by Nickolay Babchenko (@mikehummer) on CodePen.

Animations

Property animation supports: progress, pulse and progress-dark animations. Animation could be disabled if needed.

See the Pen Skeleton Webcomponents Animations by Nickolay Babchenko (@mikehummer) on CodePen.

Customization

Skeleton webcomponent could be customized in different ways:
  • CSS custom properties:
    --skeleton-height: Skeleton height: Default: 20px for the row, 40px for the circle
    
    --skeleton-width: Skeleton width: Default: 100% for the row, 40px for the circle
    
    --skeleton-margin-bottom: Skeleton margin-bottom: Default: 10px for the row, 5px for the circle
    
    --skeleton-border-radius: Skeleton border-radius: Default: 4px for the row, 50% for the circle
    
    --skeleton-background: Skeleton background: Default: #eff1f6
  • Via 'custom-styles' property (could be bind using js or html):

    From html (without framework):

    <nb-skeleton custom-styles='{"box-shadow":"0 2px 4px #ccc"}'></nb-skeleton></code>

    From js:

    el.customStyles='{"box-shadow":"0 2px 4px #ccc"}';

See the Pen Skeleton Webcomponent Customization by Nickolay Babchenko (@mikehummer) on CodePen.

Framework usage examples

  • Angular
  • React

    There is a small drawback when passing custom-styles property. The object needs to be stringified or should be passed through ref.

    More about this Stencil.js docs - react integration