Skip to content

add contrast badges - #1384

Merged
lukasoppermann merged 3 commits into
mainfrom
colorscale-component
May 8, 2026
Merged

add contrast badges#1384
lukasoppermann merged 3 commits into
mainfrom
colorscale-component

Conversation

@lukasoppermann

Copy link
Copy Markdown
Collaborator

This pull request significantly improves the ColorScale component in Storybook by enhancing its accessibility and usability. The changes add dynamic contrast ratio calculations for various foreground and background color combinations, introduce a new visual badge system for displaying these ratios, and update the component's styling for better clarity and structure.

CleanShot 2026-05-08 at 14 51 35@2x

Copilot AI review requested due to automatic review settings May 8, 2026 12:54
@lukasoppermann
lukasoppermann requested a review from a team as a code owner May 8, 2026 12:54
@lukasoppermann
lukasoppermann requested a review from liuliu-dev May 8, 2026 12:54
@changeset-bot

changeset-bot Bot commented May 8, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6ba19b0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
github-actions Bot temporarily deployed to Preview (Storybook) May 8, 2026 12:57 Inactive
@lukasoppermann lukasoppermann added the skip changeset Apply to PRs that should not result in a version bump. label May 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the Storybook ColorScale component to display contrast ratios between each swatch color and several key theme foreground/background tokens, adding a compact badge row UI and updated layout styling.

Changes:

  • Added contrast ratio calculation utilities and a probe-based approach to resolve CSS variable colors at runtime.
  • Rendered contrast “badges” (with icons + formatted ratios) and updated the swatch content structure.
  • Refreshed ColorScale styles to a flex-column layout and introduced tooltip styling for badges.
Show a summary per file
File Description
docs/storybook/stories/StorybookComponents/ColorScale/ColorScale.tsx Adds contrast computation, CSS-var probes, and renders badge UI + hex display.
docs/storybook/stories/StorybookComponents/ColorScale/ColorScale.css Updates layout styling and adds badge/tooltip presentation styles.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (2)

docs/storybook/stories/StorybookComponents/ColorScale/ColorScale.tsx:109

  • Switching from border to outline may cause the optional border to ignore the element’s border-radius (outlines don’t reliably follow rounding), which can visually regress the rounded corners set in .ColorScale--block:first/last-of-type. If rounding is desired, consider keeping a real border or using an inset box-shadow for the 1px stroke.
      style={{
        backgroundColor: `var(--${color})`,
        outline: border ? '1px solid var(--borderColor-default)' : undefined,
      }}

docs/storybook/stories/StorybookComponents/ColorScale/ColorScale.tsx:152

  • Badges rely on a hover-only tooltip (data-tooltip) and aren’t keyboard focusable, so the tooltip content isn’t accessible to keyboard/screen-reader users. Consider adding an accessible name (e.g., aria-label) and making the badge focusable (or use a title attribute) so the extra context is available without hover.
            <span key={key} className="cs-badge" data-tooltip={tooltip}>
              {icon === 'aa' ? (
                <span className="cs-aa" style={{color: `var(${cssVar})`}}>
                  Aa
                </span>
              ) : icon === 'outline-square' ? (
                <span className="cs-square cs-square--outline" style={{borderColor: `var(${cssVar})`}} />
              ) : (
                <span className="cs-square cs-square--filled" style={{backgroundColor: `var(${cssVar})`}} />
              )}
              <span className="cs-num" style={{color: numColor}}>
                {fmt(ratio)}
              </span>
            </span>
  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread docs/storybook/stories/StorybookComponents/ColorScale/ColorScale.tsx Outdated
Comment on lines +51 to +66
.cs-badge[data-tooltip]:hover::after {
content: attr(data-tooltip);
position: absolute;
bottom: calc(100% + 6px);
left: 50%;
transform: translateX(-50%);
white-space: nowrap;
background: var(--bgColor-emphasis, #1f2328);
color: var(--fgColor-onEmphasis, #ffffff);
font-size: 11px;
font-family: sans-serif;
padding: 3px 7px;
border-radius: 4px;
pointer-events: none;
z-index: 100;
}
lukasoppermann and others added 2 commits May 8, 2026 15:02
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/primer/primitives/sessions/bd328b1a-e866-40ce-b71c-259b661ba1fb

Co-authored-by: lukasoppermann <813754+lukasoppermann@users.noreply.github.com>
@github-actions
github-actions Bot temporarily deployed to Preview (Storybook) May 8, 2026 13:04 Inactive
@lukasoppermann
lukasoppermann merged commit a0d8629 into main May 8, 2026
27 of 28 checks passed
@lukasoppermann
lukasoppermann deleted the colorscale-component branch May 8, 2026 13:06
Copilot stopped work on behalf of lukasoppermann due to an error May 8, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip changeset Apply to PRs that should not result in a version bump.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants