-
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.
Add FontSizePicker component and refactor paragraph block to use it.
This change makes font size UI generic and allows other blocks to take advantage of the same UI used in the paragraph. Other changes will follow that will abstract other font size logic from paragraph (not just the UI). Themes will also be able to configure the font sizes. The future changes will use this work.
- Loading branch information
1 parent
4dc4c7b
commit cfda02b
Showing
4 changed files
with
97 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { map } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Fragment } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
import Button from '../button'; | ||
import ButtonGroup from '../button-group'; | ||
import RangeControl from '../range-control'; | ||
|
||
export default function FontSizePicker( { fontSizes = [], fallbackFontSize, value, onChange } ) { | ||
return ( | ||
<Fragment> | ||
<div className="components-font-size-picker__buttons"> | ||
<ButtonGroup aria-label={ __( 'Font Size' ) }> | ||
{ map( fontSizes, ( { size, shortName } ) => ( | ||
<Button | ||
key={ size } | ||
isLarge | ||
isPrimary={ value === size } | ||
aria-pressed={ value === size } | ||
onClick={ () => onChange( size ) } | ||
> | ||
{ shortName } | ||
</Button> | ||
) ) } | ||
</ButtonGroup> | ||
<Button | ||
isLarge | ||
onClick={ () => onChange( undefined ) } | ||
> | ||
{ __( 'Reset' ) } | ||
</Button> | ||
</div> | ||
<RangeControl | ||
className="components-font-size-picker__custom-input" | ||
label={ __( 'Custom Size' ) } | ||
value={ value || '' } | ||
initialPosition={ fallbackFontSize } | ||
onChange={ onChange } | ||
min={ 12 } | ||
max={ 100 } | ||
beforeIcon="editor-textcolor" | ||
afterIcon="editor-textcolor" | ||
/> | ||
</Fragment> | ||
); | ||
} |
4 changes: 2 additions & 2 deletions
4
core-blocks/paragraph/editor.scss → components/font-size-picker/style.scss
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