Skip to content

Commit

Permalink
Extract a fast-css-prop package.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenh committed Jan 24, 2025
1 parent 76a9c72 commit abec081
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 110 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"codegen": "yarn workspaces foreach run codegen"
},
"workspaces": [
"packages/fast-css-prop",
"packages/truss",
"packages/template-tachyons",
"packages/testing-tachyons",
Expand Down
2 changes: 1 addition & 1 deletion packages/app-tachyons-fela-prop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"preview": "vite preview"
},
"dependencies": {
"@homebound/fast-css-prop": "workspace:*",
"@homebound/truss-testing-tachyons": "workspace:*",
"fela": "^12.2.1",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/app-tachyons-fela-prop/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("App", () => {
<div>
<div>
<h1
class="black top1"
class="a b"
>
Vite1
</h1>
Expand Down
2 changes: 1 addition & 1 deletion packages/app-tachyons-fela-prop/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import react from "@vitejs/plugin-react-swc";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react({ jsxImportSource: "." })],
plugins: [react({ jsxImportSource: "@homebound/fast-css-prop" })],
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
import { maybeExpandCssProp } from "./cssProp.ts";
import { maybeExpandCssProp } from "./build/cssProp.js";

export function jsxDEV(type, props, ...children) {
return _jsxDEV(type, maybeExpandCssProp(props), ...children);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { jsx as _jsx } from "react/jsx-runtime";
import { maybeExpandCssProp } from "./cssProp.ts";
import { maybeExpandCssProp } from "./build/cssProp.js";

export function jsx(type, props, ...children) {
return _jsx(type, maybeExpandCssProp(props), ...children);
Expand Down
22 changes: 22 additions & 0 deletions packages/fast-css-prop/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@homebound/fast-css-prop",
"version": "1.136.0",
"main": "build/index.js",
"bin": "cli.js",
"scripts": {
"test": "jest"
},
"exports": {
".": "./build/cssProp.js",
"./jsx-runtime": "./jsx-runtime.js",
"./jsx-dev-runtime": "./jsx-dev-runtime.js"
},
"license": "ISC",
"dependencies": {
"fela": "^12.2.1"
},
"devDependencies": {
"@homebound/tsconfig": "^1.0.3",
"typescript": "^5.7.3"
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { createRenderer } from "fela";
import { render } from "fela-dom";
import { names } from "@homebound/truss-testing-tachyons";
// import { names } from "@homebound/truss-testing-tachyons";

// Create a renderer
const renderer = createRenderer();
// Auto-inject any CSS it creates into the DOM
render(renderer);

const existingGenerateClassName = renderer.generateClassName.bind(renderer);
renderer.generateClassName = (property: string, value: string, pseudo: string, media: string, support: string) => {
const ref = property + value + pseudo + media + support;
return names[ref] ?? existingGenerateClassName(property, value, pseudo, media, support);
};
// const existingGenerateClassName = (renderer as any).generateClassName.bind(renderer);
// (renderer as any).generateClassName = (
// property: string,
// value: string,
// pseudo: string,
// media: string,
// support: string,
// ) => {
// const ref = property + value + pseudo + media + support;
// return names[ref] ?? existingGenerateClassName(property, value, pseudo, media, support);
// };

/**
* Wraps React's JSX runtime (i.e. `createElement`) with `css` prop support.
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions packages/fast-css-prop/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "@homebound/tsconfig/tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"downlevelIteration": true,
"baseUrl": ".",
"outDir": "build/",
"plugins": [
{ "transform": "typescript-transform-paths" },
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
]
},
"include": ["./src"]
}
Loading

0 comments on commit abec081

Please sign in to comment.