agentleFS
Community-AccessCommunity-Access/accessibility-agents/skills/kb-design-system/SKILL.md

kb-design-system

Skill458 starsChanged 33 days agoMITView on GitHub

Reference data, not a reviewer. Validate design system tokens for WCAG AA/AAA contrast. Compute color token contrast, focus ring validation (WCAG 2.4.13), motion tokens, and spacing for touch targets across frameworks.

  • Installs packages

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read it when the project uses one of them.

    line 113

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Design System Accessibility Skill

This skill provides reference data for design token contrast validation, focus ring compliance, and spacing audits. Used by the design-system-auditor skill.


WCAG Contrast Ratio - Computation Reference

Step 1: Linearize sRGB Channel

For each channel C in [0, 255]:

c = C / 255
c_lin = c / 12.92              if c <= 0.04045
c_lin = ((c + 0.055) / 1.055)^2.4   otherwise

Step 2: Relative Luminance

L = 0.2126 * R_lin + 0.7152 * G_lin + 0.0722 * B_lin

Step 3: Contrast Ratio

ratio = (L_lighter + 0.05) / (L_darker + 0.05)

Quick JavaScript Implementation

function relativeLuminance(hex) {
  const c = hex.replace('#', '').match(/.{2}/g)
    .map(h => parseInt(h, 16) / 255)
    .map(c => c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4));
  return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
}

function contrastRatio(hex1, hex2) {
  const L1 = relativeLuminance(hex1);
  const L2 = relativeLuminance(hex2);
  const lighter = Math.max(L1, L2);
  const darker = Math.min(L1, L2);
  return (lighter + 0.05) / (darker + 0.05);
}

// Example
contrastRatio('#6B7280', '#FFFFFF'); // 4.83:1 - PASSES AA, fails AAA
contrastRatio('#9CA3AF', '#FFFFFF'); // 2.54:1 - FAILS AA

HSL to Hex Conversion (for CSS variable tokens)

Some design systems store colors as HSL triplets (e.g., shadcn/ui themes for Tailwind v3). Current shadcn/ui and Tailwind v4 themes use oklch(); convert those to sRGB before computing contrast.

function hslToHex(h, s, l) {
  s /= 100; l /= 100;
  const a = s * Math.min(l, 1 - l);
  const f = n => {
    const k = (n + h / 30) % 12;
    return l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
  };
  return '#' + [f(0), f(8), f(4)]
    .map(x => Math.round(x * 255).toString(16).padStart(2, '0'))
    .join('');
}

// shadcn/ui: --muted-foreground: 215.4 16.3% 46.9%
hslToHex(215.4, 16.3, 46.9); // -> #64748B (4.76:1 on white)

WCAG Contrast Thresholds

Each WCAG contrast threshold, with use case, AA, AAA and notes.

Use CaseAAAAANotes
Normal text (< 18pt / < 14pt bold)4.5:17:1Most body text
Large text (>= 18pt / >= 14pt bold)3:14.5:1Headings, display text
UI components (borders, icons)3:1-Input borders, icon buttons
Focus indicators3:1 against adjacent colors (1.4.11)3:1 focused vs unfocused, 2px perimeter area (2.4.13)2.4.13 Focus Appearance is AAA
Placeholder text4.5:1-Counts as normal text
Disabled stateExemptExemptDocumented exemption
Logo / brandExemptExemptNo requirement
Decorative contentExemptExemptMust be marked decorative

Framework Token Paths

Token paths and default palette values for Tailwind CSS, shadcn/ui and Radix, Material UI, Chakra UI and Style Dictionary are in references/framework-token-paths.md. Read it when the project uses one of them.


High-Risk Token Pairs - Known Failures

Each token pair, with its common value, ratio on white, status and notes.

Token pairCommon valueRatio on whiteStatusNotes
MUI warning.main#ed6c023.11:1FAILOrange on white - fails for normal text
MUI warning.light#ff98002.16:1FAILLight orange - critical failure
MUI info.main#0288d13.86:1FAILFails for normal text
Tailwind v3 amber-400#FBBF241.67:1FAILNever use amber-400 as text
Tailwind v3 yellow-400#FACC151.53:1FAILYellow always fails on white
Tailwind v3 gray-400#9CA3AF2.54:1FAILCommon placeholder color
Tailwind v3 gray-500#6B72804.83:1Pass AA, fails AAAOften assumed to fail; it passes AA
Chakra v2 chakra-placeholder-colorgray.500 = #7180964.02:1FAILChakra v2 default placeholder
MUI text.disabledrgba(0,0,0,0.38)~2.68:1ExemptDisabled = exempt per WCAG
MUI action.activergba(0,0,0,0.54)~4.61:1PassIcon color on white
shadcn v3 theme --muted-foregroundhsl(215.4 16.3% 46.9%)~4.76:1Pass AA, fails AAATailwind v3 shadcn theme
shadcn v3 theme --destructivehsl(0 84.2% 60.2%)~3.76:1FAILRed text on white; passes 3:1 for large text and UI

Compliant Replacements

Each failing token, with its replacement, new ratio and notes.

Failing tokenReplacementNew ratioNotes
#9CA3AF (gray-400)#6B7280 (gray-500)4.83:1Passes AA; use #595959 (7.00:1) for AAA
#6B7280 (gray-500), AAA target only#4B5563 (gray-600)7.56:1Meets AAA
#ed6c02 (MUI warning)#b45309 (amber-700)5.02:1
#ff9800 (MUI warning.light)#b45309 (amber-700)5.02:1
#FBBF24 (amber-400)#92400e (amber-800)7.09:1Keep amber-400 for backgrounds, not text
#FACC15 (yellow-400)#713f12 (yellow-900)8.67:1Keep yellow-400 for backgrounds, not text
hsl(0 84.2% 60.2%) (shadcn destructive)#b91c1c (red-700)6.47:1

