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:
1 parent
dc5e6ff800
commit
f01de83733
185 files changed
+22542
-5182
No files matched your search
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Omit specific keys from an object.
|
||||
*
|
||||
* Ported from the source app's `src/common/utils/omit.js`, used by form
|
||||
* components to strip internal-only props (form-library plumbing) before
|
||||
* spreading the rest onto the DOM node.
|
||||
*/
|
||||
export function omit<T extends object, K extends keyof T>(
|
||||
obj: T | null | undefined,
|
||||
keys: readonly (K | string)[],
|
||||
): Omit<T, K> {
|
||||
if (!obj) return {} as Omit<T, K>
|
||||
return Object.fromEntries(
|
||||
Object.entries(obj).filter(([k]) => !keys.includes(k)),
|
||||
) as Omit<T, K>
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Shared class strings, so every component draws focus, sizing, popups and
|
||||
* field text the same way. Components import these instead of repeating
|
||||
* utility soup. Keep every value a complete, literal class string: Tailwind
|
||||
* finds classes by scanning source text.
|
||||
*/
|
||||
|
||||
export type Size = 'sm' | 'md' | 'lg'
|
||||
|
||||
/** Semantic colours shared by every component that takes a `color` prop. */
|
||||
export type Color = 'primary' | 'neutral' | 'success' | 'warning' | 'danger' | 'info'
|
||||
|
||||
export const COLORS: Color[] = ['primary', 'neutral', 'success', 'warning', 'danger', 'info']
|
||||
export const SIZES: Size[] = ['sm', 'md', 'lg']
|
||||
|
||||
/**
|
||||
* Visible keyboard focus. Put it on every interactive element.
|
||||
* `outline-hidden`, not `outline-none`: in Tailwind v4 `outline-none` sets the
|
||||
* outline *style* to none, and `focus-visible:outline-2` inherits it, so no
|
||||
* ring would ever draw.
|
||||
*/
|
||||
export const focusRing =
|
||||
'outline-hidden focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500'
|
||||
|
||||
/** Focus ring for a wrapper that contains the focused control (inputs with icons). */
|
||||
export const focusWithinRing =
|
||||
'has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-primary-500'
|
||||
|
||||
/** Heights shared by every control, so a Button sits flush with an Input. */
|
||||
export const controlHeight: Record<Size, string> = {
|
||||
sm: 'h-8 text-sm',
|
||||
md: 'h-10 text-sm',
|
||||
lg: 'h-12 text-base',
|
||||
}
|
||||
|
||||
export const controlPaddingX: Record<Size, string> = {
|
||||
sm: 'px-2.5',
|
||||
md: 'px-3',
|
||||
lg: 'px-4',
|
||||
}
|
||||
|
||||
/** Icon size inside a control of each size. */
|
||||
export const iconSize: Record<Size, string> = {
|
||||
sm: '[&_svg]:size-3.5',
|
||||
md: '[&_svg]:size-4',
|
||||
lg: '[&_svg]:size-5',
|
||||
}
|
||||
|
||||
/** The bordered box of a text control. Invalid state comes from aria-invalid or Base UI's data-invalid. */
|
||||
export const controlBox =
|
||||
'rounded-lg border border-border-strong bg-surface text-fg transition-colors ' +
|
||||
'hover:border-fg-subtle ' +
|
||||
'data-invalid:border-danger-500 aria-[invalid=true]:border-danger-500 ' +
|
||||
'data-disabled:cursor-not-allowed data-disabled:opacity-55 disabled:cursor-not-allowed disabled:opacity-55'
|
||||
|
||||
/** Popups: menus, selects, popovers, dialogs. */
|
||||
/** In dark mode popups sit a step lighter than the card behind them. */
|
||||
export const popupSurface =
|
||||
'rounded-xl border border-border bg-surface text-fg shadow-popup outline-hidden dark:bg-surface-muted'
|
||||
|
||||
/** Enter and exit motion for popups that grow from their trigger. */
|
||||
export const popupMotion =
|
||||
'origin-(--transform-origin) transition-[transform,opacity] duration-150 ease-out ' +
|
||||
'data-starting-style:scale-95 data-starting-style:opacity-0 data-ending-style:scale-95 data-ending-style:opacity-0 ' +
|
||||
'motion-reduce:transition-none'
|
||||
|
||||
/** A selectable row inside a menu, select or combobox list. */
|
||||
export const listItem =
|
||||
'flex cursor-default select-none items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-fg outline-none ' +
|
||||
'data-highlighted:bg-surface-sunken data-disabled:pointer-events-none data-disabled:opacity-50'
|
||||
|
||||
export const labelText = 'text-sm font-medium text-fg'
|
||||
export const descriptionText = 'text-xs leading-5 text-fg-muted'
|
||||
export const errorText = 'text-xs font-medium leading-5 text-danger-700 dark:text-danger-400'
|
||||
export const requiredMark = 'ml-0.5 text-danger-700 dark:text-danger-400'
|
||||
@@ -1,29 +0,0 @@
|
||||
import { useEffect, type RefObject } from 'react'
|
||||
|
||||
/**
|
||||
* Fire `callback` when a mousedown lands outside every one of `elements`.
|
||||
*
|
||||
* Ported from the source app's `Select/hooks/useClickOutside`.
|
||||
* The dropdown is portalled to `document.body`, so both the control and the
|
||||
* dropdown panel are passed in — checking one alone would close the menu the
|
||||
* instant you clicked inside it.
|
||||
*/
|
||||
export function useClickOutside(
|
||||
elements: RefObject<HTMLElement | null>[],
|
||||
callback: (event: MouseEvent) => void,
|
||||
enabled = true,
|
||||
): void {
|
||||
useEffect(() => {
|
||||
if (!enabled) return
|
||||
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
const isOutside = elements.every(
|
||||
(ref) => !ref.current || !ref.current.contains(event.target as Node),
|
||||
)
|
||||
if (isOutside) callback(event)
|
||||
}
|
||||
|
||||
document.addEventListener('mousedown', handleClickOutside)
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside)
|
||||
}, [elements, callback, enabled])
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { useCallback, useState } from 'react'
|
||||
|
||||
/**
|
||||
* State that can be controlled (`value` passed) or uncontrolled (`defaultValue`),
|
||||
* for components that don't get this from Base UI. `onChange` fires in both modes.
|
||||
*/
|
||||
export function useControllableState<T>(
|
||||
value: T | undefined,
|
||||
defaultValue: T,
|
||||
onChange?: (next: T) => void,
|
||||
): [T, (next: T) => void] {
|
||||
const [internal, setInternal] = useState(defaultValue)
|
||||
const isControlled = value !== undefined
|
||||
const current = isControlled ? value : internal
|
||||
|
||||
const setValue = useCallback(
|
||||
(next: T) => {
|
||||
if (!isControlled) setInternal(next)
|
||||
onChange?.(next)
|
||||
},
|
||||
[isControlled, onChange],
|
||||
)
|
||||
|
||||
return [current, setValue]
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
import { useCallback, useEffect, useState, type RefObject } from 'react'
|
||||
|
||||
export type DropdownPlacement = 'auto' | 'up' | 'down'
|
||||
|
||||
export type DropdownPosition = {
|
||||
top?: number
|
||||
bottom?: number
|
||||
left: number
|
||||
width: number
|
||||
maxHeight: string
|
||||
}
|
||||
|
||||
const STANDARD_MAX_HEIGHT = 240
|
||||
const BUFFER = 12
|
||||
|
||||
/**
|
||||
* Fixed-position coordinates for a portalled dropdown.
|
||||
*
|
||||
* Ported from the source app's `useDropdownPosition`. The menu is rendered into
|
||||
* `document.body` so it escapes any `overflow: hidden` ancestor, which means its
|
||||
* position has to be measured rather than flowed.
|
||||
*
|
||||
* `placement: 'auto'` opens upward when there is not enough room below and more
|
||||
* room above.
|
||||
*/
|
||||
export function useDropdownPosition(
|
||||
isOpen: boolean,
|
||||
containerRef: RefObject<HTMLElement | null>,
|
||||
options: { placement?: DropdownPlacement } = {},
|
||||
): {
|
||||
dropdownPosition: DropdownPosition
|
||||
calculateInitialPosition: () => void
|
||||
} {
|
||||
const { placement = 'auto' } = options
|
||||
const [dropdownPosition, setDropdownPosition] = useState<DropdownPosition>({
|
||||
left: 0,
|
||||
width: 0,
|
||||
maxHeight: `${STANDARD_MAX_HEIGHT}px`,
|
||||
})
|
||||
|
||||
const measure = useCallback(() => {
|
||||
const node = containerRef.current
|
||||
if (!node) return
|
||||
|
||||
const rect = node.getBoundingClientRect()
|
||||
const spaceAbove = rect.top
|
||||
const spaceBelow = window.innerHeight - rect.bottom
|
||||
|
||||
const shouldOpenUp =
|
||||
placement === 'up' ||
|
||||
(placement === 'auto' &&
|
||||
spaceBelow < STANDARD_MAX_HEIGHT + BUFFER &&
|
||||
spaceAbove > spaceBelow)
|
||||
|
||||
if (shouldOpenUp) {
|
||||
const available = Math.max(spaceAbove - BUFFER, 50)
|
||||
setDropdownPosition({
|
||||
bottom: window.innerHeight - rect.top + 4,
|
||||
left: rect.left,
|
||||
width: rect.width,
|
||||
maxHeight: `${Math.min(STANDARD_MAX_HEIGHT, available)}px`,
|
||||
})
|
||||
} else {
|
||||
const available = Math.max(spaceBelow - BUFFER, 50)
|
||||
setDropdownPosition({
|
||||
top: rect.bottom + 4,
|
||||
left: rect.left,
|
||||
width: rect.width,
|
||||
maxHeight: `${Math.min(STANDARD_MAX_HEIGHT, available)}px`,
|
||||
})
|
||||
}
|
||||
}, [containerRef, placement])
|
||||
|
||||
/**
|
||||
* Measure on a frame boundary, not synchronously.
|
||||
*
|
||||
* The panel is portalled to `document.body` and the control's ref is not yet
|
||||
* attached at the moment the dropdown is switched on, so a synchronous read
|
||||
* gets nothing and leaves the panel at its zero-initialised position —
|
||||
* rendered off-screen at `left: 0; width: 0` while every DOM query still
|
||||
* "succeeds". Measuring after layout also picks up a control that moves
|
||||
* between the click and the paint.
|
||||
*/
|
||||
const calculateInitialPosition = useCallback(() => {
|
||||
requestAnimationFrame(() => measure())
|
||||
}, [measure])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) return
|
||||
const reposition = () => measure()
|
||||
reposition()
|
||||
window.addEventListener('resize', reposition)
|
||||
window.addEventListener('scroll', reposition, true)
|
||||
return () => {
|
||||
window.removeEventListener('resize', reposition)
|
||||
window.removeEventListener('scroll', reposition, true)
|
||||
}
|
||||
}, [isOpen, measure])
|
||||
|
||||
return { dropdownPosition, calculateInitialPosition }
|
||||
}
|
||||
Reference in new issue
Block a user