Coder Social home page Coder Social logo

vite-vanilla-extract-react's Introduction

vanilla-extract

vanilla-extract is a library for writing CSS in JavaScript. It is designed to be used with React, but can be used with any JavaScript framework or without one.

Vanilla-extract was co-created by Mark Dalgleish who is also the creator of css modules. In fact, it's a bit like css modules, but much more capable and with typescript as a preprocessor. Instead of writing css, you use typescript, which makes it look a bit like yet another css in js library, but without the runtime cost of one.

Setup with Vite

npm create vite@latest vite-vanilla-extract-react -- --template react-ts
cd vite-vanilla-extract-react
npm i --save-dev @vanilla-extract/vite-plugin
npm i @vanilla-extract/css @vanilla-extract/sprinkles @vanilla-extract/dynamic @vanilla-extract/recipes clsx

And then, just edit vite.config.ts to use the plugin:

import { defineConfig } from 'vite'
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vanillaExtractPlugin(), react()]
})

Random thoughts

  • With its sprinkles, it's also a bit like tailwind, but your own tailwind that lets you define your own utility classes.
  • Recipes make it a bit like Stitches, but with a different syntax.
  • Clean boundary between runtime and build time - all that is in css.ts is build time. But you can still call css functions from runtime code.

๐Ÿ’… Theming

  • No need to pass theme via context (theme provider) because it depends on css variables.
  • Unlike css variables, we can use nested objects. This is useful for defining a theme.

๐Ÿ‘€ Comparison with our latest favorite - Stitches

  • Similarly to Stitches, you can easily define variants
  • No predefined opinionated mappings to theme object using template literals. Instead, you define your own theme object and use it directly.
  • Nice autocomplete for everything, thanks to typescript and CSSType.

๐Ÿ“š Resources

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.