From 67ad0685737b82cb0e309aaaf103a67eef3a28ca Mon Sep 17 00:00:00 2001 From: Jeremy Walton Date: Thu, 5 Nov 2026 17:34:17 -0500 Subject: [PATCH 1/8] Add React components as a shadcn registry Bring the components from optics-components-react into a react/ workspace. They ship as a shadcn registry, not in the npm package. - 32 components on Base UI and cva, with kebab-case shadcn paths - Split Alert.Flash from Alert.Root and Tabs.Nav from Tabs.List - React Storybook, composed into the main Storybook under "React" - build-docs publishes it to /react and the registry to /r - Test that registry.json matches each file's imports Co-Authored-By: Claude Opus 5.5 --- .claude/launch.json | 17 + .github/workflows/linting.yml | 4 + .npmignore | 3 + .storybook/main.js | 12 + docs/plans/2026-11-05-react-components.md | 53 + package.json | 10 +- react/.storybook/main.ts | 24 + react/.storybook/preview.css | 7 + react/.storybook/preview.tsx | 35 + react/README.md | 18 + react/package.json | 28 + react/registry.json | 474 ++++ react/registry/optics/lib/flex-utilities.ts | 35 + react/registry/optics/lib/invoker-commands.ts | 9 + react/registry/optics/ui/accordion.tsx | 96 + react/registry/optics/ui/alert.tsx | 145 ++ react/registry/optics/ui/avatar.tsx | 41 + react/registry/optics/ui/badge.tsx | 29 + react/registry/optics/ui/breadcrumbs.tsx | 59 + react/registry/optics/ui/button-group.tsx | 10 + react/registry/optics/ui/button.tsx | 60 + react/registry/optics/ui/card.tsx | 51 + react/registry/optics/ui/cluster.tsx | 26 + react/registry/optics/ui/confirm-dialog.tsx | 92 + react/registry/optics/ui/content-header.tsx | 49 + react/registry/optics/ui/divider.tsx | 37 + react/registry/optics/ui/flank.tsx | 30 + react/registry/optics/ui/form.tsx | 129 + react/registry/optics/ui/frame.tsx | 25 + react/registry/optics/ui/grid.tsx | 26 + react/registry/optics/ui/icon.tsx | 67 + react/registry/optics/ui/modal.tsx | 77 + react/registry/optics/ui/navbar.tsx | 51 + react/registry/optics/ui/pagination.tsx | 44 + .../registry/optics/ui/segmented-control.tsx | 75 + react/registry/optics/ui/side-panel.tsx | 99 + react/registry/optics/ui/sidebar.tsx | 57 + react/registry/optics/ui/spinner.tsx | 30 + react/registry/optics/ui/split.tsx | 26 + react/registry/optics/ui/stack.tsx | 26 + react/registry/optics/ui/switch.tsx | 33 + react/registry/optics/ui/table.tsx | 46 + react/registry/optics/ui/tabs.tsx | 104 + react/registry/optics/ui/tag.tsx | 35 + react/registry/optics/ui/text-pair.tsx | 62 + react/registry/optics/ui/tooltip.module.css | 56 + react/registry/optics/ui/tooltip.tsx | 33 + react/stories/Introduction.mdx | 59 + react/stories/accordion.stories.tsx | 90 + react/stories/alert.stories.tsx | 176 ++ react/stories/avatar.stories.tsx | 59 + react/stories/badge.stories.tsx | 91 + react/stories/breadcrumbs.stories.tsx | 51 + react/stories/button-group.stories.tsx | 82 + react/stories/button.stories.tsx | 105 + react/stories/card.stories.tsx | 72 + react/stories/cluster.stories.tsx | 60 + react/stories/confirm-dialog.stories.tsx | 48 + react/stories/content-header.stories.tsx | 60 + react/stories/divider.stories.tsx | 65 + react/stories/flank.stories.tsx | 52 + react/stories/form.stories.tsx | 138 ++ react/stories/frame.stories.tsx | 49 + react/stories/grid.stories.tsx | 78 + react/stories/icon.stories.tsx | 93 + react/stories/modal.stories.tsx | 47 + react/stories/navbar.stories.tsx | 81 + react/stories/pagination.stories.tsx | 66 + react/stories/segmented-control.stories.tsx | 82 + react/stories/side-panel.stories.tsx | 71 + react/stories/sidebar.stories.tsx | 80 + react/stories/spinner.stories.tsx | 29 + react/stories/split.stories.tsx | 53 + react/stories/stack.stories.tsx | 57 + react/stories/switch.stories.tsx | 56 + react/stories/table.stories.tsx | 94 + react/stories/tabs.stories.tsx | 67 + react/stories/tag.stories.tsx | 81 + react/stories/text-pair.stories.tsx | 68 + react/stories/tooltip.stories.tsx | 63 + react/tsconfig.json | 19 + test/react/registry.test.cjs | 49 + yarn.lock | 2067 ++++++++++++++++- 83 files changed, 7081 insertions(+), 32 deletions(-) create mode 100644 .claude/launch.json create mode 100644 docs/plans/2026-11-05-react-components.md create mode 100644 react/.storybook/main.ts create mode 100644 react/.storybook/preview.css create mode 100644 react/.storybook/preview.tsx create mode 100644 react/README.md create mode 100644 react/package.json create mode 100644 react/registry.json create mode 100644 react/registry/optics/lib/flex-utilities.ts create mode 100644 react/registry/optics/lib/invoker-commands.ts create mode 100644 react/registry/optics/ui/accordion.tsx create mode 100644 react/registry/optics/ui/alert.tsx create mode 100644 react/registry/optics/ui/avatar.tsx create mode 100644 react/registry/optics/ui/badge.tsx create mode 100644 react/registry/optics/ui/breadcrumbs.tsx create mode 100644 react/registry/optics/ui/button-group.tsx create mode 100644 react/registry/optics/ui/button.tsx create mode 100644 react/registry/optics/ui/card.tsx create mode 100644 react/registry/optics/ui/cluster.tsx create mode 100644 react/registry/optics/ui/confirm-dialog.tsx create mode 100644 react/registry/optics/ui/content-header.tsx create mode 100644 react/registry/optics/ui/divider.tsx create mode 100644 react/registry/optics/ui/flank.tsx create mode 100644 react/registry/optics/ui/form.tsx create mode 100644 react/registry/optics/ui/frame.tsx create mode 100644 react/registry/optics/ui/grid.tsx create mode 100644 react/registry/optics/ui/icon.tsx create mode 100644 react/registry/optics/ui/modal.tsx create mode 100644 react/registry/optics/ui/navbar.tsx create mode 100644 react/registry/optics/ui/pagination.tsx create mode 100644 react/registry/optics/ui/segmented-control.tsx create mode 100644 react/registry/optics/ui/side-panel.tsx create mode 100644 react/registry/optics/ui/sidebar.tsx create mode 100644 react/registry/optics/ui/spinner.tsx create mode 100644 react/registry/optics/ui/split.tsx create mode 100644 react/registry/optics/ui/stack.tsx create mode 100644 react/registry/optics/ui/switch.tsx create mode 100644 react/registry/optics/ui/table.tsx create mode 100644 react/registry/optics/ui/tabs.tsx create mode 100644 react/registry/optics/ui/tag.tsx create mode 100644 react/registry/optics/ui/text-pair.tsx create mode 100644 react/registry/optics/ui/tooltip.module.css create mode 100644 react/registry/optics/ui/tooltip.tsx create mode 100644 react/stories/Introduction.mdx create mode 100644 react/stories/accordion.stories.tsx create mode 100644 react/stories/alert.stories.tsx create mode 100644 react/stories/avatar.stories.tsx create mode 100644 react/stories/badge.stories.tsx create mode 100644 react/stories/breadcrumbs.stories.tsx create mode 100644 react/stories/button-group.stories.tsx create mode 100644 react/stories/button.stories.tsx create mode 100644 react/stories/card.stories.tsx create mode 100644 react/stories/cluster.stories.tsx create mode 100644 react/stories/confirm-dialog.stories.tsx create mode 100644 react/stories/content-header.stories.tsx create mode 100644 react/stories/divider.stories.tsx create mode 100644 react/stories/flank.stories.tsx create mode 100644 react/stories/form.stories.tsx create mode 100644 react/stories/frame.stories.tsx create mode 100644 react/stories/grid.stories.tsx create mode 100644 react/stories/icon.stories.tsx create mode 100644 react/stories/modal.stories.tsx create mode 100644 react/stories/navbar.stories.tsx create mode 100644 react/stories/pagination.stories.tsx create mode 100644 react/stories/segmented-control.stories.tsx create mode 100644 react/stories/side-panel.stories.tsx create mode 100644 react/stories/sidebar.stories.tsx create mode 100644 react/stories/spinner.stories.tsx create mode 100644 react/stories/split.stories.tsx create mode 100644 react/stories/stack.stories.tsx create mode 100644 react/stories/switch.stories.tsx create mode 100644 react/stories/table.stories.tsx create mode 100644 react/stories/tabs.stories.tsx create mode 100644 react/stories/tag.stories.tsx create mode 100644 react/stories/text-pair.stories.tsx create mode 100644 react/stories/tooltip.stories.tsx create mode 100644 react/tsconfig.json create mode 100644 test/react/registry.test.cjs diff --git a/.claude/launch.json b/.claude/launch.json new file mode 100644 index 00000000..7704f68d --- /dev/null +++ b/.claude/launch.json @@ -0,0 +1,17 @@ +{ + "version": "0.0.1", + "configurations": [ + { + "name": "storybook", + "runtimeExecutable": "yarn", + "runtimeArgs": ["storybook", "--no-open"], + "port": 6006 + }, + { + "name": "storybook-react", + "runtimeExecutable": "yarn", + "runtimeArgs": ["storybook:react"], + "port": 6007 + } + ] +} diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 41cf18dc..f832d122 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -27,6 +27,8 @@ jobs: run: yarn lint:js - name: Run Stylelint run: yarn lint:css + - name: Typecheck React components + run: yarn lint:react - name: Run Prettier run: yarn prettier-check - name: Run Tests @@ -39,3 +41,5 @@ jobs: run: yarn build-docs:llms - name: Build Storybook run: yarn build-docs:storybook + - name: Build React Storybook and shadcn registry + run: yarn build-docs:react diff --git a/.npmignore b/.npmignore index 2c21554c..d7fddfb3 100644 --- a/.npmignore +++ b/.npmignore @@ -25,6 +25,9 @@ docs/ # Documentation .storybook +# React components are installed with the shadcn CLI, not from this package. +/react/ + # Tools and tests. Anchored to the root, so dist/tools (the contrast checker) is still published. /tools/ /test/ diff --git a/.storybook/main.js b/.storybook/main.js index f0b8fcbf..9c611fb4 100644 --- a/.storybook/main.js +++ b/.storybook/main.js @@ -29,6 +29,18 @@ const config = { }, ], + // Storybook composition: the React components have their own Storybook in react/. + // `yarn build-docs` publishes it under /react on the docs site. + refs: (_config, { configType }) => ({ + react: { + title: 'React', + url: + process.env.OPTICS_REACT_STORYBOOK_URL ?? + (configType === 'DEVELOPMENT' ? 'http://localhost:6007' : 'https://docs.optics.rolemodel.design/react'), + expanded: false, + }, + }), + core: { disableTelemetry: true, // 👈 Disables telemetry }, diff --git a/docs/plans/2026-11-05-react-components.md b/docs/plans/2026-11-05-react-components.md new file mode 100644 index 00000000..5368882b --- /dev/null +++ b/docs/plans/2026-11-05-react-components.md @@ -0,0 +1,53 @@ +# React components as a shadcn registry + +Bring the components from [optics-components-react](https://github.com/RoleModel/optics-components-react) into this repo. +They are a companion to Optics, not part of the npm package. People copy them into their app with the shadcn CLI. + +## Decisions + +- New branch off `main`. The `next/` experiment stays separate. +- Top-level `react/` folder. It is a Yarn workspace with its own `package.json` and Storybook (`@storybook/react-vite`). +- Components only. The financial dashboard and Go Fish demos stay in the old repo. +- Keep Base UI for behavior (tabs, toasts, avatar, tooltip, field). + +## Layout + +``` +react/ + registry/optics/ui/*.tsx one file per component, kebab-case + registry/optics/lib/*.ts shared helpers (flex utility variants) + stories/*.stories.tsx one story file per component + .storybook/ React Storybook, port 6007 + registry.json shadcn registry index +``` + +Files import each other as `@/registry/optics/ui/`. The shadcn CLI rewrites these to the user's own aliases on install. + +## Publishing + +- `yarn build-docs` builds the root Storybook, then the React Storybook into `storybook-static/react/`, then the registry JSON into `storybook-static/r/`. +- The root Storybook links to the React one with Storybook composition (`refs`). +- Users install with `npx shadcn@latest add https://docs.optics.rolemodel.design/r/button.json`. +- Each registry item lists `@rolemodel/optics` as a dependency. Users still import the Optics CSS once. + +## Cleanup rules for the port + +- Kebab-case file names, shadcn import paths. +- One polymorphism API: Base UI's `render` prop. Drop `Button`'s `asChild`. +- Repo Prettier config (print width 120). +- No React Compiler. It is the user's choice in their own app. + +## Steps + +1. [x] Scaffold `react/` workspace, TypeScript, Storybook +2. [x] Port and clean up components. Also split `Alert.Flash` from `Alert.Root` and `Tabs.Nav` from `Tabs.List`, so neither needs a union type. +3. [x] One story per component +4. [x] `registry.json` and `shadcn build`. `test/react/registry.test.cjs` checks it matches the imports. `.npmignore` keeps `react/` out of the npm package. +5. [x] Storybook composition and CI +6. [x] Verify: typecheck, `yarn sanity-check`, both Storybooks in the browser, a test install from the registry into a new Vite app + +## Open issues + +- `breadcrumbs__separator` has no styles in `src/components/breadcrumbs.css`. The CSS-only story has the same gap. +- `IconProps` is a union (`name` or SVG `children`), so spreading generic props into `` needs care. +- The first publish must happen before `registryDependencies` URLs resolve. Until then, test installs need a local server. diff --git a/package.json b/package.json index 30d83cb7..b6d0eeea 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,9 @@ "packageManager": "yarn@4.8.1", "description": "Optics is a css package that provides base styles and components that can be integrated and customized in a variety of projects.", "main": "dist/css/optics.css", + "workspaces": [ + "react" + ], "bin": { "optics-check-contrast": "dist/tools/check-contrast.cjs" }, @@ -14,14 +17,17 @@ "build:css-min": "postcss 'src/optics*.css' -d dist/css --ext .min.css --env=minify", "build:tokens": "node build_token_json --source=src/core/tokens --output=dist/tokens/tokens.json", "build:files": "mkdir -p dist/css/addons; cp LICENSE README.md package.json dist/; cp -rL src/addons src/core src/components dist/css; cp -r src/tools dist", - "build-docs": "yarn build-docs:llms && yarn build-docs:storybook", + "build-docs": "yarn build-docs:llms && yarn build-docs:storybook && yarn build-docs:react", "build-docs:llms": "node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON tools/build-llms-docs.mjs", "build-docs:storybook": "storybook build --docs", + "build-docs:react": "yarn workspace @rolemodel/optics-react build-storybook && yarn workspace @rolemodel/optics-react build-registry", "storybook": "yarn build-docs:llms && storybook dev -p 6006 --docs", - "lint": "yarn lint:js && yarn lint:css", + "storybook:react": "yarn workspace @rolemodel/optics-react storybook", + "lint": "yarn lint:js && yarn lint:css && yarn lint:react", "lint-fix": "yarn lint:js --fix && yarn lint:css --fix", "lint:js": "eslint 'src/stories/**/*.js'", "lint:css": "stylelint 'src/**/*.css'", + "lint:react": "yarn workspace @rolemodel/optics-react typecheck", "prettier": "prettier -w .", "prettier-check": "prettier -c .", "sanity-check": "yarn lint && yarn prettier && yarn test && yarn build && yarn check-contrast && yarn build-docs && rm -rf ./dist && rm -rf ./storybook-static && rm -rf ./llms-docs", diff --git a/react/.storybook/main.ts b/react/.storybook/main.ts new file mode 100644 index 00000000..69821b33 --- /dev/null +++ b/react/.storybook/main.ts @@ -0,0 +1,24 @@ +import { fileURLToPath } from 'node:url' +import type { StorybookConfig } from '@storybook/react-vite' + +const config: StorybookConfig = { + stories: ['../stories/**/*.mdx', '../stories/**/*.stories.tsx'], + addons: ['@storybook/addon-docs'], + framework: '@storybook/react-vite', + core: { disableTelemetry: true }, + features: { backgrounds: false }, + + async viteFinal(viteConfig) { + viteConfig.resolve ??= {} + viteConfig.resolve.alias = { + ...viteConfig.resolve.alias, + '@': fileURLToPath(new URL('..', import.meta.url)), + } + // Same reason as the root Storybook: older targets make lightningcss try to polyfill light-dark(). + viteConfig.build ??= {} + viteConfig.build.cssTarget = ['chrome123', 'edge123', 'firefox120', 'safari17.5', 'ios17.5'] + return viteConfig + }, +} + +export default config diff --git a/react/.storybook/preview.css b/react/.storybook/preview.css new file mode 100644 index 00000000..612fedc7 --- /dev/null +++ b/react/.storybook/preview.css @@ -0,0 +1,7 @@ +@import '../../src/optics.css'; +@import '../../src/addons/fonts/material_symbols_outlined_variable.css'; + +.sbdocs-preview .docs-story { + background-color: var(--op-color-background); + color: var(--op-color-on-background); +} diff --git a/react/.storybook/preview.tsx b/react/.storybook/preview.tsx new file mode 100644 index 00000000..42d6cbff --- /dev/null +++ b/react/.storybook/preview.tsx @@ -0,0 +1,35 @@ +import type { Decorator, Preview } from '@storybook/react-vite' + +import './preview.css' + +const withThemeMode: Decorator = (Story, context) => { + document.documentElement.setAttribute('data-theme-mode', context.globals.theme) + return +} + +const preview: Preview = { + parameters: { + layout: 'centered', + docs: { + toc: { headingSelector: 'h2, h3', title: 'On this page' }, + }, + options: { + storySort: { order: ['Introduction', 'Components', 'Layout'] }, + }, + }, + globalTypes: { + theme: { + description: 'Global theme mode for components', + toolbar: { + title: 'Theme', + icon: 'circlehollow', + items: ['light', 'dark'], + dynamicTitle: true, + }, + }, + }, + initialGlobals: { theme: 'light' }, + decorators: [withThemeMode], +} + +export default preview diff --git a/react/README.md b/react/README.md new file mode 100644 index 00000000..9ced731e --- /dev/null +++ b/react/README.md @@ -0,0 +1,18 @@ +# Optics React + +React components for Optics, published as a [shadcn registry](https://ui.shadcn.com/docs/registry). They are not part of the `@rolemodel/optics` npm package. User docs: [stories/Introduction.mdx](stories/Introduction.mdx). + +## Commands + +Run from the repo root: + +- `yarn storybook:react` — React Storybook on port 6007. The root Storybook (`yarn storybook`) shows it under "React" while both run. +- `yarn lint:react` — typecheck +- `yarn build-docs:react` — build the Storybook into `storybook-static/react/` and the registry into `storybook-static/r/` +- `yarn test` — includes a check that `registry.json` matches the component imports + +## Add a component + +1. Add `registry/optics/ui/.tsx`. Import other registry files as `@/registry/optics/ui/`, so the shadcn CLI can rewrite the path on install. +2. Add an item to [registry.json](registry.json). List each registry file it imports in `registryDependencies` as a full `https://docs.optics.rolemodel.design/r/.json` URL. +3. Add `stories/.stories.tsx`. diff --git a/react/package.json b/react/package.json new file mode 100644 index 00000000..f3f57190 --- /dev/null +++ b/react/package.json @@ -0,0 +1,28 @@ +{ + "name": "@rolemodel/optics-react", + "private": true, + "type": "module", + "scripts": { + "storybook": "storybook dev -p 6007 --no-open", + "build-storybook": "storybook build -o ../storybook-static/react", + "build-registry": "shadcn build -o ../storybook-static/r", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "@base-ui/react": "^1.9.0", + "class-variance-authority": "^0.7.1" + }, + "devDependencies": { + "@storybook/addon-docs": "^10.6.3", + "@storybook/react-vite": "^10.6.3", + "@types/react": "^19.3.0", + "@types/react-dom": "^19.3.0", + "@vitejs/plugin-react": "^6.2.1", + "react": "19.1.1", + "react-dom": "19.1.1", + "shadcn": "^4.23.0", + "storybook": "^10.6.3", + "typescript": "^6.0.3", + "vite": "^8.1.4" + } +} diff --git a/react/registry.json b/react/registry.json new file mode 100644 index 00000000..b0c5a992 --- /dev/null +++ b/react/registry.json @@ -0,0 +1,474 @@ +{ + "$schema": "https://ui.shadcn.com/schema/registry.json", + "name": "optics", + "homepage": "https://docs.optics.rolemodel.design", + "items": [ + { + "name": "accordion", + "type": "registry:ui", + "title": "Accordion", + "description": "Expandable sections built on native
.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "registryDependencies": ["https://docs.optics.rolemodel.design/r/icon.json"], + "files": [ + { + "path": "registry/optics/ui/accordion.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "alert", + "type": "registry:ui", + "title": "Alert", + "description": "Inline alert and flash (toast) messages.", + "dependencies": ["@base-ui/react", "@rolemodel/optics", "class-variance-authority"], + "registryDependencies": [ + "https://docs.optics.rolemodel.design/r/button.json", + "https://docs.optics.rolemodel.design/r/icon.json" + ], + "files": [ + { + "path": "registry/optics/ui/alert.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "avatar", + "type": "registry:ui", + "title": "Avatar", + "description": "User image with a fallback.", + "dependencies": ["@base-ui/react", "@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/avatar.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "badge", + "type": "registry:ui", + "title": "Badge", + "description": "Small count or status label.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/badge.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "breadcrumbs", + "type": "registry:ui", + "title": "Breadcrumbs", + "description": "Trail of links to the current page.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "registryDependencies": ["https://docs.optics.rolemodel.design/r/icon.json"], + "files": [ + { + "path": "registry/optics/ui/breadcrumbs.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "button-group", + "type": "registry:ui", + "title": "Button Group", + "description": "Joins buttons into one control.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/button-group.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "button", + "type": "registry:ui", + "title": "Button", + "description": "Button with Optics variants, sizes, and shapes.", + "dependencies": ["@base-ui/react", "@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/button.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "card", + "type": "registry:ui", + "title": "Card", + "description": "Bordered surface with header, body, and footer.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/card.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "cluster", + "type": "registry:ui", + "title": "Cluster", + "description": "Layout: wrapping row of items.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "registryDependencies": ["https://docs.optics.rolemodel.design/r/flex-utilities.json"], + "files": [ + { + "path": "registry/optics/ui/cluster.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "confirm-dialog", + "type": "registry:ui", + "title": "Confirm Dialog", + "description": "Native dialog that asks the user to confirm an action.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "registryDependencies": [ + "https://docs.optics.rolemodel.design/r/button.json", + "https://docs.optics.rolemodel.design/r/invoker-commands.json" + ], + "files": [ + { + "path": "registry/optics/ui/confirm-dialog.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "content-header", + "type": "registry:ui", + "title": "Content Header", + "description": "Page title area with context, subline, and actions.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/content-header.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "divider", + "type": "registry:ui", + "title": "Divider", + "description": "Horizontal or vertical rule.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/divider.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "flank", + "type": "registry:ui", + "title": "Flank", + "description": "Layout: one fixed side and one flexible side.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "registryDependencies": ["https://docs.optics.rolemodel.design/r/flex-utilities.json"], + "files": [ + { + "path": "registry/optics/ui/flank.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "form", + "type": "registry:ui", + "title": "Form", + "description": "Form group, label, control, hint, and error parts.", + "dependencies": ["@base-ui/react", "@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/form.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "frame", + "type": "registry:ui", + "title": "Frame", + "description": "Layout: fixed aspect ratio box.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/frame.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "grid", + "type": "registry:ui", + "title": "Grid", + "description": "Layout: equal-column grid.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "registryDependencies": ["https://docs.optics.rolemodel.design/r/flex-utilities.json"], + "files": [ + { + "path": "registry/optics/ui/grid.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "icon", + "type": "registry:ui", + "title": "Icon", + "description": "Material Symbols icon or inline SVG.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/icon.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "modal", + "type": "registry:ui", + "title": "Modal", + "description": "Native modal dialog.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "registryDependencies": [ + "https://docs.optics.rolemodel.design/r/button.json", + "https://docs.optics.rolemodel.design/r/icon.json", + "https://docs.optics.rolemodel.design/r/invoker-commands.json" + ], + "files": [ + { + "path": "registry/optics/ui/modal.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "navbar", + "type": "registry:ui", + "title": "Navbar", + "description": "Top navigation bar.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/navbar.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "pagination", + "type": "registry:ui", + "title": "Pagination", + "description": "Page links with dividers.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "registryDependencies": ["https://docs.optics.rolemodel.design/r/button.json"], + "files": [ + { + "path": "registry/optics/ui/pagination.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "segmented-control", + "type": "registry:ui", + "title": "Segmented Control", + "description": "Radio group that looks like joined buttons.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/segmented-control.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "side-panel", + "type": "registry:ui", + "title": "Side Panel", + "description": "Side panel with header, body, footer, and sections.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/side-panel.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "sidebar", + "type": "registry:ui", + "title": "Sidebar", + "description": "Side navigation in drawer, compact, or rail sizes.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/sidebar.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "spinner", + "type": "registry:ui", + "title": "Spinner", + "description": "Loading indicator.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/spinner.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "split", + "type": "registry:ui", + "title": "Split", + "description": "Layout: pushes items to each end.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "registryDependencies": ["https://docs.optics.rolemodel.design/r/flex-utilities.json"], + "files": [ + { + "path": "registry/optics/ui/split.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "stack", + "type": "registry:ui", + "title": "Stack", + "description": "Layout: vertical stack with gap.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "registryDependencies": ["https://docs.optics.rolemodel.design/r/flex-utilities.json"], + "files": [ + { + "path": "registry/optics/ui/stack.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "switch", + "type": "registry:ui", + "title": "Switch", + "description": "On/off toggle built on a checkbox.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/switch.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "table", + "type": "registry:ui", + "title": "Table", + "description": "Table with Optics variants, density, and stripes.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/table.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "tabs", + "type": "registry:ui", + "title": "Tabs", + "description": "Tabs with panels, or tab-styled navigation links.", + "dependencies": ["@base-ui/react", "@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/tabs.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "tag", + "type": "registry:ui", + "title": "Tag", + "description": "Removable label.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/tag.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "text-pair", + "type": "registry:ui", + "title": "Text Pair", + "description": "Title and subtitle pair.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "files": [ + { + "path": "registry/optics/ui/text-pair.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "tooltip", + "type": "registry:ui", + "title": "Tooltip", + "description": "Hover and focus tooltip.", + "dependencies": ["@base-ui/react", "@rolemodel/optics"], + "files": [ + { + "path": "registry/optics/ui/tooltip.tsx", + "type": "registry:ui" + }, + { + "path": "registry/optics/ui/tooltip.module.css", + "type": "registry:ui" + } + ] + }, + { + "name": "flex-utilities", + "type": "registry:lib", + "title": "Flex Utilities", + "description": "Shared cva variants for the layout components.", + "dependencies": [], + "files": [ + { + "path": "registry/optics/lib/flex-utilities.ts", + "type": "registry:lib" + } + ] + }, + { + "name": "invoker-commands", + "type": "registry:lib", + "title": "Invoker Commands", + "description": "Types for the command and commandfor button attributes.", + "dependencies": [], + "files": [ + { + "path": "registry/optics/lib/invoker-commands.ts", + "type": "registry:lib" + } + ] + } + ] +} diff --git a/react/registry/optics/lib/flex-utilities.ts b/react/registry/optics/lib/flex-utilities.ts new file mode 100644 index 00000000..30d45f03 --- /dev/null +++ b/react/registry/optics/lib/flex-utilities.ts @@ -0,0 +1,35 @@ +export const flexUtilityVariants = { + align: { + stretch: 'items-stretch', + start: 'items-start', + center: 'items-center', + end: 'items-end', + baseline: 'items-baseline', + }, + justify: { + start: 'justify-start', + center: 'justify-center', + end: 'justify-end', + between: 'justify-between', + around: 'justify-around', + }, + gap: { + none: 'gap-none', + xxs: 'gap-xxs', + xs: 'gap-xs', + sm: 'gap-sm', + md: 'gap-md', + lg: 'gap-lg', + xl: 'gap-xl', + }, + wrap: { false: 'flex-no-wrap', true: 'flex-wrap' }, + self: { + auto: 'self-auto', + start: 'self-start', + center: 'self-center', + end: 'self-end', + stretch: 'self-stretch', + baseline: 'self-baseline', + }, + grow: { false: null, true: 'flex-grow-1' }, +} diff --git a/react/registry/optics/lib/invoker-commands.ts b/react/registry/optics/lib/invoker-commands.ts new file mode 100644 index 00000000..76ce1ab0 --- /dev/null +++ b/react/registry/optics/lib/invoker-commands.ts @@ -0,0 +1,9 @@ +// @types/react does not include the Invoker Commands API yet. React 19 passes these lowercase attributes to the DOM. +declare module 'react' { + interface ButtonHTMLAttributes { + command?: string + commandfor?: string + } +} + +export {} diff --git a/react/registry/optics/ui/accordion.tsx b/react/registry/optics/ui/accordion.tsx new file mode 100644 index 00000000..237448b3 --- /dev/null +++ b/react/registry/optics/ui/accordion.tsx @@ -0,0 +1,96 @@ +import { createContext, useContext, type ComponentPropsWithoutRef } from 'react' +import { cva, cx, type VariantProps } from 'class-variance-authority' +import { Icon, type IconProps } from '@/registry/optics/ui/icon' + +interface AccordionRootProps extends ComponentPropsWithoutRef<'div'> { + name?: string + disableAnimation?: boolean +} + +type AccordionContextValue = Pick + +const AccordionContext = createContext({}) + +function AccordionRoot({ name, disableAnimation, children, ...props }: AccordionRootProps) { + return ( + +
+ {children} +
+
+ ) +} + +const accordionItemVariants = cva('accordion', { + variants: { + disableAnimation: { false: null, true: 'accordion--disable-animation' }, + }, +}) + +interface AccordionItemProps + extends Omit, 'name'>, VariantProps { + name?: string +} + +function AccordionItem({ name, disableAnimation, className, children, ...props }: AccordionItemProps) { + const context = useContext(AccordionContext) + const classes = accordionItemVariants({ + disableAnimation: disableAnimation ?? context.disableAnimation, + className, + }) + + return ( +
+ {children} +
+ ) +} + +type AccordionTriggerProps = ComponentPropsWithoutRef<'summary'> + +function AccordionTrigger({ children, ...props }: AccordionTriggerProps) { + return ( + + {children} + + ) +} + +interface AccordionMarkerProps extends Omit, 'name'> { + name?: string +} + +function AccordionMarker({ name = 'arrow_right', className, ...props }: AccordionMarkerProps) { + return +} + +type AccordionLabelProps = ComponentPropsWithoutRef<'span'> + +function AccordionLabel({ className, children, ...props }: AccordionLabelProps) { + return ( + + {children} + + ) +} + +type AccordionContentProps = ComponentPropsWithoutRef<'div'> + +function AccordionContent({ children, ...props }: AccordionContentProps) { + return ( +
+ {children} +
+ ) +} + +const Accordion = { + Root: AccordionRoot, + Item: AccordionItem, + Trigger: AccordionTrigger, + Marker: AccordionMarker, + Label: AccordionLabel, + Content: AccordionContent, +} + +export { Accordion, accordionItemVariants } diff --git a/react/registry/optics/ui/alert.tsx b/react/registry/optics/ui/alert.tsx new file mode 100644 index 00000000..0b8b6c8e --- /dev/null +++ b/react/registry/optics/ui/alert.tsx @@ -0,0 +1,145 @@ +import { createContext, useContext, type ComponentPropsWithoutRef } from 'react' +import { Toast } from '@base-ui/react/toast' +import { cva, cx, type VariantProps } from 'class-variance-authority' + +import { buttonVariants } from '@/registry/optics/ui/button' +import { Icon, type IconProps } from '@/registry/optics/ui/icon' + +const alertVariants = cva('alert', { + variants: { + variant: { + warning: 'alert--warning', + danger: 'alert--danger', + info: 'alert--info', + notice: 'alert--notice', + }, + tone: { + outlined: null, + muted: 'alert--muted', + filled: 'alert--filled', + }, + flash: { false: null, true: 'alert--flash' }, + }, +}) + +type AlertVariantProps = Omit, 'flash'> + +// Title, Description, and Close render Base UI toast parts inside a flash, so they need to know which root they are in. +const FlashContext = createContext(false) + +export interface AlertRootProps extends ComponentPropsWithoutRef<'div'>, AlertVariantProps {} + +function AlertRoot({ variant, tone, className, ...props }: AlertRootProps) { + return ( + +
+ + ) +} + +export interface AlertFlashProps extends Omit, AlertVariantProps { + className?: string +} + +function AlertFlash({ variant, tone, className, style, ...props }: AlertFlashProps) { + // alert--flash plays a fixed 5s slide-in-out animation. A toast with timeout 0 must stay, so cancel the animation. + const persistent = props.toast.timeout === 0 + + return ( + + + + ) +} + +function AlertIcon({ className, ...props }: IconProps) { + return +} + +export interface AlertMessagesProps extends ComponentPropsWithoutRef<'div'> {} + +function AlertMessages({ className, ...props }: AlertMessagesProps) { + return
+} + +export interface AlertTitleProps extends ComponentPropsWithoutRef<'div'> {} + +function AlertTitle({ className, ...props }: AlertTitleProps) { + const flash = useContext(FlashContext) + const classes = cx('alert__title', className) + + // Toast.Title defaults to an

, which brings a browser margin. A keeps the Optics spacing. + if (flash) return } className={classes} {...props} /> + + return
+} + +export interface AlertDescriptionProps extends ComponentPropsWithoutRef<'div'> {} + +function AlertDescription({ className, ...props }: AlertDescriptionProps) { + const flash = useContext(FlashContext) + const classes = cx('alert__description', className) + + // Toast.Description defaults to a

, which brings a browser margin. + if (flash) return } className={classes} {...props} /> + + return

