Installation

Get started with matix/ui in your React project.

Quickstart with your coding agent

Paste this prompt into Claude Code, Cursor, Codex, or another coding agent. The agent creates the app if the folder is empty, installs matix and its agent skills, configures StyleX, and checks the result. To set up by hand, follow the steps below.

Set up matix/ui in this project. matix/ui is a React design system built on StyleX and Base UI: https://github.com/rauschermate/matix-ui

1. If this folder is empty, create the app: `bunx create-next-app@latest . --yes --ts --empty --no-tailwind --use-bun`
2. Install matix: `bun add @matix/components @matix/tokens @matix/core @stylexjs/stylex @base-ui/react`
3. Install the matix skills: `bunx skills add rauschermate/matix-ui --skill matix matix-migrate -y`
   If that fails, read them from https://github.com/rauschermate/matix-ui/tree/master/skills
4. Follow the `matix` skill. It adds the StyleX compiler, checks the result, and covers a migration from another UI library.

1. Install dependencies

bun add @matix/components @matix/tokens @stylexjs/stylex @base-ui/react

matix/ui has peer dependencies on @stylexjs/stylex and @base-ui/react. You also need React 18+ and React DOM. @matix/tokens holds the design tokens that your own styles import.

2. Import CSS

The packages ship compiled JavaScript and precompiled CSS. Import the CSS once, in your root layout or entry file. It holds the token variables and every class the components use. Without it, the components render unstyled, with no error.

// app/layout.tsx
import '@matix/components/globals.css';

When using @matix/charts, import its compiled stylesheet too.

// Add this too when using @matix/charts
import '@matix/charts/globals.css';

3. Use components

Import components from their individual entry points for optimal tree-shaking.

import { Button } from '@matix/components/button';

export function MyComponent() {
  return (
    <Button variant="solid" size="md">
      Click me
    </Button>
  );
}

4. Set up StyleX for your own styles

The components need no compiler. Your own styles do: stylex.create, stylex.createTheme, and the styles you pass to sx. For Next.js (webpack or Turbopack), install the compiler packages:

bun add -d @stylexjs/babel-plugin@~0.19 @stylexjs/postcss-plugin@~0.19 postcss autoprefixer

Then add these files. Keep dev: false: dev: true turns on debug keys that do not match the precompiled matix keys, so sx overrides fail in next dev. Both config files pass eslint-config-next. Keep the Babel config as babel.config.js: the Next.js Babel loader rejects .mjs and .cjs names.

// babel.config.js
module.exports = {
  presets: ['next/babel'],
  plugins: [
    [
      '@stylexjs/babel-plugin',
      {
        // dev: true turns on debug keys, which do not match the precompiled
        // matix keys, so sx overrides fail in next dev.
        dev: false,
        runtimeInjection: false,
        enableInlinedConditionalMerge: true,
        treeshakeCompensation: true,
        aliases: { '@/*': [`${__dirname}/src/*`] },
        unstable_moduleResolution: { type: 'commonJS', rootDir: __dirname },
      },
    ],
  ],
};
// postcss.config.mjs
import babelConfig from './babel.config.js';

const config = {
  plugins: {
    '@stylexjs/postcss-plugin': {
      include: [
        'src/**/*.{js,jsx,ts,tsx}',
        'app/**/*.{js,jsx,ts,tsx}',
        'pages/**/*.{js,jsx,ts,tsx}',
        'components/**/*.{js,jsx,ts,tsx}',
      ],
      babelConfig: {
        babelrc: false,
        parserOpts: { plugins: ['typescript', 'jsx'] },
        plugins: babelConfig.plugins,
      },
      // The precompiled matix CSS is unlayered; keep the app rules unlayered too.
      useCSSLayers: false,
    },
    autoprefixer: {},
  },
};

export default config;
/* app/globals.css */
@stylex;

If next.config.ts sends CSS through the @tailwindcss/turbopack loader (the shadcn template does), that loader removes @stylex;. Put @stylex; in its own stylex.css file, and add condition: { all: [{ not: "foreign" }, { not: { path: /stylex\.css$/ } }] } to the Tailwind rule.

5. Set the page font and colors

Components inherit the font from the page. Without a body style, the page uses the browser serif font and an 8px margin. Style the body with the tokens, so the page follows the theme and dark mode.

// app/layout.tsx
import * as stylex from '@stylexjs/stylex';
import { colors } from '@matix/tokens/colors.stylex';
import { fontFamily, fontSize, lineHeight } from '@matix/tokens/typography.stylex';
import '@matix/components/globals.css';
import './globals.css';

const styles = stylex.create({
  body: {
    margin: 0,
    fontFamily: fontFamily.sans,
    fontSize: fontSize.base,
    lineHeight: lineHeight.normal,
    color: colors.fgBase,
    backgroundColor: colors.bgBase,
  },
});

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body {...stylex.props(styles.body)}>{children}</body>
    </html>
  );
}

Per-component imports

Always use per-component imports for the best tree-shaking. The barrel export is available for convenience but ships more code.

RecommendedBarrel (larger bundle)
import { Button } from '@matix/components/button'import { Button } from '@matix/components'
import { Dialog } from '@matix/components/dialog'import { Dialog } from '@matix/components'

Copy the source instead

To own and change the component code, copy the source into your project with the CLI, as with shadcn/ui. The CLI installs the npm packages, so skip steps 1 and 2.

npx matix init
npx matix add button dialog

Your app compiles the copied source. Set up StyleX as in step 4, without the aliases option: the copied files import each other through relative paths. Then import the components from your project, for example ./components/ui/button. If you copy a chart and your project has no @types/node, add it as a dev dependency. The charts read process.env.NODE_ENV. For the commands and the light and dark setup, read the CLI README.

Requirements

DependencyVersion
React>=18.2.0 <20.0.0
React DOM>=18.2.0 <20.0.0
@stylexjs/stylex>=0.19.0 <0.20.0
@base-ui/react>=1.9.0 <2.0.0