Skip to content

Commit 164c669

Browse files
tellthemachinesramonjdaaronrobertshawandrewserongjasmussen
authored andcommitted
Add a landing section to stylebook tabs (WordPress#66545)
Co-authored-by: tellthemachines <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]> Co-authored-by: andrewserong <[email protected]> Co-authored-by: jasmussen <[email protected]> Co-authored-by: beafialho <[email protected]>
1 parent 0a1b5a9 commit 164c669

File tree

6 files changed

+146
-11
lines changed

6 files changed

+146
-11
lines changed

packages/edit-site/src/components/global-styles/ui.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ function GlobalStylesStyleBook() {
202202
navigator.goTo( '/colors/palette' );
203203
return;
204204
}
205+
if ( blockName === 'typography' ) {
206+
// Go to typography Global Styles.
207+
navigator.goTo( '/typography' );
208+
return;
209+
}
205210

206211
// Now go to the selected block.
207212
navigator.goTo( '/blocks/' + encodeURIComponent( blockName ) );

packages/edit-site/src/components/sidebar-global-styles-wrapper/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ export default function GlobalStylesUIWrapper() {
132132
onPathChange( '/colors/palette' );
133133
return;
134134
}
135+
if ( blockName === 'typography' ) {
136+
// Go to typography Global Styles.
137+
onPathChange( '/typography' );
138+
return;
139+
}
135140

136141
// Now go to the selected block.
137142
onPathChange(

packages/edit-site/src/components/style-book/constants.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ export const STYLE_BOOK_THEME_SUBCATEGORIES: Omit<
107107
];
108108

