Skip to content

Commit

Permalink
Make useStyleOverride public
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jul 17, 2024
1 parent 8112ec2 commit df6ca27
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 17 deletions.
10 changes: 10 additions & 0 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,16 @@ _Returns_

- `any[]`: Returns the values defined for the settings.

### useStyleOverride

Override a block editor settings style. Leave the ID blank to create a new style.

_Parameters_

- _$0_ `Object`: Named parameters.
- _$0.id_ `string`: Id of the style override, leave blank to create a new style.
- _$0.css_ `string`: CSS to apply.

### useZoomOut

A hook used to set the editor mode to zoomed out mode, invoking the hook sets the mode.
Expand Down
6 changes: 3 additions & 3 deletions packages/block-editor/src/hooks/block-style-variation.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
toStyles,
getBlockSelectors,
} from '../components/global-styles';
import { useStyleOverride } from './utils';
import { usePrivateStyleOverride } from './utils';
import { getValueFromObjectPath } from '../utils/object';
import { store as blockEditorStore } from '../store';
import { globalStylesDataKey } from '../store/private-keys';
Expand Down Expand Up @@ -63,7 +63,7 @@ function getVariationNameFromClass( className, registeredStyles = [] ) {

// A helper component to apply a style override using the useStyleOverride hook.
function OverrideStyles( { override } ) {
useStyleOverride( override );
usePrivateStyleOverride( override );
}

/**
Expand Down Expand Up @@ -351,7 +351,7 @@ function useBlockProps( { name, className, clientId } ) {
);
}, [ variation, settings, styles, getBlockStyles, clientId ] );

useStyleOverride( {
usePrivateStyleOverride( {
id: `variation-${ clientId }`,
css: variationStyles,
__unstableType: 'variation',
Expand Down
6 changes: 3 additions & 3 deletions packages/block-editor/src/hooks/duotone.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
} from '../components/duotone/utils';
import { getBlockCSSSelector } from '../components/global-styles/get-block-css-selector';
import { scopeSelector } from '../components/global-styles/utils';
import { useBlockSettings, useStyleOverride } from './utils';
import { useBlockSettings, usePrivateStyleOverride } from './utils';
import { default as StylesFiltersPanel } from '../components/global-styles/filters-panel';
import { useBlockEditingMode } from '../components/block-editing-mode';
import { __unstableUseBlockElement as useBlockElement } from '../components/block-list/use-block-props/use-block-refs';
Expand Down Expand Up @@ -265,7 +265,7 @@ function useDuotoneStyles( {

const isValidFilter = Array.isArray( colors ) || colors === 'unset';

useStyleOverride(
usePrivateStyleOverride(
isValidFilter
? {
css:
Expand All @@ -276,7 +276,7 @@ function useDuotoneStyles( {
}
: undefined
);
useStyleOverride(
usePrivateStyleOverride(
isValidFilter
? {
assets:
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ export { useCachedTruthy } from './use-cached-truthy';
export { setBackgroundStyleDefaults } from './background';
export { useZoomOut } from './use-zoom-out';
export { __unstableBlockStyleVariationOverridesWithConfig } from './block-style-variation';
export { useStyleOverride } from './utils';
15 changes: 14 additions & 1 deletion packages/block-editor/src/hooks/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,20 @@ export function shouldSkipSerialization(

const pendingStyleOverrides = new WeakMap();

export function useStyleOverride( {
/**
* Override a block editor settings style. Leave the ID blank to create a new
* style.
*
* @param {Object} $0 Named parameters.
* @param {string} $0.id Id of the style override, leave blank to create a new
* style.
* @param {string} $0.css CSS to apply.
*/
export function useStyleOverride( { id, css } ) {
return usePrivateStyleOverride( { id, css } );
}

export function usePrivateStyleOverride( {
id,
css,
assets,
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export {
getShadowClassesAndStyles as __experimentalGetShadowClassesAndStyles,
useCachedTruthy,
useZoomOut,
useStyleOverride,
} from './hooks';
export * from './components';
export * from './elements';
Expand Down
3 changes: 1 addition & 2 deletions packages/block-editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { PrivateListView } from './components/list-view';
import BlockInfo from './components/block-info-slot-fill';
import { useHasBlockToolbar } from './components/block-toolbar/use-has-block-toolbar';
import { cleanEmptyObject, useStyleOverride } from './hooks/utils';
import { cleanEmptyObject } from './hooks/utils';
import BlockQuickNavigation from './components/block-quick-navigation';
import { LayoutStyle } from './components/block-list/layout';
import { BlockRemovalWarningModal } from './components/block-removal-warning-modal';
Expand Down Expand Up @@ -72,7 +72,6 @@ lock( privateApis, {
BlockInfo,
useHasBlockToolbar,
cleanEmptyObject,
useStyleOverride,
BlockQuickNavigation,
LayoutStyle,
BlockRemovalWarningModal,
Expand Down
9 changes: 1 addition & 8 deletions packages/block-library/src/gallery/gap-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@
*/
import {
__experimentalGetGapCSSValue as getGapCSSValue,
privateApis as blockEditorPrivateApis,
useStyleOverride,
} from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import { unlock } from '../lock-unlock';

const { useStyleOverride } = unlock( blockEditorPrivateApis );

export default function GapStyles( { blockGap, clientId } ) {
// --gallery-block--gutter-size is deprecated. --wp--style--gallery-gap-default should be used by themes that want to set a default
// gap on the gallery.
Expand Down

0 comments on commit df6ca27

Please sign in to comment.