Skip to content

Commit aeb981b

Browse files
committed
Proof of concept of a web component running inside of a react app
1 parent 7441c3b commit aeb981b

File tree

7 files changed

+2041
-93
lines changed

7 files changed

+2041
-93
lines changed

typescript/packages/jumble/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"private": true,
88
"type": "module",
99
"scripts": {
10-
"build": "npx vite build",
11-
"dev": "npx vite",
10+
"build": "vite build",
11+
"dev": "vite",
1212
"test": "vitest",
1313
"check": "tsc --build"
1414
},
@@ -21,6 +21,7 @@
2121
},
2222
"homepage": "https://github.com/commontoolsinc/labs#readme",
2323
"dependencies": {
24+
"@commontools/ui": "workspace:*",
2425
"@codemirror/lang-markdown": "^6.3.2",
2526
"@react-spring/web": "^9.7.5",
2627
"@tailwindcss/typography": "^0.5.16",

typescript/packages/jumble/src/main.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ import Home from "@/views/Home.tsx";
66
import PhotoFlowIndex from "@/views/experiments/photoflow/Index.tsx";
77
import PhotoSetView from "@/views/experiments/photoflow/PhotoSetView.tsx";
88
import NewSpell from "@/views/experiments/photoflow/NewSpell.tsx";
9+
import Shell from "@/views/Shell.tsx";
910

1011
createRoot(document.getElementById("root")!).render(
1112
<StrictMode>
1213
<Router>
1314
<Routes>
1415
<Route path="/" element={<Home />} />
16+
17+
<Route path="/shell" element={<Shell />} />
18+
1519
<Route path="/experiments/photoflow" element={<PhotoFlowIndex />} />
1620
<Route path="/experiments/photoflow/:photosetName" element={<PhotoSetView />} />
1721
<Route path="/experiments/photoflow/:photosetName/spells/new" element={<NewSpell />} />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference types="react-scripts" />
2+
3+
import { JSX } from "react";
4+
5+
declare global {
6+
namespace JSX {
7+
interface IntrinsicElements {
8+
[elementName: string]: React.DetailedHTMLProps<
9+
React.HTMLAttributes<HTMLElement>,
10+
HTMLElement
11+
> & {
12+
class?: string;
13+
};
14+
}
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This is all you need to import/register the @commontools/ui web components
2+
import "@commontools/ui";
3+
4+
const handleClick = () => {
5+
console.log("clicked");
6+
};
7+
8+
export default function Shell() {
9+
return (
10+
<div className="h-full relative">
11+
{/* You still use class="foo" with web components. */}
12+
<common-button class="wat" onClick={handleClick}>
13+
click me
14+
</common-button>
15+
</div>
16+
);
17+
}

typescript/packages/jumble/vite.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import tailwindcss from "@tailwindcss/vite";
55

66
// https://vite.dev/config/
77
export default defineConfig({
8-
// @ts-ignore
98
plugins: [react(), tailwindcss()],
109
resolve: {
1110
alias: {
1211
"@": path.resolve(__dirname, "./src"),
12+
// NOTE: We need to import local modules from the pnpm workspace.
13+
"@commontools/ui": path.resolve(__dirname, "../common-ui/src/index.ts"),
1314
},
1415
},
1516
});

0 commit comments

Comments
 (0)