Skip to content

Commit

Permalink
Allow specifying which html tag will be used for gatsby-image wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywils committed Feb 13, 2018
1 parent 8273ddf commit 38c224f
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions packages/gatsby-image/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class Image extends React.Component {
sizes,
resolutions,
backgroundColor,
Tag,
} = convertProps(this.props)

let bgColor
Expand All @@ -207,7 +208,7 @@ class Image extends React.Component {

// The outer div is necessary to reset the z-index to 0.
return (
<div
<Tag
className={`${
outerWrapperClassName ? outerWrapperClassName : ``
} gatsby-image-outer-wrapper`}
Expand All @@ -217,7 +218,7 @@ class Image extends React.Component {
position: style.position === `absolute` ? `initial` : `relative`,
}}
>
<div
<Tag
className={`${className ? className : ``} gatsby-image-wrapper`}
style={{
position: `relative`,
Expand All @@ -228,7 +229,7 @@ class Image extends React.Component {
ref={this.handleRef}
>
{/* Preserve the aspect ratio. */}
<div
<Tag
style={{
width: `100%`,
paddingBottom: `${100 / image.aspectRatio}%`,
Expand Down Expand Up @@ -259,7 +260,7 @@ class Image extends React.Component {

{/* Show a solid background color. */}
{bgColor && (
<div
<Tag
title={title}
style={{
backgroundColor: bgColor,
Expand Down Expand Up @@ -298,8 +299,8 @@ class Image extends React.Component {
__html: noscriptImg({ alt, title, ...image }),
}}
/>
</div>
</div>
</Tag>
</Tag>
)
}

Expand Down Expand Up @@ -327,7 +328,7 @@ class Image extends React.Component {

// The outer div is necessary to reset the z-index to 0.
return (
<div
<Tag
className={`${
outerWrapperClassName ? outerWrapperClassName : ``
} gatsby-image-outer-wrapper`}
Expand All @@ -337,7 +338,7 @@ class Image extends React.Component {
position: style.position === `absolute` ? `initial` : `relative`,
}}
>
<div
<Tag
className={`${className ? className : ``} gatsby-image-wrapper`}
style={divStyle}
ref={this.handleRef}
Expand Down Expand Up @@ -366,7 +367,7 @@ class Image extends React.Component {

{/* Show a solid background color. */}
{bgColor && (
<div
<Tag
title={title}
style={{
backgroundColor: bgColor,
Expand Down Expand Up @@ -409,8 +410,8 @@ class Image extends React.Component {
}),
}}
/>
</div>
</div>
</Tag>
</Tag>
)
}

Expand All @@ -421,6 +422,7 @@ class Image extends React.Component {
Image.defaultProps = {
fadeIn: true,
alt: ``,
Tag: `div`,
}

Image.propTypes = {
Expand All @@ -440,6 +442,7 @@ Image.propTypes = {
position: PropTypes.string,
backgroundColor: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
onLoad: PropTypes.func,
Tag: PropTypes.string,
}

export default Image

0 comments on commit 38c224f

Please sign in to comment.