diff --git a/apps/website/content/docs/grid/api-reference.mdx b/apps/website/content/docs/grid/api-reference.mdx index ce900dc05..68952cb04 100644 --- a/apps/website/content/docs/grid/api-reference.mdx +++ b/apps/website/content/docs/grid/api-reference.mdx @@ -140,6 +140,10 @@ interface SerializeRangesArgs { - `Pretable` — concise declarative preset. - `usePretable` — surface internals for advanced custom rendering. - `PretableBadge`, `PretableDelta`, `PretableEntity`, `PretableStatus` — shared cell presentations. +- `PretableButton`, `PretableIconButton`, `PretableSelect`, `PretableTextInput`, `PretableTextarea`, `PretableCheckbox` — [shared controls](/docs/grid/components#the-components), with corresponding `Props` and `Component` types. +- `PretableComponents` — the [replacement map](/docs/grid/components#replacing-a-component) accepted by the surface's `components` prop. +- `PretableSite` / `PretableBuiltInSite` — control placement names for styling and replacement logic. +- `PretableOverlayProvider` / `PretableOverlayProviderProps` — [popup portal scope](/docs/grid/components#overlay-scope) for application-owned hosts and local themes. - `getDensityHeights` — public density-aware sizing for custom renderers. - `serializeRanges` / `defaultCoerceForCopy` — clipboard primitives. - `numberFormats.money` / `numberFormats.accounting` — native numeric option helpers. diff --git a/apps/website/content/docs/grid/components.mdx b/apps/website/content/docs/grid/components.mdx index 0b32e5cf1..40122764f 100644 --- a/apps/website/content/docs/grid/components.mdx +++ b/apps/website/content/docs/grid/components.mdx @@ -1,102 +1,136 @@ --- title: Components -description: "The kit the grid renders its own chrome from — Button, IconButton, Select, TextInput, Textarea and Checkbox — how to style them, and how to replace them." +description: "Style the grid's controls, replace them with your own components, and keep editor and popup behavior intact." nav: Grid --- -`@pretable/react` renders its own controls from a small component kit, and -ships those components for you to use and to replace. This page covers the -six that ship today: `PretableButton`, `PretableIconButton`, -`PretableSelect`, `PretableTextInput`, `PretableTextarea` and `PretableCheckbox`. Here is a grid -whose kit buttons use the app's own component: +Use your design system's controls throughout the grid, including its editors +and popup menus. Choose the customization level that matches your task: + +| You want to… | Use | +| ----------------------------------------------------- | --------------------------------------------------------------------------- | +| Change colors, spacing, or borders | [Theme tokens](/docs/theming/override-tokens) and [CSS selectors](#styling) | +| Replace a control while keeping the grid's behavior | The [`components` prop](#replacing-a-component) | +| Build a different editor, such as a date-range picker | Column [`renderEditor`](/docs/grid/editing#custom-editors) | + +The kit is exported from `@pretable/react`. For the default appearance, load +the `@pretable/ui` skin as described in [Getting started](/docs). + +## Replacing a component + +Pass a replacement to `` or ``. Each slot applies +wherever that kit control appears, including inside portals. Omitted slots +keep their built-in components. + +```tsx +import { forwardRef } from "react"; +import { PretableSurface, type PretableTextInputProps } from "@pretable/react"; + +// Define the component outside the grid's render function. +const AppInput = forwardRef( + function AppInput({ site, className, ...props }, ref) { + return ( + + ); + }, +); + + row.id} + components={{ TextInput: AppInput }} +/>; +``` + +Forward the supplied **native props, handlers, ARIA/data attributes, and ref** +to the actual control. Preserve `className` and `style` when adding your own +styling. The grid uses the ref for editor autofocus, textarea sizing, popup +anchoring, and focus restoration. React 18 requires `forwardRef`; React 19 +also supports a plain `ref` prop. + +Keep each replacement's component identity stable: define it at module scope, +not inside the rendering component. An inline `components={{ TextInput: AppInput }}` +map is fine; defining a new `AppInput` function on each render remounts the field +and can lose focus or the caret. + +`site` identifies where a control is used. Fields use `cell-editor`; editor +actions use `number-increment`, `number-decrement`, `date-previous-month`, and +`date-next-month`. Branch on `site` when one placement needs different styling. +`PretableBuiltInSite` lists the built-in names and may gain new names in minor +releases; `PretableSite` also accepts application-defined strings. + +The slots cover kit controls. Structural column headers, tabs, tree expanders, +menu items, and segmented filter joins keep their specialized behavior. + +### Use your own editor controls + +These replacements keep the built-in parsing, keyboard handling, save state, +and errors. Open **Quantity** to use the replacement input and stepper buttons, +or **Notes** to use the replacement textarea. The Code tab contains the complete +controlled grid and native replacements. + + + +### Replace a button + +This example replaces `Button` across the tool panel and filter dialog, using +`site` to give Reset columns a different appearance. ## The components -Four of the six render `