@contember/react-client 1.0.0-rc.20 → 1.0.0-rc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/readme.md +39 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contember/react-client",
3
3
  "license": "Apache-2.0",
4
- "version": "1.0.0-rc.20",
4
+ "version": "1.0.0-rc.21",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "./dist/production/index.js",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "typings": "./dist/types/index.d.ts",
21
21
  "dependencies": {
22
- "@contember/client": "1.0.0-rc.20"
22
+ "@contember/client": "1.0.0-rc.21"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "react": "^17"
@@ -27,5 +27,5 @@
27
27
  "scripts": {
28
28
  "build": "vite build --mode development && vite build --mode production"
29
29
  },
30
- "readme": "# `@contember/react-client`\n\n## Usage\nIf you wish to communicate with any Contember API, wrap your code with the `ContemberClient` component:\n```tsx\nimport { ContemberClient } from '@contember/react-client'\n\n<ContemberClient\n\tapiBaseUrl=\"https://api.example.com\"\n\tproject=\"PROJECT-SLUG\"\n\tsessionToken=\"SESSION-TOKEN\"\n\tstage=\"STAGE-SLUG\"\n>\n ...\n</ContemberClient>\n```\n\n## Notable APIs\nYou'll have to look at the code for now, sorry.\n- `<RichTextRenderer />`\n- `useFileUpload`\n- `useContentApiRequest` / `useTenantApiRequest` / `useSystemApiRequest`\n"
30
+ "readme": "# `@contember/react-client`\n\n## Usage\n\nIf you wish to communicate with any Contember API, wrap your code with the `ContemberClient` component:\n\n```tsx\nimport { ContemberClient } from '@contember/react-client'\n\n<ContemberClient\n\tapiBaseUrl=\"https://api.example.com\"\n\tproject=\"PROJECT-SLUG\"\n\tsessionToken=\"SESSION-TOKEN\"\n\tstage=\"STAGE-SLUG\"\n>\n\t...\n</ContemberClient>\n```\n\n## Notable APIs\n\nYou'll have to look at the code for now, sorry.\n\n- `<RichTextRenderer />`\n- `useFileUpload`\n- `useContentApiRequest` / `useTenantApiRequest` / `useSystemApiRequest`\n\n## RichTextRenderer\n\nHere is simple exmaple of how to use the `RichTextRenderer` component with custom references and elements.\n\n```tsx\nimport { RichTextRenderer } from '@contember/react-client'\nimport Image from './myComponents/Image'\nimport Gallery from './myComponents/Gallery'\nimport Quote from './myComponents/Quote'\nimport Link from './myComponents/Link'\n\n<RichTextRenderer\n\tsourceField=\"json\"\n\trenderElement={(props) => {\n\t\tif (props.element.type === 'link' && props.reference) {\n\t\t\treturn <Link label={props.element.children[0].text} url={props.reference.target} />\n\t\t}\n\n\t\treturn props.fallback\n\t}}\n\treferenceRenderers={{\n\t\timage: (reference) => <Image reference={reference} />,\n\t\tgallery: (reference) => <Gallery reference={reference} />,\n\t\tquote: (reference) => <Quote reference={reference} />,\n\t}}\n/>\n```\n\n| Prop | Description |\n| -------------------- | ----------------------------------------------------- |\n| `sourceField` | The field in the GraphQL that contains the rich text. |\n| `renderElement` | Function that renders an element. |\n| `referenceRenderers` | Object that maps reference types to renderers. |\n"
31
31
  }
package/readme.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # `@contember/react-client`
2
2
 
3
3
  ## Usage
4
+
4
5
  If you wish to communicate with any Contember API, wrap your code with the `ContemberClient` component:
6
+
5
7
  ```tsx
6
8
  import { ContemberClient } from '@contember/react-client'
7
9
 
@@ -11,12 +13,48 @@ import { ContemberClient } from '@contember/react-client'
11
13
  sessionToken="SESSION-TOKEN"
12
14
  stage="STAGE-SLUG"
13
15
  >
14
- ...
16
+ ...
15
17
  </ContemberClient>
16
18
  ```
17
19
 
18
20
  ## Notable APIs
21
+
19
22
  You'll have to look at the code for now, sorry.
23
+
20
24
  - `<RichTextRenderer />`
21
25
  - `useFileUpload`
22
26
  - `useContentApiRequest` / `useTenantApiRequest` / `useSystemApiRequest`
27
+
28
+ ## RichTextRenderer
29
+
30
+ Here is simple exmaple of how to use the `RichTextRenderer` component with custom references and elements.
31
+
32
+ ```tsx
33
+ import { RichTextRenderer } from '@contember/react-client'
34
+ import Image from './myComponents/Image'
35
+ import Gallery from './myComponents/Gallery'
36
+ import Quote from './myComponents/Quote'
37
+ import Link from './myComponents/Link'
38
+
39
+ <RichTextRenderer
40
+ sourceField="json"
41
+ renderElement={(props) => {
42
+ if (props.element.type === 'link' && props.reference) {
43
+ return <Link label={props.element.children[0].text} url={props.reference.target} />
44
+ }
45
+
46
+ return props.fallback
47
+ }}
48
+ referenceRenderers={{
49
+ image: (reference) => <Image reference={reference} />,
50
+ gallery: (reference) => <Gallery reference={reference} />,
51
+ quote: (reference) => <Quote reference={reference} />,
52
+ }}
53
+ />
54
+ ```
55
+
56
+ | Prop | Description |
57
+ | -------------------- | ----------------------------------------------------- |
58
+ | `sourceField` | The field in the GraphQL that contains the rich text. |
59
+ | `renderElement` | Function that renders an element. |
60
+ | `referenceRenderers` | Object that maps reference types to renderers. |