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 12, 2024
1 parent 6c6a816 commit e308ab0
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,20 +14,28 @@ 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 (
<Button
isPressed={ isStyleBookOpened }
onClick={ () => {
setIsStyleBookOpened( ! isStyleBookOpened );
const updatedPath = ! isStyleBookOpened
? path.replace( 'styles', stylebookPath )
: path.replace( stylebookPath, 'styles' );
// Navigate to the updated path.
history.navigate( updatedPath );
} }
size="compact"
>
Expand All @@ -38,9 +46,11 @@ const GlobalStylesPageActions = ( {

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 @@ -63,6 +73,7 @@ export default function GlobalStylesUIWrapper() {
<GlobalStylesPageActions
isStyleBookOpened={ isStyleBookOpened }
setIsStyleBookOpened={ setIsStyleBookOpened }
path={ path }
/>
) : null
}
Expand All @@ -74,7 +85,7 @@ export default function GlobalStylesUIWrapper() {
onPathChange={ onChangeSection }
/>
</Page>
{ canvas === 'view' && isStyleBookOpened && (
{ /* { canvas === 'view' && isStyleBookOpened && (
<StyleBook
enableResizing={ false }
showCloseButton={ false }
Expand Down Expand Up @@ -112,7 +123,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 e308ab0

Please sign in to comment.