-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search block: Add typography supports (#43499)
- Loading branch information
Showing
10 changed files
with
242 additions
and
17 deletions.
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.