Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/vanilla-extract-css/vanilla-extract
- Owner: vanilla-extract-css
- License: mit
- Created: 2021-03-26T05:10:54.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-11-24T05:11:19.000Z (18 days ago)
- Last Synced: 2024-11-30T18:50:20.375Z (12 days ago)
- Language: TypeScript
- Homepage: https://vanilla-extract.style
- Size: 8.14 MB
- Stars: 9,637
- Watchers: 30
- Forks: 295
- Open Issues: 77
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-starred-test - vanilla-extract-css/vanilla-extract - Zero-runtime Stylesheets-in-TypeScript (TypeScript)
- awesome-github-star - vanilla-extract - runtime Stylesheets-in-TypeScript | vanilla-extract-css | 8725 | (TypeScript)
- awesome-rspack - @vanilla-extract/webpack-plugin - extract with webpack / Rspack. (Plugins / Rspack Plugins)
- awesome-luooooob - vanilla-extract-css/vanilla-extract - Zero-runtime Stylesheets-in-TypeScript (TypeScript)
- best-of-react - GitHub - 14% open Β· β±οΈ 06.06.2024): (Styling)
- awesome-typesafe - vanilla-extract-css/vanilla-extract - Zero-runtime Stylesheets-in-TypeScript. (**1. Libraries** / Styles)
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.tsimport { 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.tsimport { 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.