-
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.
feature: Add ability for themes to configure font sizes; Extract font…
…Size logic from paragraph (#6628) Extracts the logic to manage font sizes in a similar way to what we used to abstract the color logic. Refactors the styles, so they are not specific to paragraphs. Now, other blocks can make use of the same classes. The class names were renamed from the format is-large-text to has-large-font-size, this makes the names consistent with the names used in color classes. The new name makes clear that the primary style set is the font-size. Font sizes are now read from editor settings instead of being a constant in the paragraph block.
- Loading branch information
1 parent
94f5489
commit a975273
Showing
11 changed files
with
312 additions
and
66 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
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
14 changes: 14 additions & 0 deletions
14
packages/editor/src/components/font-sizes/font-size-picker.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,14 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { FontSizePicker } from '@wordpress/components'; | ||
import { withSelect } from '@wordpress/data'; | ||
|
||
export default withSelect( | ||
( select ) => { | ||
const { fontSizes } = select( 'core/editor' ).getEditorSettings(); | ||
return { | ||
fontSizes, | ||
}; | ||
} | ||
)( FontSizePicker ); |
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,3 @@ | ||
export { getFontSize, getFontSizeClass } from './utils'; | ||
export { default as FontSizePicker } from './font-size-picker'; | ||
export { default as withFontSizes } from './with-font-sizes'; |
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,43 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { find, kebabCase } from 'lodash'; | ||
|
||
/** | ||
* Returns the font size object based on an array of named font sizes and the namedFontSize and customFontSize values. | ||
* If namedFontSize is undefined or not found in fontSizes an object with just the size value based on customFontSize is returned. | ||
* | ||
* @param {Array} fontSizes Array of font size objects containing at least the "name" and "size" values as properties. | ||
* @param {?string} fontSizeAttribute Content of the font size attribute (slug). | ||
* @param {?number} customFontSizeAttribute Contents of the custom font size attribute (value). | ||
* | ||
* @return {?string} If fontSizeAttribute is set and an equal slug is found in fontSizes it returns the font size object for that slug. | ||
* Otherwise, an object with just the size value based on customFontSize is returned. | ||
*/ | ||
export const getFontSize = ( fontSizes, fontSizeAttribute, customFontSizeAttribute ) => { | ||
if ( fontSizeAttribute ) { | ||
const fontSizeObject = find( fontSizes, { slug: fontSizeAttribute } ); | ||
if ( fontSizeObject ) { | ||
return fontSizeObject; | ||
} | ||
} | ||
return { | ||
size: customFontSizeAttribute, | ||
}; | ||
}; | ||
|
||
/** | ||
* Returns a class based on fontSizeName. | ||
* | ||
* @param {string} fontSizeSlug Slug of the fontSize. | ||
* | ||
* @return {string} String with the class corresponding to the fontSize passed. | ||
* The class is generated by appending 'has-' followed by fontSizeSlug in kebabCase and ending with '-font-size'. | ||
*/ | ||
export function getFontSizeClass( fontSizeSlug ) { | ||
if ( ! fontSizeSlug ) { | ||
return; | ||
} | ||
|
||
return `has-${ kebabCase( fontSizeSlug ) }-font-size`; | ||
} |
Oops, something went wrong.