Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
85a9598
Edit block style variations from global styles
tellthemachines Dec 7, 2022
6c065bf
It's not working yet but we'll get there
tellthemachines Dec 8, 2022
6943f00
Hardcoded a bunch of stuff to see if it works
tellthemachines Dec 9, 2022
9f89d2e
Add back empty line
tellthemachines Dec 13, 2022
d6bf36b
update panel paths to use encodeURIComponent
tellthemachines Dec 13, 2022
fd3451b
Move updated sanitize function to 6.2 folder
tellthemachines Dec 13, 2022
91350f4
Output CSS for edited style variations
tellthemachines Dec 13, 2022
564fd4e
Any [a-z]* style variation name should be possible
tellthemachines Dec 14, 2022
822b800
Fix test failures
tellthemachines Dec 14, 2022
201f6a0
Add handling of feature selectors
tellthemachines Dec 15, 2022
6e9f10c
Add colors and typography
tellthemachines Dec 15, 2022
df3c408
Re-add changes to class-wp-theme-json
tellthemachines Dec 19, 2022
79d760b
Fix color paths
tellthemachines Dec 20, 2022
6cfb120
Add dimensions styles
tellthemachines Dec 20, 2022
3467f9d
Bump up front end specificity.
tellthemachines Dec 20, 2022
fa02475
Only core variations should be editable
tellthemachines Dec 20, 2022
60d95e2
Basic functionality to create a new variation
tellthemachines Dec 21, 2022
174f1c7
Revert adding new variations for now
tellthemachines Jan 2, 2023
510aa3f
Add preview panel to variation screen.
tellthemachines Jan 3, 2023
25048fe
ItemGroup UI
tellthemachines Jan 3, 2023
8dab200
Fix color screen bug
tellthemachines Jan 3, 2023
aac1e1b
Disable editing on default styles.
tellthemachines Jan 3, 2023
d8972ce
Fix variation showing on general block preview
tellthemachines Jan 5, 2023
967e319
Fix previews for design tools screens inside variations.
tellthemachines Jan 5, 2023
127305a
Address feedback.
tellthemachines Jan 6, 2023
513db1c
Remove default variation from panel.
tellthemachines Jan 6, 2023
a6b2d9c
Default style should always be called Default.
tellthemachines Jan 11, 2023
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
Prev Previous commit
Next Next commit
Basic functionality to create a new variation
  • Loading branch information
tellthemachines committed Jan 2, 2023
commit 60d95e21ea05f0442489e30f5c916590a347fb62
9 changes: 8 additions & 1 deletion lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -2165,9 +2165,16 @@ private static function get_block_nodes( $theme_json, $selectors = array() ) {
$variation_selectors = array();
if ( isset( $node['variations'] ) ) {
foreach ( $node['variations'] as $variation => $node ) {
// There might not be a selector if this is a newly created variation, so we need to provide one.
$variation_selector = '';
if ( isset( $selectors[ $name ]['styleVariations'][ $variation ] ) ) {
$variation_selector = $selectors[ $name ]['styleVariations'][ $variation ];
} elseif ( isset( $selectors[ $name ]['selector'] ) ) {
$variation_selector = '.is-style-' . $variation . '.is-style-' . $variation . $selectors[ $name ]['selector'];
}
$variation_selectors[] = array(
'path' => array( 'styles', 'blocks', $name, 'variations', $variation ),
'selector' => $selectors[ $name ]['styleVariations'][ $variation ],
'selector' => $variation_selector,
);
}
}
Expand Down
50 changes: 32 additions & 18 deletions packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ function GlobalStylesNavigationScreen( { className, ...props } ) {
);
}

