|
2 | 2 |
|
3 | 3 | [](https://github.com/typicode/mistcss/actions/workflows/node.js.yml) |
4 | 4 |
|
5 | | -> Write atomic React components using only CSS! (JS-from-CSS™) |
| 5 | +> Write React components using CSS only |
6 | 6 |
|
7 | | -## Why? |
| 7 | +MistCSS is a new, better and faster way to write visual components. ~~CSS-in-JS~~? Nope! JS-from-CSS 👍 |
8 | 8 |
|
9 | | -- CSS is a beautiful language 💖, getting better every year 🚀. |
10 | | -- Easily distinguish between pure visual/atomic components and more complex ones by their extension (`*.mist.css`). |
11 | | -- Write less and focus on style to avoid context-switching with JS, reducing bugs. |
12 | | -- Gain automatic type safety for your React components; MistCSS compiles to TSX. |
13 | | -- Enjoy a zero-runtime experience. |
14 | | -- Works with Next, Remix, Astro, ... any modern React framework. |
| 9 | +View the [site](https://typicode.github.io/mistcss) to learn more. |
15 | 10 |
|
16 | | -## Install |
17 | | - |
18 | | -```shell |
19 | | -npm install mistcss --save-dev |
20 | | -``` |
21 | | - |
22 | | -## Usage |
23 | | - |
24 | | -### 1. Create your first CSS component |
25 | | - |
26 | | -Assuming your React components are in `src/components`, let's create a basic Button component using CSS. |
27 | | - |
28 | | -`src/components/Button.mist.css` |
| 11 | +Supports Next.js, Remix and TailwindCSS. More to come. |
29 | 12 |
|
30 | 13 | ```css |
31 | | -@scope (.btn) { |
32 | | - button:scope { |
33 | | - /* Default style */ |
34 | | - font-size: 1rem; |
35 | | - border-radius: 0.25rem; |
36 | | - |
37 | | - &[data-size='lg'] { |
38 | | - font-size: 1.5rem; |
39 | | - } |
40 | | - |
41 | | - &[data-size='sm'] { |
42 | | - font-size: 0.75rem; |
43 | | - } |
| 14 | +@scope (.paragraph) { |
| 15 | + p { |
| 16 | + color: black; |
44 | 17 |
|
45 | | - &[data-danger] { |
46 | | - background-color: red; |
47 | | - color: white; |
| 18 | + [data-error] { |
| 19 | + color: red; |
48 | 20 | } |
49 | 21 | } |
50 | 22 | } |
51 | 23 | ``` |
52 | 24 |
|
53 | | -Note: the class in `@scope` needs to be unique across your project. Plans are in place to automate this check. |
54 | | - |
55 | | -### 2. Compile to a React component |
56 | | - |
57 | | -```shell |
58 | | -mistcss src/components/Button.mist.css |
59 | | -# Creates Button.mist.css.tsx |
60 | | -``` |
61 | | - |
62 | | -Now, you can import your React component. |
63 | | - |
64 | | -```tsx |
65 | | -import { Button } from '.components/Button.mist.css' |
66 | | - |
67 | | -export default function App() { |
68 | | - return ( |
69 | | - <main> |
70 | | - <Button size="lg" danger> |
71 | | - OMG 😱 JS from CSS |
72 | | - </Button> |
73 | | - |
74 | | - {/* 💥 TypeScript will catch the error here */} |
75 | | - <Button size="lgg">Submit</Button> |
76 | | - </main> |
77 | | - ) |
78 | | -} |
79 | | -``` |
80 | | - |
81 | | -### 3. Integrate it into your workflow |
82 | | - |
83 | | -Edit `package.json`: |
84 | | - |
85 | | -```json |
86 | | -{ |
87 | | - "scripts": { |
88 | | - "mistcss-dev": "mistcss ./src --watch", |
89 | | - "mistcss-build": "mistcss ./src" |
90 | | - } |
91 | | -} |
92 | | -``` |
93 | | - |
94 | | -Use tools like [concurrently](https://github.com/open-cli-tools/concurrently) to run it alongside your other scripts in development. |
95 | | - |
96 | | -### 4. TailwindCSS (optional) |
97 | | - |
98 | | -If you're using NextJS, you may need to add [support for nested declarations](https://tailwindcss.com/docs/using-with-preprocessors#nesting). |
| 25 | +```jsx |
| 26 | +import { Paragraph } from 'Paragraph.mist.css' |
99 | 27 |
|
100 | | -Use Tailwind's `@apply` directive to style your CSS component. For example: |
101 | | - |
102 | | -```css |
103 | | -&[data-danger] { |
104 | | - @apply bg-red-700 text-white; |
105 | | -} |
106 | | -``` |
107 | | - |
108 | | -### 5. Ignoring generated files |
109 | | - |
110 | | -Edit `.gitignore`: |
111 | | - |
112 | | -```gitignore |
113 | | -*.mist.css.tsx # Ignore compiled files |
114 | | -``` |
115 | | - |
116 | | -Edit `.prettierignore`: |
117 | | - |
118 | | -```gitignore |
119 | | -*.mist.css.tsx # Ignore compiled files |
120 | | -``` |
121 | | - |
122 | | -Edit `eslint.config.js`: |
123 | | - |
124 | | -```js |
125 | | -{ |
126 | | - ignores: ['**/*.mist.css.tsx'] |
127 | | -} |
128 | | -``` |
129 | | - |
130 | | -Edit `.vscode/settings.json`: |
131 | | - |
132 | | -```json |
133 | | -{ |
134 | | - "files.exclude": { |
135 | | - "**/*.mist.css.tsx": true |
136 | | - } |
137 | | -} |
138 | | -``` |
139 | | - |
140 | | -## The power of CSS |
141 | | - |
142 | | -Since MistCSS uses pure CSS, you can use **all** CSS features: |
143 | | - |
144 | | -- Container queries `@container`, ... |
145 | | -- CSS variables `--primary-color`, ... |
146 | | -- Media queries `@media (prefers-color-scheme: dark)`, ... |
147 | | -- And more... |
148 | | - |
149 | | -This approach allows you to stay focused on styling without the mental switch to JS. |
150 | | - |
151 | | -## Origin of the name |
152 | | - |
153 | | -``` |
154 | | -The C in CSS stands for cascade 🌊 |
155 | | -Atomized water forms mist 🌫️ |
156 | | -MistCSS creates pure CSS atomic components 🌬️ |
| 28 | +<Paragraph>I'm React component written in CSS only</Paragraph> |
| 29 | +<Paragraph error>I can accept props</Paragraph> |
157 | 30 | ``` |
158 | 31 |
|
159 | | -## Roadmap |
| 32 | +## Documentation |
160 | 33 |
|
161 | | -MistCSS is a new project, so expect **breaking changes** until `v1.0`. |
| 34 | +https://typicode.github.io/mistcss |
162 | 35 |
|
163 | | -If you like this idea and want to help, please consider having your company [sponsor](https://github.com/typicode/mistcss) it 🙇. This project is not backed by a large company. |
| 36 | +## Why the name? |
164 | 37 |
|
165 | | -- [x] Release 🥳 |
166 | | -- [x] Add TailwindCSS support |
167 | | -- [ ] Add Vite support |
168 | | -- [ ] CLI and compiler improvements |
169 | | -- [ ] v1.0 |
| 38 | +C in CSS stands for cascade 🌊 → atomized water forms mist 🌫️ → MistCSS creates pure CSS atomic components 🌬️ |
0 commit comments