Skip to content

Commit

Permalink
Give style book its own route so it can be linked to directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Dec 11, 2024
1 parent 13cd621 commit 1572726
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,42 @@ import { addQueryArgs } from '@wordpress/url';
import GlobalStylesUI from '../global-styles/ui';
import Page from '../page';
import { unlock } from '../../lock-unlock';
import StyleBook from '../style-book';
import { STYLE_BOOK_COLOR_GROUPS } from '../style-book/constants';
// import StyleBook from '../style-book';
// import { STYLE_BOOK_COLOR_GROUPS } from '../style-book/constants';

const { useLocation, useHistory } = unlock( routerPrivateApis );

const GlobalStylesPageActions = ( {
isStyleBookOpened,
setIsStyleBookOpened,
path,
} ) => {
const stylebookPath = 'styles-stylebook';
const history = useHistory();
return (
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Show Style Book' ) }
checked={ isStyleBookOpened }
onChange={ ( newValue ) => {
setIsStyleBookOpened( newValue );
const updatedPath = newValue
? path.replace( 'styles', stylebookPath )
: path.replace( stylebookPath, 'styles' );
// Navigate to the updated path.
history.navigate( updatedPath );
} }
/>
);
};

export default function GlobalStylesUIWrapper() {
const { path, query } = useLocation();

const history = useHistory();
const { canvas = 'view' } = query;
const [ isStyleBookOpened, setIsStyleBookOpened ] = useState( false );
const [ isStyleBookOpened, setIsStyleBookOpened ] = useState(
path.includes( 'styles-stylebook' )
);
const isMobileViewport = useViewportMatch( 'medium', '<' );
const [ section, onChangeSection ] = useMemo( () => {
return [
Expand All @@ -62,6 +72,7 @@ export default function GlobalStylesUIWrapper() {
<GlobalStylesPageActions
isStyleBookOpened={ isStyleBookOpened }
setIsStyleBookOpened={ setIsStyleBookOpened }
path={ path }
/>
) : null
}
Expand All @@ -73,7 +84,7 @@ export default function GlobalStylesUIWrapper() {
onPathChange={ onChangeSection }
/>
</Page>
{ canvas === 'view' && isStyleBookOpened && (
{ /* { canvas === 'view' && isStyleBookOpened && (
<StyleBook
enableResizing={ false }
showCloseButton={ false }
Expand Down Expand Up @@ -111,7 +122,7 @@ export default function GlobalStylesUIWrapper() {
);
} }
/>
) }
) } */ }
</>
);
}
2 changes: 2 additions & 0 deletions packages/edit-site/src/components/site-editor-routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { templateItemRoute } from './template-item';
import { pagesRoute } from './pages';
import { pageItemRoute } from './page-item';
import { stylebookRoute } from './stylebook';
import { stylesStylebookRoute } from './styles-stylebook';

const routes = [
pageItemRoute,
Expand All @@ -35,6 +36,7 @@ const routes = [
stylesRoute,
homeRoute,
stylebookRoute,
stylesStylebookRoute,
];

export function useRegisterSiteEditorRoutes() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* WordPress dependencies
*/
import { privateApis as routerPrivateApis } from '@wordpress/router';

/**
* Internal dependencies
*/
import Editor from '../editor';
import { unlock } from '../../lock-unlock';
import SidebarNavigationScreenGlobalStyles from '../sidebar-navigation-screen-global-styles';
import GlobalStylesUIWrapper from '../sidebar-global-styles-wrapper';
import { StyleBookPreview } from '../style-book';

const { useLocation } = unlock( routerPrivateApis );

function MobileGlobalStylesUI() {
const { query = {} } = useLocation();
const { canvas } = query;

if ( canvas === 'edit' ) {
return <Editor />;
}

return <GlobalStylesUIWrapper />;
}

export const stylesStylebookRoute = {
name: 'styles-stylebook',
path: '/styles-stylebook',
areas: {
content: <GlobalStylesUIWrapper />,
sidebar: <SidebarNavigationScreenGlobalStyles backPath="/" />,
preview: <StyleBookPreview />,
mobile: <MobileGlobalStylesUI />,
},
widths: {
content: 380,
},
};

0 comments on commit 1572726

Please sign in to comment.