Rebuild Tansy UI on Base UI with one API and dark mode (v0.3.0)

Every component is rebuilt on @base-ui/react with a single prop API,
token-only colours and dark mode, and 28 new components are added.

Components
- New: Field, FeaturedTextArea, NumberInput, Combobox, CheckboxGroup,
  Slider, ToggleGroup/Toggle, IconButton, Dialog/Modal, AlertDialog,
  Drawer/Sheet, Popover, InfoTip, DropdownMenu, Tabs, Breadcrumb,
  Pagination, Toast (Toaster, useToast), Progress, Meter, Skeleton,
  CountBadge, Avatar/AvatarGroup, Kbd, Separator, Table
- Rewritten: Button, Input, FeaturedInput, TextArea, Select,
  FeaturedSelect (real ARIA combobox), NativeSelect, Checkbox, Radio,
  Switch, Tooltip, Accordion, Alert, Spinner, Badge, Card
- Removed TextField (use Input) and sonner (use Toast)

Foundations
- Semantic tokens (surfaces, text, borders, status ramps) in
  src/styles/tokens.css, with class-based dark mode
- Visible focus rings, linked labels/descriptions/errors, alert roles by
  severity, keyboard support from Base UI
- Fixed the Classic Blue ramp; Emerald, Amber and Teal 500 steps now
  carry white text at AA
- Library build (per-component ES modules, types, tokens.css, exports)

Quality
- Vitest, Testing Library and axe tests for every component (289 tests)
- scripts/check-stories.mjs renders every story in Chrome and fails on
  errors or axe violations, including contrast; all 423 stories pass in
  light and dark mode and in all seven palettes
- Storybook: controls for every prop, open states for every popup,
  light/dark toolbar, Introduction guides, docs/CONVENTIONS.md

BREAKING CHANGE: component props changed across the kit; see CHANGELOG.md.
This commit is contained in:
thekhalidsha committed 2026-09-28 21:12:11 +05:30
1 parent dc5e6ff800
commit f01de83733
185 files changed
+22542 -5182

No files matched your search

