Skip to content

Commit 9d3d6a3

Browse files
authored
Refactor Wrap and Custom components (#1)
* Refactor Wrap * Add custom elements * Code style * Update documentation * Update version
1 parent ddb3e2b commit 9d3d6a3

File tree

12 files changed

+212
-170
lines changed

12 files changed

+212
-170
lines changed

README.md

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,66 @@
22

33
This project is a collection the loader based on styles cards on Facebook.
44

5-
## Usage:
5+
## You can use it in two ways:
66

7-
First install the dependency:
7+
**First install the dependency:**
88
```sh
99
npm i react-content-loader --save-dev
1010
```
1111

12-
After import and use:
12+
**Stylized:** [example](#facebook-style)
1313
```js
1414
// import the component
1515
import ContentLoader from 'react-content-loader'
1616

17-
const MyPage = () => (<ContentLoader />);
17+
const MyLoader = () => {
18+
return(
19+
<ContentLoader type="facebook" />
20+
)
21+
}
1822
```
1923

20-
### Options
24+
**Our in custom mode:** [example](#custom-style)
25+
```js
26+
// import the component
27+
import ContentLoader, { Rect, Circle }
28+
29+
const MyLoader = () => {
30+
return(
31+
<ContentLoader height={140} speed={1} primaryColor={'#333'} secondaryColor={'#999'}>
32+
<Circle x={195} y={30} radius={30} />
33+
<Rect x={50} y={80} height={10} radius={5} width={300} />
34+
<Rect x={75} y={100} height={10} radius={5} width={250} />
35+
</ContentLoader>
36+
)
37+
}
38+
```
39+
40+
41+
## Options
42+
43+
**ContentLoader (wrap) options:**
2144

2245
| Name | Type | Default | Description |
2346
|---|---|---|---|
24-
| style | _Object_ | | |
47+
| style | _Object_ | `null` | Ex: `{ marginTop: '50px' }` |
2548
| type | _String_ | `facebook` | Options: `facebook`, `instagram`, `code` |
2649
| speed | _Number_ | `2` | Animation speed |
50+
| height | _Number_ | `130` | Height component |
2751
| primaryColor | _String_ | `#f3f3f3` | Background the SVG |
2852
| secondaryColor | _String_ | `#ecebeb` | Animation color |
2953

54+
55+
**Custom element options:**
56+
57+
| | x | y | radius | width | height |
58+
|---|---|---|---|---|---|
59+
| **Rect** | × | × | × | × | × |
60+
| **Circle** | × | × | × |||
61+
62+
63+
## Examples
64+
3065
#### Facebook Style
3166
![Facebook Style](https://cloud.githubusercontent.com/assets/4838076/22555575/3a90ecee-e94b-11e6-97df-8054e7297bd8.gif)
3267

@@ -36,11 +71,14 @@ const MyPage = () => (<ContentLoader />);
3671
#### Code Style
3772
![Code Style](https://cloud.githubusercontent.com/assets/4838076/22555473/effa54c2-e94a-11e6-9128-9b608bcc69d9.gif)
3873

74+
#### Custom Style
75+
![Code Style](https://cloud.githubusercontent.com/assets/4838076/22760218/aa619f32-ee3c-11e6-9cd1-c4af9dd1278e.gif)
76+
3977
### Todo
4078
- [x] Code component;
79+
- [x] Custom elements;
4180
- [ ] List component;
4281
- [ ] Test in multiples browser;
43-
- [ ] A more useful new project;
4482

4583
#### Credits
4684

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-content-loader",
3-
"version": "1.1.0",
4-
"description": "This project is a collection the loader based on styles cards on Facebook.",
3+
"version": "1.2.0",
4+
"description": "This project is a collection the loader based on styles cards on Facebook, make with SVG and React.",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/danilowoz/react-content-loader"

src/CodeStyle.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/FacebookStyle.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/InstagramStyle.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/Wrap.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from 'react'
2+
3+
const Wrap = (props) => {
4+
5+
const generateId = () => {
6+
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
7+
let text = ""
8+
9+
for( let i = 0; i < 10; i++ )
10+
text += possible.charAt(Math.floor(Math.random() * possible.length))
11+
12+
return text
13+
}
14+
15+
let idClip = generateId()
16+
let idGradient = generateId()
17+
18+
return(
19+
<svg viewBox={`0 0 400 ${props.height}`} version="1.1" style={props.style} preserveAspectRatio="xMidYMid meet">
20+
<rect style={{fill: `url(#${idGradient})`}} clipPath={`url(#${idClip})`} x="0" y="0" width="400" height={props.height} />
21+
22+
<defs>
23+
<clipPath id={`${idClip}`}>
24+
{ props.children }
25+
</clipPath>
26+
27+
<linearGradient id={`${idGradient}`}>
28+
<stop offset="0%" stopColor={props.primaryColor}>
29+
<animate attributeName="offset" values="-2; 1" dur={`${props.speed}s`} repeatCount="indefinite" />
30+
</stop>
31+
<stop offset="50%" stopColor={props.secondaryColor}>
32+
<animate attributeName="offset" values="-1.5; 1.5" dur={`${props.speed}s`} repeatCount="indefinite" />
33+
</stop>
34+
<stop offset="100%" stopColor={props.primaryColor}>
35+
<animate attributeName="offset" values="-1; 2" dur={`${props.speed}s`} repeatCount="indefinite" />
36+
</stop>
37+
</linearGradient>
38+
</defs>
39+
</svg>
40+
)
41+
}
42+
43+
export default Wrap

src/custom/Circle.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
3+
const Circle = (props) => {
4+
const { x = 0, y = 0, radius = 50 } = props
5+
return <circle cx={x} cy={y} r={radius} />
6+
}
7+
8+
export default Circle

src/custom/Rect.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
3+
const Rect = (props) => {
4+
const { x = 0, y = 0, radius = 0, width = 50, height = 50 } = props
5+
return <rect x={x} y={y} rx={radius} ry={radius} width={width} height={height} />
6+
}
7+
8+
export default Rect

0 commit comments

Comments
 (0)