Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
smmoosavi committed Nov 28, 2024
1 parent 9ca69f3 commit e871be7
Show file tree
Hide file tree
Showing 18 changed files with 830 additions and 72 deletions.
2 changes: 2 additions & 0 deletions examples/jsx-xml-example/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export default tseslint.config(
'warn',
{ allowConstantExport: true },
],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
},
},
);
5 changes: 4 additions & 1 deletion examples/jsx-xml-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"test": "vitest --run",
"preview": "vite preview"
},
"dependencies": {
"jsx-xml": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand All @@ -24,6 +26,7 @@
"globals": "^15.12.0",
"typescript": "~5.6.2",
"typescript-eslint": "^8.15.0",
"vite": "^6.0.1"
"vite": "^6.0.1",
"vitest": "^1"
}
}
38 changes: 8 additions & 30 deletions examples/jsx-xml-example/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,16 @@
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;
pre {
background-color: #f9f9f9;
border: 1px solid #eaeaea;
border-radius: 8px;
padding: 1em;
text-align: left;
min-width: 400px;
max-width: 100%;
}
36 changes: 13 additions & 23 deletions examples/jsx-xml-example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
import { useState } from 'react';
import reactLogo from './assets/react.svg';
import viteLogo from '/vite.svg';
import './App.css';
import { renderReact } from './react.tsx';
import { renderClassic } from './classic.tsx';
import { renderAutomatic } from './auto.tsx';

function App() {
const [count, setCount] = useState(0);

const xmlReact = renderReact(1);
const xmlClassic = renderClassic(2);
const xmlAuto = renderAutomatic(3);
return (
<>
<div>
<a href="https://vite.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<h1>jsx-xml</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
<h2>rendered react element</h2>
<pre>{xmlReact}</pre>
<h2>render classic</h2>
<pre>{xmlClassic}</pre>
<h2>render auto import</h2>
<pre>{xmlAuto}</pre>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
);
}
Expand Down
1 change: 0 additions & 1 deletion examples/jsx-xml-example/src/assets/react.svg

This file was deleted.

30 changes: 30 additions & 0 deletions examples/jsx-xml-example/src/auto.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @jsxImportSource jsx-xml

import { render } from 'jsx-xml';

declare global {
namespace JSX {
interface IntrinsicElements {
'x:automatic': any;
'x:nice': any;
}
}
}

const props = { foo: 'bar' };

export function renderAutomatic(count: number) {
return render(
<x:automatic>
<x:nice before="value" key="66" ref="77" after="value">
{count}
</x:nice>
<x:nice before="value" key="66" ref="77" after="value">
{count}
</x:nice>
<x:nice {...props} before="value" key="66" ref="77" after="value">
{count}
</x:nice>
</x:automatic>,
).end({ headless: true, prettyPrint: true });
}
24 changes: 24 additions & 0 deletions examples/jsx-xml-example/src/classic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @jsxRuntime classic
// @jsxFrag Fragment
// @jsx h

import { render, h } from 'jsx-xml';

declare global {
namespace JSX {
interface IntrinsicElements {
'x:classic': any;
'x:nice': any;
}
}
}

export function renderClassic(count: number) {
return render(
<x:classic>
<x:nice before="value" key="66" ref="77" after="value">
{count}
</x:nice>
</x:classic>,
).end({ headless: true, prettyPrint: true });
}
38 changes: 38 additions & 0 deletions examples/jsx-xml-example/src/react.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { render, Comment } from 'jsx-xml';
import { ReactNode } from 'react';

declare global {
namespace JSX {
interface IntrinsicElements {
'x:test': any;
'x:label': any;
'x:value': any;
'x:nice': any;
}
}
}

const XLabel = (props: { children?: ReactNode }) => {
return <x:label>{props.children}</x:label>;
};

const XValue = (props: { children?: ReactNode }) => {
return <x:value>{props.children}</x:value>;
};

export function renderReact(count: number) {
const xml = render(
<x:test>
<XLabel>count</XLabel>
<XValue>{count}</XValue>
<Comment>jsx-xml in react</Comment>
<x:nice before="value" key="66" ref="77" after="value">
{count}
</x:nice>
</x:test>,
).end({
headless: true,
prettyPrint: true,
});
return xml;
}
Loading

0 comments on commit e871be7

Please sign in to comment.