Skip to content
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
47 changes: 47 additions & 0 deletions src/components/Spinner/Spinner.js
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;
56 changes: 56 additions & 0 deletions src/components/Spinner/Spinner.stories.js
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>

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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.

Show chilren when <code>loading</code> is <code>false</code>.
</strong>
</Spinner>
</div>
);
});
27 changes: 27 additions & 0 deletions src/components/Spinner/Spinner.test.js
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();
});
13 changes: 13 additions & 0 deletions src/components/Spinner/__snapshots__/Spinner.test.js.snap
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>
`;
1 change: 1 addition & 0 deletions src/components/Spinner/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Spinner';