-
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
Search block: Add typography supports #43499
Merged
aaronrobertshaw
merged 18 commits into
trunk
from
update/search-block-typography-support
Sep 12, 2022
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2fd66e1
Adding typography block supports to the search block
ramonjd 26c25da
Opting into all typography supports for the search block (with the ex…
ramonjd 910aa4b
There should be a classname for font presets
ramonjd b05d36c
Adding selectors for global styles.
ramonjd a624453
Adding typography classes in the back end
ramonjd a06e86c
Update packages/block-editor/src/hooks/use-typography-props.js
ramonjd 2bd5d91
Update packages/block-library/src/search/index.php
ramonjd 7146b68
Apply text decoration only to label and button
ramonjd 3865941
The attributes were in the wrong order! Who would have thunk it?!
ramonjd 384ce7d
Ensure typography font size and family classnames appear on the wrapp…
ramonjd f778d69
Clean up unnecessary destructuring
aaronrobertshaw baba42d
Revert "Clean up unnecessary destructuring"
aaronrobertshaw a0a201c
Revert "Ensure typography font size and family classnames appear on t…
aaronrobertshaw e62be9f
Switch approach to target inner elements again
aaronrobertshaw fb523ca
Keep linter happy
aaronrobertshaw b32ab5f
Reapply clean up and force text-decoration unset
aaronrobertshaw d0aa4a3
Avoid confusion over font-family being in classes and inline styles
aaronrobertshaw b2e2faa
Fix vertical alignment of icon only button
aaronrobertshaw 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
28 changes: 28 additions & 0 deletions
28
packages/block-editor/src/hooks/test/use-typography-props.js
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,28 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getTypographyClassesAndStyles } from '../use-typography-props'; | ||
|
||
describe( 'getTypographyClassesAndStyles', () => { | ||
it( 'should return styles and classes', () => { | ||
const attributes = { | ||
fontFamily: 'tofu', | ||
fontSize: 'large', | ||
style: { | ||
typography: { | ||
letterSpacing: '22px', | ||
fontSize: '2rem', | ||
textTransform: 'uppercase', | ||
}, | ||
}, | ||
}; | ||
expect( getTypographyClassesAndStyles( attributes ) ).toEqual( { | ||
className: 'has-tofu-font-family has-large-font-size', | ||
style: { | ||
letterSpacing: '22px', | ||
fontSize: '2rem', | ||
textTransform: 'uppercase', | ||
}, | ||
} ); | ||
} ); | ||
} ); |
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,41 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { kebabCase } from 'lodash'; | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getInlineStyles } from './style'; | ||
import { getFontSizeClass } from '../components/font-sizes'; | ||
|
||
// This utility is intended to assist where the serialization of the typography | ||
// block support is being skipped for a block but the typography related CSS | ||
// styles still need to be generated so they can be applied to inner elements. | ||
|
||
/** | ||
* Provides the CSS class names and inline styles for a block's typography support | ||
* attributes. | ||
* | ||
* @param {Object} attributes Block attributes. | ||
* | ||
* @return {Object} Typography block support derived CSS classes & styles. | ||
*/ | ||
export function getTypographyClassesAndStyles( attributes ) { | ||
const typographyStyles = attributes?.style?.typography || {}; | ||
const style = getInlineStyles( { typography: typographyStyles } ); | ||
const fontFamilyClassName = !! attributes?.fontFamily | ||
? `has-${ kebabCase( attributes.fontFamily ) }-font-family` | ||
: ''; | ||
|
||
const className = classnames( | ||
fontFamilyClassName, | ||
getFontSizeClass( attributes?.fontSize ) | ||
); | ||
|
||
return { | ||
className, | ||
style, | ||
}; | ||
} |
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
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.
Should we be marking this experimental?
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.
@ramonjd initially had this as experimental until I suggested it be stabilized as we'll be stabilizing all experimental block support APIs post-6.1. This would just be another experimental API to process. Given it follows the same pattern as the other block supports, e.g. color and border, and they're due for stabilization. I figure we can save double handling this one.
We can change this if you have strong concerns.
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.
That makes sense to me! If color/border are similar and we're not planning on making further changes before stabilising, I wouldn't be opposed to doing it pre-6.1 either. Or were we aiming to stabilise all block supports together? It might take a while to get layout up to spec 😬
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.
To my knowledge, there are no plans for further changes to these util functions. I was under the impression that we'd stabilize each block support in full, e.g. all the typography support APIs, then color, and so on. Layout support has always been a special case, so I don't think there is a rush to stabilize it before it's ready.
Regarding stabilizing the others pre-6.1, I don't think that's on the cards. My focus has been on adopting the block supports more consistently within Gutenberg and then seeing if there is anything we should alter before stabilizating them.
That said, if there's a window in which we could actually get it all done, I wouldn't be against it.