Files
StevenandGitHub 4466ba436b chore(examples): use default prettier for examples/templates (#60530)
## Description
This PR ensures that the default prettier config is used for examples
and templates.

This config is compatible with `prettier@3` as well (upgrading prettier
is bigger change that can be a future PR).

## Changes
- Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will
be needed upgrading to prettier@3)
- Added `examples/.prettierrc.json` with default config (this will
change every example)
- Added `packages/create-next-app/templates/.prettierrc.json` with
default config (this will change every template)

## Related

- Fixes #54402
- Closes #54409
2024-01-11 16:01:44 -07:00

70 lines
1.4 KiB
TypeScript

import Link from "next/link";
import React from "react";
import { Page } from "../../payload-types";
import { Button } from "../Button";
type CMSLinkType = {
type?: "custom" | "reference";
url?: string;
newTab?: boolean;
reference?: {
value: string | Page;
relationTo: "pages";
};
label?: string;
appearance?: "default" | "primary" | "secondary";
children?: React.ReactNode;
className?: string;
};
export const CMSLink: React.FC<CMSLinkType> = ({
type,
url,
newTab,
reference,
label,
appearance,
children,
className,
}) => {
const href =
type === "reference" &&
typeof reference?.value === "object" &&
reference.value.slug
? `/${reference.value.slug}`
: url;
if (!appearance) {
const newTabProps = newTab
? { target: "_blank", rel: "noopener noreferrer" }
: {};
if (type === "custom") {
return (
<a href={url} {...newTabProps} className={className}>
{label && label}
{children && children}
</a>
);
}
if (href) {
return (
<Link href={href} className={className} {...newTabProps}>
{label && label}
{children && children}
</Link>
);
}
}
const buttonProps = {
newTab,
href,
appearance,
label,
};
return <Button className={className} {...buttonProps} el="link" />;
};