Skip to content

Commit 9029577

Browse files
committed
✨ Make fadeIn prop in Img component accept number
1 parent dffb74e commit 9029577

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

packages/gatsby-image/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ You will need to add it in your graphql query as is shown in the following snipp
337337
| ---------------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------- |
338338
| `fixed` | `object` | Data returned from the `fixed` query |
339339
| `fluid` | `object` | Data returned from the `fluid` query |
340-
| `fadeIn` | `bool` | Defaults to fading in the image on load |
340+
| `fadeIn` | `number` | Defaults to fading in the image on load in 500ms |
341341
| `title` | `string` | Passed to the `img` element |
342342
| `alt` | `string` | Passed to the `img` element |
343343
| `crossOrigin` | `string` | Passed to the `img` element |

packages/gatsby-image/src/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,13 @@ class Image extends React.Component {
260260
itemProp,
261261
} = convertProps(this.props)
262262

263-
const shouldReveal = this.state.imgLoaded || this.state.fadeIn === false
264-
const shouldFadeIn = this.state.fadeIn === true && !this.state.imgCached
265-
const durationFadeIn = `0.5s`
263+
const shouldReveal =
264+
this.state.imgLoaded || Boolean(this.state.fadeIn) === false
265+
const shouldFadeIn =
266+
Boolean(this.state.fadeIn) === true && !this.state.imgCached
267+
const durationFadeIn = Number.isInteger(this.state.fadeIn)
268+
? `${this.state.fadeIn}ms`
269+
: `0.5s`
266270

267271
const imageStyle = {
268272
opacity: shouldReveal ? 1 : 0,

0 commit comments

Comments
 (0)