1.0.33 • Published 10 months ago

@scorpion11133/slate-editor-next-renderer v1.0.33

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
10 months ago

@scorpion11133/slate-editor-next-renderer

Example of data for translationsService(repoTypesExample) argument:

const repoTypesExample = {
  "111": {
    "1": "1 1 1 1",
    "2": [
      { type: "paragraph", children: [{ text: "222" }] },
      {
        type: "paragraph",
        children: [{ text: "22323 " }, { text: "ad", bold: true }],
      },
    ],
    string_with_vars: "My name is {{name}}. I am {{years}} years old.",
  },
  "222": {
    "1": "11 1",
    "2": "2",
    "333": [
      { type: "paragraph", children: [{ text: "adsdsadasd", bold: true }] },
      { type: "paragraph", children: [{ text: "asd", italic: true }] },
    ],
  },
  "333": {
    "1": "1 1 1 1 ",
    "2": [
      {
        type: "paragraph",
        children: [
          { text: "" },
          {
            type: "link",
            href: "https://tanstack.com/",
            children: [{ text: "asdasd" }],
          },
          { text: "" },
        ],
      },
    ],
  },
  "444": {
    test1: [
      { type: "paragraph", children: [{ text: "asdasd", color: "#d22d2d" }] },
    ],
  },
};

Usage example in the NextJS component:

import {RichText, translationsService} from "@scorpion11133/slate-editor-next-renderer";

const SomeComponent() {
    const t = translationsService(repoTypesExample);

    return (
        <>
            <p>{t("111.1")}</p>
            <RichText translation={t("111.2")} />
            <p>{t("111.string_with_vars", { name: "Some name", years: 2 })}</p>
            <RichText translation={t("222.333ddd")} />
            <p>{t("333.1asd")}</p>
            <RichText
                translation={t("333.2")}
                variables={{ name: "Some other name", years: 2, userId: 99999 }}
            />
            <RichText translation={t("444.test21")} />
        </>
    );
}

If the translation value is string it may be passed to any regular JSX-tag or with RichText component.

If the translation value is array use only RichText component

Types

type BaseNode = {
  type: string; 
  children: Node[];
  href?: string;
  target?: string;
  attr?: {
    className?: string;
  };
}

type Variables = Record<string, string | number> | undefined;

RichText Props

NameTypeisRequiredDescription
translationstring or BaseNode[]true
variablesVariablesfalseVariables used in the editor are enclosed in double curly braces (e.g., {{name}})
1.0.33

10 months ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago