-
Notifications
You must be signed in to change notification settings - Fork 12
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
add ripple loader component from trendkite-ui #329
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
@keyframes LOADERRIPPLE { | ||
0% { | ||
transform: scale(0, 0); | ||
opacity: 1; | ||
} | ||
|
||
100% { | ||
transform: scale(0.9, 0.9); | ||
opacity: 0; | ||
} | ||
} | ||
|
||
.Loader { | ||
display: flex; | ||
flex-flow: row nowrap; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.Loader::before { | ||
content: ''; | ||
background-color: transparent; | ||
position: absolute; | ||
opacity: 1; | ||
width: 50px; | ||
height: 50px; | ||
border-radius: 50%; | ||
border: 5px solid #0092c2; | ||
animation: LOADERRIPPLE 1.8s infinite; | ||
transform: scale(0, 0); | ||
animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1); | ||
animation-delay: 0s; | ||
} | ||
|
||
.Loader::after { | ||
content: ''; | ||
background-color: transparent; | ||
position: absolute; | ||
opacity: 1; | ||
width: 50px; | ||
height: 50px; | ||
border-radius: 50%; | ||
border: 5px solid #0092c2; | ||
animation: LOADERRIPPLE 1.8s infinite; | ||
transform: scale(0, 0); | ||
animation-timing-function: cubic-bezier(0.3, 0.61, 0.335, 1); | ||
animation-delay: -0.9s; | ||
} | ||
|
||
.sm, | ||
.sm::before, | ||
.sm::after { | ||
width: 10px; | ||
height: 10px; | ||
margin: auto; | ||
} | ||
|
||
.md, | ||
.md::before, | ||
.md::after { | ||
width: 20px; | ||
height: 20px; | ||
margin: auto; | ||
} | ||
|
||
.lg, | ||
.lg::before, | ||
.lg::after { | ||
width: 50px; | ||
height: 50px; | ||
margin: auto; | ||
} | ||
|
||
.xl, | ||
.xl::before, | ||
.xl::after { | ||
width: 100px; | ||
height: 100px; | ||
margin: auto; | ||
} |
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,40 @@ | ||
import React from 'react'; | ||
|
||
import { render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import Loader from '.'; | ||
|
||
describe('Loader', () => { | ||
it('renders', () => { | ||
render(<Loader />); | ||
}); | ||
|
||
describe('when rendered with custom style with width and height', () => { | ||
it('should override the default loader sizes', () => { | ||
const { getByTestId } = render( | ||
<Loader | ||
data-testid="loaderElem" | ||
style={{ width: '123px', height: '123px' }} | ||
/> | ||
); | ||
|
||
const loaderElem = getByTestId('loaderElem') as HTMLDivElement; | ||
expect(loaderElem.style.width).toBe('123px'); | ||
}); | ||
}); | ||
|
||
describe('when rendered with additional class names', () => { | ||
it('should not replace the default classes', () => { | ||
const { getByTestId } = render( | ||
<Loader data-testid="loaderElem" className="Loader" /> | ||
); | ||
|
||
const loaderElem = getByTestId('loaderElem') as HTMLDivElement; | ||
const loaderClasses = loaderElem.className | ||
.split(' ') | ||
.filter((classes) => classes.match('\\w*(Loader)\\w*')); | ||
expect(loaderClasses.length).toBe(2); | ||
}); | ||
}); | ||
}); |
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,28 @@ | ||
import React from 'react'; | ||
|
||
import classNames from 'classnames'; | ||
|
||
import styles from './Loader.module.css'; | ||
|
||
export type Size = 'sm' | 'md' | 'lg' | 'xl'; | ||
|
||
interface LoaderProps extends React.HTMLAttributes<HTMLDivElement> { | ||
size?: Size; | ||
} | ||
|
||
const Loader: React.FC<LoaderProps> = ({ size = 'lg', ...rest }) => { | ||
const mainClass = classNames( | ||
styles.Loader, | ||
rest.className, | ||
`${styles[size]}` | ||
); | ||
|
||
const prop = { | ||
...rest, | ||
className: mainClass, | ||
}; | ||
|
||
return <div {...prop} />; | ||
}; | ||
|
||
export default Loader; |
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,16 @@ | ||
# \<Loader\> | ||
|
||
render a loading icon | ||
|
||
### Valid Sizes | ||
|
||
Size is optional, defaults to large when omitted | ||
|
||
- sm | ||
- md | ||
- lg | ||
- xl | ||
|
||
```jsx | ||
<Loader size="md" /> | ||
``` |
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 @@ | ||
export { default } from './Loader'; |
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,83 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { select } from '@storybook/addon-knobs'; | ||
|
||
import Loader from './Loader'; | ||
import Readme from './README.md'; | ||
|
||
import { Wrap } from '../../stories/storybook-helpers'; | ||
|
||
const FlexWrapper = (props) => ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
alignContent: 'center', | ||
alignItems: 'center', | ||
marginTop: '100px', | ||
marginBottom: '100px', | ||
}} | ||
{...props} | ||
/> | ||
); | ||
|
||
storiesOf('Planets/Loader', module) | ||
.addParameters({ | ||
readme: { | ||
sidebar: Readme, | ||
}, | ||
}) | ||
.add( | ||
'Overview', | ||
() => ( | ||
<FlexWrapper> | ||
<Loader size={select('size', ['sm', 'md', 'lg', 'xl'], 'lg')} /> | ||
</FlexWrapper> | ||
), | ||
{ | ||
info: { | ||
inline: false, | ||
source: true, | ||
}, | ||
} | ||
) | ||
.add( | ||
'Examples', | ||
() => ( | ||
<> | ||
<Wrap> | ||
<Loader size="sm" /> | ||
</Wrap> | ||
<Wrap> | ||
<Loader size="md" /> | ||
</Wrap> | ||
<Wrap> | ||
<Loader size="lg" /> | ||
</Wrap> | ||
<Wrap> | ||
<Loader size="xl" /> | ||
</Wrap> | ||
<Wrap> | ||
<Loader style={{ marginLeft: '0' }} /> | ||
</Wrap> | ||
<Wrap> | ||
<Loader style={{ marginRight: '0' }} /> | ||
</Wrap> | ||
<Wrap> | ||
<div style={{ width: '50%' }}> | ||
<Loader size="lg" /> | ||
</div> | ||
</Wrap> | ||
<Wrap> | ||
<Loader style={{ marginTop: '75px', marginBottom: '75px' }} /> | ||
</Wrap> | ||
</> | ||
), | ||
{ | ||
info: { | ||
inline: false, | ||
source: true, | ||
}, | ||
} | ||
); |
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
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.
Need a second opinion on spreading custom props in the nested div rather than the wrapper div.
Attaching it to the nested div allows consumer to pass in custom sizes and have it override the default
sm
,md
,lg
,xl
options.An alternative option would be to pass a numeric to the size prop rather than enum strings. Then the custom prop can be attached to the wrapper div. This will break away from the enum string pattern used in trendkite-ui
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 don't think I'd call this an "icon", I might just say "Loader" or something, since our icons are usually svgs that you can change colors on.
If the circular image ends up being its own component, it would probably be called
Loader
, but if it's nested inside a loader component and it would need a distinct name, maybeimage
,animation
,ripple
, or something.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.
Updated the loader to render with one div and custom props would get spread on that div.
I kept the css that renders the loader's location in the center of its parent html element.
That way consumers can adjust the loader's horizontal positioning with a parent html element that has a defined width and margin.
They could also override the default horizontally centered loader position via style prop if consumers do not have control over the parent html element.