function BlockStyleVariationsScreens( { name } ) {
const blockStyleVariations = useSelect(
( select ) => {
const { getBlockStyles } = select( blocksStore );
return getBlockStyles( name );
},
[ name ]
);
if ( ! blockStyleVariations?.length ) {
return null;
}

return blockStyleVariations.map( ( variation ) => (
<ContextScreens
key={ variation.name + name }
name={ name }
parentMenu={
'/blocks/' +
encodeURIComponent( name ) +
'/variations/' +
encodeURIComponent( variation.name )
}
/>
) );
}

function ContextScreens( { name, parentMenu = '' } ) {
const hasVariationPath = parentMenu.search( 'variations' );
const variationPath =
Expand Down Expand Up @@ -212,9 +238,7 @@ function GlobalStylesStyleBook( { onClose } ) {

function GlobalStylesUI( { isStyleBookOpened, onCloseStyleBook } ) {
const blocks = getBlockTypes();
const getBlockStyles = useSelect( ( select ) => {
return select( blocksStore ).getBlockStyles;
}, [] );

return (
<NavigatorProvider
className="edit-site-global-styles-sidebar__navigator-provider"
Expand Down Expand Up @@ -251,23 +275,13 @@ function GlobalStylesUI( { isStyleBookOpened, onCloseStyleBook } ) {
/>
) ) }

{ blocks.map( ( block ) => {
const blockStyleVariations = getBlockStyles( block.name );
if ( ! blockStyleVariations?.length ) {
return null;
}
return blockStyleVariations.map( ( variation ) => (
<ContextScreens
key={ variation.name + block.name }
{ blocks.map( ( block, index ) => {
return (
<BlockStyleVariationsScreens
key={ 'screens-block-styles-' + block.name + index }
name={ block.name }
parentMenu={
'/blocks/' +
encodeURIComponent( block.name ) +
'/variations/' +
encodeURIComponent( variation.name )
}
/>
) );
);
} ) }
{ isStyleBookOpened && (
<GlobalStylesStyleBook onClose={ onCloseStyleBook } />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* WordPress dependencies
*/
import { store as blocksStore } from '@wordpress/blocks';
import { store as blocksStore, registerBlockStyle } from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';
import { Button } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -15,6 +16,10 @@ function getCoreBlockStyles( blockStyles ) {
return blockStyles?.filter( ( style ) => style.source === 'block' );
}

function getUserBlockStyles( blockStyles ) {
return blockStyles?.filter( ( style ) => style.source === 'user' );
}

export function useHasVariationsPanel( name, parentMenu = '' ) {
const isInsideVariationsPanel = parentMenu.includes( 'variations' );
const blockStyles = useSelect(
Expand All @@ -25,7 +30,11 @@ export function useHasVariationsPanel( name, parentMenu = '' ) {
[ name ]
);
const coreBlockStyles = getCoreBlockStyles( blockStyles );
return !! coreBlockStyles?.length && ! isInsideVariationsPanel;
const userBlockStyles = getUserBlockStyles( blockStyles );
return (
( !! coreBlockStyles?.length || !! userBlockStyles?.length ) &&
! isInsideVariationsPanel
);
}

export function VariationsPanel( { name } ) {
Expand All @@ -36,11 +45,29 @@ export function VariationsPanel( { name } ) {
},
[ name ]
);
const coreBlockStyles = getCoreBlockStyles( blockStyles );

const coreBlockStyles = getCoreBlockStyles( blockStyles );
const userBlockStyles = getUserBlockStyles( blockStyles );
const allBlockStyles = [ ...coreBlockStyles, ...userBlockStyles ];
return (
<>
{ coreBlockStyles.map( ( style, index ) => (
<p>
Manage and create style variations, saved block appearance
presets
</p>
<Button
variant="primary"
onClick={ () => {
registerBlockStyle( name, {
name: `custom-style-${ userBlockStyles?.length + 1 }`,
label: `Custom Style ${ userBlockStyles?.length + 1 }`,
source: 'user',
} );
} }
>
Create new style variation
</Button>
{ allBlockStyles.map( ( style, index ) => (
<NavigationButtonAsItem
key={ index }
icon={ '+' }
Expand Down