Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font Library: Include a "Select All" options for google fonts #63893

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
DropdownMenu,
SearchControl,
ProgressBar,
CheckboxControl,
} from '@wordpress/components';
import { debounce } from '@wordpress/compose';
import { sprintf, __, _x } from '@wordpress/i18n';
Expand Down Expand Up @@ -175,6 +176,25 @@ function FontCollection( { slug } ) {
setFontsToInstall( [] );
};

const selectFontCount =
fontsToInstall.length > 0 ? fontsToInstall[ 0 ]?.fontFace?.length : 0;

// Check if any fonts are selected.
const isIndeterminate =
selectFontCount > 0 &&
selectFontCount !== selectedFont?.fontFace?.length;

// Check if all fonts are selected.
const isSelectAllChecked =
selectFontCount === selectedFont?.fontFace?.length;

// Toggle select all fonts.
const toggleSelectAll = () => {
const newFonts = isSelectAllChecked ? [] : [ selectedFont ];

setFontsToInstall( newFonts );
};

const handleInstall = async () => {
setNotice( null );

Expand Down Expand Up @@ -400,6 +420,14 @@ function FontCollection( { slug } ) {
{ __( 'Select font variants to install.' ) }
</Text>
<Spacer margin={ 4 } />
<CheckboxControl
className="font-library-modal__select-all"
label={ __( 'Select all' ) }
checked={ isSelectAllChecked }
onChange={ toggleSelectAll }
indeterminate={ isIndeterminate }
__nextHasNoMarginBottom
/>
<VStack spacing={ 0 }>
<Spacer margin={ 8 } />
{ getSortedFontFaces( selectedFont ).map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,3 @@ button.font-library-modal__upload-area {
padding-left: $grid-unit-20;
}
}

Loading