Skip to content

Commit

Permalink
Release 3.1.0 (#63)
Browse files Browse the repository at this point in the history
* Add Breathing loader

* Refactor Shimmer loader
  • Loading branch information
gokcan authored May 27, 2020
1 parent abf8189 commit e7b3179
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 147 deletions.
323 changes: 188 additions & 135 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-shimmer",
"version": "3.0.3",
"version": "3.1.0",
"description": "React Image (Suspense-like) Loader component that simulates a shimmer effect",
"author": "gokcan",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @class SuspenseImage
* @version 3.0.3
* @version 3.1.0
* @author github.com/gokcan
*/

Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export { default } from './Image'
export type { ImageProps } from './Image'

// Loaders
export { Shimmer } from './loaders/shimmer/Shimmer'
export * from './loaders'
export type { ShimmerProps } from './loaders/shimmer/Shimmer'
export type { BreathingProps } from './loaders/breathing/Breathing'
26 changes: 26 additions & 0 deletions src/loaders/breathing/Breathing.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react'
import PropTypes from 'prop-types'
import clsx from 'clsx'

import './styles.css'

export interface BreathingProps {
className?: string
duration?: number
height?: number
width?: number
}

const DEFAULT_DURATION_MS = 1000

export const Breathing = ({ className, duration = DEFAULT_DURATION_MS, height, width }: BreathingProps) => {
const style = { height, width, animationDuration: `${(duration / 1000).toFixed(1)}s` }
return <div className={clsx('breathing', className)} style={style} />
}

Breathing.propTypes = {
className: PropTypes.string,
duration: PropTypes.number,
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
}
48 changes: 48 additions & 0 deletions src/loaders/breathing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
### Breathing Loader

## Usage

```jsx
import React from 'react'
import Image, { Breathing } from 'react-shimmer'

function App(props) {
return (
<div>
<Image
src='https://source.unsplash.com/random'
fallback={<Breathing />}
/>
</div>
)
}
```

or as a standalone placeholder:

```jsx
import React from 'react'
import { Breathing } from 'react-shimmer'

function App(props) {
return (
<div>
<Breathing />
</div>
)
}
```

### Properties

Property | Type | Required | Default value | Description
:--- | :--- | :--- | :--- | :---
`className`|string|no|| Override default styles with className
`width`|number|no||
`height`|number|no||
`duration`|number|no|`1000`| Animation duration (ms)
-----

## License

MIT © [gokcan](https://github.com/gokcan)
19 changes: 19 additions & 0 deletions src/loaders/breathing/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
:root {
--default-bg-color: #e1e2e4;
}

.breathing {
width: 100%;
height: 100%;
background: var(--default-bg-color);
animation: breathing ease-in-out infinite alternate;
}

@keyframes breathing {
from {
opacity: 0.25;
}
to {
opacity: 1;
}
}
1 change: 1 addition & 0 deletions src/loaders/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { Shimmer } from './shimmer/Shimmer'
export { Breathing } from './breathing/Breathing'
17 changes: 16 additions & 1 deletion src/loaders/shimmer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,28 @@ function App(props) {
}
```

or as a standalone placeholder:

```jsx
import React from 'react'
import { Shimmer } from 'react-shimmer'

function App(props) {
return (
<div>
<Shimmer width={280} height={60} />
</div>
)
}
```

### Properties

Property | Type | Required | Default value | Description
:--- | :--- | :--- | :--- | :---
`width`|number|yes||
`height`|number|yes||
`color`|string|no|`#f6f7f8`| Background color of the loader
`className`|string|no|| Override default styles with className
`duration`|number|no|`1600`| Animation duration (ms)
-----

Expand Down
2 changes: 1 addition & 1 deletion src/loaders/shimmer/Shimmer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const Shimmer = ({ className, duration, height = DEFAULT_HEIGHT, width =
const shimmerStyle = calcShimmerStyle(width, height, duration)
const style = { ...shimmerStyle, ...{ height, width } }

return <span className={clsx('shimmer', className)} style={style} />
return <div className={clsx('shimmer', className)} style={style} />
}

Shimmer.propTypes = {
Expand Down
24 changes: 17 additions & 7 deletions src/loaders/shimmer/styles.css
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
:root {
--default-bg-color: #f6f7f8;
--default-bg-moving-gradient: linear-gradient(to right, rgb(238, 238, 238) 8%, rgb(222, 222, 222) 18%, rgb(238, 238, 238) 33%);
}

.shimmer {
background: #f6f7f8;
background-image: linear-gradient(to right, rgb(238, 238, 238) 8%, rgb(222, 222, 222) 18%, rgb(238, 238, 238) 33%);
background: var(--default-bg-color);
background-image: var(--default-bg-moving-gradient);
background-repeat: no-repeat;
animation: shimmering 1.6s forwards infinite ease-in-out, fadein 0.02s forwards;
animation: shimmering forwards infinite ease-in-out, fadein 0.02s forwards;
}

@keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
from {
opacity: 0;
}

to {
opacity: 1;
}
}

@keyframes shimmering {
0% {
from {
background-position: top right;
}

100% {
to {
background-position: top left;
}
}

0 comments on commit e7b3179

Please sign in to comment.