Skip to content

Commit ccb3737

Browse files
authored
Update to example apps to support React 17 testing (#4698)
* partial progress * adding ability to switch between react 17 and 18 in the CRA apps * adding nextjs react 17 test app * test react 17 setup in original next example * test react 17 setup in tailwind example * fix nextjs config for 17 * fixing more typos * pushing temp progress for tailwind and react 17 nextjs app * removing console.log * testing that circleci still builds the apps * Revert "testing that circleci still builds the apps" This reverts commit fde37cd.
1 parent b349702 commit ccb3737

File tree

25 files changed

+890
-76
lines changed

25 files changed

+890
-76
lines changed

examples/rac-tailwind/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"private": true,
44
"scripts": {
55
"start": "parcel src/index.html",
6-
"build": "parcel build src/index.html"
6+
"build": "parcel build src/index.html",
7+
"install-17": "yarn add -W react@^17 react-dom@^17"
78
},
89
"dependencies": {
910
"@heroicons/react": "^2.0.16",

examples/rac-tailwind/src/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@ import { App } from './App';
33

44
let root = createRoot(document.getElementById('root'));
55
root.render(<App />);
6+
7+
// TODO: check on react-dom's version didn't work, figure out later
8+
// The below is for when react 17 is installed
9+
// import ReactDOM from 'react-dom';
10+
// ReactDOM.render(
11+
// <App />, document.getElementById("root")
12+
// )

examples/rsp-cra-18/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"homepage": ".",
66
"dependencies": {
77
"@adobe/react-spectrum": "latest",
8-
"@react-spectrum/tag": "^3.0.0-rc.0",
98
"@spectrum-icons/workflow": "latest",
109
"@testing-library/jest-dom": "^5.16.4",
1110
"@testing-library/react": "^13.3.0",
@@ -24,7 +23,8 @@
2423
"start": "react-scripts start",
2524
"build": "react-scripts build",
2625
"test": "react-scripts test",
27-
"eject": "react-scripts eject"
26+
"eject": "react-scripts eject",
27+
"install-17": "yarn add -W react@^17 react-dom@^17"
2828
},
2929
"eslintConfig": {
3030
"extends": [

examples/rsp-cra-18/src/App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import './App.css';
2-
import {Provider, defaultTheme, Item} from '@adobe/react-spectrum'
2+
import {Provider, defaultTheme, Item, TagGroup} from '@adobe/react-spectrum'
33
import Lighting from './Lighting';
44
import {useState} from 'react'
55
import BodyContent from './BodyContent';
6-
import {TagGroup} from '@react-spectrum/tag';
76

87
function App() {
98
let [selected, setSelection] = useState(false);

examples/rsp-cra-18/src/index.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import ReactDOM from 'react-dom/client';
1+
import ReactDOM from 'react-dom';
22
import './index.css';
33
import App from './App';
44

5-
const root = ReactDOM.createRoot(
6-
document.getElementById('root') as HTMLElement
7-
);
8-
root.render(
9-
<App />
10-
);
5+
if (ReactDOM.version.startsWith('18')) {
6+
let ReactDOMClient = require('react-dom/client');
7+
const root = ReactDOMClient.createRoot(
8+
document.getElementById('root') as HTMLElement
9+
);
10+
root.render(
11+
<App />
12+
);
13+
} else {
14+
ReactDOM.render(
15+
<App />, document.getElementById("root")
16+
)
17+
}

examples/rsp-next-ts-17/.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["next", "next/core-web-vitals"]
3+
}

examples/rsp-next-ts-17/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel

examples/rsp-next-ts-17/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Next.js Typescript example with React Spectrum
2+
3+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) and [React Spectrum](https://react-spectrum.adobe.com/index.html).
4+
5+
## Getting Started
6+
7+
First, run the development server:
8+
9+
```bash
10+
npm run dev
11+
# or
12+
yarn dev
13+
```
14+
15+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
16+
17+
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
18+
19+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.tsx`.
20+
21+
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { Item, ListView, Text, useListData } from "@adobe/react-spectrum";
2+
import { useDragAndDrop } from "@react-spectrum/dnd";
3+
import Folder from "@spectrum-icons/illustrations/Folder";
4+
5+
export default function ReorderableListView() {
6+
let list = useListData({
7+
initialItems: [
8+
{ id: "1", type: "file", name: "Adobe Photoshop" },
9+
{ id: "2", type: "file", name: "Adobe XD" },
10+
{ id: "3", type: "folder", name: "Documents", childNodes: [] },
11+
{ id: "4", type: "file", name: "Adobe InDesign" },
12+
{ id: "5", type: "folder", name: "Utilities", childNodes: [] },
13+
{ id: "6", type: "file", name: "Adobe AfterEffects" },
14+
],
15+
});
16+
17+
// Append a generated key to the item type so they can only be reordered within this list and not dragged elsewhere.
18+
let { dragAndDropHooks } = useDragAndDrop({
19+
getItems(keys) {
20+
return [...keys].map((key) => {
21+
let item = list.getItem(key);
22+
// Setup the drag types and associated info for each dragged item.
23+
return {
24+
"custom-app-type-reorder": JSON.stringify(item),
25+
"text/plain": item.name,
26+
};
27+
});
28+
},
29+
acceptedDragTypes: ["custom-app-type-reorder"],
30+
onReorder: async (e) => {
31+
let { keys, target, dropOperation } = e;
32+
33+
if (target.dropPosition === "before") {
34+
list.moveBefore(target.key, [...keys]);
35+
} else if (target.dropPosition === "after") {
36+
list.moveAfter(target.key, [...keys]);
37+
}
38+
},
39+
getAllowedDropOperations: () => ["move"],
40+
});
41+
42+
return (
43+
<ListView
44+
aria-label="Reorderable ListView"
45+
selectionMode="multiple"
46+
width="size-3600"
47+
height="size-3600"
48+
items={list.items}
49+
dragAndDropHooks={dragAndDropHooks}
50+
>
51+
{(item) => (
52+
<Item textValue={item.name}>
53+
{item.type === "folder" && <Folder />}
54+
<Text>{item.name}</Text>
55+
</Item>
56+
)}
57+
</ListView>
58+
);
59+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { View, Heading, Divider } from "@adobe/react-spectrum";
2+
import React from "react";
3+
4+
interface SectionProps {
5+
title: string;
6+
children: JSX.Element | JSX.Element[];
7+
}
8+
9+
export default function Section(props: SectionProps) {
10+
let { title, children } = props;
11+
return (
12+
<View marginBottom="size-200">
13+
<Heading id={title.toLowerCase()} level={2}>
14+
{title}
15+
</Heading>
16+
<Divider marginBottom="size-100" />
17+
{children}
18+
</View>
19+
);
20+
}

0 commit comments

Comments
 (0)