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 to activate/deactivate all fonts #63531

Merged
merged 16 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -384,6 +384,27 @@ function FontLibraryProvider( { children } ) {
return activeFonts;
};

const activateFontFamily = ( font ) => {
const initialFonts = fontFamilies?.[ font.source ] ?? [];
const newFonts = [ ...initialFonts, font ];
const activeFonts = {
...fontFamilies,
[ font.source ]: newFonts,
};
setFontFamilies( activeFonts );

if ( font.fontFace ) {
font.fontFace.forEach( ( face ) => {
loadFontFaceInBrowser(
face,
getDisplaySrcFromFontFace( face?.src ),
'all'
);
} );
}
return activeFonts;
};

const activateCustomFontFamilies = ( fontsToAdd ) => {
const fontsToActivate = cleanFontsForSave( fontsToAdd );

Expand Down Expand Up @@ -534,6 +555,8 @@ function FontLibraryProvider( { children } ) {
isInstalling,
collections,
getFontCollection,
deactivateFontFamily,
activateFontFamily,
} }
>
{ children }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Flex,
Notice,
ProgressBar,
CheckboxControl,
} from '@wordpress/components';
import { useEntityRecord, store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
Expand Down Expand Up @@ -50,8 +51,12 @@ function InstalledFonts() {
notice,
setNotice,
fontFamilies,
deactivateFontFamily,
activateFontFamily,
} = useContext( FontLibraryContext );
const [ isConfirmDeleteOpen, setIsConfirmDeleteOpen ] = useState( false );
const [ isSelectAllChecked, setIsSelectAllChecked ] = useState( true );
t-hamano marked this conversation as resolved.
Show resolved Hide resolved

const [ baseFontFamilies ] = useGlobalSetting(
'typography.fontFamilies',
undefined,
Expand Down Expand Up @@ -144,6 +149,16 @@ function InstalledFonts() {
refreshLibrary();
}, [] );

const handleSelectAll = () => {
if ( isSelectAllChecked ) {
deactivateFontFamily( libraryFontSelected );
} else {
activateFontFamily( libraryFontSelected );
}

setIsSelectAllChecked( ! isSelectAllChecked );
};

return (
<div className="font-library-modal__tabpanel-layout">
{ isResolvingLibrary && (
Expand Down Expand Up @@ -295,6 +310,18 @@ function InstalledFonts() {
</Text>
<Spacer margin={ 4 } />
<VStack spacing={ 0 }>
<Flex
className="font-library-modal__select-all"
justify="flex-start"
align="center"
gap="1rem"
>
t-hamano marked this conversation as resolved.
Show resolved Hide resolved
<CheckboxControl
label={ __( 'Select all' ) }
checked={ isSelectAllChecked }
onChange={ handleSelectAll }
/>
</Flex>
<Spacer margin={ 8 } />
{ getFontFacesToDisplay(
libraryFontSelected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,15 @@ button.font-library-modal__upload-area {
justify-content: center;
}
}

.font-library-modal__select-all {
width: 100%;
height: auto;
padding: $grid-unit-20;

.components-checkbox-control__label {
padding-left: $grid-unit-20;
font-size: 18px;
line-height: 1;
t-hamano marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading