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
Background image support: add background position controls #58592
Merged
andrewserong
merged 3 commits into
trunk
from
try/add-background-position-controls-to-background-image-support
Feb 6, 2024
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is just a quick pass at the mapping — if this PR looks okay, I'll fine-tune the logic a bit here and add some tests.
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 particular bit LGTM, but just curious: why do we need to do this mapping? Aren't the percentage values enough?
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.
Good question: we need to have at least some form of mapping so that we're not storing values like
{ x: 0.5, y: 0.5 }
in the block attributes forstyle.background.backgroundPosition
. For future proofing the feature, I think it's better if that value can be stored in the block delimiter as a real CSS value, rather than a value that's intended for the internal workings of the focal point picker. So at the very least, I think it's better if we can have the support map{ x: 0.5, y: 0.5 }
to50% 50%
.In terms of mapping the natural language values like
left
,center
, etc, that's mostly me thinking of what would be good to support for if/when we get totheme.json
support where folks might be writing the JSON a bit by hand. It'd be nice to be able to support mapping potentially handwritten values so that they work naturally with this control.For now, though, we only really need the generic decimal
0.5
>50%
mapping for this to work, so I'm happy to pare it back for this PR.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.
Very good idea!
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.
For now I've just gone with converting between percentage and coordinate values. There's a bit more nuanced to the multi-value syntax for background position, so I think that'd be better to handle separately in a follow-up code quality PR. For now I've gone with the main use case logic which is background position values that were created using this particular UI control.