feat(ui): add docking, viewport controls and composed settings

Add shared dock layouts, navigation cube, range bands, progress actions and comparison surfaces. Extend toolbar menus and loading composition, and align tokens, registry entries, documentation and the living catalog.
This commit is contained in:
Codex
2026-10-29 09:38:25 +03:00
parent a6e6c8f2d9
commit cb534dbe39
51 changed files with 2273 additions and 336 deletions
+36 -38
View File
@@ -1,4 +1,4 @@
import type { ReactNode } from "react";
import { forwardRef, type ButtonHTMLAttributes, type HTMLAttributes, type ReactNode } from "react";
import { cn } from "./cn.js";
export interface SegmentedItem<T extends string> {
@@ -7,48 +7,46 @@ export interface SegmentedItem<T extends string> {
icon?: ReactNode;
disabled?: boolean;
}
export type SegmentedControlSize = "default" | "dense";
export interface SegmentedControlProps<T extends string> {
value: T;
export type SegmentedControlProps<T extends string> = {
items: Array<SegmentedItem<T>>;
label: string;
size?: SegmentedControlSize;
className?: string;
onChange: (value: T) => void;
} & ({ selectionMode?: "single"; value: T; onChange: (value: T) => void }
| { selectionMode: "multiple"; value: readonly T[]; onChange: (value: T[]) => void });
export function SegmentedControl<T extends string>(props: SegmentedControlProps<T>) {
const { items, label, size = "default", className } = props;
const multiple = props.selectionMode === "multiple";
return <div className={cn("nodedc-segmented", className)}
role={multiple ? "group" : "tablist"} aria-label={label}
data-size={size === "default" ? undefined : size}>
{items.map(item => {
const active = props.selectionMode === "multiple" ? props.value.includes(item.value) : props.value === item.value;
return <button key={item.value} type="button" className="nodedc-segmented__item"
role={multiple ? undefined : "tab"} aria-selected={multiple ? undefined : active}
aria-pressed={multiple ? active : undefined} data-active={active ? "true" : undefined}
disabled={item.disabled} onClick={() => {
if (props.selectionMode === "multiple") {
props.onChange(active ? props.value.filter(value => value !== item.value) : [...props.value, item.value]);
} else props.onChange(item.value);
}}>{item.icon}{item.label}</button>;
})}
</div>;
}
export function SegmentedControl<T extends string>({
value,
items,
label,
size = "default",
className,
onChange,
}: SegmentedControlProps<T>) {
return (
<div
className={cn("nodedc-segmented", className)}
role="tablist"
aria-label={label}
data-size={size === "default" ? undefined : size}
>
{items.map((item) => (
<button
key={item.value}
type="button"
className="nodedc-segmented__item"
role="tab"
aria-selected={item.value === value}
data-active={item.value === value ? "true" : undefined}
disabled={item.disabled}
onClick={() => onChange(item.value)}
>
{item.icon}
{item.label}
</button>
))}
</div>
);
/** Shared capsule for independently controlled toggles and menu triggers. */
export function SegmentedGroup({ label, size = "default", className, ...props }:
HTMLAttributes<HTMLDivElement> & { label: string; size?: SegmentedControlSize }) {
return <div {...props} className={cn("nodedc-segmented", className)} role="group" aria-label={label}
data-size={size === "default" ? undefined : size} />;
}
/** Caller supplies aria-pressed for toggles or aria-expanded/haspopup for menu triggers. */
export const SegmentedButton = forwardRef<HTMLButtonElement,
ButtonHTMLAttributes<HTMLButtonElement> & { active?: boolean }
>(function SegmentedButton({ active, className, type = "button", ...props }, ref) {
return <button {...props} ref={ref} type={type} className={cn("nodedc-segmented__item", className)}
data-active={active ? "true" : undefined} />;
});