+} + +export interface AlertCloseProps extends ComponentPropsWithoutRef<'button'> { + label?: string +} + +function AlertClose({ label = 'Dismiss', className, ...props }: AlertCloseProps) { + const flash = useContext(FlashContext) + const classes = buttonVariants({ shape: 'circle', borderless: true, className: cx('alert__icon', className) }) + const closeProps = { 'data-slot': 'alert-close', className: classes, 'aria-label': label, ...props } + + if (flash) { + return ( + + + + ) + } + + return ( + + ) +} + +function AlertFlashProvider({ limit = 1, ...props }: Toast.Provider.Props) { + return +} + +function AlertFlashViewport(props: Toast.Viewport.Props) { + return ( + + + + ) +} + +const Alert = { + Root: AlertRoot, + Flash: AlertFlash, + Icon: AlertIcon, + Messages: AlertMessages, + Title: AlertTitle, + Description: AlertDescription, + Close: AlertClose, + FlashProvider: AlertFlashProvider, + FlashViewport: AlertFlashViewport, +} + +const useAlertManager = Toast.useToastManager +const createAlertManager = Toast.createToastManager + +export { Alert, alertVariants, useAlertManager, createAlertManager } diff --git a/react/registry/optics/ui/avatar.tsx b/react/registry/optics/ui/avatar.tsx new file mode 100644 index 00000000..30dc864b --- /dev/null +++ b/react/registry/optics/ui/avatar.tsx @@ -0,0 +1,41 @@ +import { Avatar as AvatarPrimitive } from '@base-ui/react/avatar' +import { cva, type VariantProps } from 'class-variance-authority' + +const avatarVariants = cva('avatar', { + variants: { + size: { + small: 'avatar--small', + medium: 'avatar--medium', + large: 'avatar--large', + }, + disabled: { false: null, true: 'avatar--disabled' }, + }, +}) + +interface AvatarRootProps extends AvatarPrimitive.Root.Props, VariantProps {} + +function AvatarRoot({ size, disabled, className, ...props }: AvatarRootProps) { + const classes = avatarVariants({ size, disabled, className }) + + return +} + +type AvatarImageProps = AvatarPrimitive.Image.Props + +function AvatarImage(props: AvatarImageProps) { + return +} + +type AvatarFallbackProps = AvatarPrimitive.Fallback.Props + +function AvatarFallback(props: AvatarFallbackProps) { + return +} + +const Avatar = { + Root: AvatarRoot, + Image: AvatarImage, + Fallback: AvatarFallback, +} + +export { Avatar, avatarVariants } diff --git a/react/registry/optics/ui/badge.tsx b/react/registry/optics/ui/badge.tsx new file mode 100644 index 00000000..dba94da0 --- /dev/null +++ b/react/registry/optics/ui/badge.tsx @@ -0,0 +1,29 @@ +import type { ComponentPropsWithoutRef } from 'react' +import { cva, type VariantProps } from 'class-variance-authority' + +const badgeVariants = cva('badge', { + variants: { + variant: { + primary: 'badge--primary', + warning: 'badge--warning', + danger: 'badge--danger', + info: 'badge--info', + notice: 'badge--notice', + }, + pill: { false: null, true: 'badge--pill' }, + notification: { + left: 'badge--notification-left', + right: 'badge--notification-right', + }, + }, +}) + +export interface BadgeProps extends ComponentPropsWithoutRef<'span'>, VariantProps {} + +function Badge({ variant, pill, notification, className, ...props }: BadgeProps) { + const classes = badgeVariants({ variant, pill, notification, className }) + + return +} + +export { Badge, badgeVariants } diff --git a/react/registry/optics/ui/breadcrumbs.tsx b/react/registry/optics/ui/breadcrumbs.tsx new file mode 100644 index 00000000..01228f92 --- /dev/null +++ b/react/registry/optics/ui/breadcrumbs.tsx @@ -0,0 +1,59 @@ +import type { ComponentPropsWithoutRef } from 'react' +import { cva, cx, type VariantProps } from 'class-variance-authority' + +import { Icon } from '@/registry/optics/ui/icon' + +const breadcrumbsVariants = cva('breadcrumbs', { + variants: { + size: { + small: 'breadcrumbs--small', + large: 'breadcrumbs--large', + }, + }, +}) + +export interface BreadcrumbsRootProps + extends ComponentPropsWithoutRef<'nav'>, VariantProps {} + +function BreadcrumbsRoot({ size, className, ...props }: BreadcrumbsRootProps) { + const classes = breadcrumbsVariants({ size, className }) + + return