react & preact support
This commit is contained in:
parent
67180bb4f3
commit
82ed03d521
38
README.md
38
README.md
|
|
@ -11,6 +11,8 @@
|
|||
Forge is a typed, local, variant-driven way to organize CSS and create
|
||||
self-contained TSX components out of discrete parts.
|
||||
|
||||
Works with **React**, **Preact**, and **Hono JSX**.
|
||||
|
||||
## css problems
|
||||
|
||||
- Styles are global and open - anything can override anything anywhere.
|
||||
|
|
@ -28,6 +30,42 @@ self-contained TSX components out of discrete parts.
|
|||
- Themes are easy.
|
||||
- Errors and feedback are provided.
|
||||
|
||||
## setup
|
||||
|
||||
Install forge and configure your JSX runtime:
|
||||
|
||||
```bash
|
||||
npm install @because/forge
|
||||
```
|
||||
|
||||
Then set `jsxImportSource` in your `tsconfig.json`:
|
||||
|
||||
```json
|
||||
// React
|
||||
{ "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "react" } }
|
||||
|
||||
// Preact
|
||||
{ "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" } }
|
||||
|
||||
// Hono
|
||||
{ "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "hono/jsx" } }
|
||||
```
|
||||
|
||||
Include the generated CSS in your app:
|
||||
|
||||
```tsx
|
||||
// SSR - render <Styles /> in your <head>
|
||||
import { Styles } from "@because/forge"
|
||||
|
||||
<head>
|
||||
<Styles />
|
||||
</head>
|
||||
|
||||
// Or get raw CSS string
|
||||
import { stylesToCSS } from "@because/forge"
|
||||
const css = stylesToCSS()
|
||||
```
|
||||
|
||||
## examples
|
||||
|
||||
### styles
|
||||
|
|
|
|||
|
|
@ -319,6 +319,44 @@ const MARKDOWN_CONTENT = `
|
|||
Forge is a typed, local, variant-driven way to organize CSS and create
|
||||
self-contained TSX components out of discrete parts.
|
||||
|
||||
Works with **React**, **Preact**, and **Hono JSX**.
|
||||
|
||||
## setup
|
||||
|
||||
Install forge and configure your JSX runtime:
|
||||
|
||||
\`\`\`bash
|
||||
npm install @because/forge
|
||||
\`\`\`
|
||||
|
||||
Then set \`jsxImportSource\` in your \`tsconfig.json\`:
|
||||
|
||||
\`\`\`tsx
|
||||
// React
|
||||
{ "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "react" } }
|
||||
|
||||
// Preact
|
||||
{ "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" } }
|
||||
|
||||
// Hono
|
||||
{ "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "hono/jsx" } }
|
||||
\`\`\`
|
||||
|
||||
Include the generated CSS in your app:
|
||||
|
||||
\`\`\`tsx
|
||||
// SSR - render <Styles /> in your <head>
|
||||
import { Styles } from "@because/forge"
|
||||
|
||||
<head>
|
||||
<Styles />
|
||||
</head>
|
||||
|
||||
// Or get raw CSS string
|
||||
import { stylesToCSS } from "@because/forge"
|
||||
const css = stylesToCSS()
|
||||
\`\`\`
|
||||
|
||||
## css problems
|
||||
|
||||
- Styles are global and open - anything can override anything anywhere.
|
||||
|
|
|
|||
11
package.json
11
package.json
|
|
@ -30,5 +30,16 @@
|
|||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"react": {
|
||||
"optional": true
|
||||
},
|
||||
"preact": {
|
||||
"optional": true
|
||||
},
|
||||
"hono": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { define } from '../index'
|
||||
import { stylesToCSS } from '../index'
|
||||
|
||||
// Uses Hono JSX's toString() for tests - framework-specific
|
||||
export function renderToString(jsx: any): string {
|
||||
return jsx.toString()
|
||||
}
|
||||
|
||||
// Get generated CSS directly from styles registry
|
||||
export function getStylesCSS(): string {
|
||||
const StylesComponent = define.Styles
|
||||
const result = StylesComponent() as any
|
||||
return result.props.dangerouslySetInnerHTML.__html as string
|
||||
return stylesToCSS()
|
||||
}
|
||||
|
||||
export function parseCSS(css: string): Record<string, Record<string, string>> {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
"module": "Preserve",
|
||||
"moduleDetection": "force",
|
||||
"jsx": "react-jsx",
|
||||
// Hono for development - consumers override with their JSX runtime (react, preact, etc.)
|
||||
"jsxImportSource": "hono/jsx",
|
||||
"allowJs": true,
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user