Skip to content

dolmios/stoop

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

113 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

A lightweight, type-safe CSS-in-JS library for React with CSS variables, built-in multi-theme support, and perfect Next.js integration.

Stoop Kid Steps Off

npm version License: MIT

About

Stoop is a CSS-in-JS libraryβ€”a TypeScript-first approach to styling that provides type-safe CSS objects with full type inference. Similar to Stitches and Vanilla Extract, Stoop focuses on type safety and developer experience.

Stoop is a minimalist implementation of Stitches' high-level features. It provides a similar API for styled, css, and variants, but omits several Stitches features.

What's missing compared to Stitches:

  • Compound variants
  • Some of Stitches' built-in utility functions (Stoop has a flexible utility system but fewer built-ins)
  • Additional Stitches APIs

Note: Both Stitches and Stoop generate CSS at runtime. We're exploring build-time extraction in future releases. For immediate build-time needs, consider Vanilla Extract or Panda CSS.

Features

  • Type-safe theming with TypeScript inference
  • CSS variables for theme tokens
  • Variant system for component variations
  • Utility functions for custom CSS transformations
  • Multiple themes with createTheme()
  • SSR support via getCssText()
  • React >=16.8.0 required (Next.js Pages & App Router supported)
  • Automatic prefix (stoop by default) for CSS class names and variables
  • Zero runtime dependencies - only React peer dependency

Installation

npm install stoop # or bun add stoop # or yarn add stoop

Quick Start

// stoop.theme.ts import { createStoop } from "stoop"; const stoop = createStoop({ theme: { colors: { primary: "#0070f3", background: "#ffffff", text: "#000000", }, space: { small: "8px", medium: "16px", large: "24px", }, }, }); export const { styled, css, createTheme, globalCss, keyframes } = stoop; // Usage const Button = styled("button", { padding: "$medium", backgroundColor: "$primary", color: "$text", variants: { variant: { primary: { backgroundColor: "$primary" }, secondary: { backgroundColor: "$background", border: "1px solid $primary" }, }, }, }); <Button variant="primary">Click me</Button>;

See the full documentation for complete setup instructions.

Documentation

πŸ“š Full Documentation β†’

For internal implementation details, see packages/stoop/ARCHITECTURE.md (developer-only).

API Overview

createStoop(config)

Creates a Stoop instance. Returns: styled, css, createTheme, globalCss, keyframes, getCssText, warmCache, preloadTheme, theme, config. If themes config is provided, also returns Provider and useTheme.

See the API Reference for complete API documentation.

Theme Tokens

Use $ prefix for theme tokens. Shorthand $token uses property-aware resolution (preferred); explicit $scale.token specifies the scale.

{ color: "$primary", // Shorthand (preferred, property-aware) padding: "$medium", // Property-aware β†’ space scale fontSize: "$fontSizes.small", // Explicit scale }

Tokens resolve to CSS variables (var(--colors-primary)), enabling instant theme switching without recompiling CSS.

Variants

Variants create component variations via props:

const Button = styled("button", { variants: { variant: { primary: { backgroundColor: "$primary" }, secondary: { backgroundColor: "$secondary" }, }, size: { small: { padding: "$small" }, large: { padding: "$large" }, }, }, }); <Button variant="primary" size="small" />;

Migration from Stitches

Stoop provides a similar API for the features it implements. Key differences:

  • CSS variables for theme tokens
  • Simple theme system with createTheme()
  • Full TypeScript inference

See the Migration Guide for migration examples.

Related Projects

CSS-in-JS Libraries:

Variant Systems:

  • CVA - Class Variance Authority for component variants
  • clsx - Tiny utility for constructing className strings

Utility-First:

Component Libraries:

  • Radix UI - Unstyled, accessible component primitives
  • Chakra UI - Component library built on Emotion
  • Mantine - React components library with Emotion

Development

This is a monorepo using Bun workspaces. The project structure:

stoop/ β”œβ”€β”€ packages/ β”‚ β”œβ”€β”€ stoop/ # Main library package β”‚ β”œβ”€β”€ stoop-ui/ # UI component library built with stoop β”‚ └── benchmarks/ # Performance benchmarks (Stoop vs Stitches) β”œβ”€β”€ apps/ β”‚ β”œβ”€β”€ website/ # Website/documentation site (Next.js) β”‚ └── playground/ # Component playground (Vite) └── scripts/ # Shared scripts 

Setup

# Install all dependencies (for all workspaces) bun install # Build all packages bun run build:all # Build individual packages bun run build # Build stoop bun run build:stoop-ui # Build stoop-ui bun run build:website # Build website (includes all packages)

Development Commands

# Development servers bun run dev # Build all packages + start website dev server bun run dev:playground # Build all packages + start playground dev server # Build commands bun run build # Build stoop package bun run build:stoop-ui # Build stoop-ui package bun run build:all # Build both stoop and stoop-ui packages bun run build:website # Build all packages + website # Publishing bun run publish # Publish stoop package to npm bun run publish:stoop-ui # Publish stoop-ui package to npm # Code quality bun run lint # Lint all packages bun run format # Format code bun run tidy # Run lint + format # Testing bun run test # Run tests bun run test:coverage # Run tests with coverage bun run test:watch # Run tests in watch mode # Benchmarks bun run benchmark # Run performance benchmarks (Stoop vs Stitches)

Working with Packages

# Work in stoop package cd packages/stoop bun run build bun run test # Work in stoop-ui package cd packages/stoop-ui bun run build bun run test # Work in website app cd apps/website bun run dev bun run build # Work in playground app cd apps/playground bun run dev bun run build

Monorepo Structure

  • packages/stoop - The main Stoop library

    • Build: bun run build
    • Test: bun run test
    • Publish: bun run publish
  • packages/stoop-ui - UI component library built with stoop

    • Build: bun run build:stoop-ui
    • Test: bun run test (from package directory)
    • Publish: bun run publish:stoop-ui
  • apps/website - Website and documentation site (Next.js)

    • Dev: bun run dev
    • Build: bun run build:website
  • apps/playground - Component playground for testing stoop-ui (Vite)

    • Dev: bun run dev:playground
    • Build: bun run build (from app directory)
  • packages/benchmarks - Performance benchmarks comparing Stoop vs Stitches

    • Run: bun run benchmark (from root)
    • Bundle analysis: bun run analyze:bundle (from package directory)

All apps use stoop and stoop-ui as workspace dependencies, so changes to the packages are automatically available in the apps after rebuilding.

Contributing

Feel free to get in touch with feedback, advice or suggestions. See Conventional Commits for new contributors.

License

MIT Β© Jackson Dolman

About

A minimalist, performant CSS-in-JS library and Stitches.dev alternative with type inference, theme creation, and variants support. Perfect for React applications.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors