WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.36k stars 4.13k forks source link

Can't import @wordpress/block-editor FontFamilyControl component #65655

Open mr660 opened 4 hours ago

mr660 commented 4 hours ago

Description

I'm creating custom block for rendering chart and i'm trying to create selector for font families for certain elements. I'm trying to follow [this] (https://github.com/WordPress/gutenberg/tree/trunk/packages/block-editor/src/components/font-family) readme with no success.

in edit.js file

import {InspectorControls, FontFamilyControl} from '@wordpress/block-editor';

export default function Edit({attributes, setAttributes}) {
    return (
        <>
            <InspectorControls>
                <FontFamilyControl
                    value={''}
                    onChange={() => {
                    }}
                />
            </InspectorControls>
        </>
}

I get error saying:

edit.js:89 Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `Edit`.

Step-by-step reproduction instructions

  1. Create custom block in theme or plugin and use code above

Environment info

Wordpress 6.6.2

Please confirm that you have searched existing issues in the repo.

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Mamaduka commented 3 hours ago

Try using __experimentalFontFamilyControl. The component is an experiment, and it's currently exported as one.

import { InspectorControls, __experimentalFontFamilyControl as FontFamilyControl } from '@wordpress/block-editor';

I'll create a PR to fix the examples in README docs.