-
Notifications
You must be signed in to change notification settings - Fork 73
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
Responsive Aspect-Ratio Sizing with padding-top css Technique #41
base: master
Are you sure you want to change the base?
Conversation
… to style via aspect ratio https://css-tricks.com/aspect-ratio-boxes/
A maybe even cleaner alternative to extracting helper functions from |
… calculation from ControlledPiano to Keyboard
Ok, I created a new If you decide to merge this, the CodeSandbox also would need an update. I didn't want to fork it and reference my fork from the readme, as it's your project and this way you can more easily update the CodeSandbox in the future. Also the old CodeSandbox should still work without problems. |
@fabb I like this idea, and thank you for creating the PR and explaining things clearly! I agree it would be great to have a standard way to do aspect ratio without the react-dimensions dependency. One note is that this change also makes it impossible to keep the existing behavior of "expand to the container's width and height" when I don't know if this is a good idea or not, but I wonder if this approach could be used by adding a wrapper container around e.g.
(this might not actually work - just trying to think of an approach that decouples the CSS logic from the component) I'll also want to take some time to make sure the padding-top approach works well across browsers and across different use cases. Unfortunately, I'm pretty busy these days so I might not get this merged for some time. But I do really appreciate the PR and I will try to get this in eventually! |
True, that's basically instrinsic vs. extrinsic sizing. Maybe add an explicit prop to switch between the two?
I wouldn't separate the container and element, since the two need to work together to utilize the padding-top technique. A problem with your example would be that the
This
Sure, don't worry. I pushed my own fork to npm in the mean time: https://www.npmjs.com/package/@fabb/react-piano/v/3.2.0-pre. I hope that's ok, I'd delete it when this PR gets merged. |
…is provided - make the prop optional and do not set it in defaultProps
What do you think of 4e9477e? This would satisfy your requirement to be able to size the component completely from the outside, and still allows to have an aspect ratio mode, without introducing new props. The It's a non-backwards-compatible change though, because for clients not providing the |
…ly in the style tag
While this now works, I'm not convinced that it provides the best experience for a client. When not setting the |
hey, sorry I haven't looked at this yet - I will take a look this weekend. |
Don‘t worry, it‘s not pressing, just an offer 😉 |
This PR shows how the styles on the
div
s ofControlledPiano
andKeyboard
could be adapted to responsively resize the keyboard without resorting to theDimensionsProvider
workaround. It uses the padding-top css Technique.I'm aware that this PR could be improved a little before merge, I just wanted to ask if you were open to this technique of responsive resizing. Especially functions from
Keyboard.js
could be extracted to be usable fromControlledPiano.js
as well, as the latter needs to know and set the aspect ratio on the containerdiv
.