最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

block editor - how to use a Text component in javascript?

programmeradmin2浏览0评论

I'm building an InspectorTools interface for a Gutenberg block. I can't figure out how to use the Text component. There aren't really any examples for use in javascript. The page / it gives this example:

import {Text} from '@wordpress/components';

const HeroPanel = () => (
    <>
        <Text variant="title.large" as="h1">Hello World!</Text>
        <Text variant="body">Greetings to you!</Text>
    </>
);

I have tried in a number of ways but I always get this error :

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

Here are a few of my attempts:

createElement(PanelRow, {}, createElement(Text, { variant: 'title.small', as: 'h3' }, __('This is a test', 'my-textdomain')) )

createElement(PanelRow, {}, createElement(Text, { as: 'h3' }, __('This is a test', 'my-textdomain')) )

createElement(PanelRow, {}, createElement(Text, { variant: 'title.small' }, __('This is a test', 'my-textdomain')) )

createElement(PanelRow, {}, createElement(Text, __('This is a test', 'my-textdomain')) )

createElement(PanelRow, {}, createElement(Text, {}, __('This is a test', 'my-textdomain')) )

createElement(PanelRow, {}, createElement(Text, { label: __('This is a test', 'my-textdomain')}) )

None of my attempts have worked, they all give the same error. What would be the correct way to use a simple Text component? My objective in this case is to create a label for a ButtonGroup component which, as far as I can tell, doesn't have a label property (I have only found an accessibilityLabel property which is created on the ButtonGroup but which is not however visible on the interface, obviously).

发布评论

评论列表(0)

  1. 暂无评论