šŸš€ Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@ubnt/uids-tokens

Package Overview
Dependencies
Maintainers
226
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@ubnt/uids-tokens

UniFi Design System tokens — the single source of truth for design tokens across all platforms.

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
0
Maintainers
226
Weekly downloads
Ā 
Created
Source

@ubnt/uids-tokens

The single source of truth for UniFi Design System tokens. Built with Style Dictionary, sourced from Figma Variables API.

ResourceURL
Token Browseruids-tokens.uidev.tools
Token Scout Reportuids-tokens.uidev.tools/latest/report.html
npm Package@ubnt/uids-tokens
Repositorygithub.com/ubiquiti/uids-tokens

Table of contents

Overview

Figma (Variables API) → fetch script → tokens/*.json → Style Dictionary → dist/

Tokens are defined as JSON (DTCG format) in tokens/, transformed by Style Dictionary into multiple output formats, and published as an npm package.

Available exports

Import pathFormatDescription
@ubnt/uids-tokensJS/TSDefault export (same as styled-components)
@ubnt/uids-tokens/css-tokensCSSCSS custom properties with light/dark theme support
@ubnt/uids-tokens/styled-componentsJS/TSTyped tokens object for CSS-in-JS
@ubnt/uids-tokens/tokens.jsonJSONFlat JSON of all resolved tokens
@ubnt/uids-tokens/themeJS/TScreateTheme(mode) — nested theme object for styled-components
@ubnt/uids-tokens/compatJS/TSmigrateTokenName() — mapping from legacy token names

Quick start

Prerequisites

Install dependencies

bun install

Build tokens

bun run build

This runs Style Dictionary and outputs:

  • dist/css-tokens/variables.css — CSS custom properties
  • dist/styled-components/index.mjs + index.d.ts — JS/TS module
  • dist/tokens.json — flat JSON
  • dist/theme/index.mjs + index.d.ts — theme adapter
  • dist/compat/index.mjs + index.d.ts — compat mapping

Run the docs site

bun run build          # must build tokens first
bun run site:dev       # starts Vite dev server

Consuming tokens

CSS variables

/* Import the CSS file in your app entry point */
@import '@ubnt/uids-tokens/css-tokens';

.my-component {
  color: var(--desktop-color-text-1);
  background: var(--desktop-color-depth-bg-0);
  padding: var(--desktop-spacing-medium);
  border-radius: var(--desktop-radius-small);
}

Theme support is built in — set data-theme="light" or data-theme="dark" on your root element:

<html data-theme="light">
  <!-- Themed tokens are automatically applied -->
</html>

JS/TS import (for non-CSS contexts)

Token keys use kebab-case matching the CSS variable names (without --). This matches the UIC internal design token convention.

import { tokens } from '@ubnt/uids-tokens/styled-components'

// Fully typed — autocomplete works
tokens['desktop-color-ublue-06-light']  // '#0066ff'
tokens['desktop-spacing-medium']        // '16px'
tokens['desktop-radius-small']          // '4px'

Prefer CSS var() in styled-components — the JS export is meant for non-CSS contexts like chart libraries or JS calculations. Using var() eliminates re-renders on theme change.

Theme adapter

The theme adapter provides a createTheme(mode) function that returns a nested, typed theme object — designed for apps using styled-components ThemeProvider.

import { createTheme } from '@ubnt/uids-tokens/theme'
import type { Theme, ThemeMode } from '@ubnt/uids-tokens/theme'

const theme = createTheme('light')

theme.color.neutral[3]        // '#eeeff1'
theme.color.primary           // '#006eff' (ublue-06)
theme.color.text[1]           // '#212327'
theme.spacing.md              // 16
theme.radius.sm               // 4
theme.font.size.md            // 14
theme.font.weight.bold        // 700
theme.zIndex.modal            // 1300
theme.animation.easing.easeInOut // 'cubic-bezier(0.4, 0, 0.2, 1)'

The theme is generated at build time by Style Dictionary — not hand-maintained. It covers all token categories: color (10 scales + semantic aliases), spacing, radius, font, shadow, sizing, opacity, z-index, animation, blur, and viewport.

Compat mapping

For gradual migration from @ubnt/ui-components token systems, the compat layer maps old names to new names:

import { migrateTokenName, compatMap } from '@ubnt/uids-tokens/compat'

// designToken['desktop-spacing-base-04'] style (network-fe)
migrateTokenName('desktop-spacing-base-04')  // 'desktop-spacing-xsmall'

// theme.palette.neutralNN style (portal)
migrateTokenName('neutral03')                // 'desktop-color-neutral-03'

// designToken('color-neutral-00', mode) style (protect)
migrateTokenName('color-neutral-00')         // 'desktop-color-neutral-00'

// cssVariables.motifs.dark.uiNN style (network-fe)
migrateTokenName('ui07')                     // 'desktop-color-neutral-07'

240 mappings covering all legacy access patterns across the 4 main consumer apps.

Token Scout

Token Scout scans Ubiquiti app repos to measure token adoption, detect freestyle (hardcoded) values, and identify Figma drift.

Live report: uids-tokens.uidev.tools/latest/report.html

Running locally

# Run against configured apps (see audit/audit.config.json)
bun run scout

# Individual subcommands
bun run scout:freestyle    # Scan for freestyle values only
bun run scout:drift        # Detect Figma drift only
bun run scout:inventory    # Generate token inventory only

# Build report for deployment
bun run scout:report       # Generates report + copies to site/public/report/

What it detects

Token systems — uids-tokens CSS vars, designToken, cssVariables, theme.palette, theme.alias, useTheme, SPACE_* constants, appTheme/ProtectTheme, Tailwind classes.

Freestyle values — hardcoded hex colors, RGB/RGBA, spacing px values, border-radius, font-size, font-weight in style contexts.

Figma drift — tokens in source but missing from build, tokens in build but not in Figma, value mismatches.

Report features

  • Per-app expandable sections with detailed findings
  • Token References table: token name, system, file:line, classification, uids-tokens counterpart
  • Freestyle Values table: value, category, file:line, what it's used for, suggested token
  • Figma drift detection with sync percentage
  • Prioritized recommendations

Configuration

Edit audit/audit.config.json to point at consumer app repos:

{
  "apps": [
    { "name": "unifi-portal", "path": "../unifi-portal" },
    { "name": "unifi-network-fe", "path": "../unifi-network-fe" }
  ]
}

Fetching tokens from Figma

This repo includes a script that pulls design token variables from Figma's Variables REST API and writes them as Style Dictionary JSON files.

Setup

  • Create a Figma personal access token at https://developers.figma.com/docs/rest-api/authentication/#access-tokens

    • Required scope: file_variables:read
    • Note: The Variables API requires a Figma Enterprise plan
  • Copy the example env file:

    cp .env.example .env
    
  • Fill in your credentials:

    FIGMA_TOKEN=your-personal-access-token
    FIGMA_FILE_KEY=your-figma-file-key
    

    The file key is the alphanumeric string in your Figma URL: https://www.figma.com/design/ABC123/My-File → ABC123

Fetch tokens

bun run tokens:fetch

Options:

-k, --file-key <key>     Override FIGMA_FILE_KEY
-t, --token <token>      Override FIGMA_TOKEN
    --published          Fetch published variables instead of local
-o, --output-dir <dir>   Output directory (default: project root)
    --dry-run            Preview output without writing files
-h, --help               Show help

After fetching, rebuild tokens:

bun run build

Switching to organization Figma

To point at your organization's Figma file instead of a personal one:

  • Update FIGMA_FILE_KEY in .env (or in GitHub repo secrets)
  • Update FIGMA_TOKEN if needed (ensure it has access to the org file)
  • Run bun run tokens:fetch to pull the new tokens

No code changes needed — the file key and token are the only configuration.

GitHub Actions

Fetch tokens (manual)

