Skip to content

Commit

Permalink
Merge pull request #608 from tomusborne/tweak/support-font-library
Browse files Browse the repository at this point in the history
Tweak: Add Customizer support for Font Library
  • Loading branch information
tomusborne authored May 28, 2024
2 parents fe89875 + 673ab18 commit 5fc64ba
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions inc/customizer/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ function generate_do_control_inline_scripts() {
'palette' => $colors,
'showGoogleFonts' => apply_filters( 'generate_font_manager_show_google_fonts', true ),
'colorPickerShouldShift' => function_exists( 'did_filter' ),
'gpFontLibrary' => class_exists( 'GeneratePress_Font_Library' )
? GeneratePress_Font_Library::get_font_families()
: array(),
'gpFontLibraryURI' => class_exists( 'GeneratePress_Font_Library' )
? GeneratePress_Font_Library::get_font_library_uri()
: '',
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ const GeneratePressFontManagerControlForm = ( props ) => {
} );

const fontFamilyExists = ( fontFamily ) => fonts.filter( ( font ) => font.fontFamily === fontFamily ).length > 0;
const gpFontLibrary = generateCustomizerControls.gpFontLibrary;
const gpFontLibraryURI = generateCustomizerControls.gpFontLibraryURI;

return (
<div>
Expand Down Expand Up @@ -305,6 +307,29 @@ const GeneratePressFontManagerControlForm = ( props ) => {
} )
}

{ !! gpFontLibrary.length > 0 && gpFontLibrary.map( ( font, index ) => (
<div className="generate-font-manager--item" key={ index }>
<div className="generate-font-manager--header">
<span
className="generate-font-manager--label"
>
{ font.name }
</span>

{ !! gpFontLibraryURI && (
<Tooltip text={ __( 'Font Library', 'generatepress' ) }>
<Button
className="generate-font-manager--open"
href={ gpFontLibraryURI }
>
{ getIcon( 'chevron-right' ) }
</Button>
</Tooltip>
) }
</div>
</div>
) ) }

<Button
isPrimary
onClick={ () => {
Expand Down
12 changes: 12 additions & 0 deletions src/customizer-controls/font-manager/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ const getFontFamilies = () => {
{ value: 'inherit', label: __( 'Inherit', 'generatepress' ) },
{ value: 'System Default', label: __( 'System Default', 'generatepress' ) },
];
const gpFontLibrary = generateCustomizerControls.gpFontLibrary;

if ( gpFontLibrary && gpFontLibrary.length > 0 ) {
gpFontLibrary.forEach( ( font ) => {
fontFamilies.push(
{
value: font.name,
label: font.name,
}
);
} );
}

if ( availableFonts.length > 0 ) {
availableFonts.forEach( ( value, i ) => {
Expand Down

0 comments on commit 5fc64ba

Please sign in to comment.