Skip to content

Commit e7b3179

Browse files
authored
Release 3.1.0 (#63)
* Add Breathing loader * Refactor Shimmer loader
1 parent abf8189 commit e7b3179

File tree

11 files changed

+320
-147
lines changed

11 files changed

+320
-147
lines changed

package-lock.json

Lines changed: 188 additions & 135 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-shimmer",
3-
"version": "3.0.3",
3+
"version": "3.1.0",
44
"description": "React Image (Suspense-like) Loader component that simulates a shimmer effect",
55
"author": "gokcan",
66
"keywords": [

src/Image.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @class SuspenseImage
3-
* @version 3.0.3
3+
* @version 3.1.0
44
* @author github.com/gokcan
55
*/
66

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ export { default } from './Image'
22
export type { ImageProps } from './Image'
33

44
// Loaders
5-
export { Shimmer } from './loaders/shimmer/Shimmer'
5+
export * from './loaders'
66
export type { ShimmerProps } from './loaders/shimmer/Shimmer'
7+
export type { BreathingProps } from './loaders/breathing/Breathing'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import clsx from 'clsx'
4+
5+
import './styles.css'
6+
7+
export interface BreathingProps {
8+
className?: string
9+
duration?: number
10+
height?: number
11+
width?: number
12+
}
13+
14+
const DEFAULT_DURATION_MS = 1000
15+
16+
export const Breathing = ({ className, duration = DEFAULT_DURATION_MS, height, width }: BreathingProps) => {
17+
const style = { height, width, animationDuration: `${(duration / 1000).toFixed(1)}s` }
18+
return <div className={clsx('breathing', className)} style={style} />
19+
}
20+
21+
Breathing.propTypes = {
22+
className: PropTypes.string,
23+
duration: PropTypes.number,
24+
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
25+
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
26+
}

src/loaders/breathing/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
### Breathing Loader
2+
3+
## Usage
4+
5+
```jsx
6+
import React from 'react'
7+
import Image, { Breathing } from 'react-shimmer'
8+
9+
function App(props) {
10+
return (
11+
<div>
12+
<Image
13+
src='https://source.unsplash.com/random'
14+
fallback={<Breathing />}
15+
/>
16+
</div>
17+
)
18+
}
19+
```
20+
21+
or as a standalone placeholder:
22+
23+
```jsx
24+
import React from 'react'
25+
import { Breathing } from 'react-shimmer'
26+
27+
function App(props) {
28+
return (
29+
<div>
30+
<Breathing />
31+
</div>
32+
)
33+
}
34+
```
35+
36+
### Properties
37+
38+
Property | Type | Required | Default value | Description
39+
:--- | :--- | :--- | :--- | :---
40+
`className`|string|no|| Override default styles with className
41+
`width`|number|no||
42+
`height`|number|no||
43+
`duration`|number|no|`1000`| Animation duration (ms)
44+
-----
45+
46+
## License
47+
48+
MIT © [gokcan](https://github.com/gokcan)

src/loaders/breathing/styles.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
:root {
2+
--default-bg-color: #e1e2e4;
3+
}
4+
5+
.breathing {
6+
width: 100%;
7+
height: 100%;
8+
background: var(--default-bg-color);
9+
animation: breathing ease-in-out infinite alternate;
10+
}
11+
12+
@keyframes breathing {
13+
from {
14+
opacity: 0.25;
15+
}
16+
to {
17+
opacity: 1;
18+
}
19+
}

src/loaders/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { Shimmer } from './shimmer/Shimmer'
2+
export { Breathing } from './breathing/Breathing'

src/loaders/shimmer/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,28 @@ function App(props) {
1818
}
1919
```
2020

21+
or as a standalone placeholder:
22+
23+
```jsx
24+
import React from 'react'
25+
import { Shimmer } from 'react-shimmer'
26+
27+
function App(props) {
28+
return (
29+
<div>
30+
<Shimmer width={280} height={60} />
31+
</div>
32+
)
33+
}
34+
```
35+
2136
### Properties
2237

2338
Property | Type | Required | Default value | Description
2439
:--- | :--- | :--- | :--- | :---
2540
`width`|number|yes||
2641
`height`|number|yes||
27-
`color`|string|no|`#f6f7f8`| Background color of the loader
42+
`className`|string|no|| Override default styles with className
2843
`duration`|number|no|`1600`| Animation duration (ms)
2944
-----
3045

src/loaders/shimmer/Shimmer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const Shimmer = ({ className, duration, height = DEFAULT_HEIGHT, width =
2424
const shimmerStyle = calcShimmerStyle(width, height, duration)
2525
const style = { ...shimmerStyle, ...{ height, width } }
2626

27-
return <span className={clsx('shimmer', className)} style={style} />
27+
return <div className={clsx('shimmer', className)} style={style} />
2828
}
2929

3030
Shimmer.propTypes = {

0 commit comments

Comments
 (0)