Skip to content

Commit 199f95c

Browse files
Integrate overview section.
1 parent 5de50f5 commit 199f95c

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

packages/edit-site/src/classic-stylebook.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ import { store as editSiteStore } from './store';
3333
import Layout from './components/layout';
3434
import { unlock } from './lock-unlock';
3535
import SidebarNavigationScreen from './components/sidebar-navigation-screen/index.js';
36-
import { StyleBookBody } from './components/style-book';
36+
import {
37+
StyleBookBody,
38+
getExamplesForSinglePageUse,
39+
} from './components/style-book';
3740
import { getExamples } from './components/style-book/examples';
3841

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

4952
const examples = getExamples();
53+
// Dedupe the examples as they include all categories with repeat sections.
54+
const examplesForSinglePageUse = getExamplesForSinglePageUse( examples );
55+
5056
const route = {
5157
name: 'stylebook',
5258
areas: {
@@ -64,7 +70,7 @@ function ClassicStylebookLayout() {
6470
showTabs={ false }
6571
isSelected={ () => null }
6672
onSelect={ () => null }
67-
examples={ examples }
73+
examples={ examplesForSinglePageUse }
6874
onClick={ () => null }
6975
settings={ settings }
7076
sizes={ sizes }

packages/edit-site/src/components/style-book/examples.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ function getOverviewBlockExamples(
7373
): BlockExample[] {
7474
const examples: BlockExample[] = [];
7575

76-
// Get theme palette from colors.
77-
const themePalette = colors.colors.find(
76+
// Get theme palette from colors if they exist.
77+
const themePalette = colors?.colors.find(
7878
( origin: ColorOrigin ) => origin.slug === 'theme'
7979
);
8080

packages/edit-site/src/components/style-book/index.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,31 @@ function useMultiOriginPalettes() {
177177
return palettes;
178178
}
179179

180+
/**
181+
* Get deduped examples for single page stylebook.
182+
* @param {Array} examples Array of examples.
183+
* @return {Array} Deduped examples.
184+
*/
185+
export function getExamplesForSinglePageUse( examples ) {
186+
const examplesForSinglePageUse = [];
187+
const overviewCategoryExamples = getExamplesByCategory(
188+
{ slug: 'overview' },
189+
examples
190+
);
191+
examplesForSinglePageUse.push( ...overviewCategoryExamples.examples );
192+
const otherExamples = examples.filter( ( example ) => {
193+
return (
194+
example.category !== 'overview' &&
195+
! overviewCategoryExamples.examples.find(
196+
( overviewExample ) => overviewExample.name === example.name
197+
)
198+
);
199+
} );
200+
examplesForSinglePageUse.push( ...otherExamples );
201+
202+
return examplesForSinglePageUse;
203+
}
204+
180205
function StyleBook( {
181206
enableResizing = true,
182207
isSelected,
@@ -203,21 +228,7 @@ function StyleBook( {
203228
[ examples ]
204229
);
205230

206-
const examplesForSinglePageUse = [];
207-
const overviewCategoryExamples = getExamplesByCategory(
208-
{ slug: 'overview' },
209-
examples
210-
);
211-
examplesForSinglePageUse.push( ...overviewCategoryExamples.examples );
212-
const otherExamples = examples.filter( ( example ) => {
213-
return (
214-
example.category !== 'overview' &&
215-
! overviewCategoryExamples.examples.find(
216-
( overviewExample ) => overviewExample.name === example.name
217-
)
218-
);
219-
} );
220-
examplesForSinglePageUse.push( ...otherExamples );
231+
const examplesForSinglePageUse = getExamplesForSinglePageUse( examples );
221232

222233
const { base: baseConfig } = useContext( GlobalStylesContext );
223234
const goTo = getStyleBookNavigationFromPath( path );

0 commit comments

Comments
 (0)