Skip to content

Commit ea7b589

Browse files
committed
feat(packages/stylish): foundations of the lib
1 parent e404a02 commit ea7b589

12 files changed

Lines changed: 1174 additions & 1676 deletions

File tree

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ indent_size = 4
2020
indent_style = space
2121
indent_size = 2
2222

23-
[package.json]
23+
[*.json]
2424
indent_style = space
2525
indent_size = 2

.rules

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Core Architecture
44

55
**Monorepo Structure**: Turborepo with pnpm workspaces
6-
- `packages/ui` (@snap-ui): Component library (React 19, TypeScript)
6+
- `packages/ui` (@snapverse/gui): Component library (React 19, TypeScript)
77
- `packages/stylish` (@snapverse/stylish): Styling system (empty/WIP)
88
- `apps/docs`: Next.js 15 demo app (port 3001)
99
- `apps/web`: Next.js 15 app (port 3000)
@@ -35,11 +35,11 @@ export default Component
3535

3636
### Package Exports
3737
UI package uses wildcard exports: `./*` maps to `./src/*/index.ts`
38-
- Consumers import: `import Accordion from "@snap-ui/accordion"`
38+
- Consumers import: `import Accordion from "@snapverse/gui/accordion"`
3939

4040
### Code Generation
4141
Turbo generator at `packages/ui/turbo/generators/config.ts`:
42-
- Run: `pnpm --filter @snap-ui generate:component`
42+
- Run: `pnpm --filter @snapverse/gui generate:component`
4343
- Uses Handlebars template with kebabCase/pascalCase helpers
4444
- Auto-appends export to package.json
4545

@@ -74,7 +74,7 @@ All components use `@snapverse/{ComponentName}` for React DevTools
7474
- Don't suggest `pnpm build` or `npm build` unless explicitly asked
7575

7676
## Development Flow
77-
1. Generate component: `pnpm --filter @snap-ui generate:component`
77+
1. Generate component: `pnpm --filter @snapverse/gui generate:component`
7878
2. Edit in `packages/ui/src/{component}/`
7979
3. Export via namespace pattern in `namespace.ts`
8080
4. Apps auto-reload via turborepo watch mode

apps/docs/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Accordion from "@snap-ui/accordion";
1+
import Accordion from "@snapverse/gui/accordion";
22

33
export default function Home() {
44
return (

apps/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"check-types": "tsc --noEmit"
1212
},
1313
"dependencies": {
14-
"@snap-ui": "workspace:*",
14+
"@snapverse/gui": "workspace:*",
1515
"next": "^15.3.0",
1616
"react": "^19.1.0",
1717
"react-dom": "^19.1.0"

apps/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"check-types": "tsc --noEmit"
1212
},
1313
"dependencies": {
14-
"@snap-ui": "workspace:*",
14+
"@snapverse/gui": "workspace:*",
1515
"next": "^15.3.0",
1616
"react": "^19.1.0",
1717
"react-dom": "^19.1.0"

packages/stylish/src/builder.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { createElement as createReactElement, HTMLAttributes } from "react";
2+
import { type ElementTagNames, type StylishProps } from "./index";
3+
4+
export const createElement = <
5+
T extends ElementTagNames,
6+
P extends React.HTMLAttributes<T> = StylishProps,
7+
>(
8+
tag: T,
9+
_props: P,
10+
children?: React.ReactNode,
11+
) => {
12+
const props = new Proxy(_props, {
13+
set(target, prop, value) {
14+
if (prop === "style" && typeof value === "object") {
15+
// Here you would implement the logic to transform the style object into a CSS class
16+
// and inject the corresponding styles into the document.
17+
// For simplicity, we will just log the styles here.
18+
console.log("Transforming style:", value);
19+
// You would replace this with the actual class name generated from the styles.
20+
target["className"] = "generated-class";
21+
return true;
22+
}
23+
return true;
24+
},
25+
});
26+
27+
return createReactElement<HTMLAttributes<typeof tag> & P>(
28+
tag,
29+
props,
30+
children,
31+
);
32+
};

packages/stylish/src/factory.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { createElement } from "./builder";
2+
3+
export const gui = {
4+
div: createElement.bind(null, "div"),
5+
span: createElement.bind(null, "span"),
6+
// ...
7+
};

packages/stylish/src/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { HTMLElementType } from "react";
2+
3+
export type ElementTagNames = HTMLElementType;
4+
5+
export type StyleProps = HTMLElement["style"];
6+
7+
export interface StylishProps extends React.ReactElement<StylishProps> {
8+
color?: string;
9+
// ...
10+
}

packages/stylish/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from "./builder";
2+
export * from "./factory";
3+
export * from "./stylesheet";
4+
export * from "./index.d";

packages/stylish/src/stylesheet.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export type CSSClass = string;
2+
3+
export const css = (
4+
strings: TemplateStringsArray,
5+
...values: unknown[]
6+
): CSSClass => {
7+
// This function would contain the logic to generate a unique class name based on the provided styles,
8+
// and inject the corresponding CSS into the document.
9+
// For simplicity, we will return a placeholder class name here.
10+
return `generated-class-${Math.random().toString(36).substr(2, 9)}`;
11+
};
12+
13+
/**
14+
*
15+
* Transforms a style prop attribute into an isolated CSS class name, adding vendor compatibility prefixes if needed.
16+
*
17+
* @param key - The CSS property name (e.g., "backgroundColor", "transform", etc.)
18+
* @param value - The CSS property value (e.g., "red", "rotate(45deg)", etc.)
19+
*
20+
* @example
21+
* // Example usage:
22+
* const className = transformStyleAttribute("backgroundColor", "red");
23+
* // This would generate a CSS class with the appropriate styles and return its name.
24+
*/
25+
export const transformxStyleAttribute = (
26+
key: string,
27+
value: unknown,
28+
): CSSClass => {
29+
return css`
30+
${key}: ${value}
31+
`;
32+
};

0 commit comments

Comments
 (0)