Created
April 3, 2020 17:05
-
-
Save alexdiliberto/d3f9a41e0f25aaa5199741be4705ce3b to your computer and use it in GitHub Desktop.
image aspect ratio component
This file contains hidden or 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
// References: | |
// https://tailwindcss.com/course/locking-images-to-a-fixed-aspect-ratio/#app | |
// https://github.com/embermap/emberconf2020-tailwind-css-best-practices | |
import Component from "@glimmer/component"; | |
import { htmlSafe } from "@ember/string"; | |
export default class AspectRatioComponent extends Component { | |
get style() { | |
let paddingBottom = this.args.ratio | |
.split(":") | |
.map(str => parseInt(str, 10)) | |
.reduce((prev, curr) => curr / prev); | |
return htmlSafe(`padding-bottom: ${paddingBottom * 100}%`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment