一键导入
tonic-ui-patterns
Coding patterns extracted from tonic-ui repository
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Coding patterns extracted from tonic-ui repository
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Generate PR descriptions and changeset entries. Use when the user mentions "PR", "pull request", "PR description", "changeset", provides a diff or describes code changes, or asks to draft a merge request. Also trigger for conventional commit message generation.
Author and migrate the slots / slotProps API (the useSlot hook) in this design system's React components — the architecture where slots.x replaces an internal part and slotProps.x merges props into it. Use this whenever you are wiring an internal component part so consumers can swap it via slots.x or configure it via slotProps.x, authoring a slot's props / handler chaining / element resolution, or migrating a component from the deprecated *Component / *Props pairs (TransitionComponent/TransitionProps, PopperComponent/PopperProps, inputComponent/inputProps, arrow, scrollView, etc.) to slots / slotProps. Trigger it even when the user only mentions "slots", "slotProps", "useSlot", "swappable part", "replace the transition/popper/arrow", or "migrate the *Component prop" while working on a React component library — even if they don't name useSlot explicitly.
Decide between Tonic UI's `sx` and `__sx` styling channels (and the `composeSx` fold) when writing or reviewing any component built on `@tonic-ui/react-base`'s `Box` — this covers `@tonic-ui/react` itself and any other package that renders `Box`-based components internally (e.g. `@tonic-ui/react-data-grid`; confirmed real instances of these anti-patterns exist there too, not just in the react package). Use this whenever you are authoring a component's base styles, routing a `useXxxStyle()` hook (or a headless-library prop-getter like react-table's `getRowProps`/`getHeaderProps`) onto a `Box`, choosing whether a style belongs in `sx`, `__sx`, style props, or pseudo props, folding an incoming `__sx`, building a wrapper that overrides a child component (e.g. MenuButton over Button, or a data-grid feature overriding a `@tonic-ui/react` component it wraps), or debugging a consumer override that "doesn't apply" or a wrapper override that gets dropped. Trigger it even when the user only mentions `sx`, `__sx`, `compo
Use this skill when adding JSDoc type definitions to React components in Tonic UI. Triggers include "add type definitions", "add JSDoc types", "document component props", or when creating new components that need type annotations.
| name | tonic-ui-patterns |
| description | Coding patterns extracted from tonic-ui repository |
| version | 1.0.0 |
| source | local-git-analysis |
| analyzed_commits | 200 |
This project uses conventional commits with scope:
| Type | Usage | Frequency |
|---|---|---|
chore | Releases, deps, tooling | ~36% |
feat | New features | ~23% |
docs | Documentation | ~18% |
ci | CI/CD workflows | ~12% |
fix | Bug fixes | ~7% |
test | Test additions | ~2% |
refactor | Code restructuring | ~1% |
Scope format: type(package/component) — e.g., feat(react/menu), fix(react/Checkbox), chore(deps-dev)
Common scopes:
react / react/<component> — Main component packagereact-hooks — Hooks packagereact-icons — Icons packagemcp — MCP server packagedeps / deps-dev — Dependency bumpsrelease — Version releaseschangesets — Changeset configPR references: Commit messages include (#<number>) at the end.
packages/
├── changelog-github/ # Custom changelog generator
├── codemod/ # Code migration tools
├── mcp/ # MCP server (TypeScript)
├── react/ # Main component library (JavaScript)
├── react-base/ # Base primitives (Box)
├── react-docs/ # Next.js documentation site
├── react-hooks/ # Shared hooks
├── react-icons/ # SVG icon components
├── styled-system/ # Styled System utilities
├── theme/ # Design tokens
└── utils/ # Shared utilities
Key: packages/react is the most frequently modified package (~38 commits in last 200).
Each component lives in packages/react/src/<component-name>/:
<component-name>/
├── ComponentName.js # Main component (forwardRef + Box base)
├── index.js # Barrel exports
├── styles.js # Style hooks (useComponentNameStyle)
├── context.js # React context (if compound component)
├── useComponentName.js # Context consumer hook
├── withComponentName.js # HOC for context injection (optional)
├── constants.js # Constants (variants, sizes)
└── __tests__/
├── ComponentName.test.js
└── __snapshots__/
└── ComponentName.test.js.snap
Components use forwardRef with useDefaultProps:
import React, { forwardRef } from 'react';
import { useDefaultProps } from '../default-props';
import { useComponentStyle } from './styles';
const Component = forwardRef((inProps, ref) => {
const {
prop1,
prop2,
...rest
} = useDefaultProps({ props: inProps, name: 'Component' });
const styleProps = useComponentStyle({ prop1 });
return (
<Box ref={ref} {...styleProps} {...rest} />
);
});
Component.displayName = 'Component';
export default Component;
For related component groups (Menu, FormControl, Accordion):
context.js) — createContext()useComponentName.js) — useContext(ComponentContext)withComponentName.js) — injects context props (optional)index.js) — named exports for all sub-componentsStyles use hooks that return style objects using Styled System tokens:
import { useColorStyle } from '../color-style';
const useComponentStyle = ({ variant }) => {
const [colorStyle] = useColorStyle();
return {
color: colorStyle.color.primary,
fontSize: 'sm',
px: '2x',
py: '1x',
};
};
Token formats: '1x', '2x', 'sm', 'md', 'lg' (Styled System spacing/sizing).
Based on recent features (Highlight, Mark, FormControl), the workflow is:
packages/react/src/<component-name>/
├── ComponentName.js
├── index.js
├── styles.js
└── __tests__/
└── ComponentName.test.js
Add to packages/react/src/index.js:
export { ComponentName } from './<component-name>';
Add to packages/react/__tests__/index.test.js to verify the export exists.
Add to packages/react-docs/pages/components/<component-name>/:
index.page.mdx — Main doc page.js) for each usage patternAdd route to packages/react-docs/config/sidebar-routes.js.
Add .changeset/<changeset-name>.md:
---
"@tonic-ui/react": minor
---
feat: Add `ComponentName` component
These files typically change together:
packages/react/src/index.js + packages/react/__tests__/index.test.js (new exports)packages/react-docs/config/sidebar-routes.js + packages/react-docs/pages/components/*/index.page.mdx (new docs)packages/react/package.json + packages/react/CHANGELOG.md + .changeset/*.md (releases)__tests__/ directories co-located with sourceComponentName.test.js__snapshots__/)@tonic-ui/react-base/test-utils/accessibility utilitiesyarn test@changesets/cli for versioningv2@tonic-ui/changelog-github generatorpublic (npm).changeset/ with descriptive names (e.g., tonic-ui-pr-1085.md).d.ts files for type definitionspx, py, color, bg), not CSS classescolorStyle.color.primary, colorStyle.color.secondary, colorStyle.color.errorexport { X } from './X' pattern