UNPKG

3.52 kBMarkdownView Raw
1# vue-content-loader
2
3[![NPM version](https://img.shields.io/npm/v/@rem/vue-content-loader.svg?style=flat)](https://npmjs.com/package/@rem/vue-content-loader) [![NPM downloads](https://img.shields.io/npm/dm/@rem/vue-content-loader.svg?style=flat)](https://npmjs.com/package/@rem/vue-content-loader) [![CircleCI](https://circleci.com/gh/egoist/vue-content-loader/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/vue-content-loader/tree/master)
4
5SVG component to create placeholder loading, like Facebook cards loading.
6
7![preview](https://user-images.githubusercontent.com/4838076/34308760-ec55df82-e735-11e7-843b-2e311fa7b7d0.gif)
8
9## Features
10
11This is a Vue port for [react-content-loader](https://github.com/danilowoz/react-content-loader).
12
13- Completely customizable: you can change the colors, speed and sizes.
14- Create your own loading: use the [online tool](https://danilowoz.github.io/create-react-content-loader/) to create your custom loader easily.
15- You can use it right now: there are a lot of presets already.
16- Performance:
17 - Tree-shakable and highly optimized bundle.
18 - Pure SVG, so it's works without any javascript, canvas, etc.
19 - Pure functional components.
20
21## Install
22
23```bash
24yarn add @rem/vue-content-loader
25```
26
27__NOTE: You're installing `@rem/vue-content-loader` instead of `vue-content-loader`.__
28
29CDN: [UNPKG](https://unpkg.com/@rem/vue-content-loader/) | [jsDelivr](https://cdn.jsdelivr.net/npm/@rem/vue-content-loader/) (available as `window.contentLoaders`)
30
31## Usage
32
33```vue
34<template>
35 <content-loader></content-loader>
36</template>
37
38<script>
39import { ContentLoader } from '@rem/vue-content-loader'
40
41export default {
42 components: {
43 ContentLoader
44 }
45}
46</script>
47```
48
49🔥 [Check out the __storybook__ to see how it rocks!](https://vue-content-loader.egoist.moe)
50
51### Built-in loaders
52
53```js
54import {
55 ContentLoader,
56 FacebookLoader,
57 CodeLoader,
58 BulletListLoader,
59 InstagramLoader,
60 ListLoader
61} from '@rem/vue-content-loader'
62```
63
64`ContentLoader` is a meta loader while other loaders are just higher-order components of it. By default `ContentLoader` only displays a simple rectangle, here's how you can use it to create custom loaders:
65
66```vue
67<ContentLoader>
68 <rect x="0" y="0" rx="3" ry="3" width="250" height="10" />
69 <rect x="20" y="20" rx="3" ry="3" width="220" height="10" />
70 <rect x="20" y="40" rx="3" ry="3" width="170" height="10" />
71 <rect x="0" y="60" rx="3" ry="3" width="250" height="10" />
72 <rect x="20" y="80" rx="3" ry="3" width="200" height="10" />
73 <rect x="20" y="100" rx="3" ry="3" width="80" height="10" />
74</ContentLoader>
75```
76
77This is also how [ListLoader](./src/ListLoader.js) is created.
78
79You can also use the [online tool](http://danilowoz.com/create-react-content-loader/) to create shapes for your custom loader, it's made for [react-content-loader](https://github.com/danilowoz/react-content-loader) but the JSX it generates can be used in Vue templates or Vue JSX as well.
80
81## API
82
83### Props
84
85
86|Prop|Type|Default|Description|
87|---|---|---|---|
88|width|number|`400`||
89|height|number|`130`||
90|speed|number|`2`||
91|preserveAspectRatio|string|`'xMidYMid meet'`||
92|primaryColor|string|`'#f9f9f9'`||
93|secondaryColor|string|`'#ecebeb'`||
94|uniquekey|string|`randomId()`|Unique ID, you need to make it consistent for SSR|
95|animate|boolean|`true`||
96
97## Credits
98
99This is basically a Vue port for [react-content-loader](https://github.com/danilowoz/react-content-loader).
100
101## License
102
103MIT &copy; [EGOIST](https://github.com/egoist)