// // Copyright 2026 DXOS.org // import '../theme/index.css'; import { type Meta, type StoryObj } from '@storybook/react-vite'; import React, { type ComponentType, Fragment, type PropsWithChildren, createContext, useContext, useEffect, useRef, useState, } from 'react'; import { ACCENT_HUES, type AccentHue, accentTokens } from '@dxos/ui-theme'; import { type MessageValence, hues } from '@dxos/ui-types'; import { translations } from '#translations'; import * as Accordion from '../components/Accordion/Accordion.tsx'; import * as AlertDialog from '../components/AlertDialog/AlertDialog.tsx'; import * as Avatar from '../components/Avatar/Avatar.tsx'; import * as Banner from '../components/Banner/Banner.tsx'; import * as Breadcrumb from '../components/Breadcrumb/Breadcrumb.tsx'; import { Button, type ButtonVariant } from '../components/Button/Button.tsx'; import * as Card from '../components/Card/Card.tsx'; import * as Carousel from '../components/Carousel/Carousel.tsx'; import { Checkbox } from '../components/Checkbox/Checkbox.tsx'; import * as Collapsible from '../components/Collapsible/Collapsible.tsx'; import * as Combobox from '../components/Combobox/Combobox.tsx'; import { Container } from '../components/Container/Container.tsx'; import * as Dialog from '../components/Dialog/Dialog.tsx'; import * as DragHandle from '../components/DragHandle/DragHandle.tsx'; import * as Editable from '../components/Editable/Editable.tsx'; import { Empty } from '../components/Empty/Empty.tsx'; import * as Field from '../components/Field/Field.tsx'; import { Group } from '../components/Group/Group.tsx'; import * as HoverCard from '../components/HoverCard/HoverCard.tsx'; import * as Icon from '../components/Icon/Icon.tsx'; import { Input } from '../components/Input/Input.tsx'; import { Link } from '../components/Link/Link.tsx'; import * as Menu from '../components/Menu/Menu.tsx'; import { MenuButton, type MenuButtonItem } from '../components/MenuButton/MenuButton.tsx'; import { NumberInput } from '../components/NumberInput/NumberInput.tsx'; import * as Panel from '../components/Panel/Panel.tsx'; import { PasswordInput } from '../components/PasswordInput/PasswordInput.tsx'; import { PinInput } from '../components/PinInput/PinInput.tsx'; import * as Popover from '../components/Popover/Popover.tsx'; import { Progress } from '../components/Progress/Progress.tsx'; import * as QrCode from '../components/QrCode/QrCode.tsx'; import * as ScrollArea from '../components/ScrollArea/ScrollArea.tsx'; import * as Select from '../components/Select/Select.tsx'; import { Separator } from '../components/Separator/Separator.tsx'; import { Skeleton } from '../components/Skeleton/Skeleton.tsx'; import * as Splitter from '../components/Splitter/Splitter.tsx'; import { Steps } from '../components/Steps/Steps.tsx'; import { Switch } from '../components/Switch/Switch.tsx'; import * as SystemButton from '../components/SystemButton/SystemButton.tsx'; import * as Tabs from '../components/Tabs/Tabs.tsx'; import * as Tag from '../components/Tag/Tag.tsx'; import { Textarea } from '../components/Textarea/Textarea.tsx'; import { Timestamp } from '../components/Timestamp/Timestamp.tsx'; import * as Toast from '../components/Toast/Toast.tsx'; import { Toggle } from '../components/Toggle/Toggle.tsx'; import * as ToggleGroup from '../components/ToggleGroup/ToggleGroup.tsx'; import * as Toolbar from '../components/Toolbar/Toolbar.tsx'; import * as Tooltip from '../components/Tooltip/Tooltip.tsx'; import * as Typography from '../components/Typography/Typography.tsx'; import * as UiInput from '../namespaces/Input.ts'; import { type Size, SIZES } from '../sizes.ts'; import { withTheme } from '../testing/index.ts'; // // Frame // const SizeContext = createContext('md'); type SectionProps = PropsWithChildren<{ id: string; title: string; }>; /** One component family: a heading over a rail-gutter Container at the frame's size. */ const Section = ({ id, title, children }: SectionProps) => { const size = useContext(SizeContext); return (

