Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated propTypes for height and width to be union type of string and number. #53

Merged
merged 2 commits into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Check [here](https://codesandbox.io/s/mqx0ql55qp)
* spinningBubbles
* spokes

## Example
## Examples

```javascript
import React from 'react';
Expand All @@ -44,15 +44,26 @@ const Example = ({ type, color }) => (
export default Example;
```

```javascript
import React from 'react';
import ReactLoading from 'react-loading';

const Example = ({ type, color }) => (
<ReactLoading type={type} color={color} height={'20%'} width={'20%'} />
);

export default Example;
```

### Props

| Name | Type | Default Value |
|:------:|:------:|:---------------:|
| type | String | balls |
| color | String | `#ffffff` |
| delay | Number | 0 (msecs) |
| height | Number | 64 (px) |
| width | Number | 64 (px) |
| height | Number or String | 64 (px) |
| width | Number or String | 64 (px) |
| className | String | `''` |


Expand Down
8 changes: 8 additions & 0 deletions lib/__tests__/react-loading.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ describe('test Loading component', () => {

expect(enzymeWrapper.instance().timeout).not.toEqual(undefined);
});

it('allows setting height and width with strings without propTypes warnings', () => {
const spyConsoleError = jest.spyOn(global.console, 'error');
const enzymeWrapper = shallow(<Loading height="20%" width="20%" />);
expect(enzymeWrapper).toHaveLength(1);
expect(spyConsoleError).not.toHaveBeenCalled();
spyConsoleError.mockRestore();
});
});
10 changes: 8 additions & 2 deletions lib/react-loading.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ export default class Loading extends Component {
color: PropTypes.string,
delay: PropTypes.number,
type: PropTypes.string,
height: PropTypes.number,
width: PropTypes.number,
height: PropTypes.oneOfType([
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Could you please update readme.md accordingly. I think we need 1-2 examples to make this clear because i can see that many people get confused by these 2 props values. What do you think?

PropTypes.string,
PropTypes.number,
]),
width: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
};

static defaultProps = {
Expand Down