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
@@ -0,0 +1,129 @@
|
||||
import { NumberField } from '@base-ui/react/number-field'
|
||||
import { Minus, Plus } from 'lucide-react'
|
||||
import type { ReactNode } from 'react'
|
||||
import { cn } from '../lib/cn'
|
||||
import { controlBox, controlHeight, controlPaddingX, iconSize, type Size } from '../lib/styles'
|
||||
import { Field } from './Field'
|
||||
import { FIELD_BOX_DISABLED_INPUT, FIELD_BOX_RING_INPUT } from './featuredinput.tokens'
|
||||
import { NUMBER_ADDON, NUMBER_STEPPER, NUMBER_STEPPER_WIDTH } from './numberinput.tokens'
|
||||
|
||||
export type NumberInputProps = {
|
||||
/** Visible label, linked to the input. */
|
||||
label?: ReactNode
|
||||
/** Help text under the input. */
|
||||
description?: ReactNode
|
||||
/** Error message; marks the input invalid and replaces `description`. */
|
||||
error?: ReactNode
|
||||
/** Shows the required mark and requires a value. */
|
||||
required?: boolean
|
||||
disabled?: boolean
|
||||
/** Shows the value but blocks changes. */
|
||||
readOnly?: boolean
|
||||
size?: Size
|
||||
/** Lowest allowed value. Stepping clamps to it. */
|
||||
min?: number
|
||||
/** Highest allowed value. Stepping clamps to it. */
|
||||
max?: number
|
||||
/** Amount the buttons and arrow keys change the value by. Shift steps by 10×. */
|
||||
step?: number
|
||||
value?: number | null
|
||||
defaultValue?: number | null
|
||||
/** Fires with the new number, or `null` when the input is cleared. */
|
||||
onValueChange?: (value: number | null) => void
|
||||
/** How the value is displayed, e.g. `{ style: 'currency', currency: 'USD' }`. */
|
||||
format?: Intl.NumberFormatOptions
|
||||
/** Locale for formatting and parsing. Defaults to the user's. */
|
||||
locale?: Intl.LocalesArgument
|
||||
/** Text or element attached before the input, such as `$`. */
|
||||
startAddon?: ReactNode
|
||||
/** Text or element attached after the input, such as `kg`. */
|
||||
endAddon?: ReactNode
|
||||
/** Identifies the field in a form. */
|
||||
name?: string
|
||||
/** Classes for the outer field wrapper. */
|
||||
className?: string
|
||||
/** Classes for the input itself. */
|
||||
inputClassName?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* A number field on Base UI NumberField: typing is parsed and formatted,
|
||||
* arrow keys and the − / + buttons step the value, and min / max clamp it.
|
||||
*/
|
||||
export function NumberInput({
|
||||
label,
|
||||
description,
|
||||
error,
|
||||
required,
|
||||
disabled,
|
||||
readOnly,
|
||||
size = 'md',
|
||||
min,
|
||||
max,
|
||||
step = 1,
|
||||
value,
|
||||
defaultValue,
|
||||
onValueChange,
|
||||
format,
|
||||
locale,
|
||||
startAddon,
|
||||
endAddon,
|
||||
name,
|
||||
className,
|
||||
inputClassName,
|
||||
}: NumberInputProps) {
|
||||
return (
|
||||
<Field
|
||||
label={label}
|
||||
description={description}
|
||||
error={error}
|
||||
required={required}
|
||||
disabled={disabled}
|
||||
name={name}
|
||||
className={className}
|
||||
>
|
||||
<NumberField.Root
|
||||
value={value}
|
||||
defaultValue={defaultValue ?? undefined}
|
||||
onValueChange={onValueChange ? (next) => onValueChange(next) : undefined}
|
||||
min={min}
|
||||
max={max}
|
||||
step={step}
|
||||
format={format}
|
||||
locale={locale}
|
||||
required={required}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
className="w-full"
|
||||
>
|
||||
<NumberField.Group
|
||||
className={cn(
|
||||
'flex w-full items-stretch overflow-hidden',
|
||||
controlHeight[size],
|
||||
iconSize[size],
|
||||
controlBox,
|
||||
'has-[[aria-invalid=true]]:border-danger-500',
|
||||
FIELD_BOX_DISABLED_INPUT,
|
||||
FIELD_BOX_RING_INPUT,
|
||||
)}
|
||||
>
|
||||
{startAddon != null && <span className={cn(NUMBER_ADDON, 'border-r')}>{startAddon}</span>}
|
||||
<NumberField.Input
|
||||
className={cn(
|
||||
'min-w-0 flex-1 bg-transparent text-fg tabular-nums outline-none placeholder:text-fg-subtle disabled:cursor-not-allowed',
|
||||
controlPaddingX[size],
|
||||
inputClassName,
|
||||
)}
|
||||
/>
|
||||
{endAddon != null && <span className={cn(NUMBER_ADDON, 'border-l')}>{endAddon}</span>}
|
||||
<NumberField.Decrement aria-label="Decrease" className={cn(NUMBER_STEPPER, NUMBER_STEPPER_WIDTH[size])}>
|
||||
<Minus aria-hidden="true" />
|
||||
</NumberField.Decrement>
|
||||
<NumberField.Increment aria-label="Increase" className={cn(NUMBER_STEPPER, NUMBER_STEPPER_WIDTH[size])}>
|
||||
<Plus aria-hidden="true" />
|
||||
</NumberField.Increment>
|
||||
</NumberField.Group>
|
||||
</NumberField.Root>
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user