Skip to content

Commit

Permalink
Integrate overview section.
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Nov 18, 2024
1 parent 5de50f5 commit 199f95c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
10 changes: 8 additions & 2 deletions packages/edit-site/src/classic-stylebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import { store as editSiteStore } from './store';
import Layout from './components/layout';
import { unlock } from './lock-unlock';
import SidebarNavigationScreen from './components/sidebar-navigation-screen/index.js';
import { StyleBookBody } from './components/style-book';
import {
StyleBookBody,
getExamplesForSinglePageUse,
} from './components/style-book';
import { getExamples } from './components/style-book/examples';

const { RouterProvider } = unlock( routerPrivateApis );
Expand All @@ -47,6 +50,9 @@ function ClassicStylebookLayout() {
);

const examples = getExamples();
// Dedupe the examples as they include all categories with repeat sections.
const examplesForSinglePageUse = getExamplesForSinglePageUse( examples );

const route = {
name: 'stylebook',
areas: {
Expand All @@ -64,7 +70,7 @@ function ClassicStylebookLayout() {
showTabs={ false }
isSelected={ () => null }
onSelect={ () => null }
examples={ examples }
examples={ examplesForSinglePageUse }
onClick={ () => null }
settings={ settings }
sizes={ sizes }
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-site/src/components/style-book/examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ function getOverviewBlockExamples(
): BlockExample[] {
const examples: BlockExample[] = [];

// Get theme palette from colors.
const themePalette = colors.colors.find(
// Get theme palette from colors if they exist.
const themePalette = colors?.colors.find(
( origin: ColorOrigin ) => origin.slug === 'theme'
);

Expand Down
41 changes: 26 additions & 15 deletions packages/edit-site/src/components/style-book/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,31 @@ function useMultiOriginPalettes() {
return palettes;
}

/**
* Get deduped examples for single page stylebook.
* @param {Array} examples Array of examples.
* @return {Array} Deduped examples.
*/
export function getExamplesForSinglePageUse( examples ) {
const examplesForSinglePageUse = [];
const overviewCategoryExamples = getExamplesByCategory(
{ slug: 'overview' },
examples
);
examplesForSinglePageUse.push( ...overviewCategoryExamples.examples );
const otherExamples = examples.filter( ( example ) => {
return (
example.category !== 'overview' &&
! overviewCategoryExamples.examples.find(
( overviewExample ) => overviewExample.name === example.name
)
);
} );
examplesForSinglePageUse.push( ...otherExamples );

return examplesForSinglePageUse;
}

function StyleBook( {
enableResizing = true,
isSelected,
Expand All @@ -203,21 +228,7 @@ function StyleBook( {
[ examples ]
);

const examplesForSinglePageUse = [];
const overviewCategoryExamples = getExamplesByCategory(
{ slug: 'overview' },
examples
);
examplesForSinglePageUse.push( ...overviewCategoryExamples.examples );
const otherExamples = examples.filter( ( example ) => {
return (
example.category !== 'overview' &&
! overviewCategoryExamples.examples.find(
( overviewExample ) => overviewExample.name === example.name
)
);
} );
examplesForSinglePageUse.push( ...otherExamples );
const examplesForSinglePageUse = getExamplesForSinglePageUse( examples );

const { base: baseConfig } = useContext( GlobalStylesContext );
const goTo = getStyleBookNavigationFromPath( path );
Expand Down

0 comments on commit 199f95c

Please sign in to comment.