Skip to content

Commit 6871488

Browse files
authored
Improvements wrap (#74)
* Prettier stuff * Centralized props * Removed the export
1 parent 4c196c4 commit 6871488

File tree

8 files changed

+35
-29
lines changed

8 files changed

+35
-29
lines changed

src/Wrap.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ export type WrapProps = {
88
children?: React.ChildrenArray<*>,
99
} & ContentLoaderProps
1010

11-
export const defaultProps = {
12-
speed: 2,
13-
width: 400,
14-
height: 130,
15-
primaryColor: '#f0f0f0',
16-
secondaryColor: '#e0e0e0',
17-
preserveAspectRatio: 'xMidYMid meet',
18-
}
19-
2011
const Wrap = (props: WrapProps): React.Element<*> => {
2112
const idClip = uid()
2213
const idGradient = uid()

src/index.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@flow
22
import * as React from 'react'
3+
import Wrap from './Wrap'
34

4-
import Wrap, { defaultProps } from './Wrap'
55
// Stylized
66
export { default as Facebook } from './stylized/FacebookStyle'
77
export { default as Instagram } from './stylized/InstagramStyle'
@@ -21,11 +21,23 @@ export type Props = {
2121
className: string,
2222
}
2323

24+
const defaultProps = {
25+
speed: 2,
26+
width: 400,
27+
height: 130,
28+
primaryColor: '#f0f0f0',
29+
secondaryColor: '#e0e0e0',
30+
preserveAspectRatio: 'xMidYMid meet',
31+
}
32+
33+
const InitialComponent = props => (
34+
<rect x="0" y="0" rx="5" ry="5" width={props.width} height={props.height} />
35+
)
36+
2437
const ContentLoader = (props: Props) => {
2538
const mergedProps = { ...defaultProps, ...props }
26-
const children = props.children
27-
? props.children
28-
: <rect x="0" y="0" rx="5" ry="5" width={mergedProps.width} height={mergedProps.height} />
39+
const children = props.children ? props.children : <InitialComponent {...mergedProps} />
40+
2941
return <Wrap {...mergedProps}>{children}</Wrap>
3042
}
3143

src/stylized/BulletListStyle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//@flow
22
import * as React from 'react'
3-
import Wrap, { defaultProps } from '../Wrap'
3+
import ContentLoader from '../index'
44
import type { WrapProps } from '../Wrap'
55

66
const BulletListStyle = (props: WrapProps): React.Element<*> => (
7-
<Wrap {...defaultProps} {...props} >
7+
<ContentLoader {...props}>
88
<circle cx="10" cy="20" r="8" />
99
<rect x="25" y="15" rx="5" ry="5" width="220" height="10" />
1010
<circle cx="10" cy="50" r="8" />
@@ -13,7 +13,7 @@ const BulletListStyle = (props: WrapProps): React.Element<*> => (
1313
<rect x="25" y="75" rx="5" ry="5" width="220" height="10" />
1414
<circle cx="10" cy="110" r="8" />
1515
<rect x="25" y="105" rx="5" ry="5" width="220" height="10" />
16-
</Wrap>
16+
</ContentLoader>
1717
)
1818

1919
export default BulletListStyle

src/stylized/CodeStyle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//@flow
22
import * as React from 'react'
3-
import Wrap, { defaultProps } from '../Wrap'
3+
import ContentLoader from '../index'
44
import type { WrapProps } from '../Wrap'
55

66
const CodeStyle = (props: WrapProps): React.Element<*> => (
7-
<Wrap {...defaultProps} {...props} >
7+
<ContentLoader {...props}>
88
<rect x="0" y="0" rx="3" ry="3" width="70" height="10" />
99
<rect x="80" y="0" rx="3" ry="3" width="100" height="10" />
1010
<rect x="190" y="0" rx="3" ry="3" width="10" height="10" />
@@ -17,7 +17,7 @@ const CodeStyle = (props: WrapProps): React.Element<*> => (
1717
<rect x="185" y="40" rx="3" ry="3" width="60" height="10" />
1818

1919
<rect x="0" y="60" rx="3" ry="3" width="30" height="10" />
20-
</Wrap>
20+
</ContentLoader>
2121
)
2222

2323
export default CodeStyle

src/stylized/FacebookStyle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//@flow
22
import * as React from 'react'
3-
import Wrap, { defaultProps } from '../Wrap'
3+
import ContentLoader from '../index'
44
import type { WrapProps } from '../Wrap'
55

66
const FacebookStyle = (props: WrapProps): React.Element<*> => (
7-
<Wrap {...defaultProps} {...props} >
7+
<ContentLoader {...props}>
88
<rect x="70" y="15" rx="4" ry="4" width="117" height="6.4" />
99
<rect x="70" y="35" rx="3" ry="3" width="85" height="6.4" />
1010
<rect x="0" y="80" rx="3" ry="3" width="350" height="6.4" />
1111
<rect x="0" y="100" rx="3" ry="3" width="380" height="6.4" />
1212
<rect x="0" y="120" rx="3" ry="3" width="201" height="6.4" />
1313
<circle cx="30" cy="30" r="30" />
14-
</Wrap>
14+
</ContentLoader>
1515
)
1616

1717
export default FacebookStyle

src/stylized/InstagramStyle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
//@flow
22
import * as React from 'react'
3-
import Wrap, { defaultProps } from '../Wrap'
3+
import ContentLoader from '../index'
44
import type { WrapProps } from '../Wrap'
55

66
const InstagramStyle = (props: WrapProps): React.Element<*> => (
7-
<Wrap {...defaultProps} {...props} height={480}>
7+
<ContentLoader {...props} height={480}>
88
<circle cx="30" cy="30" r="30" />
99

1010
<rect x="75" y="13" rx="4" ry="4" width="100" height="13" />
1111
<rect x="75" y="37" rx="4" ry="4" width="50" height="8" />
1212
<rect x="0" y="70" rx="5" ry="5" width="400" height="400" />
13-
</Wrap>
13+
</ContentLoader>
1414
)
1515

1616
export default InstagramStyle

src/stylized/ListStyle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//@flow
22
import * as React from 'react'
3-
import Wrap, { defaultProps } from '../Wrap'
3+
import ContentLoader from '../index'
44
import type { WrapProps } from '../Wrap'
55

66
const ListStyle = (props: WrapProps): React.Element<*> => (
7-
<Wrap {...defaultProps} {...props}>
7+
<ContentLoader {...props}>
88
<rect x="0" y="0" rx="3" ry="3" width="250" height="10" />
99
<rect x="20" y="20" rx="3" ry="3" width="220" height="10" />
1010
<rect x="20" y="40" rx="3" ry="3" width="170" height="10" />
1111
<rect x="0" y="60" rx="3" ry="3" width="250" height="10" />
1212
<rect x="20" y="80" rx="3" ry="3" width="200" height="10" />
1313
<rect x="20" y="100" rx="3" ry="3" width="80" height="10" />
14-
</Wrap>
14+
</ContentLoader>
1515
)
1616

1717
export default ListStyle

src/uid.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
// @flow
2-
export default (): string => Math.random().toString(36).substring(2)
2+
export default (): string =>
3+
Math.random()
4+
.toString(36)
5+
.substring(2)

0 commit comments

Comments
 (0)