Skip to content

Commit

Permalink
fix: replace @prismicio/types usage with @prismicio/client v7 (#186)
Browse files Browse the repository at this point in the history
* chore: update examples to use `@prismicio/client` v7

* chore: update remaining uses of `@prismicio/types` to `@prismicio/client`
  • Loading branch information
angeloashmore authored Jun 12, 2023
1 parent c1e469d commit 34649e2
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 103 deletions.
6 changes: 3 additions & 3 deletions examples/custom-slicezone-props/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import * as React from "react";
import {
SliceZone,
SliceComponentProps,
SliceZoneComponents,
SliceComponentType,
} from "@prismicio/react";

import { Slices, HeroSlice, ExampleSliceZone } from "./types";
import { HeroSlice, ExampleSliceZone } from "./types";

// This is the contents of a Slice Zone field.
// Normally, this would be accessed at `document.data.body`, where `document`
Expand Down Expand Up @@ -71,7 +71,7 @@ const CallToActionSlice = ({
// It is important to define this object *outside* the React component that
// uses `<SliceZone>`. This ensures the React app will not re-render
// unnecessarily.
const components: SliceZoneComponents<Slices> = {
const components: Record<string, SliceComponentType> = {
// Since HeroSlice accepts a `slice` prop, we can pass the component directly.
hero: HeroSlice,

Expand Down
4 changes: 2 additions & 2 deletions examples/custom-slicezone-props/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "module",
"dependencies": {
"@prismicio/react": "alpha"
"@prismicio/react": "../../src"
},
"devDependencies": {
"@prismicio/types": "^0.1.4"
"@prismicio/client": "^7.1.0"
}
}
14 changes: 7 additions & 7 deletions examples/custom-slicezone-props/types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as prismicT from "@prismicio/types";
import * as prismic from "@prismicio/client";

export type HeroSlice = prismicT.Slice<
export type HeroSlice = prismic.Slice<
"hero",
{
heading: prismicT.KeyTextField;
buttonText: prismicT.KeyTextField;
heading: prismic.KeyTextField;
buttonText: prismic.KeyTextField;
}
>;

export type CallToActionSlice = prismicT.Slice<
export type CallToActionSlice = prismic.Slice<
"call_to_action",
{
text: prismicT.KeyTextField;
text: prismic.KeyTextField;
}
>;

export type Slices = HeroSlice | CallToActionSlice;

export type ExampleSliceZone = prismicT.SliceZone<Slices>;
export type ExampleSliceZone = prismic.SliceZone<Slices>;
6 changes: 3 additions & 3 deletions examples/router-link/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from "react";
import * as prismicT from "@prismicio/types";
import * as prismic from "@prismicio/client";
import { PrismicLink, LinkProps } from "@prismicio/react";
import { Link } from "react-router-dom";

// This is an example Link field value. It contains a URL internal to the app.
const field: prismicT.LinkField = {
link_type: prismicT.LinkType.Web,
const field: prismic.LinkField = {
link_type: prismic.LinkType.Web,
url: "/internal-url",
};

Expand Down
4 changes: 2 additions & 2 deletions examples/router-link/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"type": "module",
"dependencies": {
"@prismicio/react": "alpha",
"@prismicio/react": "../../src",
"react-router-dom": "^5.2.0"
},
"devDependencies": {
"@prismicio/types": "^0.1.4",
"@prismicio/client": "^7.1.0",
"@types/react-router-dom": "^5.1.8"
}
}
14 changes: 7 additions & 7 deletions examples/router-link/types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as prismicT from "@prismicio/types";
import * as prismic from "@prismicio/client";

export type HeroSlice = prismicT.Slice<
export type HeroSlice = prismic.Slice<
"hero",
{
heading: prismicT.KeyTextField;
buttonText: prismicT.KeyTextField;
heading: prismic.KeyTextField;
buttonText: prismic.KeyTextField;
}
>;

export type CallToActionSlice = prismicT.Slice<
export type CallToActionSlice = prismic.Slice<
"call_to_action",
{
text: prismicT.KeyTextField;
text: prismic.KeyTextField;
}
>;

export type Slices = HeroSlice | CallToActionSlice;

export type ExampleSliceZone = prismicT.SliceZone<Slices>;
export type ExampleSliceZone = prismic.SliceZone<Slices>;
10 changes: 5 additions & 5 deletions examples/with-global-configuration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable react/display-name */

import * as React from "react";
import * as prismicT from "@prismicio/types";
import * as prismic from "@prismicio/client";
import {
PrismicProvider,
PrismicLink,
Expand All @@ -13,15 +13,15 @@ import {
import { Link } from "react-router-dom";

// This is an example Link field value. It contains a URL internal to the app.
const linkField: prismicT.LinkField = {
link_type: prismicT.LinkType.Web,
const linkField: prismic.LinkField = {
link_type: prismic.LinkType.Web,
url: "/internal-url",
};

// This is an example Rich Text field value. It contains a "Heading 1" block.
const richTextField: prismicT.RichTextField = [
const richTextField: prismic.RichTextField = [
{
type: prismicT.RichTextNodeType.heading1,
type: prismic.RichTextNodeType.heading1,
text: "Lorem ipsum",
spans: [],
},
Expand Down
4 changes: 2 additions & 2 deletions examples/with-global-configuration/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"type": "module",
"dependencies": {
"@prismicio/react": "alpha",
"@prismicio/react": "../../src",
"react-router-dom": "^5.2.0"
},
"devDependencies": {
"@prismicio/types": "^0.1.4",
"@prismicio/client": "^7.1.0",
"@types/react-router-dom": "^5.1.8"
}
}
14 changes: 7 additions & 7 deletions examples/with-global-configuration/types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as prismicT from "@prismicio/types";
import * as prismic from "@prismicio/client";

export type HeroSlice = prismicT.Slice<
export type HeroSlice = prismic.Slice<
"hero",
{
heading: prismicT.KeyTextField;
buttonText: prismicT.KeyTextField;
heading: prismic.KeyTextField;
buttonText: prismic.KeyTextField;
}
>;

export type CallToActionSlice = prismicT.Slice<
export type CallToActionSlice = prismic.Slice<
"call_to_action",
{
text: prismicT.KeyTextField;
text: prismic.KeyTextField;
}
>;

export type Slices = HeroSlice | CallToActionSlice;

export type ExampleSliceZone = prismicT.SliceZone<Slices>;
export type ExampleSliceZone = prismic.SliceZone<Slices>;
2 changes: 1 addition & 1 deletion examples/with-typescript/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# With TypeScript

This example shows how `@prismicio/react` is used in TypeScript projects. `@prismicio/react` is written in TypeScript using types from [`@prismicio/types`](https://github.com/prismicio/prismic-types).
This example shows how `@prismicio/react` is used in TypeScript projects. `@prismicio/react` is written in TypeScript using types from [`@prismicio/client`](https://github.com/prismicio/prismic-client).

You can write types for your documents using `PrismicDocument`. Components from `@prismicio/react` will type check against your document and its fields.
46 changes: 23 additions & 23 deletions examples/with-typescript/index.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import * as React from "react";
import * as prismicH from "@prismicio/helpers";
import * as prismicT from "@prismicio/types";
import * as prismic from "@prismicio/client";
import { SliceZone, PrismicRichText, PrismicLink } from "@prismicio/react";

// Documents can be typed using `@prismicio/types`
type PageDocument = prismicT.PrismicDocumentWithUID<{
title: prismicT.TitleField;
meta_description: prismicT.RichTextField;
related_links: prismicT.GroupField<{
link: prismicT.LinkField;
// Documents can be typed using `@prismicio/client`
type PageDocument = prismic.PrismicDocumentWithUID<{
title: prismic.TitleField;
meta_description: prismic.RichTextField;
related_links: prismic.GroupField<{
label: prismic.KeyTextField;
link: prismic.LinkField;
}>;

// Each Slice in a Slice Zone can be typed using `prismicT.Slice`
slices: prismicT.SliceZone<
| prismicT.Slice<
// Each Slice in a Slice Zone can be typed using `prismic.Slice`
slices: prismic.SliceZone<
| prismic.Slice<
// Slice type
"hero",
// Primary/non-repeatable fields
{
heading: prismicT.TitleField;
body: prismicT.RichTextField;
heading: prismic.TitleField;
body: prismic.RichTextField;
},
// Item/repeatable fields
{
buttonText: prismicT.KeyTextField;
buttonLink: prismicT.LinkField;
buttonText: prismic.KeyTextField;
buttonLink: prismic.LinkField;
}
>
| prismicT.Slice<
| prismic.Slice<
// Slice type
"call_to_action",
// Primary/non-repeatable fields
{
text: prismicT.RichTextField;
text: prismic.RichTextField;
},
// Item/repeatable fields
{
buttonText: prismicT.KeyTextField;
buttonLink: prismicT.LinkField;
buttonText: prismic.KeyTextField;
buttonLink: prismic.LinkField;
}
>
>;
Expand Down Expand Up @@ -70,18 +70,18 @@ export const WithDocumentLink = (): JSX.Element => {
export const WithGroupFieldLink = (): JSX.Element => {
return (
<ul>
{prismicH.isFilled.group(page.data.related_links) &&
{prismic.isFilled.group(page.data.related_links) &&
page.data.related_links.map(
(item) =>
prismicH.isFilled.link(item.link) && (
prismic.isFilled.link(item.link) && (
<li
key={
item.link.link_type === prismicT.LinkType.Document
item.link.link_type === prismic.LinkType.Document
? item.link.id
: item.link.url
}
>
<PrismicLink field={item.link}>{item}</PrismicLink>
<PrismicLink field={item.link}>{item.label}</PrismicLink>
</li>
),
)}
Expand Down
4 changes: 2 additions & 2 deletions examples/with-typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "module",
"dependencies": {
"@prismicio/react": "latest"
"@prismicio/react": "../../src"
},
"devDependencies": {
"@prismicio/types": "^0.1.25"
"@prismicio/client": "^7.1.0"
}
}
Loading

0 comments on commit 34649e2

Please sign in to comment.