{title}

{children}
); }; /** A labelled run of controls within a section. */ const Row = ({ label, children }: PropsWithChildren<{ label?: string }>) => ( {label && ( {label} )} {children} ); type TocEntry = { id: string; title: string }; /** Lists every section; the one nearest the top of the scrolling column is highlighted. */ const Toc = ({ entries, active, onSelect, }: { entries: TocEntry[]; active?: string; onSelect: (id: string) => void; }) => ( ); type SectionDef = TocEntry & { Component: ComponentType }; type FrameProps = { sections: SectionDef[]; hue: AccentHue; size: Size; }; /** The page: a document-width Panel scrolling the sections, with a table of contents beside it. */ const Frame = ({ sections, hue, size }: FrameProps) => { const [active, setActive] = useState(sections[0]?.id); const scrollRef = useRef(null); const frameRef = useRef(null); // Accent tokens are custom properties, which React's `style` typing does not name. useEffect(() => { const frame = frameRef.current; if (!frame) { return; } const tokens = Object.entries(accentTokens(hue)); tokens.forEach(([property, value]) => frame.style.setProperty(property, value)); return () => tokens.forEach(([property]) => frame.style.removeProperty(property)); }, [hue]); useEffect(() => { const root = scrollRef.current; if (!root) { return; } const visible = new Set(); const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { const id = entry.target.getAttribute('data-section'); if (id) { entry.isIntersecting ? visible.add(id) : visible.delete(id); } }); // The last in the band: the section above one scrolled to the top still touches it at its edge. const current = sections.findLast(({ id }) => visible.has(id)); if (current) { setActive(current.id); } }, // Only the top band of the column counts, so the highlighted section is the one being read. { root, rootMargin: '0px 0px -70% 0px' }, ); root.querySelectorAll('[data-section]').forEach((element) => observer.observe(element)); return () => observer.disconnect(); }, [sections]); const handleSelect = (id: string) => { const root = scrollRef.current; const section = root?.querySelector(`[data-section="${id}"]`); if (!root || !section) { return; } // Scrolls only the column: `scrollIntoView` would also scroll the story's own document. const top = section.getBoundingClientRect().top - root.getBoundingClientRect().top + root.scrollTop; root.scrollTo({ top, behavior: 'smooth' }); setActive(id); }; return (
{/* `relative` contains the controls' visually hidden native inputs, which would otherwise scroll the document. */} {sections.map(({ id, Component }) => ( ))}
); }; // // Sections // const BUTTON_VARIANTS: ButtonVariant[] = ['default', 'primary', 'outline', 'ghost', 'destructive']; const VALENCES: MessageValence[] = ['neutral', 'info', 'success', 'warning', 'error']; const ButtonSection = () => (
{BUTTON_VARIANTS.map((variant) => ( ))} Bold Italic Code
); const MenuButtonDemo = () => { const [view, setView] = useState('List'); const [extraction, setExtraction] = useState(false); const items: MenuButtonItem[] = [ { type: 'group', label: 'View' }, ...['List', 'Grid', 'Board'].map((label): MenuButtonItem => ({ type: 'option', label, selected: view === label, onSelect: () => setView(label), })), { type: 'separator' }, { type: 'checkbox', label: 'Entity extraction', checked: extraction, onCheckedChange: setExtraction }, ]; return ( <> {view} · extraction {extraction ? 'on' : 'off'} ); }; const InputSection = () => (
Name Shown to other members. Search } placeholder='Find…' /> Workspace Subdued Identity Disabled {(['success', 'info', 'warning', 'error'] as const).map((valence) => ( Handle ({valence}) A {valence} message. ))} Website Enter a valid URL. Notes