-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df52752
commit 11a8e79
Showing
12 changed files
with
250 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default } from "./loader"; | ||
export { default as LoaderBar } from "./loader-bar"; |
This file contains 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default } from "./loader.component"; | ||
export { default as LoaderBar } from "./loader-bar.component"; |
This file contains 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,33 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import styledSystemPropTypes from "@styled-system/prop-types"; | ||
import tagComponent from "../../utils/helpers/tags"; | ||
import StyledLoader from "./loader.style"; | ||
import StyledLoaderBar, { InnerBar } from "./loader-bar.style"; | ||
import { filterStyledSystemMarginProps } from "../../style/utils"; | ||
|
||
const marginPropTypes = filterStyledSystemMarginProps( | ||
styledSystemPropTypes.space | ||
); | ||
|
||
const LoaderBar = ({ size, ...rest }) => { | ||
return ( | ||
<StyledLoader {...rest} {...tagComponent("loader-bar", rest)}> | ||
<StyledLoaderBar size={size}> | ||
<InnerBar size={size} /> | ||
</StyledLoaderBar> | ||
</StyledLoader> | ||
); | ||
}; | ||
|
||
LoaderBar.defaultProps = { | ||
size: "medium", | ||
}; | ||
|
||
LoaderBar.propTypes = { | ||
...marginPropTypes, | ||
/** Size of the loader. */ | ||
size: PropTypes.oneOf(["small", "medium", "large"]), | ||
}; | ||
|
||
export default LoaderBar; |
This file contains 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,2 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const LOADER_BAR_SIZES = ["small", "medium", "large"]; |
This file contains 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,10 @@ | ||
import { MarginProps } from "styled-system"; | ||
|
||
export interface LoaderBarProps extends MarginProps { | ||
/** Size of the loaderBar. */ | ||
size?: "small" | "medium" | "large"; | ||
} | ||
|
||
declare function LoaderBar(props: LoaderBarProps): JSX.Element; | ||
|
||
export default LoaderBar; |
This file contains 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,78 @@ | ||
import React from "react"; | ||
import { mount } from "enzyme"; | ||
import StyledLoaderBar, { InnerBar } from "./loader-bar.style"; | ||
import { assertStyleMatch } from "../../__spec_helper__/test-utils"; | ||
import baseTheme from "../../style/themes/base"; | ||
import LoaderBar from "./loader-bar.component"; | ||
|
||
describe("LoaderBar", () => { | ||
let wrapper; | ||
it("renders component as expected", () => { | ||
wrapper = mount(<LoaderBar />); | ||
const innerBar = wrapper.find(InnerBar); | ||
expect(innerBar).toBeTruthy(); | ||
}); | ||
|
||
describe("when size is not specified", () => { | ||
beforeEach(() => { | ||
wrapper = mount(<LoaderBar />); | ||
}); | ||
it("renders outer bar as expected", () => { | ||
assertStyleMatch( | ||
{ | ||
backgroundColor: baseTheme.colors.loadingBarBackground, | ||
width: "256px", | ||
height: "8px", | ||
}, | ||
wrapper.find(StyledLoaderBar) | ||
); | ||
}); | ||
it("renders inner bar as expected", () => { | ||
assertStyleMatch( | ||
{ | ||
backgroundColor: baseTheme.colors.primary, | ||
width: "128px", | ||
height: "8px", | ||
}, | ||
wrapper.find(InnerBar) | ||
); | ||
}); | ||
}); | ||
|
||
describe("when size is set to small", () => { | ||
beforeEach(() => { | ||
wrapper = mount(<LoaderBar size="small" />); | ||
}); | ||
it("applies proper width and height to outer bar", () => { | ||
assertStyleMatch( | ||
{ width: "256px", height: "4px" }, | ||
wrapper.find(StyledLoaderBar) | ||
); | ||
}); | ||
|
||
it("applies proper width and height to inner bar", () => { | ||
assertStyleMatch( | ||
{ width: "128px", height: "4px" }, | ||
wrapper.find(InnerBar) | ||
); | ||
}); | ||
}); | ||
describe("when size is set to large", () => { | ||
beforeEach(() => { | ||
wrapper = mount(<LoaderBar size="large" />); | ||
}); | ||
it("applies proper width and height to outer bar", () => { | ||
assertStyleMatch( | ||
{ width: "256px", height: "16px" }, | ||
wrapper.find(StyledLoaderBar) | ||
); | ||
}); | ||
|
||
it("applies proper width and height to inner bar", () => { | ||
assertStyleMatch( | ||
{ width: "128px", height: "16px" }, | ||
wrapper.find(InnerBar) | ||
); | ||
}); | ||
}); | ||
}); |
This file contains 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,65 @@ | ||
import styled, { css, keyframes } from "styled-components"; | ||
import PropTypes from "prop-types"; | ||
import baseTheme from "../../style/themes/base"; | ||
import { LOADER_BAR_SIZES } from "./loader-bar.config"; | ||
|
||
const INNER_BAR_LENGTH = "128px"; | ||
const OUTER_BAR_LENGTH = "256px"; | ||
|
||
const innerBarAnimation = keyframes` | ||
0% { | ||
left: -${INNER_BAR_LENGTH} | ||
} | ||
100% { | ||
left: ${OUTER_BAR_LENGTH} | ||
} | ||
`; | ||
|
||
const StyledLoaderBar = styled.div` | ||
${({ size, theme }) => css` | ||
display: inline-block; | ||
height: ${getHeight(size)}; | ||
width: ${OUTER_BAR_LENGTH}; | ||
background-color: ${theme.colors.loadingBarBackground}; | ||
overflow: hidden; | ||
position: relative; | ||
`} | ||
`; | ||
|
||
const InnerBar = styled.div` | ||
${({ theme, size }) => css` | ||
position: absolute; | ||
background-color: ${theme.colors.primary}; | ||
width: ${INNER_BAR_LENGTH}; | ||
height: ${getHeight(size)} | ||
animation: 2s ${innerBarAnimation} linear 0s infinite normal none running; | ||
`} | ||
`; | ||
|
||
function getHeight(size) { | ||
switch (size) { | ||
case "small": | ||
return "4px"; | ||
case "large": | ||
return "16px"; | ||
default: | ||
return "8px"; | ||
} | ||
} | ||
|
||
StyledLoaderBar.defaultProps = { | ||
theme: baseTheme, | ||
size: "medium", | ||
}; | ||
|
||
InnerBar.defaultProps = { | ||
theme: baseTheme, | ||
size: "medium", | ||
}; | ||
|
||
StyledLoaderBar.propTypes = { | ||
size: PropTypes.oneOf(LOADER_BAR_SIZES), | ||
}; | ||
|
||
export { InnerBar }; | ||
export default StyledLoaderBar; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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