Trigger via Actions → Fetch Tokens | Dispatch → Run workflow.

This fetches tokens from Figma, commits any changes, and opens a PR.

Automatic publishing

When you push a version tag (v*), the Publish Package | Latest workflow automatically builds and publishes to npm, then deploys the docs site and Token Scout report.

Secrets required

SecretDescription
FIGMA_TOKENFigma personal access token
FIGMA_FILE_KEYFigma file key
NPMRCnpm authentication (.npmrc contents)

Releasing

This project uses commit-and-tag-version (the maintained fork of standard-version) for versioning and changelog generation.

Release workflow

Releases are a two-step process so you can review the changelog before publishing.

Step 1 — Prepare (bumps version, generates changelog, commits + tags locally):

bun run release:prepare:patch   # 0.0.0 → 0.0.1
bun run release:prepare:minor   # 0.0.1 → 0.1.0
bun run release:prepare:major   # 0.1.0 → 1.0.0

Step 2 — Review the generated CHANGELOG.md. If you need to make edits:

# Edit CHANGELOG.md, then amend the release commit
git add CHANGELOG.md && git commit --amend --no-edit

Step 3 — Publish (pushes the commit + tag, triggers npm publish + docs deploy):

bun run release:publish

Alpha releases

Trigger via Actions → Publish Package | Alpha → Run workflow to publish under the alpha npm tag.

Token naming convention

All tokens follow a {platform}-{category}-{name} pattern. Most tokens are prefixed with desktop-.

PrefixCSS variable exampleJS/TS key example
desktop-color---desktop-color-neutral-06desktop-color-neutral-06-light
desktop-spacing---desktop-spacing-mediumdesktop-spacing-medium
desktop-sizing---desktop-sizing-density-mediumdesktop-sizing-density-medium
desktop-radius---desktop-radius-smalldesktop-radius-small
desktop-shadow---desktop-shadow-blur-basedesktop-shadow-blur-base
desktop-font---desktop-font-weight-semibolddesktop-font-weight-semibold
desktop-opacity---desktop-opacity-87desktop-opacity-87
desktop-z-index---desktop-z-index-modaldesktop-z-index-modal
desktop-duration---desktop-duration-fastdesktop-duration-fast
desktop-easing---desktop-easing-ease-in-outdesktop-easing-ease-in-out
desktop-blur---desktop-blur-lgdesktop-blur-lg
viewport---viewport-12viewport-12
color- (semantic)--color-input-bg-enabledcolor-input-bg-enabled-light

Color tokens have theme variants as suffixes: -light, -dark, and -on-color. In CSS output, themed tokens are resolved per data-theme attribute. In JS/TS output, each variant is a separate key (e.g. desktop-color-neutral-06-light, desktop-color-neutral-06-dark).

Token categories

CategorySource fileTokensDescription
Color (base)tokens/color-level-1/base.json143 scalesNeutral, ublue, red, green, orange, purple, aqua, lime, yellow, navy (4 modes each)
Color (semantic)tokens/color-level-2/base.json3Input bg aliases (light/dark)
Spacingtokens/spacing/base.json15none through xxlarge-3 (0–80px)
Sizingtokens/sizing/base.json8Component density + icon sizes
Typographytokens/typography/base.json21Font size (ui-sans + inter), weight, family
Radiustokens/radius/base.json7none, small, medium, large, infinity
Shadowtokens/shadow/base.json6Offset, blur, spread primitives
Viewporttokens/viewport/base.json4Breakpoints (375, 768, 1200, 1440)
Opacitytokens/opacity/base.json130–0.98 scale (extracted from on-color-alpha)
Z-Indextokens/z-index/base.json5base, dropdown, sticky, modal, toast
Animationtokens/animation/base.json6Duration (fast/normal/slow) + easing curves
Blurtokens/blur/base.json4none, sm, md, lg

Migrating from Emotion theme to CSS variables

