1.1.3 โข Published 5 months ago
@maestrooo/rich-text-field v1.1.3
Polaris Rich Text Field
The RichTextField
component provides a streamlined way to edit Shopify rich text metafields within your embedded app.
โ ๏ธ This is not a general-purpose rich text editor. It is specifically designed for editing Shopify metafields of type
rich_text_field
, not for generating arbitrary HTML.๐ซ This component relies on the Shopify App Bridge modal and can only be used inside an embedded Shopify app that uses App Bridge v4.
๐ฆ Installation
npm i @maestrooo/rich-text-field
This library uses Slate under the hood (which is the same library that Shopify uses for their own rich text field editor, ensuring we get a consistent experience).
๐ ๏ธ Usage
Import the component and use it in your app:
import { RichTextField } from "@maestrooo/rich-text-field";
export default function MyComponent() {
return (
<RichTextField
value={metafield.jsonValue}
onChange={(newValue) => doSomething(newValue)}
/>
);
}
๐งพ Props
Prop | Type | Required | Description |
---|---|---|---|
value | object \| string \| null | โ | The current metafield value. Use metafield.jsonValue , not a stringified value. |
onChange | (value: object \| string) => void | โ | Callback triggered whenever the content changes. Returns a JSON object or an empty string. |
toolbarOptions | Array<'formatting' \| 'bold' \| 'italic' \| 'link' \| 'ordered-list' \| 'unordered-list'> | โ | Controls which tools are available in the toolbar. |
label | string | โ | Optional label for the field. |
helpText | string | โ | Optional help text displayed below the field. |
placeholder | string | โ | Placeholder text shown when the field is empty. |
error | string | โ | Optional error message displayed below the field. |
โ ๏ธ Notes
- Ensure you pass the parsed JSON object (or
""
/null
), not the raw string value of the metafield. - We recommend using
metafield.jsonValue
as the input. - The
onChange
callback returns either the updated JSON structure or an empty string when the content is cleared.