Skip to content
This repository was archived by the owner on Jan 21, 2019. It is now read-only.
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
3 changes: 3 additions & 0 deletions src/components/Spinner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ Custom size and stroke:
<div>
<Spinner size={'78'} stroke={'6'}/>
<Spinner size={70} stroke={2}/>
<Spinner size={70} block/>
<Spinner inline/>
<Spinner inline block/>
</div>
```
108 changes: 102 additions & 6 deletions src/components/Spinner/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,72 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Spinner renders correctly with additional classname 1`] = `
<div
className="fandom-spinner custom-class or-multiple-classes"
style={
Object {
"height": 30,
"width": 30,
}
}
>
<svg
height={30}
viewBox="0 0 30 30"
width={30}
xmlns="http://www.w3.org/2000/svg"
>
<g
transform="translate(15, 15)"
>
<circle
fill="none"
r={14}
strokeDasharray={87.96459430051421}
strokeDashoffset={87.96459430051421}
strokeLinecap="round"
strokeWidth={2}
/>
</g>
</svg>
</div>
`;

exports[`Spinner renders correctly with custom block 1`] = `
<div
className="fandom-spinner is-block"
style={
Object {
"height": 30,
"width": 30,
}
}
>
<svg
height={30}
viewBox="0 0 30 30"
width={30}
xmlns="http://www.w3.org/2000/svg"
>
<g
transform="translate(15, 15)"
>
<circle
fill="none"
r={14}
strokeDasharray={87.96459430051421}
strokeDashoffset={87.96459430051421}
strokeLinecap="round"
strokeWidth={2}
/>
</g>
</svg>
</div>
`;

exports[`Spinner renders correctly with custom colors (named color) 1`] = `
<div
className="fandom-spinner "
className="fandom-spinner"
style={
Object {
"height": 30,
Expand Down Expand Up @@ -34,7 +98,7 @@ exports[`Spinner renders correctly with custom colors (named color) 1`] = `

exports[`Spinner renders correctly with custom colors (rgb) 1`] = `
<div
className="fandom-spinner "
className="fandom-spinner"
style={
Object {
"height": 30,
Expand Down Expand Up @@ -66,7 +130,39 @@ exports[`Spinner renders correctly with custom colors (rgb) 1`] = `

exports[`Spinner renders correctly with custom colors (short hex) 1`] = `
<div
className="fandom-spinner "
className="fandom-spinner"
style={
Object {
"height": 30,
"width": 30,
}
}
>
<svg
height={30}
viewBox="0 0 30 30"
width={30}
xmlns="http://www.w3.org/2000/svg"
>
<g
transform="translate(15, 15)"
>
<circle
fill="none"
r={14}
strokeDasharray={87.96459430051421}
strokeDashoffset={87.96459430051421}
strokeLinecap="round"
strokeWidth={2}
/>
</g>
</svg>
</div>
`;

exports[`Spinner renders correctly with custom inline 1`] = `
<div
className="fandom-spinner is-inline"
style={
Object {
"height": 30,
Expand Down Expand Up @@ -98,7 +194,7 @@ exports[`Spinner renders correctly with custom colors (short hex) 1`] = `

exports[`Spinner renders correctly with custom size (number) 1`] = `
<div
className="fandom-spinner "
className="fandom-spinner"
style={
Object {
"height": "20",
Expand Down Expand Up @@ -130,7 +226,7 @@ exports[`Spinner renders correctly with custom size (number) 1`] = `

exports[`Spinner renders correctly with custom size (string) 1`] = `
<div
className="fandom-spinner "
className="fandom-spinner"
style={
Object {
"height": "78",
Expand Down Expand Up @@ -162,7 +258,7 @@ exports[`Spinner renders correctly with custom size (string) 1`] = `

exports[`Spinner renders correctly with default values 1`] = `
<div
className="fandom-spinner "
className="fandom-spinner"
style={
Object {
"height": 30,
Expand Down
27 changes: 26 additions & 1 deletion src/components/Spinner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const Spinner = ({
className,
size,
stroke,
block,
inline,
}) => {
const style = {
width: size,
Expand All @@ -21,9 +23,22 @@ const Spinner = ({
const r = (size - stroke) / 2;
const translate = r + (stroke / 2);
const dash = 2 * Math.PI * r;
const classes = ['fandom-spinner'];

if (block) {
classes.push('is-block');
}

if (inline) {
classes.push('is-inline');
}

if (className) {
classes.push(className);
}

return (
<div className={`fandom-spinner ${className}`} style={style}>
<div className={classes.join(' ')} style={style}>
<svg
width={size}
height={size}
Expand Down Expand Up @@ -58,12 +73,22 @@ Spinner.propTypes = {
* Stroke width
*/
stroke: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Display block and center
*/
block: PropTypes.bool,
/**
* Display contentinline based on line height
*/
inline: PropTypes.bool,
};

Spinner.defaultProps = {
className: '',
size: 30,
stroke: 2,
block: false,
inline: false,
};

export default Spinner;
21 changes: 21 additions & 0 deletions src/components/Spinner/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,24 @@ test('Spinner renders correctly with custom colors (rgb)', () => {
);
expect(component.toJSON()).toMatchSnapshot();
});

test('Spinner renders correctly with custom inline ', () => {
const component = renderer.create(
<Spinner inline />
);
expect(component.toJSON()).toMatchSnapshot();
});

test('Spinner renders correctly with custom block ', () => {
const component = renderer.create(
<Spinner block />
);
expect(component.toJSON()).toMatchSnapshot();
});

test('Spinner renders correctly with additional classname', () => {
const component = renderer.create(
<Spinner className="custom-class or-multiple-classes" />
);
expect(component.toJSON()).toMatchSnapshot();
});
17 changes: 17 additions & 0 deletions src/components/Spinner/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,21 @@
stroke: $wds-color-link;
}
}

&.is-block {
display: block;
left: auto;
margin: auto;
position: relative;
}

&.is-inline {
height: 1em;
left: 0;
margin: 0;
position: static;
top: 0;
width: auto;
}

}