Skip to content

Commit

Permalink
Merge pull request #297 from WordPress/add/font-family-labels
Browse files Browse the repository at this point in the history
Add labels around Google font family checkbox controls
  • Loading branch information
mikachan authored Apr 4, 2023
2 parents 83de623 + 072da09 commit 0374c69
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
16 changes: 13 additions & 3 deletions src/google-fonts/font-variant.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,31 @@ function FontVariant( { font, variant, isSelected, handleToggle } ) {
} );
}, [ font, variant ] );

const formattedFontFamily = font.family.toLowerCase().replace( ' ', '-' );
const fontId = `${ formattedFontFamily }-${ variant }`;

return (
<tr>
<td className="">
<input
type="checkbox"
name="google-font-variant"
id={ fontId }
value={ variant }
checked={ isSelected }
onClick={ handleToggle }
/>
</td>
<td className="">{ weight }</td>
<td className="">{ style }</td>
<td className="">
<label htmlFor={ fontId }>{ weight }</label>
</td>
<td className="">
<label htmlFor={ fontId }>{ style }</label>
</td>
<td className="demo-cell">
<Demo style={ previewStyles } />
<label htmlFor={ fontId }>
<Demo style={ previewStyles } />
</label>
</td>
</tr>
);
Expand Down
44 changes: 32 additions & 12 deletions src/google-fonts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ function GoogleFonts() {
setSelectedFont( googleFontsData.items[ value ] );
};

let selectedFontFamilyId = '';
if ( selectedFont ) {
selectedFontFamilyId = selectedFont.family
.toLowerCase()
.replace( ' ', '-' );
}

return (
<FontsPageLayout>
<main>
Expand Down Expand Up @@ -235,6 +242,7 @@ function GoogleFonts() {
<td className="">
<input
type="checkbox"
id={ `select-all-${ selectedFontFamilyId }` }
onClick={ () =>
handleToggleAllVariants(
selectedFont.family
Expand All @@ -250,22 +258,34 @@ function GoogleFonts() {
/>
</td>
<td className="">
{ __(
'Weight',
'create-block-theme'
) }
<label
htmlFor={ `select-all-${ selectedFontFamilyId }` }
>
{ __(
'Weight',
'create-block-theme'
) }
</label>
</td>
<td className="">
{ __(
'Style',
'create-block-theme'
) }
<label
htmlFor={ `select-all-${ selectedFontFamilyId }` }
>
{ __(
'Style',
'create-block-theme'
) }
</label>
</td>
<td className="">
{ __(
'Preview',
'create-block-theme'
) }
<label
htmlFor={ `select-all-${ selectedFontFamilyId }` }
>
{ __(
'Preview',
'create-block-theme'
) }
</label>
</td>
</tr>
</thead>
Expand Down

0 comments on commit 0374c69

Please sign in to comment.