Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support link variants #368

Open
wants to merge 9 commits into
base: aa/refactor-link-types
Choose a base branch
from
1 change: 1 addition & 0 deletions src/types/model/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface CustomTypeModelLinkField {
allowText?: boolean
allowTargetBlank?: boolean
repeat?: boolean
variants?: string[]
}
}

Expand Down
1 change: 1 addition & 0 deletions src/types/value/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ export type FilledLinkToWebField = {
* @internal
*/
export type OptionalLinkProperties = {
variant?: string
text?: string
}
10 changes: 10 additions & 0 deletions test/types/customType-link.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ expectType<prismic.CustomTypeModelLinkField>({
},
})

/**
* Supports optional `variants` property.
*/
expectType<prismic.CustomTypeModelLinkField>({
type: prismic.CustomTypeModelFieldType.Link,
config: {
variants: ["string"],
},
})

/**
* `@prismicio/types` extends `@prismicio/types-internal`
*/
Expand Down
17 changes: 17 additions & 0 deletions test/types/fields-link.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ expectType<prismic.LinkField>({
url: "string",
target: "string",
text: "string",
variant: "string",
})
expectType<prismic.LinkField>({
link_type: prismic.LinkType.Document,
Expand All @@ -54,6 +55,7 @@ expectType<prismic.LinkField>({
isBroken: true,
data: undefined,
text: "string",
variant: "string",
})
expectType<prismic.LinkField>({
link_type: prismic.LinkType.Media,
Expand All @@ -65,19 +67,22 @@ expectType<prismic.LinkField>({
height: "string",
width: "string",
text: "string",
variant: "string",
})
expectType<prismic.LinkField<string, string, never, "filled">>({
link_type: prismic.LinkType.Web,
url: "string",
target: "string",
text: "string",
variant: "string",
})
expectType<prismic.LinkField<string, string, never, "empty">>({
// @ts-expect-error - Empty fields cannot contain a filled link type.
link_type: prismic.LinkType.Web,
url: "string",
target: "string",
text: "string",
variant: "string",
})

/**
Expand Down Expand Up @@ -144,6 +149,18 @@ expectType<prismic.LinkField<string, string, never, "filled">>({
text: "string",
})

/**
* Empty state with variant.
*/
expectType<prismic.LinkField>({
link_type: prismic.LinkType.Any,
variant: "string",
})
expectType<prismic.LinkField<string, string, never, "empty">>({
link_type: prismic.LinkType.Any,
variant: "string",
})

/**
* Supports custom document type for document links.
*/
Expand Down
Loading