Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global Styles: Add block variations to the isactive style variation calculation #62798

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { privateApis as editorPrivateApis } from '@wordpress/editor';
import { filterObjectByProperty } from '../../../hooks/use-theme-style-variations/use-theme-style-variations-by-property';
import { unlock } from '../../../lock-unlock';

const { mergeBaseAndUserConfigs } = unlock( editorPrivateApis );
const { mergeBaseAndUserConfigs, useResolvedBlockStyleVariationsConfig } =
unlock( editorPrivateApis );
const { GlobalStylesContext, areGlobalStyleConfigsEqual } = unlock(
blockEditorPrivateApis
);
Expand Down Expand Up @@ -49,9 +50,15 @@ export default function Variation( { variation, children, isPill, property } ) {
}
};

const varitationWithBlockStyleVariation =
useResolvedBlockStyleVariationsConfig( variation );
const isActive = useMemo(
() => areGlobalStyleConfigsEqual( user, variation ),
[ user, variation ]
() =>
areGlobalStyleConfigsEqual(
user,
varitationWithBlockStyleVariation
),
[ user, varitationWithBlockStyleVariation ]
);

let label = variation?.title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function mergeBaseAndUserConfigs( base, user ) {
* @param {Object} userConfig Current user origin global styles data.
* @return {Object} Updated global styles data.
*/
function useResolvedBlockStyleVariationsConfig( userConfig ) {
export function useResolvedBlockStyleVariationsConfig( userConfig ) {
const { getBlockStyles } = useSelect( blocksStore );
const sharedVariations = userConfig?.styles?.blocks?.variations;

Expand Down
3 changes: 2 additions & 1 deletion packages/editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ResizableEditor from './components/resizable-editor';
import {
mergeBaseAndUserConfigs,
GlobalStylesProvider,
useResolvedBlockStyleVariationsConfig,
} from './components/global-styles-provider';

const { store: interfaceStore, ...remainingInterfaceApis } = interfaceApis;
Expand All @@ -41,7 +42,7 @@ lock( privateApis, {
ToolsMoreMenuGroup,
ViewMoreMenuGroup,
ResizableEditor,

useResolvedBlockStyleVariationsConfig,
// This is a temporary private API while we're updating the site editor to use EditorProvider.
useBlockEditorSettings,
interfaceStore,
Expand Down
Loading