-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '0b1d904e39bb4157124829e144d76cc8383baf34' into update-v…
…10.0.0-from-upstream
- Loading branch information
Showing
141 changed files
with
7,694 additions
and
1,096 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { node, number, string } from 'prop-types'; | ||
import classNames from 'classnames'; | ||
|
||
import css from './AspectRatioWrapper.module.css'; | ||
|
||
const AspectRatioWrapper = props => { | ||
const { children, className, rootClassName, width, height, ...rest } = props; | ||
const classes = classNames(rootClassName || css.root, className); | ||
|
||
const aspectRatio = (height / width) * 100; | ||
const paddingBottom = `${aspectRatio}%`; | ||
|
||
return ( | ||
<div className={classes} {...rest}> | ||
<div className={css.aspectPadding} style={{ paddingBottom }}> | ||
<div className={css.aspectBox}>{children}</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
AspectRatioWrapper.defaultProps = { | ||
className: null, | ||
rootClassName: null, | ||
children: null, | ||
}; | ||
|
||
AspectRatioWrapper.propTypes = { | ||
className: string, | ||
rootClassName: string, | ||
width: number.isRequired, | ||
height: number.isRequired, | ||
children: node, | ||
}; | ||
|
||
export default AspectRatioWrapper; |
21 changes: 21 additions & 0 deletions
21
src/components/AspectRatioWrapper/AspectRatioWrapper.module.css
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,21 @@ | ||
.root { | ||
/* Layout */ | ||
display: block; | ||
width: 100%; | ||
position: relative; | ||
} | ||
|
||
/* Firefox doesn't support image aspect ratio inside flexbox */ | ||
/* Aspect ratio for is given inline */ | ||
.aspectPadding { | ||
} | ||
|
||
.aspectBox { | ||
/* Layout - image will take space defined by aspect ratio wrapper */ | ||
position: absolute; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
width: 100%; | ||
} |
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
Oops, something went wrong.