+158 -99
View File
@@ -1,113 +1,172 @@
import { forwardRef, type HTMLAttributes, type ReactNode } from 'react'
import { cn } from '@/lib/cn'
import type { ComponentProps, MouseEvent, ReactNode } from 'react'
import { X } from 'lucide-react'
import { cn } from '../lib/cn'
import { focusRing } from '../lib/styles'
import {
BADGE_COLORS,
BADGE_COLOR_ALIAS,
BADGE_POSITIONS,
BADGE_ROUNDED,
BADGE_DOT,
BADGE_DOT_SIZES,
BADGE_SIZES,
DEFAULT_BADGE_SIZES,
resolveBadgeColor,
type BadgeBorder,
BADGE_STYLES,
COUNT_BADGE_PING,
COUNT_BADGE_PLACEMENT,
COUNT_BADGE_SIZES,
COUNT_BADGE_STYLES,
colorForValue,
type BadgeColor,
type BadgeDefaultSize,
type BadgeFloatingPosition,
type BadgeFloatingSize,
type BadgeType,
type BadgeSize,
type BadgeVariant,
type ColorRange,
type CountBadgePlacement,
type CountBadgeSize,
} from './badge.tokens'
/**
* Status indicator / count badge.
*
* Ported from the original `Badge` component.
*
* Two shapes:
* - `floating` (default) — pins the badge to a corner of its child (an icon or
* avatar), so the child wraps it.
* - `default` — a standalone inline chip.
*
* `colorRanges` maps a numeric `content` onto a colour band, which is how the
* source app colours pending-approval counts without a per-row className.
*/
export type BadgeProps = Omit<HTMLAttributes<HTMLDivElement>, 'content'> & {
type?: BadgeType
/** The count or label. Accepts a number — counts arrive as numbers in the source app. */
content?: ReactNode | number
color?: BadgeColor | string
/** Colour the badge by numeric value, e.g. `[{min:5,max:9,color:'warning'}]`. */
export type BadgeProps = Omit<ComponentProps<'span'>, 'color'> & {
/** Semantic colour. Overridden by a matching `colorRanges` entry. */
color?: BadgeColor
/** Visual weight. `soft` for most status labels, `solid` for emphasis. */
variant?: BadgeVariant
size?: BadgeSize
/** Shows a leading status dot. */
dot?: boolean
/** Icon before the label. Pass a decorative icon, e.g. `<Check />`. */
icon?: ReactNode
/** Renders a remove button after the label, e.g. for filter chips. */
onRemove?: (event: MouseEvent<HTMLButtonElement>) => void
/** Accessible name of the remove button. Defaults to "Remove {children}". */
removeLabel?: string
/** Colour the badge by value when `children` is a number, e.g. `[{ min: 10, max: Infinity, color: 'danger' }]`. */
colorRanges?: ColorRange[]
floatingPosition?: BadgeFloatingPosition
floatingSize?: BadgeFloatingSize
defaultSize?: BadgeDefaultSize
defaultBorder?: BadgeBorder
/** Remix-icon class name, e.g. `"ri-home-line"`. Needs the Remix font. */
defaultIcon?: string
pulse?: boolean
}
export const Badge = forwardRef<HTMLDivElement, BadgeProps>(function Badge(
{
type = 'floating',
content,
color = 'danger',
colorRanges,
children,
floatingPosition = 'top_right',
floatingSize = 'sm',
pulse = false,
className = '',
defaultSize = 'sm',
defaultBorder = 'lg',
defaultIcon,
...props
},
ref,
) {
const normalized = BADGE_COLOR_ALIAS[color] ?? (color as BadgeColor)
const computed =
type === 'floating' ? resolveBadgeColor(color, content, colorRanges) : normalized
const theme = BADGE_COLORS[computed] ?? BADGE_COLORS[normalized] ?? BADGE_COLORS.danger
if (type === 'default') {
return (
<div
ref={ref}
className={cn(
'inline-flex items-center justify-center font-medium transition-colors',
BADGE_ROUNDED[defaultBorder] ?? BADGE_ROUNDED.lg,
DEFAULT_BADGE_SIZES[defaultSize] ?? DEFAULT_BADGE_SIZES.sm,
theme,
className,
)}
{...props}
>
{defaultIcon && <i className={cn(defaultIcon, 'mr-1.5')} aria-hidden="true" />}
{children ?? content}
</div>
)
}
/** A short status label: a state, a category or a count. */
export function Badge({
color = 'neutral',
variant = 'soft',
size = 'md',
dot = false,
icon,
onRemove,
removeLabel,
colorRanges,
className,
children,
...props
}: BadgeProps) {
const resolved = colorForValue(children, colorRanges, color)
const text = typeof children === 'string' || typeof children === 'number' ? String(children) : undefined
return (
<span className="relative inline-flex">
<span
className={cn(
'inline-flex shrink-0 items-center whitespace-nowrap rounded-full border font-medium leading-none tabular-nums',
'[&_svg]:shrink-0',
BADGE_STYLES[variant][resolved],
BADGE_SIZES[size],
onRemove && 'pr-0.5',
className,
)}
{...props}
>
{dot && (
<span
aria-hidden="true"
className={cn('shrink-0 rounded-full', BADGE_DOT_SIZES[size], variant === 'solid' ? 'bg-current' : BADGE_DOT[resolved])}
/>
)}
{icon}
{children}
<div
ref={ref}
className={cn(
'absolute z-10 inline-flex items-center justify-center rounded-full font-semibold',
BADGE_POSITIONS[floatingPosition] ?? BADGE_POSITIONS.top_right,
BADGE_SIZES[floatingSize] ?? BADGE_SIZES.sm,
theme,
pulse && 'animate-pulse',
className,
)}
{...props}
>
{content}
</div>
{onRemove && (
<button
type="button"
aria-label={removeLabel ?? (text ? `Remove ${text}` : 'Remove')}
onClick={onRemove}
className={cn(
'inline-flex shrink-0 items-center justify-center rounded-full opacity-70 transition-[opacity,background-color]',
'hover:bg-current/15 hover:opacity-100',
size === 'sm' ? 'size-4' : size === 'md' ? 'size-5' : 'size-6',
focusRing,
)}
>
<X aria-hidden="true" strokeWidth={2.5} />
</button>
)}
</span>
)
})
}
export default Badge
export type CountBadgeProps = Omit<ComponentProps<'span'>, 'color'> & {
/** The element the count is pinned to: an icon, an avatar or a button. */
children: ReactNode
/** The number to show. */
count?: number
/** Counts above this show as "{max}+". */
max?: number
/** Show the badge when `count` is 0. */
showZero?: boolean
/** Show a small dot instead of the number. */
dot?: boolean
/** Which corner of the element the badge sits on. */
placement?: CountBadgePlacement
/** Draws attention with a pulsing ring (off under reduced motion). */
pulse?: boolean
color?: BadgeColor
size?: CountBadgeSize
/** Colour by value, e.g. warning from 5 and danger from 10. */
colorRanges?: ColorRange[]
/**
* Accessible name of the badge, e.g. "3 unread notifications". A function
* receives the count. Defaults to the visible text.
*/
label?: string | ((count: number) => string)
}
/** Pins a count or a dot to a corner of an element. */
export function CountBadge({
children,
count = 0,
max = 99,
showZero = false,
dot = false,
placement = 'top-end',
pulse = false,
color = 'danger',
size = 'md',
colorRanges,
label,
className,
...props
}: CountBadgeProps) {
const visible = dot || count > 0 || showZero
const display = count > max ? `${max}+` : String(count)
const name = typeof label === 'function' ? label(count) : (label ?? (dot ? undefined : display))
const resolved = colorForValue(count, colorRanges, color)
const sizes = COUNT_BADGE_SIZES[size]
return (
<span className={cn('relative inline-flex shrink-0 align-middle', className)} {...props}>
{children}
{visible && (
<span
role="status"
aria-label={name}
className={cn(
'pointer-events-none absolute z-10 inline-flex items-center justify-center rounded-full font-semibold leading-none tabular-nums ring-2 ring-surface',
COUNT_BADGE_PLACEMENT[placement],
COUNT_BADGE_STYLES[resolved],
dot ? sizes.dot : sizes.count,
)}
>
{pulse && (
<span
aria-hidden="true"
className={cn(
'absolute inset-0 -z-10 animate-ping rounded-full opacity-60 motion-reduce:hidden',
COUNT_BADGE_PING[resolved],
)}
/>
)}
{!dot && <span aria-hidden={name ? true : undefined}>{display}</span>}
</span>
)}
</span>
)
}