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

@duiup/primitives

v1.0.1

Published

Typography, spacing, and color primitives for duiup design system

Downloads

4

Readme

Duiup Primitives

npm package

This repo contains values for color, spacing, and typography primitives for use with [Duiup][duiup], an extension of GitHub's Primer design system.

duiup primitives diagram

Install

This repository is distributed on npm. After installing npm, you can install @duiup/primitives with this command.

npm install --save @duiup/primitives

Usage

Storybook | Docs

Primitive data is served in several formats from the dist/ folder:

  • dist/scss contains SCSS files that define CSS variables to be imported into other SCSS files
  • dist/json contains JSON files for each set of primitives
  • dist/js contains CommonJS-style JavaScript modules for each set of primitives, as well as an index file that loads all of the primitives for all primitive types; you can access this via require('@duiup/primitives'). The JavaScript modules also include TypeScript typings files for use in TypeScript projects.

Deprecating variables

To deprecate a variable, define a mapping from the deprecated variable to its replacement(s) in a file called deprecated.json in the appropriate subdirectory of data:

  data/
    colors/
+     deprecated.json
    spacing/
    ...
// data/colors/deprecated.json

{
  "text.primary": "fg.default", // this means: `text.primary` is deprecated. Use `fg.default` instead
  "auto.blue.4": ["accent.fg, accent.emphasis"], // this means: `auto.blue.4` is deprecated. Use `accent.fg` or `accent.emphasis` instead
  "text.white": null // this means: `text.white` is deprecated. We don't have a replacement for it
}

During the build process, the deprecated.json files will be added to a dist/deprecated directory organized by variable category:

  dist/
    js/
    ts/
    json/
    scss/
+   deprecated/
+     colors.json

Removing variables

When you're ready to remove a variable, first remove it's definitions:

// data/colors/vars/global_light.ts
import {get} from '../../../src/utils-v1'

export default {
  text: {
-   primary: get('scale.gray.9'),
    secondary: get('scale.gray.6')
  }
}
// data/colors/vars/global_dark.ts
import {get} from '../../../src/utils-v1'

export default {
  text: {
-   primary: get('scale.gray.1'),
    secondary: get('scale.gray.3')
  }
}

Then remove it from deprecated.json and add it to removed.json:

// data/colors/deprecated.json
{
- "text.primary": "fg.default"
}
// data/colors/removed.json
{
+ "text.primary": "fg.default"
}

During the build process, the removed.json files will be added to a dist/removed directory organized by variable category:

  dist/
    js/
    ts/
    json/
    scss/
    deprecated/
+   removed/
+     colors.json

V8 Tokens

With @duiup/primitives, design tokens are located as json files in the src/tokens directory. Those tokens are compiled with style dictionary in scripts/buildTokens.ts.

To make working with tokens easier, we added some additional functionality on top of what style dictionary comes with:

Extending and Overwriting

We have two main color modes: light and dark. Additionally we have specific accessibility modes based on those, such as light high contrast.

We added a way to create a mode by only including the changes from the main mode. We call this overrides. Overrides are cerated in src/tokens/functional/color/[light|dark]/overrides/ and have to be added to themes.config.ts to work. In the individual files, e.g. light.high-contrast.json5 you can now add tokens in the same structure as in any main file, e.g. primitives-light.json5 to replace them.

Transforming Colors with Alpha and Mix

Alpha

You can create color tokens that inherit a color but have a different alpha value by adding the alpha property. Note: The original alpha value will be replaced by your value. If you add alpha: 0.4 to a color, it doesn't matter if the color you reference has no alpha or alpha: 0.7, the new token will always have newly the defined value of alpha: 0.4.

{
  muted: {
    $value: '{base.color.blue.3}',
    alpha: 0.4, // the opacity value of the color === 40% opaque
    $type: 'color',
  }
}

Mix

In rare cases, you may need to create a color between two steps in the color scale, e.g. between gray.4 and gray.5. A common example are interactive states, like hover where a full step on the color scale would be to much. For those cases you can use the mix property.

The mix proeprty mixes the color it gets into the main color from the $value attribute. The amount added is controlled by the weight. A weight of 0.1 adds 10% of the color, and a weight of 0.75 adds 75%.

A mix proprty must always have a color and a weight child. color can be a hex value or a reference to a valid color. The weight property must receive a value between 0.0 and 1.

{
  control: {
  $value: '{base.color.gray.4}', // main color
  $type: 'color',
  mix: {
    color: '{base.color.gray.5}', // color to mix into the main color
    weight: 0.2, // amount of the mix color that is added === 20% of gray.5 is mix into gray.4
  },
}
}

License

MIT © GitHub