Skip to content

Commit 485ad1d

Browse files
committed
init
0 parents  commit 485ad1d

19 files changed

+10288
-0
lines changed

.babelrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
["@babel/preset-env", {
4+
"modules": false
5+
}]
6+
],
7+
"plugins": [
8+
"transform-vue-jsx"
9+
]
10+
}

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

.storybook/config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { configure } from '@storybook/vue'
2+
3+
function loadStories() {
4+
// You can require as many stories as you need.
5+
require('../stories')
6+
}
7+
8+
configure(loadStories, module)

.storybook/poi.config.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// poi.config.js
2+
module.exports = {
3+
// Use your storybook config as entry
4+
entry: '.storybook/config.js',
5+
outDir: '.storybook/dist',
6+
// If you want storybook addons:
7+
// entry: ['.storybook/config.js', '.storybook/addons.js']
8+
plugins: [
9+
require('@poi/plugin-storybook')()
10+
]
11+
}

README.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# vue-content-loader
2+
3+
[![NPM version](https://img.shields.io/npm/v/vue-content-loader.svg?style=flat)](https://npmjs.com/package/vue-content-loader) [![NPM downloads](https://img.shields.io/npm/dm/vue-content-loader.svg?style=flat)](https://npmjs.com/package/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+
5+
SVG component to create placeholder loading, like Facebook cards loading.
6+
7+
## Install
8+
9+
```bash
10+
yarn add @rem/vue-content-loader
11+
```
12+
13+
__NOTE: You're installing `@rem/vue-content-loader` instead of `vue-content-loader`.__
14+
15+
CDN: [UNPKG](https://unpkg.com/@rem/vue-content-loader/) | [jsDelivr](https://cdn.jsdelivr.net/npm/@rem/vue-content-loader/) (available as `window.contentLoaders`)
16+
17+
## Usage
18+
19+
```vue
20+
<template>
21+
<content-loader></content-loader>
22+
</template>
23+
24+
<script>
25+
import { ContentLoader } from '@rem/vue-content-loader'
26+
27+
export default {
28+
components: {
29+
ContentLoader
30+
}
31+
}
32+
</script>
33+
```
34+
35+
🔥 [Check out the __storybook__ to see how it rocks!](https://vue-content-loader.egoist.moe)
36+
37+
### Built-in loaders
38+
39+
```js
40+
import {
41+
ContentLoader,
42+
FacebookLoader,
43+
CodeLoader,
44+
BulletListLoader,
45+
InstagramLoader,
46+
ListLoader
47+
} from '@rem/vue-content-loader'
48+
```
49+
50+
`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:
51+
52+
```vue
53+
<ContentLoader>
54+
<rect x="0" y="0" rx="3" ry="3" width="250" height="10" />
55+
<rect x="20" y="20" rx="3" ry="3" width="220" height="10" />
56+
<rect x="20" y="40" rx="3" ry="3" width="170" height="10" />
57+
<rect x="0" y="60" rx="3" ry="3" width="250" height="10" />
58+
<rect x="20" y="80" rx="3" ry="3" width="200" height="10" />
59+
<rect x="20" y="100" rx="3" ry="3" width="80" height="10" />
60+
</ContentLoader>
61+
```
62+
63+
This is also how [ListLoader](./src/ListLoader.js) is created.
64+
65+
## API
66+
67+
### Props
68+
69+
70+
|Prop|Type|Default|Description|
71+
|---|---|---|---|
72+
|width|number|`400`||
73+
|height|number|`130`||
74+
|speed|number|`2`||
75+
|preserveAspectRatio|string|`'xMidYMid meet'`||
76+
|primaryColor|string|`'#f9f9f9'`||
77+
|secondaryColor|string|`'#ecebeb'`||
78+
|uniquekey|string|`randomId()`|Unique ID, you need to change it for SSR|
79+
|animate|boolean|`true`||
80+
81+
82+
## License
83+
84+
MIT &copy; [EGOIST](https://github.com/egoist)

circle.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: 2
2+
jobs:
3+
build:
4+
working_directory: ~/repo
5+
docker:
6+
- image: circleci/node:latest
7+
branches:
8+
ignore:
9+
- gh-pages # list of branches to ignore
10+
- /release\/.*/ # or ignore regexes
11+
steps:
12+
- checkout
13+
- restore_cache:
14+
key: dependency-cache-{{ checksum "yarn.lock" }}
15+
- run:
16+
name: install dependences
17+
command: yarn install
18+
- save_cache:
19+
key: dependency-cache-{{ checksum "yarn.lock" }}
20+
paths:
21+
- ./node_modules
22+
- run:
23+
name: test
24+
command: yarn run test:cov

package.json

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "@rem/vue-content-loader",
3+
"version": "0.0.0",
4+
"description": "SVG component to create placeholder loading, like Facebook cards loading.",
5+
"repository": {
6+
"url": "egoist/vue-content-loader",
7+
"type": "git"
8+
},
9+
"publishConfig": {
10+
"access": "public"
11+
},
12+
"main": "dist/vue-content-loader.cjs.js",
13+
"files": [
14+
"dist"
15+
],
16+
"sideEffects": false,
17+
"scripts": {
18+
"prepublishOnly": "npm run build",
19+
"test": "tyu",
20+
"build": "bili --format cjs,es,umd,umd-min --module-name contentLoaders",
21+
"storybook": "poi --config .storybook/poi.config.js",
22+
"build:storybook": "poi build --config .storybook/poi.config.js"
23+
},
24+
"author": {
25+
"name": "EGOIST",
26+
"email": "0x142857@gmail.com"
27+
},
28+
"license": "MIT",
29+
"poi": {
30+
"entry": "example/index.js",
31+
"dist": "example/dist",
32+
"homepage": "./"
33+
},
34+
"bili": {
35+
"format": [
36+
"cjs",
37+
"umd"
38+
],
39+
"name": "vue-content-loader"
40+
},
41+
"devDependencies": {
42+
"@poi/plugin-storybook": "^10.0.0-beta.2",
43+
"@storybook/vue": "^3.3.15",
44+
"babel-plugin-transform-vue-jsx": "^4",
45+
"bili": "^3.0.12",
46+
"mini-css-extract-plugin": "^0.2.0",
47+
"poi": "^10.0.0-beta.6",
48+
"tyu": "^1.0.0",
49+
"vue-test-utils": "^1.0.0-beta.9",
50+
"webpack": "^4.2.0"
51+
},
52+
"dependencies": {
53+
"babel-helper-vue-jsx-merge-props": "^2.0.3"
54+
}
55+
}

src/BulletListLoader.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import ContentLoader from './ContentLoader'
2+
3+
export default {
4+
name: 'BulletListLoader',
5+
functional: true,
6+
props: ContentLoader.props,
7+
render(h, { data }) {
8+
return (
9+
<ContentLoader {...data}>
10+
<circle cx="10" cy="20" r="8" />
11+
<rect x="25" y="15" rx="5" ry="5" width="220" height="10" />
12+
<circle cx="10" cy="50" r="8" />
13+
<rect x="25" y="45" rx="5" ry="5" width="220" height="10" />
14+
<circle cx="10" cy="80" r="8" />
15+
<rect x="25" y="75" rx="5" ry="5" width="220" height="10" />
16+
<circle cx="10" cy="110" r="8" />
17+
<rect x="25" y="105" rx="5" ry="5" width="220" height="10" />
18+
</ContentLoader>
19+
)
20+
}
21+
}

src/CodeLoader.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import ContentLoader from './ContentLoader'
2+
3+
export default {
4+
name: 'CodeLoader',
5+
functional: true,
6+
props: ContentLoader.props,
7+
render(h, { data }) {
8+
return (
9+
<ContentLoader {...data}>
10+
<rect x="0" y="0" rx="3" ry="3" width="70" height="10" />
11+
<rect x="80" y="0" rx="3" ry="3" width="100" height="10" />
12+
<rect x="190" y="0" rx="3" ry="3" width="10" height="10" />
13+
14+
<rect x="15" y="20" rx="3" ry="3" width="130" height="10" />
15+
<rect x="155" y="20" rx="3" ry="3" width="130" height="10" />
16+
17+
<rect x="15" y="40" rx="3" ry="3" width="90" height="10" />
18+
<rect x="115" y="40" rx="3" ry="3" width="60" height="10" />
19+
<rect x="185" y="40" rx="3" ry="3" width="60" height="10" />
20+
21+
<rect x="0" y="60" rx="3" ry="3" width="30" height="10" />
22+
</ContentLoader>
23+
)
24+
}
25+
}

src/ContentLoader.js

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import uid from './uid'
2+
3+
export default {
4+
name: 'ContentLoader',
5+
6+
functional: true,
7+
8+
props: {
9+
width: {
10+
type: Number,
11+
default: 400
12+
},
13+
height: {
14+
type: Number,
15+
default: 130
16+
},
17+
speed: {
18+
type: Number,
19+
default: 2
20+
},
21+
preserveAspectRatio: {
22+
type: String,
23+
default: 'xMidYMid meet'
24+
},
25+
primaryColor: {
26+
type: String,
27+
default: '#f9f9f9'
28+
},
29+
secondaryColor: {
30+
type: String,
31+
default: '#ecebeb'
32+
},
33+
uniquekey: {
34+
type: String
35+
},
36+
animate: {
37+
type: Boolean,
38+
default: true
39+
}
40+
},
41+
42+
render(h, { props, data, children }) {
43+
const idClip = props.uniquekey ? `${props.uniquekey}-idClip` : uid()
44+
const idGradient = props.uniquekey ? `${props.uniquekey}-idGradient` : uid()
45+
46+
return (
47+
<svg
48+
{...data}
49+
viewBox={`0 0 ${props.width} ${props.height}`}
50+
version="1.1"
51+
preserveAspectRatio={props.preserveAspectRatio}
52+
>
53+
<rect
54+
style={{ fill: `url(#${idGradient})` }}
55+
clip-path={`url(#${idClip})`}
56+
x="0"
57+
y="0"
58+
width={props.width}
59+
height={props.height}
60+
/>
61+
62+
<defs>
63+
<clipPath id={idClip}>
64+
{children || (
65+
<rect
66+
x="0"
67+
y="0"
68+
rx="5"
69+
ry="5"
70+
width={props.width}
71+
height={props.height}
72+
/>
73+
)}
74+
</clipPath>
75+
76+
<linearGradient id={idGradient}>
77+
<stop offset="0%" stop-color={props.primaryColor}>
78+
{props.animate ? (
79+
<animate
80+
attributeName="offset"
81+
values="-2; 1"
82+
dur={`${props.speed}s`}
83+
repeatCount="indefinite"
84+
/>
85+
) : null}
86+
</stop>
87+
<stop offset="50%" stop-color={props.secondaryColor}>
88+
{props.animate ? (
89+
<animate
90+
attributeName="offset"
91+
values="-1.5; 1.5"
92+
dur={`${props.speed}s`}
93+
repeatCount="indefinite"
94+
/>
95+
) : null}
96+
</stop>
97+
<stop offset="100%" stop-color={props.primaryColor}>
98+
{props.animate ? (
99+
<animate
100+
attributeName="offset"
101+
values="-1; 2"
102+
dur={`${props.speed}s`}
103+
repeatCount="indefinite"
104+
/>
105+
) : null}
106+
</stop>
107+
</linearGradient>
108+
</defs>
109+
</svg>
110+
)
111+
}
112+
}

src/FacebookLoader.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import ContentLoader from './ContentLoader'
2+
3+
export default {
4+
name: 'FacebookLoader',
5+
functional: true,
6+
render(h, { data }) {
7+
return (
8+
<ContentLoader {...data}>
9+
<rect x="70" y="15" rx="4" ry="4" width="117" height="6.4" />
10+
<rect x="70" y="35" rx="3" ry="3" width="85" height="6.4" />
11+
<rect x="0" y="80" rx="3" ry="3" width="350" height="6.4" />
12+
<rect x="0" y="100" rx="3" ry="3" width="380" height="6.4" />
13+
<rect x="0" y="120" rx="3" ry="3" width="201" height="6.4" />
14+
<circle cx="30" cy="30" r="30" />
15+
</ContentLoader>
16+
)
17+
}
18+
}

0 commit comments

Comments
 (0)