5.24.1 • Published 9 months ago

@purpurds/rich-text v5.24.1

Weekly downloads
-
License
AGPL-3.0-only
Repository
-
Last release
9 months ago

import { Meta, Stories, ArgTypes, Primary, Subtitle } from "@storybook/blocks";

import * as RichTextStories from "./src/rich-text.stories"; import packageInfo from "./package.json";

RichText

Version {packageInfo.version} Component takes in json data and returns ReactNodes.

Showcase

Properties

Installation

Via NPM

Add the dependency to your consumer app like "@purpurds/purpur": "^x.y.z"

Basic usage

import { RichText } from "@purpurds/purpur";

export const MyComponent = () => {
  return (
    <div>
      <RichText data={richJson} />
    </div>
  );
};

Override a node

If you need to override a node you can pass in customNodeTypes as a prop

import { RichText } from "@purpurds/purpur";

export const MyComponent = () => {
  return (
    <div>
      <RichText
        data={richJson}
        customNodeTypes={{
          "header-2": (_, children) => <h1>{children}</h1>,
        }}
      />
    </div>
  );
};

Usage with custom callbacks

Custom callbacks can be used to optimize images, wrap links or add custom styling

import { RichText } from "@purpurds/purpur";
import Link from "next/link";

const link = (children: React.ReactNode[], href?: string): ReactNode => {
  return (
    <Link href={href}>
      <a>{children}</a>
    </Link>
  );
};

const image = (src: string, alt?: string): ReactNode => {
  return <img src={`${src}?q=70`} alt={alt} />;
};

const image = (src: string, alt?: string, contentType?: string): ReactNode => {
  const format = contentType === "image/jpg" ? "webp" : "gif";
  return <img src={`${src}?fm=${format}&q=70`} alt={alt} />;
};

const videoPoster = (url: string): string => {
  return `${url}?q=70`;
};

export const MyComponent = () => {
  return <RichText data={richJson} link={link} image={image} videoPoster={videoPoster} />;
};
5.24.1

9 months ago

5.24.0

9 months ago

5.23.0

9 months ago

5.21.1

9 months ago

5.21.0

9 months ago

5.22.0

9 months ago

5.18.3

10 months ago

5.18.2

10 months ago

5.18.1

10 months ago

5.18.0

10 months ago

5.19.1

9 months ago

5.19.0

9 months ago

5.17.0

10 months ago

5.20.1

9 months ago

5.20.0

9 months ago

5.16.1

10 months ago

5.16.0

10 months ago

5.15.1

10 months ago

5.15.0

10 months ago

5.14.0

11 months ago

5.5.0

1 year ago

5.3.0

1 year ago

5.1.2

1 year ago

5.13.0

11 months ago

5.11.2

11 months ago

5.11.1

11 months ago

5.11.0

11 months ago

5.8.2

1 year ago

5.8.1

1 year ago

5.8.0

1 year ago

5.4.3

1 year ago

5.6.0

1 year ago

5.4.2

1 year ago

5.4.1

1 year ago

5.4.0

1 year ago

5.2.0

1 year ago

5.12.0

11 months ago

5.10.1

11 months ago

5.10.0

12 months ago

5.9.0

1 year ago

5.7.0

1 year ago

5.1.1

1 year ago

5.1.0

1 year ago

5.0.0

1 year ago

4.5.0

1 year ago

4.6.0

1 year ago

4.5.1

1 year ago

4.4.0

1 year ago

4.3.0

1 year ago

4.2.0

1 year ago

4.1.1

1 year ago

4.1.0

1 year ago

4.0.2

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

3.7.1

1 year ago

3.7.0

1 year ago

3.6.0

1 year ago

3.5.1

1 year ago

3.5.0

1 year ago

3.4.0

1 year ago

3.3.2

1 year ago

3.3.1

1 year ago

3.3.0

1 year ago

3.2.0

1 year ago

3.1.0

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.8.0

1 year ago