Skip to content

Commit a3d1878

Browse files
Andaristdanilowoz
authored andcommitted
Added named exports and removed type prop (#72)
1 parent 044e99d commit a3d1878

File tree

10 files changed

+39
-95
lines changed

10 files changed

+39
-95
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ Npm: `$ npm i react-content-loader --save`
3232

3333
```jsx
3434
// import the component
35-
import ContentLoader from 'react-content-loader'
35+
import ContentLoader, { Facebook } from 'react-content-loader'
3636

37-
const MyLoader = () => <ContentLoader type="facebook" />
37+
const MyLoader = () => <ContentLoader />
38+
const MyFacebookLoader = () => <Facebook />
3839
```
3940

4041
**Or in custom mode, using the
@@ -55,7 +56,6 @@ const MyLoader = () => (
5556

5657
| Name | Type | Default | Description |
5758
| ------------------- | -------- | --------------- | --------------------------------------------------------------- |
58-
| type | _String_ | `facebook` | Options: `facebook`, `instagram`, `list`, `bullet-list`, `code` |
5959
| speed | _Number_ | `2` | Animation speed |
6060
| width | _Number_ | `400` | **viewBox** width of SVG |
6161
| height | _Number_ | `130` | **viewBox** height of SVG |

src/Wrap.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ 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+
1120
const Wrap = (props: WrapProps): React.Element<*> => {
1221
const idClip = uid()
1322
const idGradient = uid()

src/index.js

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//@flow
22
import * as React from 'react'
33

4-
import Wrap from './Wrap'
4+
import Wrap, { defaultProps } from './Wrap'
55
// Stylized
6-
import FacebookStyle from './stylized/FacebookStyle'
7-
import InstagramStyle from './stylized/InstagramStyle'
8-
import CodeStyle from './stylized/CodeStyle'
9-
import ListStyle from './stylized/ListStyle'
10-
import BulletListStyle from './stylized/BulletListStyle'
6+
export { default as Facebook } from './stylized/FacebookStyle'
7+
export { default as Instagram } from './stylized/InstagramStyle'
8+
export { default as Code } from './stylized/CodeStyle'
9+
export { default as List } from './stylized/ListStyle'
10+
export { default as BulletList } from './stylized/BulletListStyle'
1111

1212
export type Props = {
1313
style: { [key: string]: any },
@@ -22,38 +22,11 @@ export type Props = {
2222
}
2323

2424
const ContentLoader = (props: Props) => {
25-
if (props.children) {
26-
return <Wrap {...props}>{props.children}</Wrap>
27-
}
28-
29-
switch (props.type.toLowerCase()) {
30-
case 'instagram':
31-
return <InstagramStyle {...props} />
32-
33-
case 'code':
34-
return <CodeStyle {...props} />
35-
36-
case 'list':
37-
return <ListStyle {...props} />
38-
39-
case 'bullet-list':
40-
return <BulletListStyle {...props} />
41-
42-
default:
43-
case 'facebook':
44-
return <FacebookStyle {...props} />
45-
}
25+
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} />
29+
return <Wrap {...mergedProps}>{children}</Wrap>
4630
}
4731

48-
ContentLoader.defaultProps = {
49-
type: 'facebook',
50-
speed: 2,
51-
width: 400,
52-
height: 130,
53-
primaryColor: '#f0f0f0',
54-
secondaryColor: '#e0e0e0',
55-
preserveAspectRatio: 'xMidYMid meet',
56-
className: '',
57-
};
58-
5932
export default ContentLoader

src/stylized/BulletListStyle.js

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

66
const BulletListStyle = (props: WrapProps): React.Element<*> => (
7-
<Wrap {...props}>
7+
<Wrap {...defaultProps} {...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" />

src/stylized/CodeStyle.js

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

66
const CodeStyle = (props: WrapProps): React.Element<*> => (
7-
<Wrap {...props}>
7+
<Wrap {...defaultProps} {...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" />

src/stylized/FacebookStyle.js

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

66
const FacebookStyle = (props: WrapProps): React.Element<*> => (
7-
<Wrap {...props}>
7+
<Wrap {...defaultProps} {...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" />

src/stylized/InstagramStyle.js

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

66
const InstagramStyle = (props: WrapProps): React.Element<*> => (
7-
<Wrap {...props} height={480}>
7+
<Wrap {...defaultProps} {...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" />

src/stylized/ListStyle.js

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

66
const ListStyle = (props: WrapProps): React.Element<*> => (
7-
<Wrap {...props}>
7+
<Wrap {...defaultProps} {...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" />

stories/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22

33
import { storiesOf } from '@storybook/react'
44

5-
import ContentLoader from '../src/index'
5+
import ContentLoader, { Facebook, Instagram, Code, List, BulletList } from '../src/index'
66

77
let defaultStyle = {
88
width: 400,
@@ -25,27 +25,27 @@ const MyLoader = () => {
2525
storiesOf('ContentLoader', module)
2626
.add('facebook style', () => (
2727
<Container>
28-
<ContentLoader />
28+
<Facebook />
2929
</Container>
3030
))
3131
.add('instagram style', () => (
3232
<Container>
33-
<ContentLoader type="instagram" />
33+
<Instagram />
3434
</Container>
3535
))
3636
.add('code style', () => (
3737
<Container>
38-
<ContentLoader type="code" />
38+
<Code />
3939
</Container>
4040
))
4141
.add('list style', () => (
4242
<Container>
43-
<ContentLoader type="list" />
43+
<List />
4444
</Container>
4545
))
4646
.add('bullet list style', () => (
4747
<Container>
48-
<ContentLoader type="bullet-list" />
48+
<BulletList />
4949
</Container>
5050
))
5151
.add('custom style', () => (

tests/index.js

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,8 @@ Enzyme.configure({ adapter: new Adapter() })
1111
chai.use(chaiEnzyme())
1212

1313
import ContentLoader from '../src/index'
14-
import FacebookStyle from '../src/stylized/FacebookStyle'
15-
import InstagramStyle from '../src/stylized/InstagramStyle'
16-
import CodeStyle from '../src/stylized/CodeStyle'
1714

1815
describe('<ContentLoader />:', () => {
19-
describe('Type props are used', () => {
20-
describe('when type is facebook', () => {
21-
const wrapper = mount(<ContentLoader type={'facebook'} />)
22-
23-
it('should render <FacebookStyle />', () => {
24-
expect(wrapper).to.have.descendants(FacebookStyle)
25-
})
26-
})
27-
28-
describe('when type is instagram', () => {
29-
const wrapper = mount(<ContentLoader type={'instagram'} />)
30-
31-
it('should render <InstagramStyle />', () => {
32-
expect(wrapper).to.have.descendants(InstagramStyle)
33-
})
34-
})
35-
36-
describe('when type is code', () => {
37-
const wrapper = mount(<ContentLoader type={'code'} />)
38-
39-
it('should render <CodeStyle />', () => {
40-
expect(wrapper).to.have.descendants(CodeStyle)
41-
})
42-
})
43-
44-
describe('when type is undefined', () => {
45-
const wrapper = mount(<ContentLoader />)
46-
47-
it('should render <FacebookStyle />', () => {
48-
expect(wrapper).to.have.descendants(FacebookStyle)
49-
})
50-
})
51-
52-
})
53-
5416
describe('when type is custom', () => {
5517

5618
const wrapper = mount(

0 commit comments

Comments
 (0)