diff --git a/src/editor/components/CodeView.js b/src/editor/components/CodeView.js index ff76a7f..e3a429e 100644 --- a/src/editor/components/CodeView.js +++ b/src/editor/components/CodeView.js @@ -44,17 +44,6 @@ const CodeView = ( { themeConfig } ) => { return part.replace( /%2F/g, '/' ); } ); - /** - * Elements nested under blocks are stored in the styles object - * as `blocks.blockName.elements.elementName`. This code ensures - * that the correct path is used in these cases. - * - * e.g. `/blocks/core%2Fbutton/link` -> `blocks.['core/button'].elements.link` - */ - if ( pathParts[ 0 ] === 'blocks' && pathParts.length >= 3 ) { - pathParts.splice( 2, 0, 'elements' ); - } - /** * Traverse the theme config object to find the code section * that relates to the current navigator location. diff --git a/src/editor/components/NavBlockList.js b/src/editor/components/NavBlockList.js index 5beb3b3..52c3d0b 100644 --- a/src/editor/components/NavBlockList.js +++ b/src/editor/components/NavBlockList.js @@ -1,4 +1,6 @@ import { useContext } from '@wordpress/element'; +import { html, styles } from '@wordpress/icons'; +import { __ } from '@wordpress/i18n'; import EditorContext from '../context/EditorContext'; @@ -7,6 +9,7 @@ import getThemeOption from '../../utils/get-theme-option'; import NavListItem from './NavListItem'; import NavElementList from './NavElementList'; +import NavVariationList from './NavVariationList'; /** * Nav Block list @@ -32,10 +35,20 @@ const NavBlockList = () => { // check if the block has any styles that aren't elements const { elements, ...rest } = blockStyles; const hasBlockStyles = Object.keys( rest ).length > 0; + const varHasStyles = rest?.variations; const route = '/blocks/' + encodeURIComponent( block.name ); + const elementRoute = + '/blocks/' + + encodeURIComponent( block.name ) + + '/elements'; const elementsSelector = `blocks.${ block.name }.elements`; + const varRoute = + '/blocks/' + + encodeURIComponent( block.name ) + + '/variations'; + return ( { route={ route } hasStyles={ hasBlockStyles } > - + + + + + + ); } ) } diff --git a/src/editor/components/NavVariationList.js b/src/editor/components/NavVariationList.js new file mode 100644 index 0000000..b974c38 --- /dev/null +++ b/src/editor/components/NavVariationList.js @@ -0,0 +1,55 @@ +import { isEmpty } from 'lodash'; + +import { useContext } from '@wordpress/element'; +import { handle } from '@wordpress/icons'; + +import EditorContext from '../context/EditorContext'; +import getThemeOption from '../../utils/get-theme-option'; + +import NavListItem from './NavListItem'; + +/** + * Nav Variation list + * + * Renders the variations list in the navigation panel + * + * @param {Object} props Component props + * @param {string} props.selector Selector to locate these variations in the schema + * @param {string} props.route Base route to use when navigating to child elements + */ +const NavVariationList = ( { selector, route } ) => { + const { themeConfig } = useContext( EditorContext ); + + // get styles for all variations at this selector + const themeVarStyles = + getThemeOption( `styles.${ selector }`, themeConfig ) || {}; + + const varStyles = Object.entries( themeVarStyles ).map( ( tab ) => { + return { + name: tab[ 0 ], + }; + } ); + + return ( + <> + + + ); +}; + +export default NavVariationList; diff --git a/src/editor/components/StylesPanel.js b/src/editor/components/StylesPanel.js index 9efa7d5..cecd956 100644 --- a/src/editor/components/StylesPanel.js +++ b/src/editor/components/StylesPanel.js @@ -36,7 +36,7 @@ const StylesPanel = () => { { /* block/element screen */ } - + { { /* block/element/psuedo screen */ } - + + { /* block/variation screen */ } + + + + { /* element screen */ }