-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Letter-spacing and enable this for site title and site tagline (#…
…31118) * Add Letter-spacing and enable this for site title and site tagline
- Loading branch information
Showing
11 changed files
with
176 additions
and
4 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
46 changes: 46 additions & 0 deletions
46
packages/block-editor/src/components/letter-spacing-control/index.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,46 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalUnitControl as UnitControl } from '@wordpress/components'; | ||
import { Platform } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
const isWeb = Platform.OS === 'web'; | ||
|
||
const CSS_UNITS = [ | ||
{ | ||
value: 'px', | ||
label: isWeb ? 'px' : __( 'Pixels (px)' ), | ||
default: '2', | ||
}, | ||
{ | ||
value: 'em', | ||
label: isWeb ? 'em' : __( 'Relative to parent font size (em)' ), | ||
default: '.2', | ||
}, | ||
{ | ||
value: 'rem', | ||
label: isWeb ? 'rem' : __( 'Relative to root font size (rem)' ), | ||
default: '.2', | ||
}, | ||
]; | ||
|
||
/** | ||
* Control for letter-spacing. | ||
* | ||
* @param {Object} props Component props. | ||
* @param {string} props.value Currently selected letter-spacing. | ||
* @param {Function} props.onChange Handles change in letter-spacing selection. | ||
* @return {WPElement} Letter-spacing control. | ||
*/ | ||
export default function LetterSpacingControl( { value, onChange } ) { | ||
return ( | ||
<UnitControl | ||
label={ __( 'Letter-spacing' ) } | ||
value={ value } | ||
__unstableInputWidth="60px" | ||
units={ CSS_UNITS } | ||
onChange={ onChange } | ||
/> | ||
); | ||
} |
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,71 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { hasBlockSupport } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import LetterSpacingControl from '../components/letter-spacing-control'; | ||
import useSetting from '../components/use-setting'; | ||
import { cleanEmptyObject } from './utils'; | ||
|
||
/** | ||
* Key within block settings' supports array indicating support for letter-spacing | ||
* e.g. settings found in `block.json`. | ||
*/ | ||
export const LETTER_SPACING_SUPPORT_KEY = '__experimentalLetterSpacing'; | ||
|
||
/** | ||
* Inspector control panel containing the letter-spacing options. | ||
* | ||
* @param {Object} props Block properties. | ||
* @return {WPElement} Letter-spacing edit element. | ||
*/ | ||
export function LetterSpacingEdit( props ) { | ||
const { | ||
attributes: { style }, | ||
setAttributes, | ||
} = props; | ||
|
||
const isDisabled = useIsLetterSpacingDisabled( props ); | ||
|
||
if ( isDisabled ) { | ||
return null; | ||
} | ||
|
||
function onChange( newSpacing ) { | ||
setAttributes( { | ||
style: cleanEmptyObject( { | ||
...style, | ||
typography: { | ||
...style?.typography, | ||
letterSpacing: newSpacing, | ||
}, | ||
} ), | ||
} ); | ||
} | ||
|
||
return ( | ||
<LetterSpacingControl | ||
value={ style?.typography?.letterSpacing } | ||
onChange={ onChange } | ||
/> | ||
); | ||
} | ||
|
||
/** | ||
* Checks if letter-spacing settings have been disabled. | ||
* | ||
* @param {string} name Name of the block. | ||
* @return {boolean} Whether or not the setting is disabled. | ||
*/ | ||
export function useIsLetterSpacingDisabled( { name: blockName } = {} ) { | ||
const notSupported = ! hasBlockSupport( | ||
blockName, | ||
LETTER_SPACING_SUPPORT_KEY | ||
); | ||
const hasLetterSpacing = useSetting( 'typography.customLetterSpacing' ); | ||
|
||
return notSupported || ! hasLetterSpacing; | ||
} |
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