From 24b0b9ccd10cf31b47bd31ff74fcb1a27cb2bdd7 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Thu, 14 Sep 2023 22:08:32 +0100 Subject: [PATCH 01/11] Add e2e test for variant panel --- .../specs/site-editor/font-library.spec.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/e2e/specs/site-editor/font-library.spec.js b/test/e2e/specs/site-editor/font-library.spec.js index e6521cb7c540bc..d474cbcbb92eb7 100644 --- a/test/e2e/specs/site-editor/font-library.spec.js +++ b/test/e2e/specs/site-editor/font-library.spec.js @@ -70,5 +70,26 @@ test.describe( 'Font Library', () => { page.getByRole( 'heading', { name: 'Fonts' } ) ).toBeVisible(); } ); + + test( 'should show font variant panel when clicking on a font family', async ( { + page, + } ) => { + await page.getByRole( 'button', { name: /styles/i } ).click(); + await page + .getByRole( 'button', { name: /typography styles/i } ) + .click(); + await page + .getByRole( 'button', { + name: /manage fonts/i, + } ) + .click(); + await page.getByRole( 'button', { name: /system font/i } ).click(); + await expect( + page.getByRole( 'heading', { name: /system font/i } ) + ).toBeVisible(); + await expect( + page.getByRole( 'checkbox', { name: /system font normal/i } ) + ).toBeVisible(); + } ); } ); } ); From f41449d10babb15728b11951452cfb264b3a5665 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Thu, 14 Sep 2023 22:08:53 +0100 Subject: [PATCH 02/11] Update CheckboxControl to allow for custom label --- packages/components/src/checkbox-control/README.md | 3 ++- packages/components/src/checkbox-control/index.tsx | 14 ++++++++------ .../test/__snapshots__/index.tsx.snap | 8 ++++---- .../components/src/checkbox-control/test/index.tsx | 7 +++++++ packages/components/src/checkbox-control/types.ts | 5 +++-- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/packages/components/src/checkbox-control/README.md b/packages/components/src/checkbox-control/README.md index 4bc19ed9bfe5f0..bfa02fcc4a7821 100644 --- a/packages/components/src/checkbox-control/README.md +++ b/packages/components/src/checkbox-control/README.md @@ -77,11 +77,12 @@ const MyCheckboxControl = () => { The set of props accepted by the component will be specified below. Props not included in this set will be applied to the input element. -#### `label`: `string` +#### `label`: `string|false` A label for the input field, that appears at the side of the checkbox. The prop will be rendered as content a label element. If no prop is passed an empty label is rendered. +If the prop is set to false no label is rendered. - Required: No diff --git a/packages/components/src/checkbox-control/index.tsx b/packages/components/src/checkbox-control/index.tsx index 1b7cae04cd81f6..705cebe93e0870 100644 --- a/packages/components/src/checkbox-control/index.tsx +++ b/packages/components/src/checkbox-control/index.tsx @@ -125,12 +125,14 @@ export function CheckboxControl( /> ) : null } - + { label !== false && ( + + ) } ); } diff --git a/packages/components/src/checkbox-control/test/__snapshots__/index.tsx.snap b/packages/components/src/checkbox-control/test/__snapshots__/index.tsx.snap index 408f18d8c7e770..13a2c44dd593a4 100644 --- a/packages/components/src/checkbox-control/test/__snapshots__/index.tsx.snap +++ b/packages/components/src/checkbox-control/test/__snapshots__/index.tsx.snap @@ -11,8 +11,8 @@ Snapshot Diff: > @@ -33,8 +33,8 @@ Snapshot Diff: ); } From caad4f0f2b7438d2e38aadb44d8f3437a01335e0 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Wed, 15 Nov 2023 15:38:52 +0000 Subject: [PATCH 04/11] Use kebabCase for checkbox id --- .../font-library-modal/library-font-variant.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/library-font-variant.js b/packages/edit-site/src/components/global-styles/font-library-modal/library-font-variant.js index 9e3739d76c8e5c..c7dea7d9540f6d 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/library-font-variant.js +++ b/packages/edit-site/src/components/global-styles/font-library-modal/library-font-variant.js @@ -3,16 +3,14 @@ */ import { useContext } from '@wordpress/element'; import { CheckboxControl, Flex } from '@wordpress/components'; -/** - * Internal dependencies - */ -import { getFontFaceVariantName } from './utils'; /** * Internal dependencies */ +import { getFontFaceVariantName } from './utils'; import { FontLibraryContext } from './context'; import FontFaceDemo from './font-demo'; +import { kebabCase } from '../../../../../block-editor/src/utils/object'; function LibraryFontVariant( { face, font } ) { const { isFontActivated, toggleActivateFont } = @@ -36,7 +34,7 @@ function LibraryFontVariant( { face, font } ) { }; const displayName = font.name + ' ' + getFontFaceVariantName( face ); - const checkboxId = `${ font.slug }-${ face.fontStyle }`; + const checkboxId = kebabCase( displayName ); return ( ); } From 9757a12e327522c6fe527ae6e132525a870484e3 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Wed, 15 Nov 2023 16:39:00 +0000 Subject: [PATCH 06/11] Use font slug in checkbox id --- .../font-library-modal/collection-font-variant.js | 4 +++- .../global-styles/font-library-modal/library-font-variant.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/collection-font-variant.js b/packages/edit-site/src/components/global-styles/font-library-modal/collection-font-variant.js index a0e99561c09dc8..8c2b36d3adee9f 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/collection-font-variant.js +++ b/packages/edit-site/src/components/global-styles/font-library-modal/collection-font-variant.js @@ -25,7 +25,9 @@ function CollectionFontVariant( { }; const displayName = font.name + ' ' + getFontFaceVariantName( face ); - const checkboxId = kebabCase( displayName ); + const checkboxId = kebabCase( + `${ font.slug }-${ getFontFaceVariantName( face ) }` + ); return (