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

Export client-side and server-side component maps instead of only the individual components #144

Merged
merged 5 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pantheon-systems/pcc-cli",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud CLI",
"version": "2.0.17",
"version": "2.0.18",
"type": "module",
"license": "MIT",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pantheon-systems/pcc-sdk-core",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud SDK Core",
"version": "2.0.17",
"version": "2.0.18",
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
4 changes: 2 additions & 2 deletions packages/react-sample-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"name": "@pantheon-systems/pcc-react-sample-library",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud Sample Component Library for React",
"version": "2.0.17",
"version": "2.0.18",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"private": true,
"typesVersions": {
"*": {
"*": [
Expand Down Expand Up @@ -70,6 +69,7 @@
},
"dependencies": {
"@pantheon-systems/pcc-sdk-core": "latest",
"@pantheon-systems/pcc-react-sdk": "latest",
"@pantheon-systems/pds-toolkit-react": "1.0.0-dev.55",
"markdown-it": "^13.0.2",
"query-string": "^8.1.0"
Expand Down
8 changes: 4 additions & 4 deletions packages/react-sample-library/src/components/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ type Props = {
fallbackIcon?: "user" | "users";
};

export default function Avatar({
export const reactComponent = ({
image,
size,
className,
fallbackIcon,
}: Props) {
}: Props) => {
return (
<BaseAvatar
imageSrc={image}
Expand All @@ -24,9 +24,9 @@ export default function Avatar({
fallbackIcon={fallbackIcon}
/>
);
}
};

Avatar.smartComponentDefinition = {
export const smartComponentDefinition = {
title: "Avatar",
iconUrl: null,
fields: {
Expand Down
8 changes: 4 additions & 4 deletions packages/react-sample-library/src/components/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import { type SmartComponentMap } from "@pantheon-systems/pcc-sdk-core";

// TODO: Infer the type of the props from the smart component definition
// https://getpantheon.atlassian.net/browse/PCC-827
export default function Badge({
export const reactComponent = ({
successType,
label,
hasStatusType,
}: BadgeProps) {
}: BadgeProps) => {
return (
<BaseBadge
successType={successType}
label={label}
hasStatusType={hasStatusType}
/>
);
}
};

Badge.smartComponentDefinition = {
export const smartComponentDefinition = {
title: "Badge",
iconUrl: null,
fields: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import { type SmartComponentMap } from "@pantheon-systems/pcc-sdk-core";

// TODO: Infer the type of the props from the smart component definition
// https://getpantheon.atlassian.net/browse/PCC-827
export default function BannerNotification({
type,
message,
}: BannerNotificationProps) {
export const reactComponent = ({ type, message }: BannerNotificationProps) => {
return <BaseBannerNotification type={type} message={message} />;
}
};

BannerNotification.smartComponentDefinition = {
export const smartComponentDefinition = {
title: "Banner Notification",
iconUrl: null,
fields: {
Expand Down
8 changes: 4 additions & 4 deletions packages/react-sample-library/src/components/Blockquote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { type SmartComponentMap } from "@pantheon-systems/pcc-sdk-core";

// TODO: Infer the type of the props from the smart component definition
// https://getpantheon.atlassian.net/browse/PCC-827
export default function Blockquote({
export const reactComponent = ({
type,
quote,
person,
source,
className,
}: BlockquoteProps) {
}: BlockquoteProps) => {
return (
<BaseBlockquote
type={type}
Expand All @@ -22,9 +22,9 @@ export default function Blockquote({
className={className}
/>
);
}
};

Blockquote.smartComponentDefinition = {
export const smartComponentDefinition = {
title: "Blockquote",
iconUrl: null,
fields: {
Expand Down
6 changes: 3 additions & 3 deletions packages/react-sample-library/src/components/CTALink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ interface Props {
linkText: string;
}

export default function CTALink({ size, className, href, linkText }: Props) {
export const reactComponent = ({ size, className, href, linkText }: Props) => {
return (
<BaseCTALink
size={size}
className={className}
linkContent={<a href={href}>{linkText}</a>}
/>
);
}
};

CTALink.smartComponentDefinition = {
export const smartComponentDefinition = {
title: "CTA Link",
iconUrl: null,
fields: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { type SmartComponentMap } from "@pantheon-systems/pcc-sdk-core";

// TODO: Infer the type of the props from the smart component definition
// https://getpantheon.atlassian.net/browse/PCC-827
export default function InlineBannerNotification({
export const reactComponent = ({
title,
text,
type,
}: InlineBannerNotificationProps) {
}: InlineBannerNotificationProps) => {
return <BaseInlineBannerNotification title={title} text={text} type={type} />;
}
};

InlineBannerNotification.smartComponentDefinition = {
export const smartComponentDefinition = {
title: "Inline Banner Notification",
iconUrl: null,
fields: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { type SmartComponentMap } from "@pantheon-systems/pcc-sdk-core";

// TODO: Infer the type of the props from the smart component definition
// https://getpantheon.atlassian.net/browse/PCC-827
export default function SectionBannerNotification({
export const reactComponent = ({
message,
type,
isDismissible,
id,
title,
className,
}: SectionBannerNotificationProps) {
}: SectionBannerNotificationProps) => {
return (
<BaseSectionBannerNotification
message={message}
Expand All @@ -24,9 +24,9 @@ export default function SectionBannerNotification({
className={className}
/>
);
}
};

SectionBannerNotification.smartComponentDefinition = {
export const smartComponentDefinition = {
title: "Section Banner Notification",
iconUrl: null,
fields: {
Expand Down
8 changes: 4 additions & 4 deletions packages/react-sample-library/src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { type SmartComponentMap } from "@pantheon-systems/pcc-sdk-core";

// TODO: Infer the type of the props from the smart component definition
// https://getpantheon.atlassian.net/browse/PCC-827
export default function Tooltip({
export const reactComponent = ({
content,
triggerIcon,
triggerAccessibleText,
triggerText,
className,
}: TooltipProps) {
}: TooltipProps) => {
return (
<BaseTooltip
content={content}
Expand All @@ -22,9 +22,9 @@ export default function Tooltip({
className={className}
/>
);
}
};

Tooltip.smartComponentDefinition = {
export const smartComponentDefinition = {
title: "Tooltip",
iconUrl: null,
fields: {
Expand Down
80 changes: 72 additions & 8 deletions packages/react-sample-library/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,72 @@
export { default as Avatar } from "./Avatar";
export { default as Badge } from "./Badge";
export { default as BannerNotification } from "./BannerNotification";
export { default as Blockquote } from "./Blockquote";
export { default as CTALink } from "./CTALink";
export { default as InlineBannerNotification } from "./InlineBannerNotification";
export { default as SectionBannerNotification } from "./SectionBannerNotification";
export { default as Tooltip } from "./Tooltip";
import {
ServersideSmartComponentMap,
SmartComponentMap,
} from "@pantheon-systems/pcc-react-sdk/components";
import * as Avatar from "./Avatar";
import * as Badge from "./Badge";
import * as BannerNotification from "./BannerNotification";
import * as Blockquote from "./Blockquote";
import * as CTALink from "./CTALink";
import * as InlineBannerNotification from "./InlineBannerNotification";
import * as SectionBannerNotification from "./SectionBannerNotification";
import * as Tooltip from "./Tooltip";

// Adding a PANTHEON_ prefix to help developers using
// this library avoid naming conflicts.
export const ClientSmartComponentMap: SmartComponentMap = {
PANTHEON_AVATAR: {
...Avatar.smartComponentDefinition,
reactComponent: Avatar.reactComponent,
},
PANTHEON_BADGE: {
...Badge.smartComponentDefinition,
reactComponent: Badge.reactComponent,
},
PANTHEON_BANNER_NOTIFICATION: {
...BannerNotification.smartComponentDefinition,
reactComponent: BannerNotification.reactComponent,
},
PANTHEON_BLOCKQUOTE: {
...Blockquote.smartComponentDefinition,
reactComponent: Blockquote.reactComponent,
},
PANTHEON_CTA_LINK: {
...CTALink.smartComponentDefinition,
reactComponent: CTALink.reactComponent,
},
PANTHEON_INLINE_BANNER_NOTIFICATION: {
...InlineBannerNotification.smartComponentDefinition,
reactComponent: InlineBannerNotification.reactComponent,
},
PANTHEON_SECTION_BANNER_NOTIFICATION: {
...SectionBannerNotification.smartComponentDefinition,
reactComponent: SectionBannerNotification.reactComponent,
},
PANTHEON_TOOLTIP: {
...Tooltip.smartComponentDefinition,
reactComponent: Tooltip.reactComponent,
},
};

// Clone the client-side map and remove reactComponent from each entry.
export const ServerSmartComponentMap: ServersideSmartComponentMap = {};

Object.entries(ClientSmartComponentMap).forEach(([k, v]) => {
const serverSideConfig: Omit<typeof v, "reactComponent"> &
Partial<{
reactComponent: unknown;
}> = Object.assign({}, v);
delete serverSideConfig.reactComponent;
ServerSmartComponentMap[k] = serverSideConfig;
});

export {
Avatar,
Badge,
BannerNotification,
Blockquote,
CTALink,
InlineBannerNotification,
SectionBannerNotification,
Tooltip,
};
2 changes: 1 addition & 1 deletion packages/react-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pantheon-systems/pcc-react-sdk",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud React SDK",
"version": "2.0.17",
"version": "2.0.18",
"license": "MIT",
"keywords": [
"pcc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ import MarkdownRenderer from "./Markdown";
import PantheonTreeRenderer from "./PantheonTreeRenderer";
import PantheonTreeV2Renderer from "./PantheonTreeV2Renderer";

export type ServersideSmartComponentMap = {
[K in keyof CoreSmartComponentMap]: CoreSmartComponentMap[K];
};

export type SmartComponentMap = {
[K in keyof CoreSmartComponentMap]: CoreSmartComponentMap[K] & {
reactComponent: Parameters<typeof React.createElement>[0];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
reactComponent: (props: any) => React.JSX.Element;
};
};

Expand Down
1 change: 1 addition & 0 deletions packages/react-sdk/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export {
default as ArticleRenderer,
ServersideSmartComponentMap,
SmartComponentMap,
} from "./ArticleRenderer";
2 changes: 1 addition & 1 deletion packages/vue-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pantheon-systems/pcc-vue-sdk",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud Vue SDK",
"version": "2.0.17",
"version": "2.0.18",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down
Loading
Loading