|
2 | 2 |
|
3 | 3 | **Zero-runtime CSS in JS and Compiler** |
4 | 4 |
|
5 | | -- For Next.js App router(RSC) |
6 | | -- Console lover |
7 | | -- Client Component (Non async Server Component) |
8 | | -- Zero-runtime (statically generated during build) |
9 | | -- Hot Reload (A smooth development experience) |
10 | | -- Hard Type (AutoComplete with TypeScript is works) |
11 | | -- Media (Media Query provides modern functions) |
| 5 | +Typed CSS X is an innovative CSS-in-JS solution designed for the Next.js App Router (RSC). |
| 6 | +Key features: |
12 | 7 |
|
13 | | -All types are property(camelCase): String | Number. |
14 | | -The compiler assigns px to number unless there is an exception. |
| 8 | +- Client Component support |
| 9 | +- Zero-runtime (statically generated during build time) |
| 10 | +- Hot Reload |
| 11 | +- type check (compile time and autocomplete) |
15 | 12 |
|
16 | | -The className property and style are converted to an underscore with a hash as className. |
17 | | -This can be written directly to a css.ts or css.tsx file. |
| 13 | +For detailed documentation, visit our [typedcssx site](https://typedcssx.vercel.app/). |
18 | 14 |
|
19 | | -In development mode with we can see hot reloading preview by adding 'use client'. |
| 15 | +## Quick Start |
20 | 16 |
|
21 | | -## Style.create and Style.set |
22 | | - |
23 | | -```ts |
| 17 | +```typescript |
| 18 | +// Header.css.tsx |
24 | 19 | import { Style } from 'typedcssx'; |
25 | 20 |
|
26 | | -export const styles = Style.create({ |
27 | | - header_nav: { |
28 | | - position: 'absolute', |
29 | | - top: 0, |
30 | | - }, |
31 | | -}); |
32 | | - |
33 | | -export const navStyle = Style.set({ |
34 | | - '& a': { |
35 | | - fontSize: 16, |
36 | | - color: '#333', |
37 | | - }, |
38 | | -}); |
39 | | -``` |
40 | | - |
41 | | -## Example of use |
42 | | - |
43 | | -```tsx |
44 | | -import { styles, navStyle } from './style.css'; |
45 | | - |
46 | | -const Header = () => { |
47 | | - return ( |
48 | | - <header className={styles.header_nav}> |
49 | | - <nav className={navStyle}> |
50 | | - <a>content</a> |
51 | | - <a>home</a> |
52 | | - </nav> |
53 | | - </header> |
54 | | - ); |
55 | | -}; |
56 | | -``` |
57 | | - |
58 | | -## Global function |
59 | | - |
60 | | -Style.gloabl and Style.root is do not use it in a variable scope. |
61 | | -Wherever they are, the compiler reads them and writes them to the StyleSheet. |
62 | | - |
63 | | -development there preview it, you need to load it in the 'use client' place and render it. |
64 | | - |
65 | | -```ts |
66 | | -Style.global({ |
67 | | - h1: { |
68 | | - color: 'var(--color-font)', |
69 | | - background: 'var(--color-background)', |
70 | | - }, |
71 | | - 'h2:hover': { |
72 | | - color: 'skyblue', |
73 | | - }, |
74 | | -}); |
75 | | - |
76 | | -Style.root({ |
77 | | - '--color-font': '#333', |
78 | | - '--color-background': '#fff', |
79 | | -}); |
80 | | -``` |
81 | | - |
82 | | -## MediaQuery |
83 | | - |
84 | | -```ts |
85 | | -import { Style, media } from 'typedcssx'; |
86 | | -const small = media('300px <= width <= 600px'); |
87 | | -const large = media('200px <= width <= 1400px'); |
88 | | - |
89 | | -export const styles = Style.create({ |
90 | | - header_nav: { |
| 21 | +const styles = Style.create({ |
| 22 | + header: { |
91 | 23 | fontSize: 18, |
92 | | - color: 'white', |
93 | | - ...small({ |
94 | | - fontSize: 12, |
95 | | - color: 'pink', |
96 | | - }), |
| 24 | + color: 'blue', |
97 | 25 | }, |
98 | | - footer_nav: { |
99 | | - margin: 0, |
100 | | - padding: 0, |
101 | | - }, |
102 | | - ...large({ |
103 | | - footer_nav: { |
104 | | - margin: 24, |
105 | | - padding: 24, |
106 | | - }, |
107 | | - }), |
108 | 26 | }); |
109 | | -``` |
110 | | - |
111 | | -It's can enclose selectors or properties directly. |
112 | | -media is a higher-order function, so you can directly create wrapper functions for small, large, etc. |
113 | | - |
114 | | -## Build Setting and Global CSS |
115 | 27 |
|
116 | | -add file extension in tsconfig.json |
117 | | - |
118 | | -```json |
119 | | - "include": ["**/*.css.ts", "**/*.css.tsx"] |
| 28 | +const Header = () => <header className={styles.header}>Hello, Typed CSS X!</header>; |
120 | 29 | ``` |
121 | | - |
122 | | -add package.json scripts field. |
123 | | - |
124 | | -```json |
125 | | - "scripts": { |
126 | | - "build": "npm run compile && next build", |
127 | | - "compile": "cd node_modules/typedcssx && npm run compile" |
128 | | - } |
129 | | -``` |
130 | | - |
131 | | -import the global style in layout.tsx |
132 | | - |
133 | | -```tsx |
134 | | -import '../../node_modules/typedcssx/dist/core/styles/global.css'; |
135 | | -``` |
136 | | - |
137 | | -## License |
138 | | - |
139 | | -MIT License |
0 commit comments