-
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.
Move
getSpacingPresetCssVar
to outermost utils folder
- Loading branch information
Showing
8 changed files
with
37 additions
and
36 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
20 changes: 20 additions & 0 deletions
20
packages/block-editor/src/utils/get-spacing-preset-css-var.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,20 @@ | ||
/** | ||
* Converts a spacing preset into a custom value. | ||
* | ||
* @param {string} value Value to convert. | ||
* | ||
* @return {string | undefined} CSS var string for given spacing preset value. | ||
*/ | ||
export function getSpacingPresetCssVar( value ) { | ||
if ( ! value ) { | ||
return; | ||
} | ||
|
||
const slug = value.match( /var:preset\|spacing\|(.+)/ ); | ||
|
||
if ( ! slug ) { | ||
return value; | ||
} | ||
|
||
return `var(--wp--preset--spacing--${ slug[ 1 ] })`; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as transformStyles } from './transform-styles'; | ||
export { default as getPxFromCssUnit } from './get-px-from-css-unit'; | ||
export { useBlockBindingsUtils } from './block-bindings'; | ||
export { getSpacingPresetCssVar } from './get-spacing-preset-css-var'; |
15 changes: 15 additions & 0 deletions
15
packages/block-editor/src/utils/test/get-spacing-preset-css-var.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,15 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getSpacingPresetCssVar } from '../get-spacing-preset-css-var'; | ||
|
||
describe( 'getSpacingPresetCssVar', () => { | ||
it( 'should return original value if not a string in spacing presets var format', () => { | ||
expect( getSpacingPresetCssVar( '20px' ) ).toBe( '20px' ); | ||
} ); | ||
it( 'should return a string in spacing presets css var format with slug from provided value', () => { | ||
expect( getSpacingPresetCssVar( 'var:preset|spacing|20' ) ).toBe( | ||
'var(--wp--preset--spacing--20)' | ||
); | ||
} ); | ||
} ); |