-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(sandbox): add react 19 rc example (#1792)
- Loading branch information
Showing
28 changed files
with
951 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
export default tseslint.config({ | ||
languageOptions: { | ||
// other options... | ||
parserOptions: { | ||
project: ['./tsconfig.node.json', './tsconfig.app.json'], | ||
tsconfigRootDir: import.meta.dirname, | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked` | ||
- Optionally add `...tseslint.configs.stylisticTypeChecked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config: | ||
|
||
```js | ||
// eslint.config.js | ||
import react from 'eslint-plugin-react' | ||
|
||
export default tseslint.config({ | ||
// Set the react version | ||
settings: { react: { version: '18.3' } }, | ||
plugins: { | ||
// Add the react plugin | ||
react, | ||
}, | ||
rules: { | ||
// other rules... | ||
// Enable its recommended rules | ||
...react.configs.recommended.rules, | ||
...react.configs['jsx-runtime'].rules, | ||
}, | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import js from "@eslint/js" | ||
import globals from "globals" | ||
import reactHooks from "eslint-plugin-react-hooks" | ||
import reactRefresh from "eslint-plugin-react-refresh" | ||
import tseslint from "typescript-eslint" | ||
|
||
export default tseslint.config( | ||
{ ignores: ["dist"] }, | ||
{ | ||
extends: [js.configs.recommended, ...tseslint.configs.recommended], | ||
files: ["**/*.{ts,tsx}"], | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
globals: globals.browser, | ||
}, | ||
plugins: { | ||
"react-hooks": reactHooks, | ||
"react-refresh": reactRefresh, | ||
}, | ||
rules: { | ||
...reactHooks.configs.recommended.rules, | ||
"react-refresh/only-export-components": ["warn", { allowConstantExport: true }], | ||
}, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + TS</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "react-19", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc -b && vite build", | ||
"lint": "eslint .", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@zag-js/accordion": "workspace:*", | ||
"@zag-js/dom-query": "workspace:*", | ||
"@zag-js/react": "workspace:*", | ||
"@zag-js/shared": "workspace:*", | ||
"@zag-js/stringify-state": "workspace:*", | ||
"lucide-react": "0.428.0", | ||
"react": "19.0.0-rc-b57d2823-20240822", | ||
"react-dom": "19.0.0-rc-b57d2823-20240822" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.9.0", | ||
"@types/react": "^18.3.3", | ||
"@types/react-dom": "^18.3.0", | ||
"@vitejs/plugin-react": "^4.3.1", | ||
"eslint": "^9.9.0", | ||
"eslint-plugin-react-hooks": "^5.1.0-rc.0", | ||
"eslint-plugin-react-refresh": "^0.4.9", | ||
"globals": "^15.9.0", | ||
"typescript": "^5.5.3", | ||
"typescript-eslint": "^8.0.1", | ||
"vite": "^5.4.1" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#root { | ||
max-width: 1280px; | ||
margin: 0 auto; | ||
padding: 2rem; | ||
text-align: center; | ||
} | ||
|
||
.logo { | ||
height: 6em; | ||
padding: 1.5em; | ||
will-change: filter; | ||
transition: filter 300ms; | ||
} | ||
.logo:hover { | ||
filter: drop-shadow(0 0 2em #646cffaa); | ||
} | ||
.logo.react:hover { | ||
filter: drop-shadow(0 0 2em #61dafbaa); | ||
} | ||
|
||
@keyframes logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
a:nth-of-type(2) .logo { | ||
animation: logo-spin infinite 20s linear; | ||
} | ||
} | ||
|
||
.card { | ||
padding: 2em; | ||
} | ||
|
||
.read-the-docs { | ||
color: #888; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Accordion from "./pages/accordion" | ||
|
||
function App() { | ||
return ( | ||
<div className="page"> | ||
<aside className="nav"> | ||
<header>Zagjs</header> | ||
<a>Accordion</a> | ||
</aside> | ||
<Accordion /> | ||
</div> | ||
) | ||
} | ||
|
||
export default App |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as dialog from "@zag-js/dialog" | ||
import { useMachine, normalizeProps, Portal } from "@zag-js/react" | ||
import { useId } from "react" | ||
|
||
interface Props extends Omit<dialog.Context, "open.controlled" | "id"> { | ||
defaultOpen?: boolean | ||
} | ||
|
||
export function Dialog(props: Props) { | ||
const { open, defaultOpen, ...context } = props | ||
|
||
const [state, send] = useMachine( | ||
dialog.machine({ | ||
id: useId(), | ||
open: open ?? defaultOpen, | ||
}), | ||
{ | ||
context: { | ||
...context, | ||
"open.controlled": open !== undefined, | ||
open, | ||
}, | ||
}, | ||
) | ||
|
||
const api = dialog.connect(state, send, normalizeProps) | ||
|
||
return ( | ||
<> | ||
<button {...api.getTriggerProps()}>Open Dialog</button> | ||
{api.open && ( | ||
<Portal> | ||
<div {...api.getBackdropProps()} /> | ||
<div {...api.getPositionerProps()}> | ||
<div {...api.getContentProps()}> | ||
<h2 {...api.getTitleProps()}>Edit profile</h2> | ||
<p {...api.getDescriptionProps()}>Make changes to your profile here. Click save when you are done.</p> | ||
<div> | ||
<input placeholder="Enter name..." /> | ||
<button>Save</button> | ||
</div> | ||
<button {...api.getCloseTriggerProps()}>Close</button> | ||
</div> | ||
</div> | ||
</Portal> | ||
)} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useId, useState } from "react" | ||
import { createPortal } from "react-dom" | ||
|
||
type IFrameProps = React.ComponentProps<"iframe"> | ||
|
||
export const IFrame = function IFrame(props: IFrameProps) { | ||
const { children, ...rest } = props | ||
|
||
const [frameRef, setFrameRef] = useState<HTMLIFrameElement | null>(null) | ||
const mountNode = frameRef?.contentWindow?.document.body | ||
|
||
return ( | ||
<iframe title={`frame:${useId()}`} ref={setFrameRef} {...rest}> | ||
{mountNode ? createPortal(children, mountNode) : null} | ||
</iframe> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
export function LoaderBar(props: { title?: string }) { | ||
const title = props.title || "loader bars" | ||
|
||
return ( | ||
<svg className="spinner" height="24" width="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"> | ||
<title>{title}</title> | ||
<g fill="currentColor"> | ||
<rect height="6" width="2" fill="currentColor" x="11" /> | ||
<rect | ||
height="2" | ||
width="6" | ||
fill="currentColor" | ||
opacity="0.9" | ||
transform="matrix(0.7071 -0.7071 0.7071 0.7071 1.3935 14.6361)" | ||
x="15.364" | ||
y="4.636" | ||
/> | ||
<rect height="2" width="6" fill="currentColor" opacity="0.8" x="18" y="11" /> | ||
<rect | ||
height="6" | ||
width="2" | ||
fill="currentColor" | ||
opacity="0.7" | ||
transform="matrix(0.7071 -0.7071 0.7071 0.7071 -7.6066 18.364)" | ||
x="17.364" | ||
y="15.364" | ||
/> | ||
<rect height="6" width="2" fill="currentColor" opacity="0.6" x="11" y="18" /> | ||
<rect | ||
height="2" | ||
width="6" | ||
fill="currentColor" | ||
opacity="0.5" | ||
transform="matrix(0.7071 -0.7071 0.7071 0.7071 -11.3346 9.3639)" | ||
x="2.636" | ||
y="17.364" | ||
/> | ||
<rect height="2" width="6" fill="currentColor" opacity="0.4" y="11" /> | ||
<rect | ||
height="6" | ||
width="2" | ||
fill="currentColor" | ||
opacity="0.3" | ||
transform="matrix(0.7071 -0.7071 0.7071 0.7071 -2.3345 5.636)" | ||
x="4.636" | ||
y="2.636" | ||
/> | ||
</g> | ||
</svg> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function Print(props: { title: string; value: any }) { | ||
const { value, title } = props | ||
return ( | ||
<div className="output"> | ||
<p>{title}</p> | ||
<pre data-testid="output">{JSON.stringify(value, null, 2)}</pre> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const Show = (props: { when: boolean; children: React.ReactNode }) => { | ||
const { when, children } = props | ||
return when ? <>{children}</> : null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { highlightState } from "@zag-js/stringify-state" | ||
|
||
type StateVisualizerProps = { | ||
state: Record<string, any> | ||
label?: string | ||
omit?: string[] | ||
} | ||
|
||
export function StateVisualizer(props: StateVisualizerProps) { | ||
const { state, label, omit } = props | ||
|
||
return ( | ||
<div className="viz"> | ||
<pre dir="ltr"> | ||
<details open> | ||
<summary> {label || "Visualizer"} </summary> | ||
<div dangerouslySetInnerHTML={{ __html: highlightState(state, omit) }} /> | ||
</details> | ||
</pre> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.