UX: Use aspect ratio to calculate width and height precisely

Followup on 1da265d
This commit is contained in:
Vinoth Kannan 2018-11-29 09:32:03 +05:30
parent c388cacb81
commit 5db50d6cdc
5 changed files with 67 additions and 10 deletions

View File

@ -6,5 +6,12 @@ export default Ember.Component.extend({
@computed("src")
cdnSrc(src) {
return Discourse.getURLWithCDN(src);
},
@computed("width", "height")
style(width, height) {
if (width && height) {
return Ember.String.htmlSafe(`--aspect-ratio: ${width / height};`);
}
}
});

View File

@ -1,3 +1,5 @@
{{#if src}}
<img src={{cdnSrc}} class={{class}} width={{width}} height={{height}}>
<div class="{{class}} aspect-image" style={{style}}>
<img src={{cdnSrc}} width={{width}} height={{height}}>
</div>
{{/if}}

View File

@ -41,13 +41,21 @@
width: 100%;
}
.logo {
.logo.aspect-image img {
display: block;
width: auto;
height: 40px;
margin: 0 auto 1em auto;
}
@supports (--custom: property) {
.logo.aspect-image img {
--height: 40px;
width: calc(var(--height) * var(--aspect-ratio));
max-width: 100%;
}
}
h3 .fa {
color: $primary;
}

View File

@ -221,11 +221,31 @@ button.dismiss-read {
clear: both;
}
.category-logo {
width: auto;
max-height: 150px;
.category-logo.aspect-image {
float: left;
margin: 0.25em 1em 0.5em 0;
img {
width: auto;
max-height: 150px;
}
}
@supports (--custom: property) {
.category-logo.aspect-image {
--max-height: 150px;
max-height: var(--max-height);
width: calc(var(--max-height) * var(--aspect-ratio));
max-width: 25%;
height: auto;
img {
width: 100%;
height: inherit;
max-width: initial;
max-height: initial;
}
}
}
/* Tablet (portrait) ----------- */

View File

@ -478,12 +478,32 @@ ol.category-breadcrumb {
padding-top: 10px;
}
.category-logo {
.category-logo.aspect-image {
display: block;
width: auto;
max-width: 100%;
max-height: 150px;
padding: 8px 0;
margin: 8px 0;
img {
width: auto;
max-width: 100%;
max-height: 150px;
}
}
@supports (--custom: property) {
.category-logo.aspect-image {
--max-height: 150px;
max-height: var(--max-height);
width: calc(var(--max-height) * var(--aspect-ratio));
max-width: 100%;
height: auto;
img {
width: 100%;
height: inherit;
max-width: initial;
max-height: initial;
}
}
}
button.dismiss-read {