Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vanilla-extract-css/vanilla-extract

Zero-runtime Stylesheets-in-TypeScript
https://github.com/vanilla-extract-css/vanilla-extract

Last synced: 3 days ago
JSON representation

Zero-runtime Stylesheets-in-TypeScript

Awesome Lists containing this project

README

        

# 🧁 vanilla-extract

**Zero-runtime Stylesheets-in-TypeScript.**

Write your styles in TypeScript (or JavaScript) with locally scoped class names and CSS Variables, then generate static CSS files at build time.

Basically, it’s [β€œCSS Modules](https://github.com/css-modules/css-modules)-in-TypeScript” but with scoped CSS Variables + heaps more.

πŸ”₯ Β  All styles generated at build time β€” just like [Sass](https://sass-lang.com), [Less](http://lesscss.org), etc.

✨   Minimal abstraction over standard CSS.

πŸ¦„ Β  Works with any front-end framework β€” or even without one.

🌳 Β  Locally scoped class names β€” just like [CSS Modules.](https://github.com/css-modules/css-modules)

πŸš€ Β  Locally scoped [CSS Variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties), `@keyframes` and `@font-face` rules.

🎨   High-level theme system with support for simultaneous themes. No globals!

πŸ›  Β  Utils for generating variable-based `calc` expressions.

πŸ’ͺ Β  Type-safe styles via [CSSType.](https://github.com/frenic/csstype)

πŸƒβ€β™‚οΈ Β  Optional runtime version for development and testing.

πŸ™ˆ Β  Optional API for dynamic runtime theming.

---

🌐 [Check out the documentation site for setup guides, examples and API docs.](https://vanilla-extract.style)

---

πŸ–₯ Β  [Try it out for yourself in CodeSandbox.](https://codesandbox.io/s/github/vanilla-extract-css/vanilla-extract/tree/master/examples/webpack-react?file=/src/App.css.ts)

---

**Write your styles in `.css.ts` files.**

```ts
// styles.css.ts

import { createTheme, style } from '@vanilla-extract/css';

export const [themeClass, vars] = createTheme({
color: {
brand: 'blue'
},
font: {
body: 'arial'
}
});

export const exampleStyle = style({
backgroundColor: vars.color.brand,
fontFamily: vars.font.body,
color: 'white',
padding: 10
});
```

> πŸ’‘ Once you've [configured your build tooling,](https://vanilla-extract.style/documentation/getting-started/) these `.css.ts` files will be evaluated at build time. None of the code in these files will be included in your final bundle. Think of it as using TypeScript as your preprocessor instead of Sass, Less, etc.

**Then consume them in your markup.**

```ts
// app.ts

import { themeClass, exampleStyle } from './styles.css.ts';

document.write(`

Hello world!



`);
```

---

Want to work at a higher level while maximising style re-use? Check out 🍨 [Sprinkles](https://vanilla-extract.style/documentation/packages/sprinkles), our official zero-runtime atomic CSS framework, built on top of vanilla-extract.

---

## Thanks

- [Nathan Nam Tran](https://twitter.com/naistran) for creating [css-in-js-loader](https://github.com/naistran/css-in-js-loader), which served as the initial starting point for [treat](https://seek-oss.github.io/treat), the precursor to this library.
- [Stitches](https://stitches.dev/) for getting us excited about CSS-Variables-in-JS.
- [SEEK](https://www.seek.com.au) for giving us the space to do interesting work.

## License

MIT.