# Consuming `@aisquare/ui` in an app

Run `doctor` to check all of this at once.

## Setup

```bash
pnpm add @aisquare/ui
```

**1. Tailwind preset + content glob.** Both, or components render unstyled.

```ts
// tailwind.config.ts
import aisquare from "@aisquare/ui/tailwind.preset";

export default {
  presets: [aisquare],
  content: [
    "./src/**/*.{ts,tsx}",
    "./node_modules/@aisquare/ui/dist/**/*.{js,mjs}", // scan the lib's own class strings
  ],
};
```

The preset provides the brand tokens plus the Onyx utilities (`nx-*`, `elev-*`, `nx-rim`,
`key`/`raise`) and the elevation/glass custom properties. The content glob is what makes Tailwind
actually emit the classes the library's source references.

**2. Token CSS at the app root.**

```css
@import "@aisquare/ui/tokens/tokens.template.css";
@import "@aisquare/ui/tokens/fonts.css";
@import "@aisquare/ui/tokens/shadcn-extras.css"; /* only if you use Sidebar or Chart */
```

Skip `tokens.template.css` only if the app already defines the same HSL triplets itself.

**3. `--success` and `--warning` must exist in `:root`.** If the app owns its tokens rather than
importing the template, these two are the ones most often forgotten, and status and success
components then render with no color.

**4. Optional: `@aisquare/ui/onyx-hex.css`** — the CSS-only path to the Onyx material, for apps
that cannot add the preset.

## Diagnosing

| Symptom | Cause |
|---|---|
| Everything renders unstyled | Preset not registered, **or** the content glob misses `node_modules/@aisquare/ui`. These look identical. |
| Status / success components have no color | `--success` / `--warning` undefined. |
| Cards and panels look flat, no lift | Elevation tokens missing — preset or `onyx-hex.css` not loaded. |
| A border is sliced at the notch | A real `border` on a notched surface. Use `nx-rim`. |
| Glass panel is a flat fill | `--glass*` tokens missing, or an `isolation: isolate` ancestor walling off `backdrop-filter`. |
| Notched surface renders as a plain square | Browser without `clip-path: shape()`. The `@supports` fallback degrades to a rounded rect by design. |
| One component is unstyled, the rest are fine | An arbitrary bracket class in the library's source that your content glob does not cover. Fix it upstream (rule TOK-2). |

## Import rules

```tsx
import { Button, Dialog, cn, nx, elev, springs } from "@aisquare/ui";
import { Button as StockButton } from "@aisquare/ui/stock";  // only for upstream parity
```

- Never deep-import `@aisquare/ui/dist/...` or `.../src/...`.
- Never import Radix, `clsx`, `cva`, or `tailwind-merge` directly in app code. The library wraps
  them, and `cn` (clsx + tailwind-merge) is what lets a caller's `className` override a component
  default — bare `clsx` keeps both classes and lets source order decide.
- Subpaths: `/stock` (unbranded shadcn), `/chat` (transcript leaves, motion-free so they load
  under jsdom), `/icons`, `/tailwind.preset`.

## What an app may and may not do

**May:** pass `className` for **layout** — grid placement, margin, width, flex.

**May not:**

- restyle a component's identity from the app (colors, borders, radii, shadows, fonts)
- override library selectors or `data-slot` attributes in global CSS, or use `!important`
- copy library source into the app, or `patch-package` it
- add a second component library

If a component cannot do what you need, add a prop or a variant **upstream** and bump the
version. That is one PR, and it fixes it for every consumer instead of one.