Storybook addon-a11y Configuration

npm install --save-dev @storybook/addon-a11y
// .storybook/main.js (ESM; Storybook 10 is ESM-only)
export default {
  addons: ['@storybook/addon-a11y'],
};

// .storybook/preview.js - global configuration
export const parameters = {
  a11y: {
    options: {
      runOnly: { type: 'tag', values: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa'] },
    },
    config: {
      rules: [
        { id: 'target-size', enabled: true },       // WCAG 2.5.8; off by default in axe
      ],
    },
    // 'todo' (the default) reports violations as warnings; 'error' fails the test
    test: 'error',
  },
};

// Per-story override
export const MyStory = {
  parameters: {
    a11y: {
      config: {
        rules: [{ id: 'color-contrast', enabled: false }],  // Document WHY
      }
    }
  }
};

axe-core has no focus-visible rule; check focus indicators manually or with Playwright.

Running Storybook a11y Checks in CI

# Storybook 9 and later recommend the Vitest addon (npx storybook add @storybook/addon-vitest),
# which runs the a11y checks with each story test. The test runner still works:
npm install --save-dev @storybook/test-runner

# package.json scripts
{
  "scripts": {
    "storybook:test": "test-storybook",
    "storybook:test:a11y": "test-storybook --ci"
  }
}

# Run in CI
npx storybook dev --port 6006 &
npx wait-on tcp:6006
npx test-storybook --ci

WCAG 2.4.13 Focus Appearance Requirements (AAA, exceeds AA baseline)

WCAG 2.4.13 Focus Appearance (Level AAA in WCAG 2.2) - exceeds the 2.4.7 Focus Visible (AA) baseline, but recommended as best practice:

  1. Area: The focus indicator is at least as large as the area of a 2 CSS pixel thick perimeter of the unfocused component
  2. Contrast change: The focus indicator area has a contrast ratio of at least 3:1 between the same pixels in the focused and unfocused states
  3. Exceptions: The indicator is determined by the user agent and cannot be adjusted by the author, or the author has not modified the indicator or its background

Obscuring by author content is a separate requirement: 2.4.11 Focus Not Obscured (Minimum, AA) and 2.4.12 (Enhanced, AAA).

Minimum Compliant Focus Ring Implementation

/* Focus ring that meets 1.4.11 at AA and helps meet 2.4.13 (AAA) */
:focus-visible {
  outline: 2px solid #0054B3;      /* >= 2px width */
  outline-offset: 2px;             /* Separates from component edge */
  /* #0054B3 on #FFF = 7.19:1 -> passes 3:1 for UI components */
}

/* Dark mode variant */
@media (prefers-color-scheme: dark) {
  :focus-visible {
    outline-color: #7CAFFF;        /* lighter blue on dark background */
    /* #7CAFFF on #1E1E1E = 7.49:1 */
  }
}

/* VIOLATION patterns to detect */
:focus { outline: none; }                           /* Hard fail */
:focus { outline: 0; }                              /* Hard fail */
:focus-visible { box-shadow: none; outline: none; } /* Hard fail */
button:focus { outline: none; }                     /* Hard fail */
*:focus { outline-color: transparent; }             /* Hard fail */

Focus Ring Token Validation Checklist

Each check, with its requirement and tool.

CheckRequirementTool
outline-width >= 2pxWCAG 2.4.13 (AAA) area requirementCSS audit
Focus color contrast >= 3:1Against adjacent background (1.4.11)Contrast calculator
Focus state differs from unfocusedVisible change requiredVisual inspection
No outline: none without replacementN/Agrep / CSS audit
Present in both light and dark modesConsistentVisual inspection

Design Token File Discovery Commands

# Find all token files in a project
find . -type f \( \
  -name "tokens.json" \
  -o -name "design-tokens.json" \
  -o -name "colors.json" \
  -o -name "variables.css" \
  -o -name "tokens.css" \
  -o -name "_variables.scss" \
  -o -name "theme.ts" \
  -o -name "theme.js" \
  -o -name "tailwind.config.*" \
\) \
-not -path "*/node_modules/*" \
-not -path "*/.next/*" \
-not -path "*/dist/*"

# PowerShell equivalent
Get-ChildItem -Recurse -File -Include tokens.json,design-tokens.json,colors.json,`
  variables.css,tokens.css,_variables.scss,theme.ts,theme.js,tailwind.config.js,tailwind.config.ts `
  | Where-Object FullName -notmatch 'node_modules|\.next|dist'

Severity Classification

Each finding, with its severity (the a11y-core values).

FindingSeverity
Text token below 3:1critical
Text token 3:1-4.49:1 (normal text)serious
Text token 4.5:1-6.99:1, AAA targetminor
UI component token below 3:1serious
Focus ring missing completelycritical
Focus ring below 2px (2.4.13, AAA)minor
Focus ring contrast below 3:1serious
Touch target token below 24 x 24px (WCAG 2.5.8)serious
Touch target token below 44 x 44px (WCAG 2.5.5)minor
No prefers-reduced-motion resetminor
Placeholder color below 4.5:1serious
Disabled token below 3:1none - note only (documented exemption)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.