109109
export const STYLE_BOOK_CATEGORIES: StyleBookCategory[] = [
110+
{
111+
slug: 'overview',
112+
title: __( 'Overview' ),
113+
blocks: [],
114+
},
110115
{
111116
slug: 'text',
112117
title: __( 'Text' ),
@@ -249,6 +254,10 @@ export const STYLE_BOOK_IFRAME_STYLES = `
249254
.edit-site-style-book__example-preview {
250255
width: 100%;
251256
}
257+
258+
.is-wide .edit-site-style-book__example-preview {
259+
width: calc(100% - 120px);
260+
}
252261
253262
.edit-site-style-book__example-preview .block-editor-block-list__insertion-point,
254263
.edit-site-style-book__example-preview .block-list-appender {

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

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,103 @@ function getColorExamples( colors: MultiOriginPalettes ): BlockExample[] {
6262
return examples;
6363
}
6464

65+
/**
66+
* Returns examples for the overview page.
67+
*
68+
* @param {MultiOriginPalettes} colors Global Styles color palettes per origin.
69+
* @return {BlockExample[]} An array of block examples.
70+
*/
71+
function getOverviewBlockExamples(
72+
colors: MultiOriginPalettes
73+
): BlockExample[] {
74+
const examples: BlockExample[] = [];
75+
76+
// Get theme palette from colors.
77+
const themePalette = colors.colors.find(
78+
( origin: ColorOrigin ) => origin.slug === 'theme'
79+
);
80+
81+
if ( themePalette ) {
82+
const themeColorexample: BlockExample = {
83+
name: 'theme-colors',
84+
title: __( 'Colors' ),
85+
category: 'overview',
86+
content: (
87+
<ColorExamples colors={ themePalette.colors } type={ colors } />
88+
),
89+
};
90+
91+
examples.push( themeColorexample );
92+
}
93+
94+
const headingBlock = createBlock( 'core/heading', {
95+
content: __(
96+
`AaBbCcDdEeFfGgHhiiJjKkLIMmNnOoPpQakRrssTtUuVVWwXxxYyZzOl23356789X{(…)},2!*&:/A@HELFO™`
97+
),
98+
level: 1,
99+
} );
100+
const firstParagraphBlock = createBlock( 'core/paragraph', {
101+
content: __(
102+
`A paragraph in a website refers to a distinct block of text that is used to present and organize information. It is a fundamental unit of content in web design and is typically composed of a group of related sentences or thoughts focused on a particular topic or idea. Paragraphs play a crucial role in improving the readability and user experience of a website. They break down the text into smaller, manageable chunks, allowing readers to scan the content more easily.`
103+
),
104+
} );
105+
const secondParagraphBlock = createBlock( 'core/paragraph', {
106+
content: __(
107+
`Additionally, paragraphs help structure the flow of information and provide logical breaks between different concepts or pieces of information. In terms of formatting, paragraphs in websites are commonly denoted by a vertical gap or indentation between each block of text. This visual separation helps visually distinguish one paragraph from another, creating a clear and organized layout that guides the reader through the content smoothly.`
108+
),
109+
} );
110+
111+
const textExample = {
112+
name: 'typography',
113+
title: __( 'Typography' ),
114+
category: 'overview',
115+
blocks: [
116+
headingBlock,
117+
createBlock(
118+
'core/group',
119+
{
120+
layout: {
121+
type: 'grid',
122+
columnCount: 2,
123+
minimumColumnWidth: '12rem',
124+
},
125+
style: {
126+
spacing: {
127+
blockGap: '1.5rem',
128+
},
129+
},
130+
},
131+
[ firstParagraphBlock, secondParagraphBlock ]
132+
),
133+
],
134+
};
135+
examples.push( textExample );
136+
137+
const otherBlockExamples = [
138+
'core/image',
139+
'core/separator',
140+
'core/buttons',
141+
'core/pullquote',
142+
'core/search',
143+
];
144+
145+
// Get examples for other blocks and put them in order of above array.
146+
otherBlockExamples.forEach( ( blockName ) => {
147+
const blockType = getBlockType( blockName );
148+
if ( blockType && blockType.example ) {
149+
const blockExample: BlockExample = {
150+
name: blockName,
151+
title: blockType.title,
152+
category: 'overview',
153+
blocks: getBlockFromExample( blockName, blockType.example ),
154+
};
155+
examples.push( blockExample );
156+
}
157+
} );
158+
159+
return examples;
160+
}
161+
65162
/**
66163
* Returns a list of examples for registered block types.
67164
*
@@ -109,5 +206,12 @@ export function getExamples( colors: MultiOriginPalettes ): BlockExample[] {
109206
};
110207
const colorExamples = getColorExamples( colors );
111208

112-
return [ headingsExample, ...colorExamples, ...nonHeadingBlockExamples ];
209+
const overviewBlockExamples = getOverviewBlockExamples( colors );
210+
211+
return [
212+
headingsExample,
213+
...colorExamples,
214+
...nonHeadingBlockExamples,
215+
...overviewBlockExamples,
216+
];
113217
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,22 @@ function StyleBook( {
203203
[ examples ]
204204
);
205205

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 );
221+
206222
const { base: baseConfig } = useContext( GlobalStylesContext );
207223
const goTo = getStyleBookNavigationFromPath( path );
208224

@@ -286,7 +302,7 @@ function StyleBook( {
286302
</Tabs>
287303
) : (
288304
<StyleBookBody
289-
examples={ examples }
305+
examples={ examplesForSinglePageUse }
290306
isSelected={ isSelected }
291307
onClick={ onClick }
292308
onSelect={ onSelect }

test/e2e/specs/site-editor/style-book.spec.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,10 @@ test.describe( 'Style Book', () => {
5252
'[name="style-book-canvas"]'
5353
);
5454

55+
// In the Overview tab, expect a button for the main typography section.
5556
await expect(
5657
styleBookIframe.getByRole( 'button', {
57-
name: 'Open Headings styles in Styles panel',
58-
} )
59-
).toBeVisible();
60-
await expect(
61-
styleBookIframe.getByRole( 'button', {
62-
name: 'Open Paragraph styles in Styles panel',
58+
name: 'Open Typography styles in Styles panel',
6359
} )
6460
).toBeVisible();
6561

@@ -83,13 +79,13 @@ test.describe( 'Style Book', () => {
8379
await page
8480
.frameLocator( '[name="style-book-canvas"]' )
8581
.getByRole( 'button', {
86-
name: 'Open Headings styles in Styles panel',
82+
name: 'Open Image styles in Styles panel',
8783
} )
8884
.click();
8985

9086
await expect(
9187
page.locator(
92-
'role=region[name="Editor settings"i] >> role=heading[name="Heading"i]'
88+
'role=region[name="Editor settings"i] >> role=heading[name="Image"i]'
9389
)
9490
).toBeVisible();
9591
} );
@@ -103,7 +99,7 @@ test.describe( 'Style Book', () => {
10399
await page
104100
.frameLocator( '[name="style-book-canvas"]' )
105101
.getByRole( 'button', {
106-
name: 'Open Quote styles in Styles panel',
102+
name: 'Open Pullquote styles in Styles panel',
107103
} )
108104
.click();
109105

0 commit comments

Comments
 (0)