Skip to content

Commit 21aed74

Browse files
authored
Merge pull request #53 from dcgudeman/propType-change
updated propTypes for height and width to be union type of string and number.
2 parents 00016c5 + 4d6b6cb commit 21aed74

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Check [here](https://codesandbox.io/s/mqx0ql55qp)
3131
* spinningBubbles
3232
* spokes
3333

34-
## Example
34+
## Examples
3535

3636
```javascript
3737
import React from 'react';
@@ -44,15 +44,26 @@ const Example = ({ type, color }) => (
4444
export default Example;
4545
```
4646

47+
```javascript
48+
import React from 'react';
49+
import ReactLoading from 'react-loading';
50+
51+
const Example = ({ type, color }) => (
52+
<ReactLoading type={type} color={color} height={'20%'} width={'20%'} />
53+
);
54+
55+
export default Example;
56+
```
57+
4758
### Props
4859

4960
| Name | Type | Default Value |
5061
|:------:|:------:|:---------------:|
5162
| type | String | balls |
5263
| color | String | `#ffffff` |
5364
| delay | Number | 0 (msecs) |
54-
| height | Number | 64 (px) |
55-
| width | Number | 64 (px) |
65+
| height | Number or String | 64 (px) |
66+
| width | Number or String | 64 (px) |
5667
| className | String | `''` |
5768

5869

lib/__tests__/react-loading.spec.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,12 @@ describe('test Loading component', () => {
5151

5252
expect(enzymeWrapper.instance().timeout).not.toEqual(undefined);
5353
});
54+
55+
it('allows setting height and width with strings without propTypes warnings', () => {
56+
const spyConsoleError = jest.spyOn(global.console, 'error');
57+
const enzymeWrapper = shallow(<Loading height="20%" width="20%" />);
58+
expect(enzymeWrapper).toHaveLength(1);
59+
expect(spyConsoleError).not.toHaveBeenCalled();
60+
spyConsoleError.mockRestore();
61+
});
5462
});

lib/react-loading.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ export default class Loading extends Component {
88
color: PropTypes.string,
99
delay: PropTypes.number,
1010
type: PropTypes.string,
11-
height: PropTypes.number,
12-
width: PropTypes.number,
11+
height: PropTypes.oneOfType([
12+
PropTypes.string,
13+
PropTypes.number,
14+
]),
15+
width: PropTypes.oneOfType([
16+
PropTypes.string,
17+
PropTypes.number,
18+
]),
1319
};
1420

1521
static defaultProps = {

0 commit comments

Comments
 (0)