-
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
- Loading branch information
1 parent
09db904
commit d0a4747
Showing
11 changed files
with
302 additions
and
65 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
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.