forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store: Replace thumb placeholder with WC generic placeholder image (A…
…utomattic#21841) * Replace thumb placeholder with WC generic placeholder * Converts this change to a single component that accepts image props and displays the placeholder if neccessary * Handle PR feedback: Add optional placeholder attribute for providing a fallback Remove extra spaces, and move product css rule out of classNames call
- Loading branch information
1 parent
c9a6a98
commit c28274a
Showing
10 changed files
with
98 additions
and
102 deletions.
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
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
56 changes: 56 additions & 0 deletions
56
client/extensions/woocommerce/components/image-thumb/index.js
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,56 @@ | ||
/** @format */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
|
||
const ImageThumb = ( { width, height, src, alt, placeholder, ...props } ) => { | ||
const style = { | ||
width, | ||
height, | ||
minHeight: height, | ||
}; | ||
|
||
const imageClasses = classNames( 'image-thumb', { | ||
hasImage: src, | ||
} ); | ||
|
||
if ( ! src ) { | ||
if ( placeholder ) { | ||
style.backgroundImage = `url( ${ placeholder } )`; | ||
} | ||
|
||
return ( | ||
<div className={ imageClasses }> | ||
<div className="image-thumb__placeholder" style={ style } /> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className={ imageClasses } style={ style }> | ||
<img src={ src } style={ style } alt={ alt } { ...props } /> | ||
</div> | ||
); | ||
}; | ||
|
||
ImageThumb.propTypes = { | ||
width: PropTypes.number, | ||
height: PropTypes.number, | ||
className: PropTypes.string, | ||
src: PropTypes.string, | ||
placeholder: PropTypes.string, | ||
alt: PropTypes.string.isRequired, | ||
}; | ||
|
||
ImageThumb.defaultProps = { | ||
width: 40, | ||
height: 40, | ||
className: '', | ||
src: '', | ||
}; | ||
|
||
export default ImageThumb; |
24 changes: 24 additions & 0 deletions
24
client/extensions/woocommerce/components/image-thumb/style.scss
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,24 @@ | ||
.image-thumb__placeholder { | ||
background-size: cover; | ||
background-image: url( '/calypso/images/extensions/woocommerce/image-placeholder.png' ); | ||
border: 1px solid $gray-light; | ||
} | ||
|
||
.image-thumb { | ||
display: inline-block; | ||
position: relative; | ||
|
||
&.hasImage { | ||
overflow: hidden; | ||
} | ||
|
||
img { | ||
position: absolute; | ||
left: 50%; | ||
top: 50%; | ||
height: 100%; | ||
width: auto; | ||
-webkit-transform: translate( -50%, -50% ); | ||
transform: translate( -50%, -50% ); | ||
} | ||
} |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.