2.4.1 • Published 11 months ago

svelte5-skeleton v2.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

svelte5-skeleton

NPM version NPM downloads Svelte v5

Simple implementation of SVG skeletons in Svelte 5 with types

example

Forked from denisstasyev/svelte-skeleton.

:rocket: Features

This is Svelte's component to create custom SVG skeletons to improve level of UX of loading images and interface.

  • Easy to use (Svelte component allow to use any SVG forms, such as <rect /> and <circle />)
  • Fully customizable: you can adjust the colors, sizes and speed :t-rex:
  • Works fine with SSR
  • Light size :fire:
  • Pure SVG: any custom SVG shapes can be used
  • All backgrounds within one Svelte component will be synchronized
  • Supports types
  • Respects Users' Motion Preferences

P.S. It's recommended to use this package only for middle or large images. If you want to achieve the best UX for icons, use this package with animate = false.

Install

npm i svelte5-skeleton -D

Usage

<script>
  import Skeleton from 'svelte5-skeleton/Skeleton.svelte'

  ...
</script>

<Skeleton height="360" width="360">
  <rect width="96" height="72" x="0" y="0" rx="12" ry="12" />
  <rect width="260" height="10" x="108" y="19" rx="5" ry="5" />
  <rect width="150" height="10" x="108" y="43" rx="5" ry="5" />

  <rect width="96" height="72" x="0" y="96" rx="12" ry="12" />
  <rect width="260" height="10" x="108" y="115" rx="5" ry="5" />
  <rect width="150" height="10" x="108" y="139" rx="5" ry="5" />

  <!-- Any custom SVG shapes -->
</Skeleton>

Also you can combine it with Svelte's {#await ...}:

{#await promise}
<!-- promise is pending -->
<Skeleton height="360" width="360">
  <rect width="96" height="72" x="0" y="0" rx="12" ry="12" />
  <rect width="260" height="10" x="108" y="19" rx="5" ry="5" />
  <rect width="150" height="10" x="108" y="43" rx="5" ry="5" />
</Skeleton>
{:then value}
<!-- promise was fulfilled -->
<YourCoolComponent {value} />
{:catch error}
<!-- promise was rejected -->
<Error title="{error.message}" />
{/await}

API

Parameters

NameTypeDefaultDescription
primaryColorstring'#ebecef'Main background color
secondaryColorstring'#f5f5f7'Animation line color
heightnumber200
widthnumber, string400
speednumber, string2
animatebooleantrue
secondaryColorPercentWidthnumber100Initial secondaryColor-part offset
ariaLabelstringnullAria Label

Please note that some older browsers (like Internet Explorer 11) do not support SVG animations. They will only show the background color without the animation line. To create skeletons for these browsers, you need to write your own CSS animations.

License

This library is available under the MIT license.

2.4.1

11 months ago

2.4.0

11 months ago

2.3.0

11 months ago

2.2.0

11 months ago

2.1.0

11 months ago

2.0.0

11 months ago