The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Update Twenty UI front component documentation (#28518)
Raphaël Bosi0ed0bd08b106
diff --git a/packages/twenty-agent-skills/references/design/front-component-ui.md b/packages/twenty-agent-skills/references/design/front-component-ui.mdindex 9e7f92f7372..6f87cd2e296 100644--- a/packages/twenty-agent-skills/references/design/front-component-ui.md+++ b/packages/twenty-agent-skills/references/design/front-component-ui.md@@ -76,7 +76,7 @@ const ActivitySummary = ({ onRefresh }: { onRefresh: () => void }) => {};```-Every `themeCssVariables` value is a CSS reference string. Do not perform arithmetic on it. Use numeric tokens from `useTheme()` when a component prop expects a number, such as an icon's `size`.+Every `themeCssVariables` value is a CSS reference string. In front components, `useTheme()` also returns CSS references by default, including for tokens typed as numbers. Use these references in CSS styles, without arithmetic. Use an explicit numeric value when a component prop requires a number, such as an icon's `size`.Prefer component `size`, `variant`, and color props before overriding their styles. Keep custom spacing, radii, borders, and typography consistent with nearby Twenty UI controls. Avoid adding a heavy card frame or shadow when the host already provides the surface.diff --git a/packages/twenty-agent-skills/references/develop-app/front-components.md b/packages/twenty-agent-skills/references/develop-app/front-components.mdindex 74f2da48b2b..669e82ea528 100644--- a/packages/twenty-agent-skills/references/develop-app/front-components.md+++ b/packages/twenty-agent-skills/references/develop-app/front-components.md@@ -45,7 +45,7 @@ Keep imports narrow:Keep the SDK packages and `twenty-ui` in `devDependencies`. Import shared components from their family entry point, such as `twenty-ui/components/input` for `MainButton` and `LightButton`, `twenty-ui/components/feedback` for `Callout`, `twenty-ui/components/layout` for `Section`, and `twenty-ui/components/navigation` for `Dropdown`. Use `twenty-ui/primitives/input` for foundational controls such as `Button`, `Field` and `Input`.-The front component renderer provides the styles and a Twenty `ThemeProvider` around the remote root. In the app, inherit the workspace color scheme without adding another root provider, forcing light or dark mode, or importing the standalone stylesheets. For isolated examples or local story-style verification, wrapping the component in `ThemeProvider` from `twenty-ui/theme` is also acceptable.+Twenty loads the UI stylesheets and applies the workspace color scheme on the host. In the app, inherit the workspace color scheme without adding another root provider, forcing light or dark mode, or importing the standalone stylesheets. For isolated examples or local story-style verification, wrapping the component in `ThemeProvider` from `twenty-ui/theme` is also acceptable.The canonical Twenty UI front component example is `packages/twenty-front-component-renderer/src/__stories__/showcase/twenty-ui-example.front-component.tsx`. It imports `Button` from `twenty-ui/primitives/input`; `Chip`, `Status`, and `Tag` from `twenty-ui/primitives/data-display`; `Section` from `twenty-ui/components/layout`; and `ThemeProvider` from `twenty-ui/theme`. Its explicit provider is for the isolated showcase.@@ -53,7 +53,7 @@ Read theme tokens with the `useTheme()` hook from `twenty-ui/theme` inside the cPrefer Twenty UI icons from `twenty-ui/icon` when one exists. Use inline SVG only for app-specific marks or icons that are not available from `twenty-ui/icon`.-Import individual icons, not `IconsProvider` or `useIcons`, which bundle the dynamic icon catalog. Use `themeCssVariables` only for CSS values inside render-time code; its values are CSS reference strings, so do not perform arithmetic on them. Use `useTheme()` when a prop needs a resolved value.+Import individual icons, not `IconsProvider` or `useIcons`, which bundle the dynamic icon catalog. Use `themeCssVariables` only for CSS values inside render-time code. In front components, `useTheme()` also returns CSS reference strings by default, including for tokens typed as numbers. Do not perform arithmetic on those references or pass them to APIs requiring resolved numbers.## Host UI And Runtime Constraintsdiff --git a/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx b/packages/twenty-docs/developers/extend/apps/layout/front-components.mdxindex b4744514928..44a910fd91a 100644--- a/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx+++ b/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx@@ -922,7 +922,7 @@ Front components support multiple styling approaches. You can use:## Using Twenty UI components-Twenty ships its component library as the [`twenty-ui`](https://www.npmjs.com/package/twenty-ui) package. Front components can use it for buttons, tags, status pills, chips, avatars, icons, typography, and theme tokens that automatically match the workspace's light and dark theme.+Twenty ships its component library as the [`twenty-ui`](https://www.npmjs.com/package/twenty-ui) package. Prefer its controls and theme tokens to give front components the same appearance and interactions as the rest of Twenty. Browse the [shared components](/ui/components/overview) and [primitives](/ui/primitives/overview) for examples, props, and composition APIs.<Warning>`twenty-ui` is still in alpha. Its version number follows the Twenty SDK@@ -931,49 +931,72 @@ Twenty ships its component library as the [`twenty-ui`](https://www.npmjs.com/pa### Installation-`twenty-ui` is published alongside the SDK packages with the same version. Add it to your app, pinned to the version of `twenty-sdk` and `twenty-client-sdk` you use:+New apps scaffolded with `create-twenty-app` already include `twenty-ui`. For an existing app, add it as a development dependency, pinned to the same version as `twenty-sdk` and `twenty-client-sdk`. For example, if your SDK packages use `2.51.0`:```bash-yarn add -D [email protected]+yarn add -D [email protected]```-`twenty-ui` is bundled into your front component at build time, so it only needs to be a dependency of your app — there is nothing to configure at runtime.+`twenty-ui` is bundled at build time, either into each front component or into your app's [shared dependencies bundle](#sharing-dependencies-across-front-components). Twenty loads the component and theme stylesheets and applies the workspace's active color scheme. You do not need to import `twenty-ui/style.css`, the theme stylesheets, or add a root `ThemeProvider` as you would in a standalone React application.### Importing components-Import from the matching subpath rather than the package root, so only the components you use end up in your bundle:--Foundational controls are grouped under `twenty-ui/primitives/<family>`.-Shared design presets and app building blocks are available from `twenty-ui/components`.-These entry points do not require `monaco-editor`.--| Subpath | What it exports |-| ------------------------------------ | -------------------------------------------------------------------------- |-| `twenty-ui/components` | Shared presets, pickers, menu rows, dropdowns, toasts, and the JSON viewer |-| `twenty-ui/primitives/accessibility` | Hidden elements |-| `twenty-ui/primitives/data-display` | Avatars, chips, tags, color samples, and status indicators |-| `twenty-ui/primitives/feedback` | Banners, progress bars, and loaders |-| `twenty-ui/primitives/input` | Buttons and form controls |-| `twenty-ui/primitives/layout` | Expansion, separators, direction, and resizing |-| `twenty-ui/primitives/navigation` | Action links, list items, and tabs |-| `twenty-ui/primitives/surfaces` | Cards, menus, nonmodal popovers, and tooltips |-| `twenty-ui/primitives/typography` | Text and headings |-| `twenty-ui/icon` | `Icon*` components (e.g. `IconCheck`) |-| `twenty-ui/theme` | `ThemeProvider`, `themeCssVariables` |--Use [`Dropdown`](/ui/components/navigation/dropdown) for action menus, option pickers, and form panels.+Import from the matching public family subpath to keep dependencies focused:++Foundational controls are grouped under `twenty-ui/primitives/<family>`. Shared design presets and app building blocks are grouped under `twenty-ui/components/<family>`. The aggregate `twenty-ui/components` entry point remains available, but family imports make it easier to [share only the dependencies you use](#sharing-dependencies-across-front-components).++| Subpath | What it exports |+| ------------------------------------ | ----------------------------------------------------------------------------- |+| `twenty-ui/components/input` | Main and light buttons, search and image inputs, and country/currency pickers |+| `twenty-ui/components/data-display` | Avatar groups, JSON trees, metrics, command blocks, and icon tiles |+| `twenty-ui/components/feedback` | Callouts, inline banners, and notifications |+| `twenty-ui/components/layout` | Sections, overflowing lists, and icon transitions |+| `twenty-ui/components/navigation` | Dropdowns, menu compositions, and tab actions |+| `twenty-ui/components/settings` | Settings rows |+| `twenty-ui/primitives/accessibility` | Hidden elements |+| `twenty-ui/primitives/data-display` | Avatars, chips, tags, color samples, and status indicators |+| `twenty-ui/primitives/feedback` | Banners, progress bars, and loaders |+| `twenty-ui/primitives/input` | Buttons and form controls |+| `twenty-ui/primitives/layout` | Expansion, separators, direction, and resizing |+| `twenty-ui/primitives/navigation` | Breadcrumbs, list items, and tabs |+| `twenty-ui/primitives/surfaces` | Cards, nonmodal popovers, and tooltips |+| `twenty-ui/primitives/typography` | Text and headings |+| `twenty-ui/icon` | `Icon*` components (e.g. `IconCheck`) |+| `twenty-ui/theme` | `useTheme`, `themeCssVariables`, and `ThemeProvider` |++Use [`MainButton`](/ui/components/input/main-button) for prominent actions and [`LightButton`](/ui/components/input/light-button) for lightweight actions. Use `Button`, `Field`, `Input`, `Select`, and other primitives from `twenty-ui/primitives/input` for foundational controls and forms. Follow each compound control's documented parts, such as `Field.Root`, `Field.Label`, and `Field.Description`.++Use [`Dropdown`](/ui/components/navigation/dropdown) from `twenty-ui/components/navigation` for action menus, option pickers, and nonmodal form panels. Use `enqueueSnackbar` from `twenty-sdk/front-component` for host notifications.The standalone `Dialog` and `AlertDialog` APIs are also exported by Twenty UI, but direct use in front components is prohibited. Use the [host communication API](#host-communication-api) for dialogs.+These entry points do not require Monaco. The separate `twenty-ui/components/code-editor` entry point depends on Monaco, whose script loader is unsupported in the front component sandbox, so `CodeEditor` cannot become interactive there.+```tsximport { defineFrontComponent } from 'twenty-sdk/define';-import { Button } from 'twenty-ui/primitives/input';+import { enqueueSnackbar } from 'twenty-sdk/front-component';+import { MainButton } from 'twenty-ui/components/input';import { Status, Tag } from 'twenty-ui/primitives/data-display';+import { useTheme } from 'twenty-ui/theme';const StyledWidget = () => {+ const theme = useTheme();++ const handleClick = async () => {+ await enqueueSnackbar({ message: 'Clicked!', variant: 'success' });+ };+return (- <div style={{ padding: '16px', display: 'flex', gap: '8px' }}>- <Button onClick={() => alert('Clicked!')}>Click me</Button>+ <div+ style={{+ padding: theme.spacing[4],+ display: 'flex',+ alignItems: 'center',+ flexWrap: 'wrap',+ gap: theme.spacing[2],+ }}+ >+ <MainButton onClick={handleClick}>Click me</MainButton><Tag color="green">Active</Tag><Status color="green">Online</Status></div>@@ -999,9 +1022,9 @@ Each named icon is tree-shaken, so importing a handful adds little to your bundl### Theming and theme tokens-Twenty UI components automatically match the workspace's light and dark theme — the renderer applies the active color scheme on the host, and the components resolve their colors against it.+Twenty UI components automatically match the workspace's light and dark theme. The renderer applies the active color scheme on the host, and the components resolve their CSS variables against it.-To use the same design tokens in your own inline styles, call the `useTheme()` hook. It returns Twenty's theme tokens (spacing, colors, radii, fonts) wired to the active theme, with no `ThemeProvider` setup needed in your component:+To use the same design tokens in your own inline styles, call `useTheme()` inside the component body. In front components it returns CSS variable references by default, so styles follow the host's active theme without a local `ThemeProvider`:```tsximport { useTheme } from 'twenty-ui/theme';@@ -1023,7 +1046,9 @@ const Card = () => {};```-Because `useTheme()` is a hook, you read tokens inside the component body, so the values always reflect the live theme. The same token map is also exported as the `themeCssVariables` constant, but prefer `useTheme()` in front components — a module-level constant that dereferences `themeCssVariables` can be undefined while the app manifest is extracted.+The same CSS references are exported as `themeCssVariables` from `twenty-ui/theme`. Read them inside the component body: the CLI mocks `twenty-ui` during manifest extraction, so dereferencing imported theme constants at module scope can fail the build.++CSS reference strings are not resolved JavaScript numbers, even for tokens such as `theme.icon.size.md`. Do not perform arithmetic on them or pass them to APIs that require numbers. See [Theming](/ui/theming) and [Tokens](/ui/tokens) for semantic paths and CSS variable names.To branch on the active scheme explicitly, read it with `useColorScheme()` from `twenty-sdk/front-component`, which returns `'light'` or `'dark'`.diff --git a/packages/twenty-docs/developers/extend/apps/tutorials/document-generator/building-the-ui.mdx b/packages/twenty-docs/developers/extend/apps/tutorials/document-generator/building-the-ui.mdxindex abc547cdc7c..9094924016e 100644--- a/packages/twenty-docs/developers/extend/apps/tutorials/document-generator/building-the-ui.mdx+++ b/packages/twenty-docs/developers/extend/apps/tutorials/document-generator/building-the-ui.mdx@@ -114,10 +114,13 @@ export default defineFrontComponent({```<Warning>-Style with inline CSS variables (`var(--t-color-blue)`), not values imported from-`twenty-ui`. The SDK mocks that package during build, so module-level imports of-theme constants would be `undefined`. See the-[full component](https://github.com/twentyhq/twenty/blob/main/packages/twenty-apps/examples/document-generator/src/front-components/generate-document-form.front-component.tsx).+ Read `useTheme()` or `themeCssVariables` from `twenty-ui/theme` inside the+ component body when styling with Twenty's tokens. The CLI mocks `twenty-ui`+ during manifest extraction, so dereferencing imported theme constants at+ module scope can fail the build. See [Theming and theme+ tokens](/developers/extend/apps/layout/front-components#theming-and-theme-tokens)+ and the [full+ component](https://github.com/twentyhq/twenty/blob/main/packages/twenty-apps/examples/document-generator/src/front-components/generate-document-form.front-component.tsx).</Warning>## A command to open it