Skip to content

Commit

Permalink
Centralize client side global styles mappings (#25056)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored Sep 8, 2020
1 parent 149849e commit d978655
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
7 changes: 0 additions & 7 deletions packages/block-editor/src/hooks/padding.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,3 @@ export function PaddingEdit( props ) {
native: null,
} );
}

export const paddingStyleMappings = {
paddingTop: [ 'spacing', 'padding', 'top' ],
paddingRight: [ 'spacing', 'padding', 'right' ],
paddingBottom: [ 'spacing', 'padding', 'bottom' ],
paddingLeft: [ 'spacing', 'padding', 'left' ],
};
19 changes: 3 additions & 16 deletions packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ import { createHigherOrderComponent } from '@wordpress/compose';
*/
import { COLOR_SUPPORT_KEY, ColorEdit } from './color';
import { TypographyPanel, TYPOGRAPHY_SUPPORT_KEYS } from './typography';
import {
PADDING_SUPPORT_KEY,
PaddingEdit,
paddingStyleMappings,
} from './padding';
import { PADDING_SUPPORT_KEY, PaddingEdit } from './padding';
import SpacingPanelControl from '../components/spacing-panel-control';
import { STYLE_MAPPINGS } from './utils';

const styleSupportKeys = [
...TYPOGRAPHY_SUPPORT_KEYS,
Expand Down Expand Up @@ -52,18 +49,8 @@ function compileStyleValue( uncompiledValue ) {
* @return {Object} Flattened CSS variables declaration
*/
export function getInlineStyles( styles = {} ) {
const mappings = {
...paddingStyleMappings,
lineHeight: [ 'typography', 'lineHeight' ],
fontSize: [ 'typography', 'fontSize' ],
background: [ 'color', 'gradient' ],
backgroundColor: [ 'color', 'background' ],
color: [ 'color', 'text' ],
'--wp--style--color--link': [ 'color', 'link' ],
};

const output = {};
Object.entries( mappings ).forEach(
Object.entries( STYLE_MAPPINGS ).forEach(
( [ styleKey, ...otherObjectKeys ] ) => {
const [ objectKeys ] = otherObjectKeys;

Expand Down
13 changes: 13 additions & 0 deletions packages/block-editor/src/hooks/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ export const cleanEmptyObject = ( object ) => {
? undefined
: cleanedNestedObjects;
};

export const STYLE_MAPPINGS = {
lineHeight: [ 'typography', 'lineHeight' ],
fontSize: [ 'typography', 'fontSize' ],
background: [ 'color', 'gradient' ],
backgroundColor: [ 'color', 'background' ],
color: [ 'color', 'text' ],
'--wp--style--color--link': [ 'color', 'link' ],
paddingTop: [ 'spacing', 'padding', 'top' ],
paddingRight: [ 'spacing', 'padding', 'right' ],
paddingBottom: [ 'spacing', 'padding', 'bottom' ],
paddingLeft: [ 'spacing', 'padding', 'left' ],
};
1 change: 1 addition & 0 deletions packages/block-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './components';
export * from './utils';
export { storeConfig } from './store';
export { SETTINGS_DEFAULTS } from './store/defaults';
export { STYLE_MAPPINGS as __EXPERIMENTAL_STYLE_MAPPINGS } from './hooks/utils';

0 comments on commit d978655

Please sign in to comment.