canvas-component-utils
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImport utilities from the package:
drupal-canvasjsx
import { FormattedText, Image } from 'drupal-canvas';从包中导入实用工具:
drupal-canvasjsx
import { FormattedText, Image } from 'drupal-canvas';FormattedText
FormattedText
Use to render HTML content from props. This is required for any
prop with in component.yml.
FormattedTextcontentMediaType: text/htmlyaml
undefined使用来渲染来自props的HTML内容。对于component.yml中标记有的任何prop,都需要使用该组件。
FormattedTextcontentMediaType: text/htmlyaml
undefinedcomponent.yml
component.yml
props:
properties:
text:
title: Text
type: string
contentMediaType: text/html
x-formatting-context: block
examples:
- <p>This is <strong>formatted</strong> text.</p>
```jsx
import { FormattedText } from 'drupal-canvas';
const Text = ({ text, className }) => (
<FormattedText className={className}>{text}</FormattedText>
);When to use FormattedText:
- Props that accept rich text/HTML content
- Any prop with
contentMediaType: text/html - Content that may contain ,
<p>,<strong>,<em>, or other HTML tags<a>
Do NOT use FormattedText for:
- Plain text props (type: string without contentMediaType)
- Headings or titles (use regular elements)
props:
properties:
text:
title: Text
type: string
contentMediaType: text/html
x-formatting-context: block
examples:
- <p>This is <strong>formatted</strong> text.</p>
```jsx
import { FormattedText } from 'drupal-canvas';
const Text = ({ text, className }) => (
<FormattedText className={className}>{text}</FormattedText>
);何时使用FormattedText:
- 可接受富文本/HTML内容的props
- 任何带有的prop
contentMediaType: text/html - 可能包含、
<p>、<strong>、<em>或其他HTML标签的内容<a>
请勿将FormattedText用于:
- 纯文本props(类型为string且无contentMediaType标记)
- 标题或页头(使用常规元素)
Image
Image
Use for responsive image rendering. It handles responsive behavior and
optimization automatically.
Imageyaml
undefined使用进行响应式图片渲染。它会自动处理响应式行为和优化。
Imageyaml
undefinedcomponent.yml
component.yml
props:
properties:
image:
title: Image
type: object
$ref: json-schema-definitions://canvas.module/image
examples:
- src: https://example.com/photo.jpg
alt: Description of image
width: 800
height: 600
```jsx
import { Image } from 'drupal-canvas';
const Card = ({ image }) => {
const { src, alt, width, height } = image;
return (
<Image
src={src}
alt={alt}
width={width}
height={height}
className="w-full rounded-lg object-cover"
/>
);
};Image props:
- - Image URL (required)
src - - Alt text for accessibility (required)
alt - - Original image width
width - - Original image height
height - - Tailwind classes for styling
className
props:
properties:
image:
title: Image
type: object
$ref: json-schema-definitions://canvas.module/image
examples:
- src: https://example.com/photo.jpg
alt: Description of image
width: 800
height: 600
```jsx
import { Image } from 'drupal-canvas';
const Card = ({ image }) => {
const { src, alt, width, height } = image;
return (
<Image
src={src}
alt={alt}
width={width}
height={height}
className="w-full rounded-lg object-cover"
/>
);
};Image的props:
- - 图片URL(必填)
src - - 用于无障碍访问的替代文本(必填)
alt - - 图片原始宽度
width - - 图片原始高度
height - - 用于样式的Tailwind类
className