Skip to content

Commit

Permalink
Upgrade next to v14 (#2837)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding authored Dec 12, 2023
1 parent 2ca80cb commit 3301a56
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 256 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@
"webpack-dev-server": "4.9.3",
"@changesets/assemble-release-plan@^5.2.2": "patch:@changesets/assemble-release-plan@npm%3A5.2.2#./.yarn/patches/@changesets-assemble-release-plan-npm-5.2.2-11f5894b70.patch",
"modular-scripts/rollup": "2.79.1",
"@salt-ds/lab": "workspace:*"
"@salt-ds/lab": "workspace:*",
"next": "^14.0.0",
"@next/eslint-plugin-next": "^14.0.0"
},
"browserslist": {
"production": [
Expand Down
26 changes: 13 additions & 13 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@
"gen:css": "yarn node './cssGen.js'"
},
"dependencies": {
"@jpmorganchase/mosaic-cli": "^0.1.0-beta.59",
"@jpmorganchase/mosaic-components": "^0.1.0-beta.59",
"@jpmorganchase/mosaic-content-editor-plugin": "^0.1.0-beta.59",
"@jpmorganchase/mosaic-layouts": "^0.1.0-beta.59",
"@jpmorganchase/mosaic-site-components": "^0.1.0-beta.59",
"@jpmorganchase/mosaic-site-preset-styles": "^0.1.0-beta.59",
"@jpmorganchase/mosaic-source-git-repo": "^0.1.0-beta.59",
"@jpmorganchase/mosaic-source-local-folder": "^0.1.0-beta.59",
"@jpmorganchase/mosaic-standard-generator": "^0.1.0-beta.59",
"@jpmorganchase/mosaic-store": "^0.1.0-beta.59",
"@jpmorganchase/mosaic-theme": "^0.1.0-beta.59",
"@jpmorganchase/mosaic-cli": "^0.1.0-beta.60",
"@jpmorganchase/mosaic-components": "^0.1.0-beta.60",
"@jpmorganchase/mosaic-content-editor-plugin": "^0.1.0-beta.60",
"@jpmorganchase/mosaic-layouts": "^0.1.0-beta.60",
"@jpmorganchase/mosaic-site-components": "^0.1.0-beta.60",
"@jpmorganchase/mosaic-site-preset-styles": "^0.1.0-beta.60",
"@jpmorganchase/mosaic-source-git-repo": "^0.1.0-beta.60",
"@jpmorganchase/mosaic-source-local-folder": "^0.1.0-beta.60",
"@jpmorganchase/mosaic-standard-generator": "^0.1.0-beta.60",
"@jpmorganchase/mosaic-store": "^0.1.0-beta.60",
"@jpmorganchase/mosaic-theme": "^0.1.0-beta.60",
"@philpl/buble": "^0.19.7",
"@types/react": "^18.0.26",
"lodash-es": "^4.17.21",
"next": "^13.5.2",
"next": "^14.0.4",
"next-auth": "^4.23.1",
"raw-loader": "^4.0.2"
},
"devDependencies": {
"@next/eslint-plugin-next": "^13.5.2",
"@next/eslint-plugin-next": "^14.0.4",
"@types/node": "^16.0.0",
"concurrently": "^8.0.0",
"cross-env": "^7.0.3",
Expand Down
45 changes: 38 additions & 7 deletions site/src/components/components/LivePreview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { FC, ChangeEvent, useState, ReactNode, ReactElement } from "react";
import {
FC,
ChangeEvent,
useState,
ReactNode,
ReactElement,
useEffect,
ElementType,
} from "react";
import clsx from "clsx";
import { Switch } from "@salt-ds/core";
import { SaltProvider } from "@salt-ds/core";
Expand Down Expand Up @@ -34,11 +42,34 @@ export const LivePreview: FC<LivePreviewProps> = ({

const isMobileView = useIsMobileView();

const ComponentExample: () => ReactElement =
require(`../../examples/${componentName}`)[exampleName];
const [ComponentExample, setComponentExample] = useState<{
Example?: ElementType;
sourceCode: string;
}>({
Example: undefined,
sourceCode: "",
});
useEffect(() => {
async function fetchExample() {
const Example = (
(await import(`../../examples/${componentName}`)) as Record<
string,
ElementType
>
)[exampleName];
const sourceCode = (
(await import(
`!!raw-loader!../../examples/${componentName}/${exampleName}.tsx`
)) as Record<string, string>
).default;

return { Example, sourceCode };
}

const codePreview =
require(`!!raw-loader!../../examples/${componentName}/${exampleName}.tsx`).default;
fetchExample()
.then((data) => setComponentExample(data))
.catch((e) => console.error(`Failed to load example ${exampleName}`, e));
}, [exampleName, componentName]);

const {
density,
Expand Down Expand Up @@ -75,7 +106,7 @@ export const LivePreview: FC<LivePreviewProps> = ({
<div className={styles.exampleWithSwitch}>
<div className={styles.example}>
<SaltProvider density={density}>
{ComponentExample && <ComponentExample />}
{ComponentExample.Example && <ComponentExample.Example />}
</SaltProvider>
</div>
<SaltProvider density="medium">
Expand All @@ -92,7 +123,7 @@ export const LivePreview: FC<LivePreviewProps> = ({

{showCode && (
<Pre className={styles.codePreview}>
<div className="language-tsx">{codePreview}</div>
<div className="language-tsx">{ComponentExample.sourceCode}</div>
</Pre>
)}
</div>
Expand Down
49 changes: 38 additions & 11 deletions site/src/components/components/PropsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useEffect } from "react";
import { FC, useEffect, useState } from "react";
import ReactMarkdown from "react-markdown";
import { Table } from "../mdx/table";
import { code, p, ul } from "../mdx";
Expand Down Expand Up @@ -32,21 +32,48 @@ type ComponentData = {
props: Props;
};

type JSONData = {
props: Record<
string,
{
name: string;
type: { name: string };
description: string;
defaultValue?: { value: string };
}
>;
displayName?: string;
};

export const PropsTable: FC<PropsTableType> = ({
packageName = "core",
componentName,
}) => {
const props: ComponentData[] = require(`../../props/${packageName}-props.json`);

const propsTableData = props.find(
({ displayName }) => displayName === componentName
)?.props;
const [props, setProps] = useState({} as JSONData["props"]);

useEffect(() => {
if (!propsTableData) {
console.warn(`No props were found for the ${componentName} component.`);
async function fetchProps() {
const props = (await import(`../../props/${packageName}-props.json`))
.default as JSONData[];

return props.find(({ displayName }) => displayName === componentName)
?.props;
}
}, []);

fetchProps()
.then((propsTableData) => {
if (!propsTableData) {
console.warn(
`No props were found for the ${componentName} component.`
);
} else {
setProps(propsTableData);
}
})
.catch(() => {
console.warn(`No props were found for the ${componentName} component.`);
});
}, [packageName, componentName]);

return (
<Table>
Expand All @@ -59,8 +86,8 @@ export const PropsTable: FC<PropsTableType> = ({
</tr>
</thead>
<tbody>
{propsTableData &&
Object.values(propsTableData).map(
{props &&
Object.values(props).map(
({ name, type, description, defaultValue }) => (
<tr key={name}>
<td>{name}</td>
Expand Down
7 changes: 5 additions & 2 deletions site/src/components/mdx/pre/Pre.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { FC, PropsWithChildren } from "react";
import { components } from "@jpmorganchase/mosaic-site-components";
import type { PreProps } from "@jpmorganchase/mosaic-components";
import {
Pre as InnerPre,
withMarkdownSpacing,
} from "@jpmorganchase/mosaic-components";
import styles from "./Pre.module.css";

const MosaicPre = components.pre;
const MosaicPre = withMarkdownSpacing(InnerPre);

export const Pre: FC<PropsWithChildren<PreProps>> = ({ ...props }) => (
<div className={styles.pre}>
Expand Down
6 changes: 4 additions & 2 deletions site/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import {
ImageProvider,
LinkProvider,
ThemeProvider,
getMarkdownComponents,
withMarkdownSpacing,
} from "@jpmorganchase/mosaic-components";
import { LayoutProvider } from "@jpmorganchase/mosaic-layouts";
import { useCreateStore, StoreProvider } from "@jpmorganchase/mosaic-store";
import { components as mosaicComponents } from "@jpmorganchase/mosaic-site-components";
import { layouts as mosaicLayouts } from "@jpmorganchase/mosaic-layouts";
import { SessionProvider } from "next-auth/react";
import { themeClassName } from "@jpmorganchase/mosaic-theme";
Expand All @@ -40,10 +41,11 @@ import * as saltComponents from "../components";
import { MyAppProps } from "../types/mosaic";

const components = {
...mosaicComponents,
...getMarkdownComponents(),
...saltComponents,
Homepage,
Image,
img: withMarkdownSpacing(Image),
};

const layoutComponents = { ...mosaicLayouts, ...saltLayouts };
Expand Down
Loading

1 comment on commit 3301a56

@vercel
Copy link

@vercel vercel bot commented on 3301a56 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.