-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feature: Add ability for themes to configure font sizes; Extract fontSize logic from paragraph #6628
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
Merged
jorgefilipecosta
merged 1 commit into
master
from
update/extracted-fontsize-logic-paragraph
Jul 27, 2018
Merged
feature: Add ability for themes to configure font sizes; Extract fontSize logic from paragraph #6628
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
My initial reaction without looking through to see the implementation: Why do we have both
fontSize.classandgetFontSizeClass?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.
We use fontSize.class on the edit method because there it was already computed by the HOC. On the save function we don't use the HOC so we use the getFontSizeClass.
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.
Seems unnecessarily disjointed.
Uh oh!
There was an error while loading. Please reload this page.
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.
The alternatives are:
- not passing class in the HOC and use getFontSizeClass in the edit method (when editing we know class is going to be required so not passing it already is just adding more work to the developers).
- -try to use the HOC in the save (it seems unnecessary as most of its functionality is not used).- Edited: I think this is not an option because the HOC requires context and setAttributes which we don't have on save.
It seems the current version is better than the alternative we have it is also the same that we are doing in the colors logic so a change in this mechanism will require an update to the existing color mechanism so we keep the consistency.