npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dsgen

v0.4.1

Published

Create your own design system using CSS variables

Downloads

10

Readme

🚧 This project is under heavy development 🚧

The goal of this project is to ease creation and usage of a basic CSS design system (design tokens). Our aim is to bring Tailwind's design system benefits to a regular CSS workflow.

As a result you will use a configurable set of CSS variables throughout your styles while your IDE and linter will assist you with snippets and auto fixing.

Main parts of the project:

  • Style variables to hold global values meaningful for the whole project (colors, typography and so on)
  • IDE snippets to ease usage of variables for developers
  • Linting configuration to enforce usage of variables and fight the habit of using absolute values

All these parts are connected via special configuration file containing rules of your design system.

Installation

Prerequisites

Project installation

  1. Add this project as dev dependency
  2. Copy dsgen.config.js to the root of your project
  3. Make changes to your dsgen.config.js:
    • Adjust design tokens (colors, fonts, etc.)
    • Adjust media queries list
    • Set CSS file path
  4. Run generation script: npx dsgen, it will generate:
    • CSS file with CSS variables and custom media variables (see example design-tokens.css here)
    • Snippets for IDEs (see examples in snippets directory here)
  5. Import generated CSS file inside your index.css:
    @import 'design-tokens.css';
  6. Add snippets to your IDE
  7. Configure stylelint

Configuration file

You can see full example in dsgen.config.js file in this repo.

Tokens from this config will be converted to CSS file and IDE snippets.

Theming support

To create multiple themes:

  • Add themes object to config, where key is theme name and value is theme selector. E.g.:
    themes: {
      default: ':root',
      dark: 'html.theme_dark',
    },
  • Now you can add multiple values for each variable:
    textColors: {
      primary: {
        default: '#111',
        dark: '#eee',
      },
    }

Style variables

CSS variables generated from config are exported to a separate file. Don't change this file manually as it will be fully rewritten after config update.

See example CSS file in design-tokens.css.

z-indices

For z-indices we recommend using postcss-easy-z to manually declare relations between them.

IDE snippets

IDE snippets are also generated from config file.

Some examples:

@mobile         -> @media (--mobile) {}
color-primary   -> color: var(--color-primary);
bgc-secondary   -> background-color: var(--color-bg-secondary);
fz-s            -> font-size: var(--font-size-s);

WebStorm and other JetBrains IDEs

JetBrains IDEs don't support project snippets, so you'll need to add snippets globally. Place snippets file inside jba_config/templates in the IDE configuration directory.

E.g. on Mac OS: ~/Library/Application\ Support/JetBrains/WebStorm2021.1/jba_config/templates/

Then restart IDE, and you'll see snippets group available in Preferences:

You'll need to manually enable/disable snippets groups if you are working on multiple projects with different design system configs.

To make this process easier please vote for per-project templates in JetBrains IDEs.

Visual Studio Code

By default, VS Code snippets are placed inside .vscode folders. That way snippets will be available only for current project.

You'll need to update .gitignore to commit snippets without committing other workspace settings:

.vscode/*
!.vscode/*.code-snippets

Linting configuration

We use linting to enforce usage of CSS variables instead of absolute values. To achieve that we use stylelint-declaration-strict-value plugin for stylelint.

Configuring stylelint

// stylelint.config.js
module.exports = {
  extends: ['dsgen/stylelint.config'],
}

Auto fixing

Other benefit of using stylelint-declaration-strict-value is that it supports auto fixing. We use dsgen config file to determine which absolute values should be replaced with CSS variables.

E.g. with this config:

// dsgen.config.js
module.exports = {
  fontSizes: {
    s: '12px',
    m: '16px',
    l: '24px',
  },
}
.component {
  font-size: 16px;
}

/* becomes */
.component {
  font-size: var(--font-size-m);
}