diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index c9868de2..47ffd6ed 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -30,11 +30,17 @@ Cross out all that don't apply with ~~ ~~ around it like ~~this~~ - [ ] Did you add a component? - [ ] Have you added it to the dependency graph? - [ ] Have you added it to the docs? + - [ ] Have you added a React component, or noted why not? (see `react/README.md`) - [ ] Did you update a component? - [ ] Have you updated the dependency graph? - [ ] Have you updated the docs? -- [ ] Do you need to update the package version? - - [ ] Did you update the example pages in `.storybook/assets`? + - [ ] Have you updated the React component in `react/registry/optics/ui/`, with its stories and MDX page, to match? +- [ ] Did you change a React component? + - [ ] Have you updated `react/registry.json` if its imports changed? + - [ ] Have you checked it in the React Storybook? (yarn storybook:react) +- [ ] Do you need to update the package version? Don't edit it by hand. Run `yarn set-optics-version `, such as `yarn set-optics-version 2.6.2`. It sets the version in `package.json`, the `.storybook/assets` example pages, and every React component. + - [ ] Have you run `yarn set-optics-version `? + - [ ] Have you adjusted the React components for this release? - [ ] Were any changes made to the top level optics.css file? - [ ] Were those changes reflected in the other top level files? 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..57459a8d 100644 --- a/.storybook/main.js +++ b/.storybook/main.js @@ -29,6 +29,16 @@ 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: configType === 'DEVELOPMENT' ? 'http://localhost:6007' : 'https://docs.optics.rolemodel.design/react', + expanded: false, + }, + }), + core: { disableTelemetry: true, // 👈 Disables telemetry }, diff --git a/package.json b/package.json index 30d83cb7..4c6b94c1 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,18 @@ "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", + "set-optics-version": "node tools/set-optics-version.mjs", + "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..931536f6 --- /dev/null +++ b/react/.storybook/main.ts @@ -0,0 +1,31 @@ +import { fileURLToPath } from 'node:url' +import type { StorybookConfig } from '@storybook/react-vite' +import remarkGfm from 'remark-gfm' + +const config: StorybookConfig = { + stories: ['../stories/**/*.mdx', '../stories/**/*.stories.tsx'], + addons: [ + { + name: '@storybook/addon-docs', + // GitHub-flavored Markdown, for the Parts and Props tables in the MDX pages. + options: { mdxPluginOptions: { mdxCompileOptions: { remarkPlugins: [remarkGfm] } } }, + }, + ], + 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..cac8d016 --- /dev/null +++ b/react/.storybook/preview.css @@ -0,0 +1,25 @@ +@import '../../src/optics.css'; +@import '../../src/addons/fonts/material_symbols_outlined_variable.css'; +@import '../../src/addons/fonts/phosphor_icons.css'; +@import '../../src/addons/fonts/tabler_icons.css'; +@import '../../src/addons/fonts/feather_icons.css'; +@import '../../src/addons/fonts/lucide_icons.css'; + +/* Prism marks JSX tags with .tag, which picks up the Optics .tag component styles. */ +pre .token.tag { + display: inline; + padding: 0; + border-radius: 0; + background-color: transparent; + font-size: inherit; + font-weight: inherit; + letter-spacing: inherit; + line-height: inherit; + user-select: text; + white-space: inherit; +} + +.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..cd78c3b4 --- /dev/null +++ b/react/.storybook/preview.tsx @@ -0,0 +1,64 @@ +import type { Decorator, Preview } from '@storybook/react-vite' + +import { setIconPack } from '../registry/optics/lib/icon-pack' +import './preview.css' + +// The code panel names each component by its displayName. Name compound parts the way they are written, +// so the code reads `` and not ``. +const components = import.meta.glob>('../registry/optics/ui/*.tsx', { eager: true }) +for (const exports of Object.values(components)) { + for (const [exportName, value] of Object.entries(exports)) { + if (!value || typeof value !== 'object') continue + for (const [part, component] of Object.entries(value)) { + if (typeof component === 'function') Object.assign(component, { displayName: `${exportName}.${part}` }) + } + } +} + +const withThemeMode: Decorator = (Story, context) => { + document.documentElement.setAttribute('data-theme-mode', context.globals.theme) + return +} + +const withIconPack: Decorator = (Story, context) => { + setIconPack(context.globals.iconPack) + return +} + +const preview: Preview = { + parameters: { + layout: 'centered', + docs: { + toc: { headingSelector: 'h2, h3', title: 'On this page' }, + // Show the JSX each story renders, with the current args, instead of the story's source. + source: { type: 'dynamic', excludeDecorators: true }, + }, + options: { + storySort: { order: ['Introduction', 'Components', 'Layout'] }, + }, + }, + globalTypes: { + theme: { + description: 'Global theme mode for components', + toolbar: { + title: 'Theme', + icon: 'circlehollow', + items: ['light', 'dark'], + dynamicTitle: true, + }, + }, + iconPack: { + description: 'Icon pack for Icon (setIconPack)', + toolbar: { + title: 'Icon pack', + icon: 'star', + items: ['material-symbols', 'phosphor', 'tabler', 'feather', 'lucide'], + dynamicTitle: true, + }, + }, + }, + initialGlobals: { theme: 'light', iconPack: 'material-symbols' }, + decorators: [withThemeMode, withIconPack], +} + +export default preview diff --git a/react/README.md b/react/README.md new file mode 100644 index 00000000..6f982cf1 --- /dev/null +++ b/react/README.md @@ -0,0 +1,20 @@ +# 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 +- `yarn set-optics-version ` — bump the Optics version in `package.json`, the `.storybook/assets` example pages, and every React component and MDX page. Then adjust any component the release changed. + +## Add a component + +1. Add `registry/optics/ui/.tsx`. Line 1 is `// Optics version: X.Y.Z`, and its MDX page says the same version. Both match the root `package.json` version (`yarn test` checks this). Import other registry files as `@/registry/optics/ui/`, so the shadcn CLI can rewrite the path on install. Give it only the options its CSS docs page offers; don't add new ones. To let a part render a different element, use Base UI's `render` prop (`useRender` for plain elements), not `asChild` or `as`. +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` and `stories/.mdx`. Copy the pattern in [accordion.stories.tsx](stories/accordion.stories.tsx) and [accordion.mdx](stories/accordion.mdx): one args-driven `render`, one story per variation on the CSS docs page, and an MDX page with the same sections as the CSS docs. + - The code panel shows the JSX each story returns. Return library components directly, not through local helper components, and pass `undefined` instead of `false` so only real props show. diff --git a/react/package.json b/react/package.json new file mode 100644 index 00000000..37e65cd0 --- /dev/null +++ b/react/package.json @@ -0,0 +1,29 @@ +{ + "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", + "remark-gfm": "^4.0.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..2961f811 --- /dev/null +++ b/react/registry.json @@ -0,0 +1,498 @@ +{ + "$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-pack.json", + "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-pack.json", + "https://docs.optics.rolemodel.design/r/icon.json" + ], + "files": [ + { + "path": "registry/optics/ui/alert.tsx", + "type": "registry:ui" + }, + { + "path": "registry/optics/ui/alert.module.css", + "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-pack.json", + "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/dialog.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": "Icon from the app's icon pack, or an inline SVG.", + "dependencies": ["@rolemodel/optics", "class-variance-authority"], + "registryDependencies": ["https://docs.optics.rolemodel.design/r/icon-pack.json"], + "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/dialog.json", + "https://docs.optics.rolemodel.design/r/icon-pack.json", + "https://docs.optics.rolemodel.design/r/icon.json" + ], + "files": [ + { + "path": "registry/optics/ui/modal.tsx", + "type": "registry:ui" + } + ] + }, + { + "name": "navbar", + "type": "registry:ui", + "title": "Navbar", + "description": "Top navigation bar.", + "dependencies": ["@base-ui/react", "@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.", + "files": [ + { + "path": "registry/optics/lib/flex-utilities.ts", + "type": "registry:lib" + } + ] + }, + { + "name": "dialog", + "type": "registry:lib", + "title": "Dialog", + "description": "Shared trigger and close handler for Modal and Confirm Dialog.", + "registryDependencies": ["https://docs.optics.rolemodel.design/r/button.json"], + "files": [ + { + "path": "registry/optics/lib/dialog.tsx", + "type": "registry:lib" + } + ] + }, + { + "name": "icon-pack", + "type": "registry:lib", + "title": "Icon Pack", + "description": "Sets the app's icon pack and maps icon names to its classes.", + "files": [ + { + "path": "registry/optics/lib/icon-pack.ts", + "type": "registry:lib" + } + ] + } + ] +} diff --git a/react/registry/optics/lib/dialog.tsx b/react/registry/optics/lib/dialog.tsx new file mode 100644 index 00000000..2280daf7 --- /dev/null +++ b/react/registry/optics/lib/dialog.tsx @@ -0,0 +1,27 @@ +import { Button, type ButtonProps } from '@/registry/optics/ui/button' + +// @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 interface DialogTriggerProps extends ButtonProps { + for: string +} + +function DialogTrigger({ for: commandfor, ...props }: DialogTriggerProps) { + 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..2ff8b6cb --- /dev/null +++ b/react/registry/optics/ui/avatar.tsx @@ -0,0 +1,54 @@ +// Optics version: 2.6.1 +import type { MouseEvent } from 'react' +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: { true: 'avatar--disabled' }, + }, +}) + +interface AvatarRootProps extends AvatarPrimitive.Root.Props, VariantProps {} + +function AvatarRoot({ size, disabled, className, render =
, onClick, ...props }: AvatarRootProps) { + const classes = avatarVariants({ size, disabled, className }) + + // avatar--disabled only blocks the pointer. A disabled link must also leave the tab order and ignore Enter. + const disabledProps = disabled + ? { + 'aria-disabled': true, + tabIndex: -1, + onClick: (event: MouseEvent) => event.preventDefault(), + } + : { onClick } + + // Optics shows the hover state on any avatar that is not a div, so a plain avatar must be a div. + // Pass `render={}` for a linked avatar. + 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..a49ff4fc --- /dev/null +++ b/react/registry/optics/ui/badge.tsx @@ -0,0 +1,30 @@ +// Optics version: 2.6.1 +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: { 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..49cc37b2 --- /dev/null +++ b/react/registry/optics/ui/breadcrumbs.tsx @@ -0,0 +1,61 @@ +// Optics version: 2.6.1 +import type { ComponentPropsWithoutRef } from 'react' +import { cva, cx, type VariantProps } from 'class-variance-authority' + +import { Icon } from '@/registry/optics/ui/icon' +import { builtInIconName } from '@/registry/optics/lib/icon-pack' + +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