Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zapal-tech/payload-lexical-react

Payload CMS rich text Lexical editor to React JSX renderer
https://github.com/zapal-tech/payload-lexical-react

Last synced: about 2 months ago
JSON representation

Payload CMS rich text Lexical editor to React JSX renderer

Awesome Lists containing this project

README

        

# Lexical to React JSX made easy

Designed for Payload CMS RichText Lexical editor. Rendering Lexical to React JSX.

## Install

```
npm i @zapal/payload-lexical-react
```

## Basic Usage

```jsx
import {
PayloadLexicalReact,
PayloadLexicalReactProps
} from "@zapal/payload-lexical-react";

const BlogPost = () => {
const content = await fetchLexicalEditorState();

return (



);
}
```

Get started by passing your Lexical rich text serialized state to the component. Default setup renders the most basic
styles only. P.S.: You can use it with the `@tailwindcss/typography` package to instantly style your rich text.

## Properties

### elements

In order to customize the result, use the `elements` prop to override the default elements rendering behavior:

```jsx
import { defaultElements, PayloadLexicalReact } from '@zapal/payload-lexical-react';

{
const Component = props.tag;
const style = { color: '#f84c0b', backgroundColor: '#000' };

return {props.children};
},
paragraph: (props) =>

{props.children}

,
}}
/>;
```

### mark

To customize rendering of text marks like bold, italic etc., add your own `mark` function:

```jsx
import { PayloadLexicalReact } from '@zapal/payload-lexical-react';

{
if (mark.bold) return {mark.text};
if (mark.italic) return {mark.text};
// Other marks go here if needed

return <>{mark.text}>;
}}
/>;
```

### blocks

Payload CMS Lexical RichText Editor comes with BlocksFeature included. You can render custom blocks like this:

```jsx
import {
BlockNode,
PayloadLexicalReact,
} from "@zapal/payload-lexical-react";

type HorizontalGutter = {
text: string;
large?: boolean;
};


content={content}
blocks={{
horizontalGutter: (props) => (


{props.fields.data.text}

),
}}
/>
```