-
Notifications
You must be signed in to change notification settings - Fork 392
feat(Spinner): Adding Spinner component #100
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import cx from 'classnames'; | ||
|
|
||
| const Spinner = ({ | ||
| loading, | ||
| size, | ||
| inline, | ||
| children, | ||
| inverse, | ||
| className, | ||
| ...props | ||
| }) => { | ||
| if (loading) { | ||
| const classes = cx(className, 'spinner', `spinner-${size}`, { | ||
| 'spinner-inline': inline, | ||
| 'spinner-inverse': inverse, | ||
| }); | ||
|
|
||
| return <div className={classes} {...props} />; | ||
| } | ||
|
|
||
| if (children) { | ||
| return children; | ||
| } | ||
|
|
||
| return null; | ||
| }; | ||
|
|
||
| Spinner.propTypes = { | ||
| loading: PropTypes.bool, | ||
| inline: PropTypes.bool, | ||
| inverse: PropTypes.bool, | ||
| size: PropTypes.oneOf(['lg', 'md', 'sm', 'xs']), | ||
| children: PropTypes.node, | ||
| className: PropTypes.string, | ||
| }; | ||
|
|
||
| Spinner.defaultProps = { | ||
| loading: false, | ||
| size: 'md', | ||
| inline: false, | ||
| inverse: false, | ||
| className: '', | ||
| }; | ||
|
|
||
| export default Spinner; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import React from 'react'; | ||
| import { storiesOf } from '@storybook/react'; | ||
| import { withKnobs, select, boolean } from '@storybook/addon-knobs'; | ||
|
|
||
| import { defaultTemplate } from '../../../storybook/decorators/storyTemplates'; | ||
| import Spinner from './index'; | ||
|
|
||
| const stories = storiesOf('Widgets', module); | ||
|
|
||
| stories.addDecorator(withKnobs); | ||
| stories.addDecorator( | ||
| defaultTemplate({ | ||
| title: 'Spinner', | ||
| documentationLink: | ||
| 'http://www.patternfly.org/pattern-library/widgets/#spinner', | ||
| }), | ||
| ); | ||
|
|
||
| stories.addWithInfo('Spinner', () => { | ||
| const loading = boolean('Loading', true); | ||
| const inline = boolean('Inline', false); | ||
| const inverse = boolean('Inverse', false); | ||
| const size = select('Size', ['lg', 'md', 'sm', 'xs'], 'md'); | ||
|
|
||
| const wrapperStyle = { | ||
| backgroundColor: inverse ? 'black' : 'white', | ||
| color: inverse ? 'white' : 'black', | ||
| padding: '15px', | ||
| }; | ||
|
|
||
| const spinnerProps = { | ||
| loading, | ||
| size, | ||
| inline, | ||
| inverse, | ||
| }; | ||
|
|
||
| if (inline) { | ||
| return ( | ||
| <div style={wrapperStyle}> | ||
| <Spinner {...spinnerProps} /> | ||
| Some inline text here. | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div style={wrapperStyle}> | ||
| <Spinner {...spinnerProps}> | ||
| <strong> | ||
| Show chilren when <code>loading</code> is <code>false</code>. | ||
| </strong> | ||
| </Spinner> | ||
| </div> | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* eslint-env jest */ | ||
|
|
||
| import React from 'react'; | ||
| import Spinner from './index'; | ||
| import renderer from 'react-test-renderer'; | ||
|
|
||
| test('Spinner should not render children when loading', () => { | ||
| const component = renderer.create( | ||
| <Spinner loading> | ||
| <span>Children should not render.</span> | ||
| </Spinner>, | ||
| ); | ||
|
|
||
| let tree = component.toJSON(); | ||
| expect(tree).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('Spinner should render children when not loading', () => { | ||
| const component = renderer.create( | ||
| <Spinner size="lg"> | ||
| <span>Children should be rendered.</span> | ||
| </Spinner>, | ||
| ); | ||
|
|
||
| let tree = component.toJSON(); | ||
| expect(tree).toMatchSnapshot(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Spinner should not render children when loading 1`] = ` | ||
| <div | ||
| className="spinner spinner-md" | ||
| /> | ||
| `; | ||
|
|
||
| exports[`Spinner should render children when not loading 1`] = ` | ||
| <span> | ||
| Children should be rendered. | ||
| </span> | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './Spinner'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't seen this use case in the current test pages, but maybe I am missing something.
@jgiardino thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@priley86 Can you elaborate on the use case you're referring to? I'm guessing you're referring to the use of
<strong>here. But based on what I'm seeing in the storybook, the contents inside the<Spinner>component are the contents that display when loading is false, so the use of<strong>here is really just a placeholder for those contents, and not really part of the design pattern.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jgiardino yeah that's correct.