Git Product home page Git Product logo

vanilla-extract's Introduction

🧁 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-in-TypeScript” but with scoped CSS Variables + heaps more.

πŸ”₯ Β  All styles generated at build time β€” just like Sass, Less, etc.

✨   Minimal abstraction over standard CSS.

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

🌳 Β  Locally scoped class names β€” just like CSS Modules.

πŸš€ Β  Locally scoped CSS Variables, @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.

πŸƒβ€β™‚οΈ Β  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.


πŸ–₯ Β  Try it out for yourself in CodeSandbox.


Write your styles in .css.ts files.

// 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, 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.

// app.ts

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

document.write(`
  <section class="${themeClass}">
    <h1 class="${exampleStyle}">Hello world!</h1>
  </section>
`);

Want to work at a higher level while maximising style re-use? Check out 🍨 Sprinkles, our official zero-runtime atomic CSS framework, built on top of vanilla-extract.


Thanks

  • Nathan Nam Tran for creating css-in-js-loader, which served as the initial starting point for treat, the precursor to this library.
  • Stitches for getting us excited about CSS-Variables-in-JS.
  • SEEK for giving us the space to do interesting work.

License

MIT.

vanilla-extract's People

Contributors

mattcompiles avatar seek-oss-ci avatar markdalgleish avatar vanilla-extract-ci avatar michaeltaranto avatar askoufis avatar mrm007 avatar benjervis avatar graup avatar andrewleedham avatar roginfarrer avatar syfxlin avatar lekoarts avatar joshuakgoldberg avatar aspirisen avatar chaficnajjar avatar brendan-csel avatar kosmotema avatar rtkaaho avatar sombreroelgringo avatar shuding avatar kossnocorp avatar samrobbins85 avatar wobsoriano avatar riccardoperra avatar reiss-d avatar prettycoffee avatar phil-lgr avatar cromodder avatar otaviomad avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.