-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allowing different aspect ratios on base-component #1331
Allowing different aspect ratios on base-component #1331
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
Nice! I do, however, think we should stay as close to standards as possible (and generally implement them by the book). Did you see that all AMP-tags support the This can be used to do what this PR implements. Its main problem is that mutual exclusion has to be handled by the author. For this PR, I think the right way to more forward would be to implement |
Thinking about this some more, I'd really like feedback on the |
Apart from creating bloated code, |
I'd second that the question about the Ads is slightly a special case because iframe can actually have code that reacts to size changes. But other elements do not. For instance, in case of an image - one simply has to use a different image source. One negative from With that in mind, could you please clarify what you mean by "refresh" above? |
I could have explained myself better, sorry about that. Our use case is similar to that of amp-ad, and as @dvoytenko suggested this will cause a completely new ad to be presented to the user, which is undesirable for many reasons. |
I understand. I'm very open to adding support for |
Thanks for answering Malte, |
For ads it is actually often desirable to load a different ad on different screen resolution. E.g. desktop ads often sell for higher prices, and so one wants to switch to a different "slot id" or whatever terminology the ad network uses. I believe that CSS standard media queries should work on AMP elements. In particular when they use There are really 3 cases here, that people want to support
(3) is what is proposed here. I'd like us to see whether this can just be achieved in CSS. If it cannot or if that seems overly awkward, we need to do research what the standard answer in responsive design is and implement that in as standardized and idiomatic fashion as possible. |
Exactly! option (3) is what we are after, and i agree completely that it's best to do this in css, if possible. |
Yeah, I definitely see the benefit. This directly addresses two rather ingrained problems in CSS:
The proposed solution also seems fairly clean to me, although expressing aspect ratios via media query seems a bit counterintuitive to me here. Feels like it's best to design aspect ratio based on the width breakpoints of the element itself. So, I'm wondering if one of these options would work better:
|
We like option (1), especially because it allows the page author to use an element query instead of media query, which make expression of certain layouts easier (like having a responsive element on 50% of the page width) Option (2) can also work, if we can express the width in percentage and not only absolute values, like:
since our widget occupies 100% of the available width. We can take a crack at implementing option (1) assuming we can use a 'px' unit and and create a syntax like so:
@dvoytenko is this what you meant? |
@Effie Yes. This is pretty much what I meant. I took
We can't use |
@nitzanvolman @Effie I got a lot of pushback on the proposed format. The main problem is that we can't support static layout fast with it. Instead, I'd like to come back to the original idea of defining aspects via media query. I do think it should support your case still pretty well (in part because that's what you already proposed and I set you off track), but please let me know. In this case, we will do the following steps:
On aspects vs heights. Since we will allow not only Let me know what you think. If this is good, I think this PR is very close. |
@dvoytenko I think your suggestion is good. |
CLAs look good, thanks! |
@nitzanvolman Sure. Please go ahead and implement. So, decisions wise:
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
a08a3e2
to
a636897
Compare
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
@dvoytenko I believe this is it, please review and let us know if there is anything we missed. |
src="img/hero@1x.jpg" | ||
srcset="img/hero@1x.jpg 1x, img/hero@2x.jpg 2x" | ||
layout="responsive" width="360" placeholder | ||
aspects="(min-width:1420px) 20%, (min-width:1320px) 25%, (min-width:1000px) 40%, (min-width:760px) 85%, (min-width:500px) 100%, 120%" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should change to heights
, right?
This looks great! Just a few smallish comments. Please also add tests for Thanks a lot! |
@@ -39,9 +39,10 @@ let SizeListOptionDef; | |||
* See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#Attributes | |||
* See http://www.w3.org/html/wg/drafts/html/master/semantics.html#attr-img-sizes | |||
* @param {string} s | |||
* @param {boolean} opt_allowPercentAsLength when parsing heights |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boolean=
All looks good! Just one minor comment. And please squash the commits. I will fix the Travis in the meantime. |
181335c
to
0319a36
Compare
rebased again, squashed, and added |
@nitzanvolman could you please give CLA another chance? I think it was broken and now it's fixed. Let me know if it doesn't let you sign again. |
This will require help from my IT guys. Will try to get this done tomorrow when it's daylight... |
@dvoytenko I singed the CLA again - should be ok now. |
@nitzanvolman I got to the bottom of the CLA problem, I believe. The commit belongs to @Effie and the pull request belongs to you. So, I think we can either have Effie sign CLA as well or resend the PR with commit under your name. |
@dvoytenko I'm not sure technically how @Effie should sign, note that we are contributing this on behalf of a cooperation, in which case the instructions are to list the authorized signer and the primary contact person on the form, and include all of the committers of that cooperation in a dedicated google apps group (which we did: amp at taboola.com) |
Yes, could you please ask him to do this? |
No, having Effie comment isn't going to do anything. It's still going to have trouble finding Nitzan's CLA because of a bug (Googlers: b/23383092), but I've manually verified both and this is fine to merge. I'll try and get that bug fixed next week so that future collaborative PRs like this don't get stuck again. |
Awesome, thanks, @willnorris ! |
Allowing different aspect ratios on base-component
thanks @willnorris and @dvoytenko |
All merged! Thanks @nitzanvolman ! |
The current implementation assumes that in a responsive scenario the aspect ratio of a component remains the same across all the responsive breakpoints. This behaviour may not always be desired as in some cases a different aspect ratio may be needed for different screen sizes.
This pull request adds a "aspects" attribute to the base component, which accepts a series of media queries and a desired aspect ratio in % units (similar to the sizes css attribute)
See: examples/responsive.amp.html which was also added as a part of this request