diff --git a/CHANGELOG.md b/CHANGELOG.md index cff953b..743fe1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ All notable changes to this project will be documented in this file. +## 1.21.0 - 2026-10-01 + +Changes since 1.20.2: + +### Added + +- UUID badges show a small colored circle in front of the short id. Its color comes from the first 6 hex digits of the UUID, so the same id always gets the same color, and its border uses the badge text color to stay visible in both themes. +- UUID badges get lighter on hover to show they can be clicked. +- `Badge` accepts an optional `className`. +- A Storybook "Colors" story for UuidBadge with six sample ids and a button to randomize them. + ## 1.20.2 - 2026-09-30 Changes since 1.20.1: diff --git a/client/.storybook/stories/UuidBadge.stories.tsx b/client/.storybook/stories/UuidBadge.stories.tsx index 2da9d83..7c27499 100644 --- a/client/.storybook/stories/UuidBadge.stories.tsx +++ b/client/.storybook/stories/UuidBadge.stories.tsx @@ -1,5 +1,7 @@ import type { Meta, StoryObj } from '@storybook/react-vite'; +import { useState } from 'react'; import { expect, within } from 'storybook/test'; +import { Button } from '../../src/ui/Button/Button'; import { UuidBadge } from '../../src/ui/UuidBadge/UuidBadge'; const meta: Meta = { @@ -19,3 +21,43 @@ export const Default: Story = { await expect(badge).toHaveTextContent('61d2…0b2e'); }, }; + +const SAMPLE_IDS = [ + '61d2b1c2-7664-4dca-974f-436c2ee90b2e', + 'e83f0a5d-1b9c-4f27-8d6e-2a4c9b7f1e03', + '0c7a94f1-3e52-4b8d-a1f6-9d2e5c8b4a70', + 'f4b21e8c-9a07-4c63-b5d2-7e1f0a3c6d98', + '8d5e3a10-c4f7-4e29-9b81-5f6a2d0c7e14', + '2a9fc067-58d3-4a1e-86b4-c3e7f19d5b2a', +]; + +function Gallery() { + const [ids, setIds] = useState(SAMPLE_IDS); + return ( +
+
+ {ids.map((id) => ( + + ))} +
+ +
+ ); +} + +export const Colors: Story = { + render: () => , + play: async ({ canvasElement }) => { + // Each sample id gets its own badge + const canvas = within(canvasElement); + for (const id of SAMPLE_IDS) { + await expect(canvas.getByTitle(id)).toBeInTheDocument(); + } + }, +}; diff --git a/client/src/ui/Badge/Badge.tsx b/client/src/ui/Badge/Badge.tsx index 4a36a44..8ff5f33 100644 --- a/client/src/ui/Badge/Badge.tsx +++ b/client/src/ui/Badge/Badge.tsx @@ -6,12 +6,13 @@ export type BadgeVariant = 'success' | 'error' | 'warning' | 'info' | 'neutral' export interface BadgeProps { variant?: BadgeVariant; dot?: boolean; + className?: string; children: React.ReactNode; } -export function Badge({ variant = 'neutral', dot = false, children }: BadgeProps) { +export function Badge({ variant = 'neutral', dot = false, className, children }: BadgeProps) { return ( - + {dot && diff --git a/client/src/ui/UuidBadge/UuidBadge.module.css b/client/src/ui/UuidBadge/UuidBadge.module.css index b74b70e..e08aeec 100644 --- a/client/src/ui/UuidBadge/UuidBadge.module.css +++ b/client/src/ui/UuidBadge/UuidBadge.module.css @@ -4,6 +4,23 @@ position: relative; } +.badge { + transition: background var(--transition); +} + +.badge:hover { + background: color-mix(in srgb, var(--color-neutral-bg) 85%, white); +} + +.swatch { + width: 8px; + height: 8px; + border-radius: 50%; + border: 1px solid currentColor; + box-sizing: border-box; + flex-shrink: 0; +} + .button { all: unset; cursor: pointer; diff --git a/client/src/ui/UuidBadge/UuidBadge.tsx b/client/src/ui/UuidBadge/UuidBadge.tsx index 6d97ce1..a1a91e3 100644 --- a/client/src/ui/UuidBadge/UuidBadge.tsx +++ b/client/src/ui/UuidBadge/UuidBadge.tsx @@ -7,9 +7,15 @@ export interface UuidBadgeProps { id: string; } +function uuidColor(id: string): string | null { + const hex = id.replace(/-/g, '').slice(0, 6); + return /^[0-9a-f]{6}$/i.test(hex) ? `#${hex}` : null; +} + export function UuidBadge({ id }: UuidBadgeProps) { const [copied, setCopied] = useState(false); const short = `${id.slice(0, 4)}…${id.slice(-4)}`; + const color = uuidColor(id); const handleClick = (e: React.MouseEvent) => { e.stopPropagation(); @@ -21,7 +27,10 @@ export function UuidBadge({ id }: UuidBadgeProps) { return ( - + + {color && ( +