Most Ubiquiti apps (e.g. unifi-portal) use Emotion with a theme object from @ubnt/ui-components that provides tokens via theme.palette.*, theme.space.*, etc. This section explains how to migrate from that pattern to CSS variables from this package.

Setup

  • Install the package:
pnpm add @ubnt/uids-tokens
  • Import the CSS file once in your app entry point:
import '@ubnt/ui-components/styles/normalize.css';
import '@ubnt/ui-components/styles/reset.css';
import '@ubnt/uids-tokens/css-tokens';

No other setup is needed — CssVariableProvider from @ubnt/ui-components already sets data-theme on the body, which activates the correct light/dark values automatically.

The pattern

Every ${({ theme }) => theme.palette.xxx} callback becomes a plain var() reference:

// Before — JS callback on every render
const Card = styled.div`
  background-color: ${({ theme }) => theme.palette.neutral01};
  border: 1px solid ${({ theme }) => theme.palette.neutral03};
  border-radius: ${({ theme }) => theme.radius.small}px;
  padding: ${({ theme }) => theme.space.medium}px;
  color: ${({ theme }) => theme.palette.text1};
`;

// After — pure CSS, no JS callbacks
const Card = styled.div`
  background-color: var(--desktop-color-neutral-01);
  border: 1px solid var(--desktop-color-neutral-03);
  border-radius: var(--desktop-radius-small);
  padding: var(--desktop-spacing-medium);
  color: var(--desktop-color-text-1);
`;

Token name mapping

The mapping from theme.palette.* (camelCase) to CSS variables (kebab-case) is straightforward:

Emotion themeCSS variable
theme.palette.neutral00var(--desktop-color-neutral-00)
theme.palette.neutral12var(--desktop-color-neutral-12)
theme.palette.ublue06var(--desktop-color-ublue-06)
theme.palette.green06var(--desktop-color-green-06)
theme.palette.red06var(--desktop-color-red-06)
theme.palette.text1var(--desktop-color-text-1)
theme.palette.text3var(--desktop-color-text-3)
theme.palette.depthBg0var(--desktop-color-depth-bg-0)
theme.palette.depthBg2var(--desktop-color-depth-bg-2)
theme.palette.globalPrimaryvar(--desktop-color-global-primary)
theme.palette.aquaGradientvar(--desktop-color-aqua-gradient)
theme.radius.smallvar(--desktop-radius-small)
theme.space.mediumvar(--desktop-spacing-medium)

Important: CSS variables include the unit, so don't add px after them. Write padding: var(--desktop-spacing-medium); not padding: var(--desktop-spacing-medium)px;.

For programmatic migration, use the compat mapping — migrateTokenName() handles all known patterns.

When to keep using the JS export

Use CSS variables (@ubnt/uids-tokens/css-tokens) for everything in styled components and CSS. Only use the JS export when you need raw token values in JavaScript:

import { tokens } from '@ubnt/uids-tokens';

// Charting libraries that need raw color values
const chartConfig = {
  color: tokens['desktop-color-ublue-06-light'],
};

// Dynamic calculations that need numeric values
const spacingPx = parseInt(tokens['desktop-spacing-medium'], 10) * 2;

Benefits

  • No re-renders — theme changes are handled by CSS, not React context
  • No runtime cost — no JS callbacks executed during render
  • No ThemeProvider dependency — components work without Emotion's ThemeProvider
  • Cleaner code — styled components become plain CSS template strings
  • Single source of truth — tokens come from Figma, not hardcoded in palette.ts

Project structure

uids-tokens/
ā”œā”€ā”€ .github/workflows/       # GitHub Actions
│   ā”œā”€ā”€ deploy-docs.yml            # Deploys docs + report to uidev.tools
│   ā”œā”€ā”€ fetch-tokens.yml           # Reusable fetch workflow
│   ā”œā”€ā”€ fetch-tokens.dispatch.yml  # Manual trigger
│   ā”œā”€ā”€ publish-package.yml        # Reusable publish workflow
│   ā”œā”€ā”€ publish-package.latest.yml # Publish on tag push
│   └── publish-package.alpha.yml  # Publish alpha channel
ā”œā”€ā”€ audit/                    # Token Scout — adoption scanner
│   ā”œā”€ā”€ src/
│   │   ā”œā”€ā”€ index.ts               # CLI entry point
│   │   ā”œā”€ā”€ types.ts               # Type definitions
│   │   ā”œā”€ā”€ reporter/              # HTML report generator (Scout-style)
│   │   ā”œā”€ā”€ drift/                 # Figma drift detection
│   │   ā”œā”€ā”€ freestyle/             # Freestyle scanner + token system detection
│   │   └── inventory/             # Token inventory builder
│   ā”œā”€ā”€ audit.config.json          # Default app config
│   └── audit-output/              # Generated reports
ā”œā”€ā”€ dist/                     # Build output (gitignored)
│   ā”œā”€ā”€ css-tokens/variables.css
│   ā”œā”€ā”€ styled-components/index.mjs + index.d.ts
│   ā”œā”€ā”€ theme/index.mjs + index.d.ts
│   ā”œā”€ā”€ compat/index.mjs + index.d.ts
│   └── tokens.json
ā”œā”€ā”€ site/                # Vite token browser (uids-tokens.uidev.tools)
ā”œā”€ā”€ infra/                    # CloudFront functions for routing
ā”œā”€ā”€ scripts/
│   └── figma-fetch/          # Figma Variables API fetch
ā”œā”€ā”€ src/
│   └── compat/               # Compat mapping source
ā”œā”€ā”€ tokens/                   # Source token files (DTCG JSON)
│   ā”œā”€ā”€ animation/
│   ā”œā”€ā”€ blur/
│   ā”œā”€ā”€ color-level-1/
│   ā”œā”€ā”€ color-level-2/
│   ā”œā”€ā”€ opacity/
│   ā”œā”€ā”€ radius/
│   ā”œā”€ā”€ shadow/
│   ā”œā”€ā”€ sizing/
│   ā”œā”€ā”€ spacing/
│   ā”œā”€ā”€ typography/
│   ā”œā”€ā”€ viewport/
│   └── z-index/
ā”œā”€ā”€ build/                    # Style Dictionary build pipeline
│   ā”œā”€ā”€ index.ts              # Entry point
│   ā”œā”€ā”€ helpers.ts            # Shared helpers
│   ā”œā”€ā”€ transforms.ts         # Custom transforms
│   └── formats/              # Custom output formats (css, js, theme)
ā”œā”€ā”€ package.json
ā”œā”€ā”€ llms.txt                  # Machine-readable context for LLMs
└── tsconfig.json

Roadmap

Figma

The following issues need to be resolved in the Figma variables file. See docs/FIGMA_FIXES.md for full details.

  • Typography — typo in font-weight value ("boid" instead of "bold") Fixed in source
  • Naming convention gaps — frosted-glass, black, white missing desktop-color- prefix Fixed in source
  • Missing token types — opacity, timing, z-index, blur Added as hand-authored tokens
  • Typography — font-size tokens duplicated across ui-sans and inter variants with different values
  • Typography — font-weight tokens duplicated at two nesting levels (string vs number types)
  • Naming typos — mob-bg-seconday (missing "r", should be mob-bg-secondary)
  • Naming typos — color-data-experience-needimprv (unclear abbreviation)
  • Structural — tokens/color/base.json maps to an empty collection
  • Structural — redundant viewport wrapper group produces double-prefixed names (--viewport-viewport-*)
  • Structural — color-level-2 tokens are missing on-color and on-color-alpha modes
  • Structural — many on-color and on-color-alpha values are identical (missing alpha channel?)

Package

  • Release @ubnt/uids-tokens 1.0.0
  • Get first consumer app migrated to uids-tokens
  • CI-integrated Token Scout scanning (run on PR to detect regressions)

FAQs

Package last updated on 10 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts