Skip to content

Commit 3fac666

Browse files
pallymoredanilowoz
authored andcommitted
Setup flow and convert existing component files (#21)
* add flow and babel-preset-flow * convert index.js to flow * convert Wrap.js to use flow * convert CodeStyle.js * convert other stylized component files to use flow * convert Rect and Circle to use flow * add type checking for React.Element
1 parent afb6de5 commit 3fac666

File tree

12 files changed

+112
-53
lines changed

12 files changed

+112
-53
lines changed

.babelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets": ["es2015", "stage-2", "react"]
3-
}
2+
"presets": ["es2015", "stage-2", "react", "flow"]
3+
}

.flowconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[ignore]
2+
3+
[include]
4+
5+
[libs]
6+
7+
[lints]
8+
9+
[options]

package-lock.json

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"name": "react-content-loader",
33
"version": "1.4.1",
4-
"description":
5-
"This project is a collection the loader based on styles cards on Facebook, make with SVG and React.",
4+
"description": "This project is a collection the loader based on styles cards on Facebook, make with SVG and React.",
65
"repository": {
76
"type": "git",
87
"url": "https://github.com/danilowoz/react-content-loader"
@@ -14,22 +13,28 @@
1413
"url": "https://github.com/danilowoz/react-content-loader/issues"
1514
},
1615
"homepage": "https://github.com/danilowoz/react-content-loader",
17-
"keywords": ["react", "facebook-style", "loader", "loading", "content", "svg"],
16+
"keywords": [
17+
"react",
18+
"facebook-style",
19+
"loader",
20+
"loading",
21+
"content",
22+
"svg"
23+
],
1824
"options": {
1925
"mocha": "--require scripts/mocha_runner ./tests/**/*.js ./tests/*.js"
2026
},
2127
"scripts": {
22-
"watch":
23-
"babel --plugins transform-es2015-modules-umd src --watch --ignore tests --out-dir ./dist",
24-
"prepublish":
25-
"babel --plugins transform-es2015-modules-umd src --ignore tests --out-dir ./dist",
28+
"watch": "babel --plugins transform-es2015-modules-umd src --watch --ignore tests --out-dir ./dist",
29+
"prepublish": "babel --plugins transform-es2015-modules-umd src --ignore tests --out-dir ./dist",
2630
"lint": "eslint 'src/**/*.js'",
2731
"prettier": "prettier --write 'src/**/*.{js,jsx,json,css}'",
2832
"testonly": "mocha $npm_package_options_mocha",
2933
"test": "npm run lint && npm run testonly",
3034
"test-watch": "npm run testonly -- --watch --watch-extensions js",
3135
"storybook": "start-storybook -p 6006",
32-
"build-storybook": "build-storybook"
36+
"build-storybook": "build-storybook",
37+
"flow": "flow"
3338
},
3439
"devDependencies": {
3540
"@storybook/react": "^3.1.9",
@@ -39,6 +44,7 @@
3944
"babel-plugin-transform-es2015-modules-umd": "^6.6.5",
4045
"babel-polyfill": "^6.7.4",
4146
"babel-preset-es2015": "^6.6.0",
47+
"babel-preset-flow": "^6.23.0",
4248
"babel-preset-react": "^6.5.0",
4349
"babel-preset-stage-2": "^6.5.0",
4450
"chai": "^3.5.0",
@@ -49,6 +55,7 @@
4955
"eslint-plugin-babel": "^3.1.0",
5056
"eslint-plugin-prettier": "^2.2.0",
5157
"eslint-plugin-react": "^4.2.3",
58+
"flow-bin": "^0.57.3",
5259
"jsdom": "^8.1.0",
5360
"mocha": "^2.4.5",
5461
"nodemon": "^1.9.1",

src/Wrap.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import React from 'react'
1+
//@flow
2+
import * as React from 'react'
23
import uuid from 'uuid'
34

4-
const Wrap = props => {
5+
import type { Props as ContentLoaderProps } from './index';
6+
7+
export type WrapProps = {
8+
children?: React.ChildrenArray<*>
9+
} & ContentLoaderProps
10+
11+
const Wrap = (props: WrapProps): React.Element<*> => {
512
let idClip = uuid.v1()
613
let idGradient = uuid.v1()
714

src/custom/Circle.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
import React from 'react'
1+
//@flow
2+
import * as React from 'react'
23

3-
const Circle = props => {
4+
type Props = {
5+
x: number,
6+
y: number,
7+
radius: number,
8+
}
9+
10+
const Circle = (props: Props): React.Element<*> => {
411
const { x = 0, y = 0, radius = 50 } = props
512
return <circle cx={x} cy={y} r={radius} />
613
}

src/custom/Rect.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
import React from 'react'
1+
//@flow
2+
import * as React from 'react'
23

3-
const Rect = props => {
4+
type Props = {
5+
x: number,
6+
y: number,
7+
radius: number,
8+
width: number,
9+
height: number,
10+
}
11+
12+
const Rect = (props: Props): React.Element<*> => {
413
const { x = 0, y = 0, radius = 0, width = 50, height = 50 } = props
514
return <rect x={x} y={y} rx={radius} ry={radius} width={width} height={height} />
615
}

src/index.js

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { Component } from 'react'
2-
import PropTypes from 'prop-types'
1+
//@flow
2+
import * as React from 'react'
33

44
import Wrap from './Wrap'
55
// Stylized
@@ -11,8 +11,37 @@ import ListStyle from './stylized/ListStyle'
1111
import Rect from './custom/Rect'
1212
import Circle from './custom/Circle'
1313

14-
class ContentLoader extends Component {
15-
constructor(props) {
14+
export type Props = {
15+
style: {[key: string]: any},
16+
type: string,
17+
speed: number,
18+
width: number,
19+
height: number,
20+
primaryColor: string,
21+
secondaryColor: string,
22+
}
23+
24+
type State = {
25+
style: {[key: string]: any},
26+
type: string,
27+
speed: number,
28+
width: number,
29+
height: number,
30+
primaryColor: string,
31+
secondaryColor: string,
32+
}
33+
34+
class ContentLoader extends React.Component<Props, State> {
35+
static defaultProps = {
36+
type: 'facebook',
37+
speed: 2,
38+
width: 400,
39+
height: 130,
40+
primaryColor: '#f0f0f0',
41+
secondaryColor: '#e0e0e0',
42+
}
43+
44+
constructor(props: Props) {
1645
super(props)
1746

1847
this.state = {
@@ -35,43 +64,20 @@ class ContentLoader extends Component {
3564
switch (this.state.type.toLowerCase()) {
3665
case 'instagram':
3766
return <InstagramStyle {...this.state} />
38-
break
3967

4068
case 'code':
4169
return <CodeStyle {...this.state} />
42-
break
4370

4471
case 'list':
4572
return <ListStyle {...this.state} />
46-
break
4773

4874
default:
4975
case 'facebook':
5076
return <FacebookStyle {...this.state} />
51-
break
5277
}
5378
}
5479
}
5580
}
5681

57-
ContentLoader.propTypes = {
58-
style: PropTypes.object,
59-
type: PropTypes.string,
60-
speed: PropTypes.number,
61-
width: PropTypes.number,
62-
height: PropTypes.number,
63-
primaryColor: PropTypes.string,
64-
secondaryColor: PropTypes.string,
65-
}
66-
67-
ContentLoader.defaultProps = {
68-
type: 'facebook',
69-
speed: 2,
70-
width: 400,
71-
height: 130,
72-
primaryColor: '#f0f0f0',
73-
secondaryColor: '#e0e0e0',
74-
}
75-
7682
export default ContentLoader
7783
export { Rect, Circle }

src/stylized/CodeStyle.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import React from 'react'
1+
//@flow
2+
import * as React from 'react'
23
import Wrap from '../Wrap'
4+
import type { WrapProps } from '../Wrap';
35

4-
const CodeStyle = props => {
6+
const CodeStyle = (props: WrapProps): React.Element<*> => {
57
return (
68
<Wrap {...props}>
79
<rect x="0" y="0" rx="3" ry="3" width="70" height="10" />

src/stylized/FacebookStyle.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import React from 'react'
1+
//@flow
2+
import * as React from 'react'
23
import Wrap from '../Wrap'
4+
import type { WrapProps } from '../Wrap';
35

4-
const FacebookStyle = props => {
6+
const FacebookStyle = (props: WrapProps): React.Element<*> => {
57
return (
68
<Wrap {...props}>
79
<rect x="0" y="0" rx="5" ry="5" width="70" height="70" />

0 commit comments

Comments
 (0)