Public API authoring
Subpath exports, imports, naming, public types, generics and JSDoc for primitives.
Each src/<primitive>/index.tsx is an explicit public API boundary. Keep implementation details module-local and publish the complete surface through separate export { ... } and export type { ... } manifests at the bottom of the file. Do not mix scattered inline exports with the manifest or use wildcard exports.
Base UI imports
Import a Base UI part once per module and read its types from that binding's namespace, such as BaseRadio.Root.Props. Use import type only when the module has no runtime use of the part. Do not keep a value import and a type import of the same module side by side.
Add a public utility subpath only when an application consumer needs it. Inside the package, use an existing utility entrypoint; otherwise import directly from @base-ui/utils.
React imports
Use React namespace imports throughout this package, including tests. Use import * as React from 'react' when calling React runtime APIs, and import type * as React from 'react' when referencing only React types. A runtime namespace import also covers React types; do not add separate named type imports. JSX alone does not require an explicit React import.
Use namespace imports for react-dom, react-dom/client, and react-dom/server as well. Write grouping fragments as <React.Fragment> and remove unnecessary fragment wrappers.
Component writing style
Define named components with function declarations or function expressions. Arrow functions remain appropriate for event handlers and render props. Name function expressions when JavaScript cannot infer their name. Use event or error instead of e.
Subpaths and names
Every public primitive needs a matching package.json#exports subpath. Import relatively between package components; consumers import only through public subpaths.
Keep package-private helpers in src/internal/; top-level runtime utility modules in src/ are public utility subpaths. Components share code through the owning component's entrypoint or an explicit internal module, not another component's implementation files.
Use the primitive name without a Root suffix for the canonical boundary and matching props type: Select and SelectProps, Drawer and DrawerProps.
Every runtime component must have an accurate, importable props type with the matching name. Use a direct alias for an unchanged Base UI part. Define Dify-authored composite props at the Dify UI boundary instead of copying upstream shapes. Derive CVA variant props with NonNullableVariantProps (src/internal/variant-props.ts) rather than raw VariantProps so public props do not leak null.
Use a discriminated union when one prop changes the valid shape of related props, such as controlled versus uncontrolled state or single versus multiple selection. Use DistributiveOmit (src/internal/distributive-omit.ts) instead of Omit when removing keys from a union so its branches stay discriminated.
Generic contracts
Preserve generic relationships end to end, including picker Value and Multiple, form values, radio and slider values, and overlay payloads or handles. Do not erase caller-owned types with any or a hard-coded string. Use unknown only as the safe default for independently consumed anatomy whose value JSX cannot infer from its parent.
Do not add a root-only generic when separately rendered anatomy can produce values outside the root's inferred type. Preserve the upstream contract until the whole component family can enforce one value type. Tabs intentionally follows Base UI's non-generic root because its current tab value type is any | null; do not advertise a type relationship the complete anatomy cannot enforce.
Preserve upstream anatomy when its parts own distinct semantics, interaction, or positioning. Create a Dify-authored convenience component only when the package adds a shared contract; do not hide primitive parts merely to shorten a consumer call site.
Keep the public surface small
A type is not public merely because Base UI names it or an implementation once exported it. In addition to matching component props, export a type only when it pairs with a public factory or a real consumer must name it independently.
State, controlled-state helpers, context values, render helpers, styling helpers, and upstream passthrough aliases are private by default. Public props already provide contextual typing for inline render and event callbacks. Expose styling helpers only when consumers need to reuse appearance independently.
Event details and reasons are the exception. A component that aliases or wraps a Base UI part re-exports that part's *EventDetails and *EventReason types under its own name. A composite that only uses a part internally does not. State and enum namespaces stay private.
Preserve upstream className and style callbacks. Resolve className with the owning Base UI part's state before merging default classes with cn(), including through composite wrappers. Forward style unchanged unless the wrapper needs to merge styles; then resolve its callback first. Do not add state callbacks to native DOM props or unrelated custom APIs. See Styling.
JSDoc
Document every prop the package declares, or whose upstream default it changes, with a short statement and an @default that matches the runtime value. Keep upstream documentation for passthrough props by deriving their types with Pick or a direct alias instead of copying text. Write only what stays true while the API is unchanged.
Documentation pages
Place each page at content/<section>/<slug>/index.mdx. Set its title and description in frontmatter and list its slug in the section’s meta.json in sidebar order. The root content/meta.json determines section order. Use absolute site paths for links.
Documentation demos
Give every visible text-entry control a placeholder that hints at the expected format or offers a Dify-specific example, even when it starts with a value; never repeat or stand in for the label. Start free-text examples with "e.g."; show formatted values such as URLs and email addresses as the pattern itself. The hero demo of a text-entry component shows its empty state with the placeholder visible unless an initial value is essential to what it demonstrates. Omit placeholders only for hidden inputs, controls whose disabled empty state is intentional, and number fields where a hint adds nothing.
Keep the hero demo focused on the primitive itself and the minimum context needed to operate it, so readers reach the component immediately and most of the source code shows its own anatomy. Do not wrap a standalone control in a decorative card or synthetic header bar.
Add surrounding layout or sibling controls only when removing them would leave the primitive unintelligible or untriggerable, clarify why it is chosen over a neighboring primitive, or break the API contract being demonstrated. Carry realism through domain vocabulary and data rather than extra chrome; the preview stage already provides a bordered surface, so multi-row contexts use borderless lists instead of nested cards.
Give each example a single non-redundant question and enough data or configuration to genuinely exercise that feature. Do not repeat the same behavior across two examples on one page, export one named component per demo file, and size containers fluidly (w-full max-w-*) instead of hard-coding bare widths.
Give every interactive element on the stage complete hover, active, focus-visible and disabled states using package primitives and tokens without overriding component styling contracts. Anchored popup triggers keep a visible open state with data-popup-open:, modal and transient hint triggers do not, and region triggers cover their full interactive surface without dead perimeter padding.
Keep demos uncontrolled by default and introduce state only when the example specifically demonstrates controlled ownership, shared state or payload flow. Ordinary items and buttons may remain side-effect-free instead of accumulating unrelated state, but controls must never silently discard user input or rely on #hash links that mutate the documentation URL.
Evidence
Use local public-subpath type tests to protect generic inference, required relationships, and intentional errors. Read current official Base UI documentation and installed type declarations before changing an upstream-derived contract.