-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Move layout custom properties to filter. #37438
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Used with the default, horizontal flex orientation. | ||
const justifyContentMap = { | ||
left: 'flex-start', | ||
right: 'flex-end', | ||
center: 'center', | ||
'space-between': 'space-between', | ||
}; | ||
|
||
// Used with the vertical (column) flex orientation. | ||
const alignItemsMap = { | ||
left: 'flex-start', | ||
right: 'flex-end', | ||
center: 'center', | ||
}; | ||
|
||
export function addStylesToLayout( | ||
styleContent, | ||
selector, | ||
appendSelectors, | ||
layout | ||
) { | ||
if ( ! layout ) { | ||
return styleContent; | ||
} | ||
|
||
const { orientation = 'horizontal' } = layout; | ||
const justifyContent = | ||
justifyContentMap[ layout.justifyContent ] || justifyContentMap.left; | ||
const alignItems = | ||
alignItemsMap[ layout.justifyContent ] || alignItemsMap.left; | ||
|
||
let customProperties = ``; | ||
|
||
if ( orientation === 'horizontal' ) { | ||
// --layout-justification-setting allows children to inherit the value | ||
// regardless or row or column direction. | ||
customProperties += ` | ||
--layout-justification-setting: ${ justifyContent }; | ||
--layout-direction: row; | ||
--layout-wrap: ${ layout.flexWrap || 'wrap' }; | ||
--layout-justify: ${ justifyContent }; | ||
--layout-align: center; | ||
`; | ||
} else { | ||
customProperties += ` | ||
--layout-justification-setting: ${ alignItems }; | ||
--layout-direction: column; | ||
--layout-justify: initial; | ||
--layout-align: ${ alignItems }; | ||
`; | ||
} | ||
|
||
return `${ styleContent } ${ appendSelectors( selector ) } { | ||
${ customProperties } | ||
}`; | ||
} |
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
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
2 changes: 1 addition & 1 deletion
2
test/integration/fixtures/blocks/core__navigation__deprecated-1.serialized.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<!-- wp:navigation {"layout":{"type":"flex","setCascadingProperties":"true","orientation":"horizontal"}} --> | ||
<!-- wp:navigation {"layout":{"type":"flex","orientation":"horizontal"}} --> | ||
<!-- wp:navigation-link {"label":"WordPress","url":"https://www.wordpress.org/"} /--> | ||
<!-- /wp:navigation --> |
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
2 changes: 1 addition & 1 deletion
2
test/integration/fixtures/blocks/core__navigation__deprecated-v4.serialized.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<!-- wp:navigation {"overlayMenu":"never","fontFamily":"cambria-georgia","layout":{"type":"flex","setCascadingProperties":"true","orientation":"horizontal"}} /--> | ||
<!-- wp:navigation {"overlayMenu":"never","fontFamily":"cambria-georgia","layout":{"type":"flex","orientation":"horizontal"}} /--> |
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
2 changes: 1 addition & 1 deletion
2
test/integration/fixtures/blocks/core__navigation__deprecated-v5.serialized.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<!-- wp:navigation {"overlayMenu":"never","layout":{"type":"flex","setCascadingProperties":"true","justifyContent":"center","orientation":"vertical"}} /--> | ||
<!-- wp:navigation {"overlayMenu":"never","layout":{"type":"flex","justifyContent":"center","orientation":"vertical"}} /--> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
}, | ||
"layout": { | ||
"type": "flex", | ||
"setCascadingProperties": "true", | ||
"orientation": "horizontal" | ||
} | ||
}, | ||
|
2 changes: 1 addition & 1 deletion
2
test/integration/fixtures/blocks/core__navigation__deprecated.serialized.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<!-- wp:navigation {"style":{"typography":{"textTransform":"lowercase","textDecoration":"line-through","fontStyle":"italic","fontWeight":"100"}},"layout":{"type":"flex","setCascadingProperties":"true","orientation":"horizontal"}} --> | ||
<!-- wp:navigation {"style":{"typography":{"textTransform":"lowercase","textDecoration":"line-through","fontStyle":"italic","fontWeight":"100"}},"layout":{"type":"flex","orientation":"horizontal"}} --> | ||
<!-- wp:navigation-link {"label":"WordPress","url":"https://www.wordpress.org/"} /--> | ||
<!-- /wp:navigation --> |
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.
Do we need extra filters (aka new APIs to support)? Can't we rely on
render_block
for the backend andeditor.BlockListBlock
for the frontend?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.
Also potentially we don't need any filter, we can just add the logic to the "render_callback" of the navigation block in the backend and to "edit" function of the navigation block in the frontend?
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.
render_block
andeditor.BlockListBlock
won't work because we can't get the layout properties from them. Would it help to name the filter__unstable
while we figure out what works best in terms of API? Or is that naming convention not applicable to filters?We could do something along these lines, but if we want to keep all the logic in the Nav block it might be easier (and cleaner) to just output all the
items-justified-
etc. classnames and hook the CSS off those.